@tsdotnet/queue 1.3.1 → 1.3.2

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.
@@ -1,39 +1,22 @@
1
+ import { IterableCollectionBase } from '@tsdotnet/collection-base';
2
+ import { InvalidOperationException, ArgumentNullException } from '@tsdotnet/exceptions';
3
+
1
4
  /*!
2
5
  * @author electricessence / https://github.com/electricessence/
3
6
  * @license MIT
4
7
  */
5
- import { IterableCollectionBase } from '@tsdotnet/collection-base';
6
- import { InvalidOperationException, ArgumentNullException } from '@tsdotnet/exceptions';
7
- export default class QueueBase extends IterableCollectionBase {
8
- /**
9
- * The number of items currently in the queue.
10
- * @returns {number}
11
- */
8
+ class QueueBase extends IterableCollectionBase {
12
9
  get count() {
13
10
  return this.getCount();
14
11
  }
15
- /**
16
- * Returns true if the queue is empty.
17
- * @return {boolean}
18
- */
19
12
  get isEmpty() {
20
13
  return this.getCount() === 0;
21
14
  }
22
- /**
23
- * Adds an item to the end of the queue.
24
- * @param value
25
- * @returns {this}
26
- */
27
15
  enqueue(value) {
28
16
  this._enqueueInternal(value);
29
17
  this.incrementVersion();
30
18
  return this;
31
19
  }
32
- /**
33
- * Adds items to the end of the queue.
34
- * @param {Iterable} values
35
- * @returns {this}
36
- */
37
20
  enqueueMultiple(values) {
38
21
  if (!values)
39
22
  return this;
@@ -46,20 +29,10 @@ export default class QueueBase extends IterableCollectionBase {
46
29
  this.incrementVersion();
47
30
  return this;
48
31
  }
49
- /**
50
- * Adds items to the end of the queue.
51
- * @param values
52
- * @returns {this}
53
- */
54
32
  enqueueThese(...values) {
55
33
  return this.enqueueMultiple(values);
56
34
  }
57
- /**
58
- * Produces an iterable that dequeues items when iterated. Stops when empty.
59
- * @return {Iterable}
60
- */
61
35
  consumer() {
62
- // eslint-disable-next-line @typescript-eslint/no-this-alias
63
36
  const _ = this;
64
37
  return {
65
38
  *[Symbol.iterator]() {
@@ -69,12 +42,6 @@ export default class QueueBase extends IterableCollectionBase {
69
42
  }
70
43
  };
71
44
  }
72
- /**
73
- * Pulls an entry from the head of the queue and returns it.
74
- * Returns undefined if the queue is already empty and throwIfEmpty is false.
75
- * @throws {InvalidOperationException} If the queue is already empty and throwIfEmpty is true.
76
- * @param throwIfEmpty
77
- */
78
45
  dequeue(throwIfEmpty = false) {
79
46
  if (throwIfEmpty && this.isEmpty)
80
47
  throw new InvalidOperationException('Cannot dequeue an empty queue.');
@@ -82,12 +49,6 @@ export default class QueueBase extends IterableCollectionBase {
82
49
  this.incrementVersion();
83
50
  return item;
84
51
  }
85
- /**
86
- * 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.
87
- * @throws {ArgumentNullException} If no out delegate was specified.
88
- * @param out The 'out' handler that receives the value if it exists.
89
- * @returns {boolean} True if a value was retrieved. False if not.
90
- */
91
52
  tryDequeue(out) {
92
53
  if (!out)
93
54
  throw new ArgumentNullException('out');
@@ -98,29 +59,18 @@ export default class QueueBase extends IterableCollectionBase {
98
59
  out(item);
99
60
  return true;
100
61
  }
101
- /**
102
- * Returns the entry at the head of the queue.
103
- * Returns undefined if the queue is already empty and throwIfEmpty is false.
104
- * @throws {InvalidOperationException} If the queue is already empty and throwIfEmpty is true.
105
- * @param {boolean} throwIfEmpty
106
- * @return {T | undefined}
107
- */
108
62
  peek(throwIfEmpty = false) {
109
63
  if (throwIfEmpty && this.isEmpty)
110
64
  throw new InvalidOperationException('Cannot call peek on an empty queue.');
111
65
  return this._peekInternal();
112
66
  }
113
- /**
114
- * Clears the list.
115
- */
116
67
  dispose() {
117
68
  this.clear();
118
69
  }
119
- /**
120
- * Clears the list.
121
- */
122
70
  recycle() {
123
71
  this.clear();
124
72
  }
125
73
  }
126
- //# sourceMappingURL=QueueBase.js.map
74
+
75
+ export { QueueBase as default };
76
+ //# sourceMappingURL=QueueBase.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"QueueBase.js","sourceRoot":"","sources":["../../src/QueueBase.ts"],"names":[],"mappings":"A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AAAE,YAAA,MAAM,IAAI,qBAAqB,CAAC,KAAK,CAAC;QAC/C,IAAG,IAAI,CAAC,OAAO;AAAE,YAAA,OAAO,KAAK;AAC7B,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,EAAG;QACrC,IAAI,CAAC,gBAAgB,EAAE;QACvB,GAAG,CAAC,IAAI,CAAC;AACT,QAAA,OAAO,IAAI;IACZ;IA+BA,IAAI,CAAE,eAAwB,KAAK,EAAA;AAElC,QAAA,IAAG,YAAY,IAAI,IAAI,CAAC,OAAO;AAAE,YAAA,MAAM,IAAI,yBAAyB,CAAC,qCAAqC,CAAC;AAC3G,QAAA,OAAO,IAAI,CAAC,aAAa,EAAE;IAC5B;IAiBA,OAAO,GAAA;QAEN,IAAI,CAAC,KAAK,EAAE;IACb;IAKA,OAAO,GAAA;QAEN,IAAI,CAAC,KAAK,EAAE;IACb;AAOA;;;;"}
@@ -0,0 +1,8 @@
1
+ import Queue from './Queue.js';
2
+ export { default as LinkQueue } from './LinkQueue.js';
3
+ export { default as QueueBase } from './QueueBase.js';
4
+
5
+
6
+
7
+ export { Queue, Queue as default };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
@@ -2,29 +2,14 @@
2
2
  * @author electricessence / https://github.com/electricessence/
3
3
  * @license MIT
4
4
  */
5
- import QueueBase from './QueueBase';
6
- /**
7
- * A `LinkQueue<T>` will have different performance characteristics than a Queue using an array as its storage.
8
- * Most cases will be served well by `Queue<T>`.
9
- * `LinkQueue<T>` may outperform `Queue<T>` within a capacity range above 50 and below 50,000.
10
- */
5
+ import QueueBase from './QueueBase.js';
11
6
  export default class LinkQueue<T> extends QueueBase<T> {
12
7
  private _root;
13
8
  private _tail?;
14
9
  private _count;
15
10
  constructor(initialEntries?: Iterable<T> | null);
16
- /**
17
- * Returns the number of items currently in the queue.
18
- * @returns {number}
19
- */
20
11
  getCount(): number;
21
- /**
22
- * Dequeues entries into an array.
23
- */
24
12
  dump(max?: number): T[];
25
- /**
26
- * Clears the list.
27
- */
28
13
  clear(): number;
29
14
  protected _dequeueInternal(): T | undefined;
30
15
  protected _peekInternal(): T | undefined | never;
@@ -1,4 +1,4 @@
1
- import QueueBase from './QueueBase';
1
+ import QueueBase from './QueueBase.js';
2
2
  export default class Queue<T> extends QueueBase<T> {
3
3
  protected _array: T[];
4
4
  protected _head: number;
@@ -7,21 +7,9 @@ export default class Queue<T> extends QueueBase<T> {
7
7
  constructor(initialEntries?: T[]);
8
8
  getCount(): number;
9
9
  clear(): number;
10
- /**
11
- * Dequeues entries into an array.
12
- */
13
10
  dump(max?: number): T[];
14
11
  setCapacity(capacity: number): this;
15
- /**
16
- * 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.
17
- * @param out The 'out' handler that receives the value if it exists.
18
- * @returns {boolean} True if a value was retrieved. False if not.
19
- */
20
12
  tryDequeue(out: (value: T) => void): boolean;
21
- /**
22
- * Trims excess items in the underlying array.
23
- * @param {number} threshold
24
- */
25
13
  trimExcess(threshold?: number): void;
26
14
  protected _enqueueInternal(item: T): void;
27
15
  protected _dequeueInternal(): T | undefined;
@@ -0,0 +1,27 @@
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
+ get count(): number;
8
+ get isEmpty(): boolean;
9
+ enqueue(value: T): this;
10
+ enqueueMultiple(values: Iterable<T>): this;
11
+ enqueueThese(...values: T[]): this;
12
+ consumer(): Iterable<T>;
13
+ dequeue(): T | undefined;
14
+ dequeue(throwIfEmpty: true): T | never;
15
+ dequeue(throwIfEmpty: boolean): T | undefined | never;
16
+ tryDequeue(out: (dequeued: T) => void): boolean;
17
+ peek(): T | undefined;
18
+ peek(throwIfEmpty: true): T | never;
19
+ peek(throwIfEmpty: boolean): T | undefined | never;
20
+ abstract dump(max?: number): T[];
21
+ abstract clear(): number;
22
+ dispose(): void;
23
+ recycle(): void;
24
+ protected abstract _dequeueInternal(): T | undefined;
25
+ protected abstract _peekInternal(): T | undefined;
26
+ protected abstract _enqueueInternal(value: T): void;
27
+ }
@@ -0,0 +1,5 @@
1
+ import Queue from './Queue.js';
2
+ export { Queue };
3
+ export { default as LinkQueue } from './LinkQueue.js';
4
+ export { default as QueueBase } from './QueueBase.js';
5
+ export default Queue;
package/package.json CHANGED
@@ -1,22 +1,18 @@
1
1
  {
2
2
  "name": "@tsdotnet/queue",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
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",
11
8
  "exports": {
12
9
  ".": {
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"
10
+ "types": "./dist/types/index.d.ts",
11
+ "import": "./dist/esm/index.js",
12
+ "require": "./dist/cjs/index.js"
18
13
  }
19
14
  },
15
+ "types": "./dist/types/index.d.ts",
20
16
  "keywords": [
21
17
  "queue",
22
18
  "fifo",
@@ -25,23 +21,6 @@
25
21
  "dequeue",
26
22
  "iterable"
27
23
  ],
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
24
  "repository": {
46
25
  "type": "git",
47
26
  "url": "git+https://github.com/tsdotnet/queue.git"
@@ -51,45 +30,39 @@
51
30
  },
52
31
  "homepage": "https://github.com/tsdotnet/queue#readme",
53
32
  "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"
33
+ "@eslint/js": "^10.0.1",
34
+ "@rollup/plugin-typescript": "^12.3.0",
35
+ "@types/node": "^25.5.0",
36
+ "@vitest/coverage-v8": "^4.1.0",
37
+ "cpy-cli": "^7.0.0",
38
+ "eslint": "^10.0.3",
39
+ "rimraf": "^6.1.3",
40
+ "rollup": "^4.59.0",
41
+ "typedoc": "^0.28.17",
42
+ "typescript": "^5.9.3",
43
+ "typescript-eslint": "^8.57.1",
44
+ "vitest": "^4.1.0"
68
45
  },
69
46
  "dependencies": {
70
- "@tsdotnet/collection-base": "^2.1.0",
71
- "@tsdotnet/exceptions": "^1.2.2",
47
+ "@tsdotnet/collection-base": "^2.1.11",
48
+ "@tsdotnet/exceptions": "^1.2.9",
72
49
  "tslib": "^2.8.1"
73
50
  },
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
- ]
51
+ "scripts": {
52
+ "clean": "rimraf dist",
53
+ "copy:dts": "cpy \"src/**/*.d.ts\" dist/types --parents || echo No .d.ts files to copy",
54
+ "build:types": "pnpm copy:dts && tsc -p tsconfig.types.json",
55
+ "build:esm": "rollup -c rollup.config.js",
56
+ "build:cjs": "tsc -p tsconfig.cjs.json",
57
+ "build": "pnpm clean && pnpm build:types && pnpm build:esm && pnpm build:cjs && pnpm typecheck:tests",
58
+ "test": "vitest run",
59
+ "typecheck": "tsc --noEmit",
60
+ "typecheck:tests": "tsc -p tests/tsconfig.json --noEmit",
61
+ "lint": "eslint src/**/*.ts",
62
+ "docs": "rimraf docs && typedoc --options typedoc.json --readme none",
63
+ "bump": "pnpm run precommit && pnpm version patch",
64
+ "precommit": "pnpm build && pnpm test && pnpm lint && git status -s",
65
+ "preversion": "pnpm lint && pnpm test",
66
+ "postversion": "git push && git push --tags && pnpm run docs && git add -A && git commit -m \"Updated docs.\" docs && git push"
94
67
  }
95
- }
68
+ }
@@ -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/L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