aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/util/Queue.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/webpack/lib/util/Queue.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/webpack/lib/util/Queue.js')
-rw-r--r--node_modules/webpack/lib/util/Queue.js88
1 files changed, 46 insertions, 42 deletions
diff --git a/node_modules/webpack/lib/util/Queue.js b/node_modules/webpack/lib/util/Queue.js
index ef3ffdc80..6615e9f77 100644
--- a/node_modules/webpack/lib/util/Queue.js
+++ b/node_modules/webpack/lib/util/Queue.js
@@ -1,42 +1,46 @@
-"use strict";
-
-module.exports = class Queue {
- constructor(items) {
- this.first = null;
- this.last = null;
- this.length = 0;
- if(items) {
- for(const item of items) {
- this.enqueue(item);
- }
- }
- }
-
- enqueue(item) {
- const first = this.first;
- const node = {
- item,
- next: null
- };
- if(first === null) {
- this.last = node;
- } else {
- first.next = node;
- }
- this.first = node;
- this.length++;
- }
-
- dequeue() {
- const last = this.last;
- if(last === null)
- return undefined;
- const next = last.next;
- if(next === null) {
- this.first = null;
- }
- this.last = next;
- this.length--;
- return last.item;
- }
-};
+"use strict";
+
+/**
+ * @template T
+ */
+class Queue {
+ /**
+ * @param {Iterable<T>=} items The initial elements.
+ */
+ constructor(items) {
+ /** @private @type {Set<T>} */
+ this.set = new Set(items);
+ /** @private @type {Iterator<T>} */
+ this.iterator = this.set[Symbol.iterator]();
+ }
+
+ /**
+ * Returns the number of elements in this queue.
+ * @returns {number} The number of elements in this queue.
+ */
+ get length() {
+ return this.set.size;
+ }
+
+ /**
+ * Appends the specified element to this queue.
+ * @param {T} item The element to add.
+ * @returns {void}
+ */
+ enqueue(item) {
+ this.set.add(item);
+ }
+
+ /**
+ * Retrieves and removes the head of this queue.
+ * @returns {T | undefined} The head of the queue of `undefined` if this queue is empty.
+ */
+ dequeue() {
+ const result = this.iterator.next();
+ if (result.done) return undefined;
+ this.set.delete(result.value);
+ return result.value;
+ }
+}
+
+module.exports = Queue;