@tsdotnet/queue 1.3.0 → 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.
- package/LICENSE +21 -21
- package/README.md +11 -12
- package/dist/cjs/LinkQueue.js +2 -17
- package/dist/cjs/LinkQueue.js.map +1 -1
- package/dist/cjs/Queue.js +6 -26
- package/dist/cjs/Queue.js.map +1 -1
- package/dist/cjs/QueueBase.js +0 -53
- package/dist/cjs/QueueBase.js.map +1 -1
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/LinkQueue.js +6 -18
- package/dist/esm/LinkQueue.js.map +1 -1
- package/dist/esm/Queue.js +10 -27
- package/dist/esm/Queue.js.map +1 -1
- package/dist/esm/QueueBase.js +7 -57
- package/dist/esm/QueueBase.js.map +1 -1
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/{LinkQueue.d.ts → types/LinkQueue.d.ts} +1 -16
- package/dist/{Queue.d.ts → types/Queue.d.ts} +1 -13
- package/dist/types/QueueBase.d.ts +27 -0
- package/dist/types/index.d.ts +5 -0
- package/package.json +38 -66
- package/dist/QueueBase.d.ts +0 -106
- package/dist/umd/LinkQueue.js +0 -117
- package/dist/umd/LinkQueue.js.map +0 -1
- package/dist/umd/Queue.js +0 -175
- package/dist/umd/Queue.js.map +0 -1
- package/dist/umd/QueueBase.js +0 -139
- package/dist/umd/QueueBase.js.map +0 -1
- package/eslint.config.mjs +0 -23
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
|
package/dist/umd/Queue.js.map
DELETED
|
@@ -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,C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AAG,IAAI,EAAE,IAAI,GAAW,CAAC,CAAC,KAAK,CAAC;YACvC,KAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAC,IAAI,EAAE,CAAC,EAAE;gBAAE,MAAM,CAAC,CAAC,WAAW,CAAC,CAAC,CAAE,CAAC;QACrD,CAAC;QAEO,WAAW,CAAE,KAAa;YAEjC,MAAM,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;YAC7B,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5D,CAAC;KACD;IAlMD,wBAkMC"}
|
package/dist/umd/QueueBase.js
DELETED
|
@@ -1,139 +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", "@tsdotnet/collection-base", "@tsdotnet/exceptions"], factory);
|
|
12
|
-
}
|
|
13
|
-
})(function (require, exports) {
|
|
14
|
-
"use strict";
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const collection_base_1 = require("@tsdotnet/collection-base");
|
|
17
|
-
const exceptions_1 = require("@tsdotnet/exceptions");
|
|
18
|
-
class QueueBase extends collection_base_1.IterableCollectionBase {
|
|
19
|
-
/**
|
|
20
|
-
* The number of items currently in the queue.
|
|
21
|
-
* @returns {number}
|
|
22
|
-
*/
|
|
23
|
-
get count() {
|
|
24
|
-
return this.getCount();
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Returns true if the queue is empty.
|
|
28
|
-
* @return {boolean}
|
|
29
|
-
*/
|
|
30
|
-
get isEmpty() {
|
|
31
|
-
return this.getCount() === 0;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Adds an item to the end of the queue.
|
|
35
|
-
* @param value
|
|
36
|
-
* @returns {this}
|
|
37
|
-
*/
|
|
38
|
-
enqueue(value) {
|
|
39
|
-
this._enqueueInternal(value);
|
|
40
|
-
this.incrementVersion();
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Adds items to the end of the queue.
|
|
45
|
-
* @param {Iterable} values
|
|
46
|
-
* @returns {this}
|
|
47
|
-
*/
|
|
48
|
-
enqueueMultiple(values) {
|
|
49
|
-
if (!values)
|
|
50
|
-
return this;
|
|
51
|
-
let hasValues = false;
|
|
52
|
-
for (const v of values) {
|
|
53
|
-
hasValues = true;
|
|
54
|
-
this._enqueueInternal(v);
|
|
55
|
-
}
|
|
56
|
-
if (hasValues)
|
|
57
|
-
this.incrementVersion();
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Adds items to the end of the queue.
|
|
62
|
-
* @param values
|
|
63
|
-
* @returns {this}
|
|
64
|
-
*/
|
|
65
|
-
enqueueThese(...values) {
|
|
66
|
-
return this.enqueueMultiple(values);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Produces an iterable that dequeues items when iterated. Stops when empty.
|
|
70
|
-
* @return {Iterable}
|
|
71
|
-
*/
|
|
72
|
-
consumer() {
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
74
|
-
const _ = this;
|
|
75
|
-
return {
|
|
76
|
-
*[Symbol.iterator]() {
|
|
77
|
-
while (_.getCount()) {
|
|
78
|
-
yield _.dequeue(true);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Pulls an entry from the head of the queue and returns it.
|
|
85
|
-
* Returns undefined if the queue is already empty and throwIfEmpty is false.
|
|
86
|
-
* @throws {InvalidOperationException} If the queue is already empty and throwIfEmpty is true.
|
|
87
|
-
* @param throwIfEmpty
|
|
88
|
-
*/
|
|
89
|
-
dequeue(throwIfEmpty = false) {
|
|
90
|
-
if (throwIfEmpty && this.isEmpty)
|
|
91
|
-
throw new exceptions_1.InvalidOperationException('Cannot dequeue an empty queue.');
|
|
92
|
-
const item = this._dequeueInternal();
|
|
93
|
-
this.incrementVersion();
|
|
94
|
-
return item;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 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.
|
|
98
|
-
* @throws {ArgumentNullException} If no out delegate was specified.
|
|
99
|
-
* @param out The 'out' handler that receives the value if it exists.
|
|
100
|
-
* @returns {boolean} True if a value was retrieved. False if not.
|
|
101
|
-
*/
|
|
102
|
-
tryDequeue(out) {
|
|
103
|
-
if (!out)
|
|
104
|
-
throw new exceptions_1.ArgumentNullException('out');
|
|
105
|
-
if (this.isEmpty)
|
|
106
|
-
return false;
|
|
107
|
-
const item = this._dequeueInternal();
|
|
108
|
-
this.incrementVersion();
|
|
109
|
-
out(item);
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Returns the entry at the head of the queue.
|
|
114
|
-
* Returns undefined if the queue is already empty and throwIfEmpty is false.
|
|
115
|
-
* @throws {InvalidOperationException} If the queue is already empty and throwIfEmpty is true.
|
|
116
|
-
* @param {boolean} throwIfEmpty
|
|
117
|
-
* @return {T | undefined}
|
|
118
|
-
*/
|
|
119
|
-
peek(throwIfEmpty = false) {
|
|
120
|
-
if (throwIfEmpty && this.isEmpty)
|
|
121
|
-
throw new exceptions_1.InvalidOperationException('Cannot call peek on an empty queue.');
|
|
122
|
-
return this._peekInternal();
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Clears the list.
|
|
126
|
-
*/
|
|
127
|
-
dispose() {
|
|
128
|
-
this.clear();
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Clears the list.
|
|
132
|
-
*/
|
|
133
|
-
recycle() {
|
|
134
|
-
this.clear();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.default = QueueBase;
|
|
138
|
-
});
|
|
139
|
-
//# sourceMappingURL=QueueBase.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueueBase.js","sourceRoot":"","sources":["../../src/QueueBase.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;IAEH,+DAAiE;IACjE,qDAAsF;IAEtF,MAA8B,SAC7B,SAAQ,wCAAyB;QAEjC;;;WAGG;QACH,IAAI,KAAK;YAER,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;QACxB,CAAC;QAED;;;WAGG;QACH,IAAI,OAAO;YAEV,OAAO,IAAI,CAAC,QAAQ,EAAE,KAAG,CAAC,CAAC;QAC5B,CAAC;QAED;;;;WAIG;QACH,OAAO,CAAE,KAAQ;YAEhB,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;YAC7B,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QACb,CAAC;QAED;;;;WAIG;QACH,eAAe,CAAE,MAAmB;YAEnC,IAAG,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAC;YACxB,IAAI,SAAS,GAAG,KAAK,CAAC;YACtB,KAAI,MAAM,CAAC,IAAI,MAAM,EACrB,CAAC;gBACA,SAAS,GAAG,IAAI,CAAC;gBACjB,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC;YAC1B,CAAC;YACD,IAAG,SAAS;gBAAE,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtC,OAAO,IAAI,CAAC;QACb,CAAC;QAED;;;;WAIG;QACH,YAAY,CAAE,GAAG,MAAW;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C;QAED;;WAEG;QACH,OAAO;YAEN,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;KAOD;IAxMD,4BAwMC"}
|
package/eslint.config.mjs
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
|
-
import tseslint from 'typescript-eslint';
|
|
3
|
-
|
|
4
|
-
export default tseslint.config(
|
|
5
|
-
eslint.configs.recommended,
|
|
6
|
-
...tseslint.configs.recommended,
|
|
7
|
-
{
|
|
8
|
-
rules: {
|
|
9
|
-
"semi": ["warn", "always"],
|
|
10
|
-
"indent": ["warn", "tab", { "SwitchCase": 1 }],
|
|
11
|
-
"@typescript-eslint/no-explicit-any": "off"
|
|
12
|
-
},
|
|
13
|
-
files: ['src/**/*.ts'],
|
|
14
|
-
languageOptions: {
|
|
15
|
-
ecmaVersion: 2022,
|
|
16
|
-
sourceType: 'module',
|
|
17
|
-
globals: {
|
|
18
|
-
console: 'readonly',
|
|
19
|
-
process: 'readonly'
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
);
|