Sha256: e3e334c6fd29f9b082e155e12569b0c5bba85b02c6ae0704ce81cac17c55bedd

Contents?: true

Size: 940 Bytes

Versions: 27

Compression:

Stored size: 940 Bytes

Contents

"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;

Version data entries

27 entries across 26 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/webpack/lib/util/Queue.js
disco_app-0.18.0 test/dummy/node_modules/webpack/lib/util/Queue.js
disco_app-0.18.2 test/dummy/node_modules/webpack/lib/util/Queue.js
disco_app-0.16.1 test/dummy/node_modules/webpack/lib/util/Queue.js
disco_app-0.15.2 test/dummy/node_modules/webpack/lib/util/Queue.js
disco_app-0.18.4 test/dummy/node_modules/webpack/lib/util/Queue.js
disco_app-0.18.1 test/dummy/node_modules/webpack/lib/util/Queue.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/webpack/lib/util/Queue.js
disco_app-0.14.0 test/dummy/node_modules/webpack/lib/util/Queue.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/webpack/lib/util/Queue.js
tang-0.2.1 spec/tang_app/node_modules/webpack/lib/util/Queue.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/webpack/lib/util/Queue.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/webpack/lib/util/Queue.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/webpack/lib/util/Queue.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/webpack/lib/util/Queue.js
tang-0.2.0 spec/tang_app/node_modules/webpack/lib/util/Queue.js
tang-0.1.0 spec/tang_app/node_modules/webpack/lib/util/Queue.js
tang-0.0.9 spec/tang_app/node_modules/webpack/lib/util/Queue.js
enju_library-0.3.8 spec/dummy/node_modules/webpack/lib/util/Queue.js
jester-data-8.0.0 node_modules/webpack/lib/util/Queue.js