@tsdotnet/queue 1.3.1 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +11 -12
  3. package/dist/{LinkQueue.d.ts → cjs/LinkQueue.d.ts} +1 -16
  4. package/dist/cjs/LinkQueue.js +2 -17
  5. package/dist/cjs/LinkQueue.js.map +1 -1
  6. package/dist/{Queue.d.ts → cjs/Queue.d.ts} +1 -13
  7. package/dist/cjs/Queue.js +6 -26
  8. package/dist/cjs/Queue.js.map +1 -1
  9. package/dist/cjs/QueueBase.d.ts +27 -0
  10. package/dist/cjs/QueueBase.js +0 -53
  11. package/dist/cjs/QueueBase.js.map +1 -1
  12. package/dist/cjs/index.d.ts +5 -0
  13. package/dist/cjs/index.js +12 -0
  14. package/dist/cjs/index.js.map +1 -0
  15. package/dist/cjs/package.json +1 -0
  16. package/dist/esm/LinkQueue.js +6 -18
  17. package/dist/esm/LinkQueue.js.map +1 -1
  18. package/dist/esm/Queue.js +10 -27
  19. package/dist/esm/Queue.js.map +1 -1
  20. package/dist/esm/QueueBase.js +7 -57
  21. package/dist/esm/QueueBase.js.map +1 -1
  22. package/dist/esm/index.js +8 -0
  23. package/dist/esm/index.js.map +1 -0
  24. package/dist/types/LinkQueue.d.ts +19 -0
  25. package/dist/types/Queue.d.ts +19 -0
  26. package/dist/types/QueueBase.d.ts +27 -0
  27. package/dist/types/index.d.ts +5 -0
  28. package/dist/umd/package.json +1 -0
  29. package/dist/umd/queue.js +313 -0
  30. package/dist/umd/queue.js.map +1 -0
  31. package/dist/umd/queue.min.js +10 -0
  32. package/dist/umd/queue.min.js.map +1 -0
  33. package/package.json +69 -65
  34. package/dist/QueueBase.d.ts +0 -106
  35. package/dist/umd/LinkQueue.js +0 -117
  36. package/dist/umd/LinkQueue.js.map +0 -1
  37. package/dist/umd/Queue.js +0 -175
  38. package/dist/umd/Queue.js.map +0 -1
  39. package/dist/umd/QueueBase.js +0 -139
  40. package/dist/umd/QueueBase.js.map +0 -1
  41. package/eslint.config.mjs +0 -23
package/package.json CHANGED
@@ -1,22 +1,44 @@
1
1
  {
2
2
  "name": "@tsdotnet/queue",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "A simple and fast FIFO collection for enqueuing and dequeuing items.",
5
5
  "author": "electricessence",
6
6
  "license": "MIT",
7
- "type": "commonjs",
8
- "main": "./dist/cjs/Queue.js",
9
- "module": "./dist/esm/Queue.js",
10
- "types": "./dist/Queue.d.ts",
7
+ "type": "module",
8
+ "main": "./dist/cjs/index.js",
9
+ "module": "./dist/esm/index.js",
11
10
  "exports": {
12
11
  ".": {
13
- "types": "./dist/Queue.d.ts",
14
- "require": "./dist/cjs/Queue.js",
15
- "import": "./dist/esm/Queue.js",
16
- "umd": "./dist/umd/Queue.js",
17
- "default": "./dist/cjs/Queue.js"
12
+ "module-sync": {
13
+ "types": "./dist/types/index.d.ts",
14
+ "default": "./dist/esm/index.js"
15
+ },
16
+ "module": {
17
+ "types": "./dist/types/index.d.ts",
18
+ "default": "./dist/esm/index.js"
19
+ },
20
+ "import": {
21
+ "types": "./dist/types/index.d.ts",
22
+ "default": "./dist/esm/index.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/cjs/index.d.ts",
26
+ "default": "./dist/cjs/index.js"
27
+ },
28
+ "default": {
29
+ "types": "./dist/types/index.d.ts",
30
+ "default": "./dist/esm/index.js"
31
+ }
32
+ },
33
+ "./package.json": "./package.json",
34
+ "./umd": {
35
+ "types": "./dist/cjs/index.d.ts",
36
+ "default": "./dist/umd/queue.js"
18
37
  }
19
38
  },
39
+ "types": "./dist/types/index.d.ts",
40
+ "unpkg": "./dist/umd/queue.min.js",
41
+ "jsdelivr": "./dist/umd/queue.min.js",
20
42
  "keywords": [
21
43
  "queue",
22
44
  "fifo",
@@ -25,23 +47,6 @@
25
47
  "dequeue",
26
48
  "iterable"
27
49
  ],
28
- "scripts": {
29
- "clean": "rimraf dist",
30
- "build:cjs": "tsc -p tsconfig.cjs.json",
31
- "build:esm": "tsc -p tsconfig.esm.json",
32
- "build:umd": "tsc -p tsconfig.umd.json",
33
- "build:types": "cpy \"src/**/*.d.ts\" dist --parents && tsc -p tsconfig.types.json",
34
- "build": "pnpm i && pnpm run clean && concurrently \"pnpm:build:*\"",
35
- "bump": "pnpm run precommit && pnpm version patch",
36
- "docs": "rimraf docs && typedoc --options typedoc.json --readme none",
37
- "lint": "eslint src/**/*.ts",
38
- "precommit": "pnpm i && pnpm run build && pnpm run lint && pnpm run validate && pnpm run test && git status -s",
39
- "prepublishOnly": "pnpm run build && pnpm run validate && pnpm run test",
40
- "preversion": "pnpm run lint && pnpm run test",
41
- "postversion": "git push && git push --tags && pnpm run docs && git add -A && git commit -m \"Updated docs.\" docs && git push",
42
- "test": "tsx node_modules/mocha/bin/_mocha tests/**/*.ts",
43
- "validate": "node ./.build/validate-package.js"
44
- },
45
50
  "repository": {
46
51
  "type": "git",
47
52
  "url": "git+https://github.com/tsdotnet/queue.git"
@@ -51,45 +56,44 @@
51
56
  },
52
57
  "homepage": "https://github.com/tsdotnet/queue#readme",
53
58
  "devDependencies": {
54
- "@eslint/js": "^9.33.0",
55
- "@types/chai": "^5.2.2",
56
- "@types/mocha": "^10.0.10",
57
- "@types/node": "^24.3.0",
58
- "chai": "^5.2.1",
59
- "concurrently": "^9.2.0",
60
- "cpy-cli": "^6.0.0",
61
- "eslint": "^9.33.0",
62
- "mocha": "^11.7.1",
63
- "rimraf": "^6.0.1",
64
- "tsx": "^4.20.4",
65
- "typedoc": "^0.28.10",
66
- "typescript": "^5.9.2",
67
- "typescript-eslint": "^8.39.1"
59
+ "@eslint/js": "^10.0.1",
60
+ "@rollup/plugin-terser": "^1.0.2",
61
+ "@rollup/plugin-typescript": "^12.3.1",
62
+ "@types/node": "^26.6.6",
63
+ "@vitest/coverage-v8": "^5.1.1",
64
+ "cpy-cli": "^7.0.0",
65
+ "eslint": "^10.15.0",
66
+ "rimraf": "^6.1.4",
67
+ "rollup": "^4.68.7",
68
+ "typedoc": "^0.28.20",
69
+ "typescript": "~6.0.3",
70
+ "typescript-eslint": "^8.73.0",
71
+ "typescript-native": "npm:typescript@^7.0.2",
72
+ "vite": "^8.3.8",
73
+ "vitest": "^5.1.1"
68
74
  },
69
75
  "dependencies": {
70
- "@tsdotnet/collection-base": "^2.1.0",
71
- "@tsdotnet/exceptions": "^1.2.2",
72
- "tslib": "^2.8.1"
76
+ "@tsdotnet/collection-base": "^2.2.0",
77
+ "@tsdotnet/exceptions": "^1.3.0",
78
+ "tslib": "^2.9.1"
73
79
  },
74
- "pnpm": {
75
- "overrides": {
76
- "hosted-git-info@<2.8.9": ">=2.8.9",
77
- "y18n@=4.0.0": ">=4.0.1",
78
- "lodash@<4.17.20": ">=4.17.20",
79
- "shell-quote@<=1.7.2": ">=1.7.3",
80
- "lodash@<4.17.21": ">=4.17.21",
81
- "json5@<1.0.2": ">=1.0.2",
82
- "json5@>=2.0.0 <2.2.2": ">=2.2.2",
83
- "minimatch@<3.0.5": ">=3.0.5",
84
- "semver@<5.7.2": ">=5.7.2",
85
- "semver@>=6.0.0 <6.3.1": ">=6.3.1",
86
- "semver@>=7.0.0 <7.5.2": ">=7.5.2",
87
- "get-func-name@<2.0.1": ">=2.0.1",
88
- "@babel/traverse@<7.23.2": ">=7.23.2",
89
- "braces@<3.0.3": ">=3.0.3"
90
- },
91
- "ignoredBuiltDependencies": [
92
- "esbuild"
93
- ]
80
+ "scripts": {
81
+ "clean": "rimraf dist",
82
+ "copy:dts": "cpy \"src/**/*.d.ts\" dist/types --parents || echo No .d.ts files to copy",
83
+ "copy:dts:cjs": "cpy \"src/**/*.d.ts\" dist/cjs --parents || echo No .d.ts files to copy",
84
+ "build:types": "pnpm copy:dts && node ./node_modules/typescript-native/bin/tsc -p tsconfig.types.json",
85
+ "build:esm": "rollup -c rollup.config.js",
86
+ "build:umd": "rollup -c rollup.umd.config.js",
87
+ "build:cjs": "node ./node_modules/typescript-native/bin/tsc -p tsconfig.cjs.json && pnpm copy:dts:cjs && node -e \"require('node:fs').writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' }) + '\\n')\"",
88
+ "build": "pnpm clean && pnpm build:types && pnpm build:esm && pnpm build:umd && pnpm build:cjs && pnpm typecheck:tests",
89
+ "test": "vitest run",
90
+ "typecheck": "node ./node_modules/typescript-native/bin/tsc --noEmit",
91
+ "typecheck:tests": "node ./node_modules/typescript-native/bin/tsc -p tests/tsconfig.json --noEmit",
92
+ "lint": "eslint src/**/*.ts",
93
+ "docs": "rimraf docs && typedoc --options typedoc.json --readme none",
94
+ "bump": "pnpm run precommit && pnpm version patch",
95
+ "precommit": "pnpm build && pnpm test && pnpm lint && git status -s",
96
+ "preversion": "pnpm lint && pnpm test",
97
+ "postversion": "git push && git push --tags && pnpm run docs && git add -A && git commit -m \"Updated docs.\" docs && git push"
94
98
  }
95
- }
99
+ }
@@ -1,106 +0,0 @@
1
- /*!
2
- * @author electricessence / https://github.com/electricessence/
3
- * @license MIT
4
- */
5
- import { IterableCollectionBase } from '@tsdotnet/collection-base';
6
- export default abstract class QueueBase<T> extends IterableCollectionBase<T> {
7
- /**
8
- * The number of items currently in the queue.
9
- * @returns {number}
10
- */
11
- get count(): number;
12
- /**
13
- * Returns true if the queue is empty.
14
- * @return {boolean}
15
- */
16
- get isEmpty(): boolean;
17
- /**
18
- * Adds an item to the end of the queue.
19
- * @param value
20
- * @returns {this}
21
- */
22
- enqueue(value: T): this;
23
- /**
24
- * Adds items to the end of the queue.
25
- * @param {Iterable} values
26
- * @returns {this}
27
- */
28
- enqueueMultiple(values: Iterable<T>): this;
29
- /**
30
- * Adds items to the end of the queue.
31
- * @param values
32
- * @returns {this}
33
- */
34
- enqueueThese(...values: T[]): this;
35
- /**
36
- * Produces an iterable that dequeues items when iterated. Stops when empty.
37
- * @return {Iterable}
38
- */
39
- consumer(): Iterable<T>;
40
- /**
41
- * Pulls an entry from the head of the queue and returns it.
42
- * Returns undefined if the queue is already empty.
43
- */
44
- dequeue(): T | undefined;
45
- /**
46
- * Pulls an entry from the head of the queue and returns it.
47
- * Returns undefined if the queue is already empty and throwIfEmpty is false.
48
- * @throws {InvalidOperationException} If the queue is already empty and throwIfEmpty is true.
49
- * @param throwIfEmpty
50
- */
51
- dequeue(throwIfEmpty: true): T | never;
52
- /**
53
- * Pulls an entry from the head of the queue and returns it.
54
- * Returns undefined if the queue is already empty and throwIfEmpty is false.
55
- * @throws {InvalidOperationException} If the queue is already empty and throwIfEmpty is true.
56
- * @param throwIfEmpty
57
- */
58
- dequeue(throwIfEmpty: boolean): T | undefined | never;
59
- /**
60
- * Checks to see if the queue has entries an pulls an entry from the head of the queue and passes it to the out handler.
61
- * @throws {ArgumentNullException} If no out delegate was specified.
62
- * @param out The 'out' handler that receives the value if it exists.
63
- * @returns {boolean} True if a value was retrieved. False if not.
64
- */
65
- tryDequeue(out: (dequeued: T) => void): boolean;
66
- /**
67
- * Returns the entry at the head of the queue.
68
- * Returns undefined if the queue is already empty.
69
- */
70
- peek(): T | undefined;
71
- /**
72
- * Returns the entry at the head of the queue.
73
- * Returns undefined if the queue is already empty and throwIfEmpty is false.
74
- * @throws {InvalidOperationException} If the queue is already empty and throwIfEmpty is true.
75
- * @param throwIfEmpty
76
- */
77
- peek(throwIfEmpty: true): T | never;
78
- /**
79
- * Returns the entry at the head of the queue.
80
- * Returns undefined if the queue is already empty and throwIfEmpty is false.
81
- * @throws {InvalidOperationException} If the queue is already empty and throwIfEmpty is true.
82
- * @param throwIfEmpty
83
- */
84
- peek(throwIfEmpty: boolean): T | undefined | never;
85
- /**
86
- * Dequeues entries into an array.
87
- * @param {number} max
88
- * @return {T[]}
89
- */
90
- abstract dump(max?: number): T[];
91
- /**
92
- * Clears the list.
93
- */
94
- abstract clear(): number;
95
- /**
96
- * Clears the list.
97
- */
98
- dispose(): void;
99
- /**
100
- * Clears the list.
101
- */
102
- recycle(): void;
103
- protected abstract _dequeueInternal(): T | undefined;
104
- protected abstract _peekInternal(): T | undefined;
105
- protected abstract _enqueueInternal(value: T): void;
106
- }
@@ -1,117 +0,0 @@
1
- /*!
2
- * @author electricessence / https://github.com/electricessence/
3
- * @license MIT
4
- */
5
- (function (factory) {
6
- if (typeof module === "object" && typeof module.exports === "object") {
7
- var v = factory(require, exports);
8
- if (v !== undefined) module.exports = v;
9
- }
10
- else if (typeof define === "function" && define.amd) {
11
- define(["require", "exports", "tslib", "./QueueBase"], factory);
12
- }
13
- })(function (require, exports) {
14
- "use strict";
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- const tslib_1 = require("tslib");
17
- const QueueBase_1 = tslib_1.__importDefault(require("./QueueBase"));
18
- /**
19
- * A `LinkQueue<T>` will have different performance characteristics than a Queue using an array as its storage.
20
- * Most cases will be served well by `Queue<T>`.
21
- * `LinkQueue<T>` may outperform `Queue<T>` within a capacity range above 50 and below 50,000.
22
- */
23
- class LinkQueue extends QueueBase_1.default {
24
- _root = {};
25
- _tail;
26
- _count = 0;
27
- constructor(initialEntries) {
28
- super();
29
- if (initialEntries)
30
- this.enqueueMultiple(initialEntries);
31
- }
32
- /**
33
- * Returns the number of items currently in the queue.
34
- * @returns {number}
35
- */
36
- getCount() {
37
- return this._count;
38
- }
39
- /**
40
- * Dequeues entries into an array.
41
- */
42
- dump(max = Infinity) {
43
- if (!this.count)
44
- return [];
45
- const result = [];
46
- const root = this._root;
47
- if (isFinite(max)) {
48
- while (0 <= --max) {
49
- const n = root.next;
50
- if (!this._dequeueNodeInternal(n))
51
- break;
52
- result.push(n.value);
53
- }
54
- }
55
- else {
56
- let n = root.next;
57
- while (this._dequeueNodeInternal(n)) {
58
- result.push(n.value);
59
- n = root.next;
60
- }
61
- }
62
- this.incrementVersion();
63
- return result;
64
- }
65
- /**
66
- * Clears the list.
67
- */
68
- clear() {
69
- const count = this._count;
70
- this._root.next = undefined;
71
- this._tail = undefined;
72
- this._count = 0;
73
- return count;
74
- }
75
- _dequeueInternal() {
76
- const n = this._root.next;
77
- return this._dequeueNodeInternal(n) ? n.value : undefined;
78
- }
79
- _peekInternal() {
80
- return this._root.next?.value;
81
- }
82
- *_getIterator() {
83
- let current, next = this._root.next;
84
- while (next) {
85
- current = next;
86
- next = current.next;
87
- yield current.value;
88
- }
89
- }
90
- _enqueueInternal(value) {
91
- const newTail = { value: value };
92
- const tail = this._tail;
93
- if (tail)
94
- tail.next = newTail;
95
- else
96
- this._root.next = newTail;
97
- this._tail = newTail;
98
- this._count++;
99
- }
100
- _dequeueNodeInternal(n) {
101
- if (!n)
102
- return false;
103
- this._root.next = n.next;
104
- if (n.next)
105
- n.next = undefined;
106
- else
107
- this._tail = undefined;
108
- const count = this._count;
109
- if (!count)
110
- throw new Error('Dequeuing empty collection.');
111
- this._count = count - 1;
112
- return true;
113
- }
114
- }
115
- exports.default = LinkQueue;
116
- });
117
- //# sourceMappingURL=LinkQueue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LinkQueue.js","sourceRoot":"","sources":["../../src/LinkQueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;IAEH,oEAAoC;IAEpC;;;;OAIG;IACH,MAAqB,SACpB,SAAQ,mBAAY;QAEZ,KAAK,GAAY,EAAE,CAAC;QACpB,KAAK,CAAgB;QACrB,MAAM,GAAW,CAAC,CAAC;QAE3B,YAAa,cAAmC;YAE/C,KAAK,EAAE,CAAC;YACR,IAAG,cAAc;gBAAE,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QACzD,CAAC;QAED;;;WAGG;QACH,QAAQ;YAEP,OAAO,IAAI,CAAC,MAAM,CAAC;QACpB,CAAC;QAED;;WAEG;QACH,IAAI,CAAE,MAAc,QAAQ;YAE3B,IAAG,CAAC,IAAI,CAAC,KAAK;gBAAE,OAAO,EAAE,CAAC;YAC1B,MAAM,MAAM,GAAQ,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;YA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AK,CAAC,IAAI,CAAC;YAE9D,OAAM,IAAI,EACV,CAAC;gBACA,OAAO,GAAG,IAAI,CAAC;gBACf,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;gBACpB,MAAM,OAAO,CAAC,KAAK,CAAC;YACrB,CAAC;QACF,CAAC;QAES,gBAAgB,CAAE,KAAQ;YAEnC,MAAM,OAAO,GAAG,EAAC,KAAK,EAAE,KAAK,EAAC,CAAC;YAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;YACxB,IAAG,IAAI;gBAAE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;;gBACxB,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YAC/B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC;YACrB,IAAI,CAAC,MAAM,EAAE,CAAC;QACf,CAAC;QAEO,oBAAoB,CAAE,CAA2B;YAExD,IAAG,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;YACpB,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;YACzB,IAAG,CAAC,CAAC,IAAI;gBAAE,CAAC,CAAC,IAAI,GAAG,SAAS,CAAC;;gBACzB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC;YAC1B,IAAG,CAAC,KAAK;gBAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;YAC1D,IAAI,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,CAAC;YACxB,OAAO,IAAI,CAAC;QACb,CAAC;KACD;IA/GD,4BA+GC"}
package/dist/umd/Queue.js DELETED
@@ -1,175 +0,0 @@
1
- /*
2
- * @author electricessence / https://github.com/electricessence/
3
- * @license MIT
4
- * Based Upon: http://referencesource.microsoft.com/#System/CompMod/system/collections/generic/queue.cs
5
- */
6
- (function (factory) {
7
- if (typeof module === "object" && typeof module.exports === "object") {
8
- var v = factory(require, exports);
9
- if (v !== undefined) module.exports = v;
10
- }
11
- else if (typeof define === "function" && define.amd) {
12
- define(["require", "exports", "tslib", "./QueueBase"], factory);
13
- }
14
- })(function (require, exports) {
15
- "use strict";
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const tslib_1 = require("tslib");
18
- /* eslint-disable @typescript-eslint/no-this-alias */
19
- const QueueBase_1 = tslib_1.__importDefault(require("./QueueBase"));
20
- const MINIMUM_GROW = 4;
21
- const DEFAULT_CAPACITY = 4;
22
- const SHRINK_THRESHOLD = 42;
23
- class Queue extends QueueBase_1.default {
24
- _array;
25
- _head = 0; // First valid element in the queue
26
- _tail = 0; // Last valid element in the queue
27
- _size = 0; // Number of elements.
28
- constructor(initialEntries) {
29
- super();
30
- if (!initialEntries)
31
- this._array = new Array(DEFAULT_CAPACITY);
32
- else {
33
- this._array = initialEntries.slice();
34
- this._tail = this._size = this._array.length;
35
- }
36
- }
37
- getCount() {
38
- return this._size;
39
- }
40
- clear() {
41
- const _ = this, size = _._size;
42
- _._array.length = 0;
43
- _._head = 0;
44
- _._tail = 0;
45
- _._size = 0;
46
- _.incrementVersion();
47
- return size;
48
- }
49
- /**
50
- * Dequeues entries into an array.
51
- */
52
- dump(max = Infinity) {
53
- const _ = this;
54
- const result = new Array(Math.min(max, _._size));
55
- if (isFinite(max)) {
56
- if (max !== 0) {
57
- let i = 0;
58
- while (max-- && _._size)
59
- result[i++] = _._dequeueInternal();
60
- }
61
- }
62
- else {
63
- while (_._size)
64
- result.push(_._dequeueInternal());
65
- }
66
- _.incrementVersion();
67
- return result;
68
- }
69
- setCapacity(capacity) {
70
- if (isNaN(capacity))
71
- return this;
72
- if (capacity < 0)
73
- capacity = 0;
74
- const _ = this;
75
- const array = _._array, len = array.length;
76
- if (capacity == len)
77
- return this;
78
- const head = _._head, tail = _._tail, size = _._size;
79
- if (!size) {
80
- array.length = capacity;
81
- this._head = 0;
82
- this._tail = 0;
83
- return this;
84
- }
85
- // Special case where we can simply extend or shrink the length of the array.
86
- if (head < tail && capacity >= tail) {
87
- array.length = capacity;
88
- return this;
89
- }
90
- // We create a new array because modifying an existing one could be slow.
91
- const newArray = new Array(capacity);
92
- let i, n = 0;
93
- if (head < tail) {
94
- for (i = head; i < tail; i++)
95
- newArray[n++] = array[i];
96
- }
97
- else {
98
- for (i = head; i < len; i++)
99
- newArray[n++] = array[i];
100
- for (i = 0; i < tail; i++)
101
- newArray[n++] = array[i];
102
- }
103
- this._array = newArray;
104
- _._head = 0;
105
- _._tail = (size == capacity) ? 0 : size;
106
- _.incrementVersion();
107
- return this;
108
- }
109
- /**
110
- * Checks to see if the queue has entries an pulls an entry from the head of the queue and passes it to the out handler.
111
- * @param out The 'out' handler that receives the value if it exists.
112
- * @returns {boolean} True if a value was retrieved. False if not.
113
- */
114
- tryDequeue(out) {
115
- const _ = this;
116
- if (super.tryDequeue(out)) {
117
- if (_._size < _._array.length / 2)
118
- _.trimExcess(SHRINK_THRESHOLD);
119
- return true;
120
- }
121
- return false;
122
- }
123
- /**
124
- * Trims excess items in the underlying array.
125
- * @param {number} threshold
126
- */
127
- trimExcess(threshold) {
128
- const _ = this;
129
- const size = _._size;
130
- if (size < Math.floor(_._array.length * 0.9) && (!threshold && threshold !== 0 || isNaN(threshold) || threshold < size))
131
- _.setCapacity(size);
132
- }
133
- _enqueueInternal(item) {
134
- const _ = this;
135
- const size = _._size;
136
- let len = _._array.length;
137
- if (size === len) {
138
- let newCapacity = len * 2;
139
- if (newCapacity < len + MINIMUM_GROW)
140
- newCapacity = len + MINIMUM_GROW;
141
- _.setCapacity(newCapacity);
142
- len = _._array.length;
143
- }
144
- const tail = _._tail % len;
145
- _._array[tail] = item;
146
- _._tail = (tail + 1) % len;
147
- _._size = size + 1;
148
- }
149
- _dequeueInternal() {
150
- if (!this._size)
151
- return undefined;
152
- const array = this._array, head = this._head;
153
- const removed = array[head];
154
- array[head] = undefined; // protect the data.
155
- this._head = (head + 1) % array.length;
156
- this._size--;
157
- return removed;
158
- }
159
- _peekInternal() {
160
- const _ = this;
161
- return _._size ? _._array[_._head] : undefined;
162
- }
163
- *_getIterator() {
164
- const _ = this, size = _._size;
165
- for (let i = 0; i < size; i++)
166
- yield _._getElement(i);
167
- }
168
- _getElement(index) {
169
- const _ = this, a = _._array;
170
- return _._size ? a[(_._head + index) % a.length] : undefined;
171
- }
172
- }
173
- exports.default = Queue;
174
- });
175
- //# sourceMappingURL=Queue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Queue.js","sourceRoot":"","sources":["../../src/Queue.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;;;;;;;;;;;;IAEH,qDAAqD;IAErD,oEAAoC;IAEpC,MAAM,YAAY,GAAW,CAAC,CAAC;IAC/B,MAAM,gBAAgB,GAAW,CAAC,CAAC;IACnC,MAAM,gBAAgB,GAAW,EAAE,CAAC;IAEpC,MAAqB,KACpB,SAAQ,mBAAY;QAGV,MAAM,CAAM;QACZ,KAAK,GAAW,CAAC,CAAC,CAAE,mCAAmC;QACvD,KAAK,GAAW,CAAC,CAAC,CAAC,kCAAkC;QACrD,KAAK,GAAW,CAAC,CAAC,CAAC,sBAAsB;QAEnD,YAAa,cAAoB;YAEhC,KAAK,EAAE,CAAC;YAER,IAAG,CAAC,cAAc;gBACjB,IAAI,CAAC,MAAM,GAAG,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;iBAE3C,CAAC;gBACA,IAAI,CAAC,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,CAAC;gBACrC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;YAC9C,CAAC;QACF,CAAC;QAED,QAAQ;YAEP,OAAO,IAAI,CAAC,KAAK,CAAC;QACnB,CAAC;QAED,KAAK;YAEJ,MAAM,CAAC,GAAG,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC;YAC/B,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG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