@dcrosstech/dct-ts-utils 1.1.0 → 1.2.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.
- package/dist/index.cjs +523 -0
- package/dist/index.d.cts +142 -0
- package/dist/index.d.ts +142 -8
- package/dist/index.js +487 -8
- package/package.json +23 -12
- package/dist/lib/fifoqueue.d.ts +0 -12
- package/dist/lib/fifoqueue.js +0 -31
- package/dist/lib/heap.d.ts +0 -25
- package/dist/lib/heap.js +0 -73
- package/dist/lib/priorityqueue.d.ts +0 -16
- package/dist/lib/priorityqueue.js +0 -40
- package/dist/lib/queue.d.ts +0 -9
- package/dist/lib/queue.js +0 -1
- package/dist/lib/retry.d.ts +0 -19
- package/dist/lib/retry.js +0 -107
- package/dist/lib/semaphore.d.ts +0 -33
- package/dist/lib/semaphore.js +0 -121
- package/dist/lib/sleep.d.ts +0 -10
- package/dist/lib/sleep.js +0 -60
- package/dist/lib/stablepriorityqueue.d.ts +0 -13
- package/dist/lib/stablepriorityqueue.js +0 -40
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { BinaryHeap } from "./heap";
|
|
2
|
-
export class StablePriorityQueue {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.seq = 0;
|
|
5
|
-
this.heap = new BinaryHeap((a, b) => {
|
|
6
|
-
if (a.priority !== b.priority)
|
|
7
|
-
return a.priority - b.priority;
|
|
8
|
-
return a.seq - b.seq; // FIFO on ties
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
size() {
|
|
12
|
-
return this.heap.size();
|
|
13
|
-
}
|
|
14
|
-
isEmpty() {
|
|
15
|
-
return this.heap.isEmpty();
|
|
16
|
-
}
|
|
17
|
-
peek() {
|
|
18
|
-
return this.heap.peek()?.value;
|
|
19
|
-
}
|
|
20
|
-
enqueue(value, priority = 0) {
|
|
21
|
-
if (!Number.isFinite(priority)) {
|
|
22
|
-
throw new TypeError(`priority must be finite; got ${priority}`);
|
|
23
|
-
}
|
|
24
|
-
this.heap.push({
|
|
25
|
-
value,
|
|
26
|
-
priority: Math.trunc(priority),
|
|
27
|
-
seq: this.seq++,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
dequeue() {
|
|
31
|
-
return this.heap.pop()?.value;
|
|
32
|
-
}
|
|
33
|
-
clear() {
|
|
34
|
-
this.heap.clear();
|
|
35
|
-
this.seq = 0;
|
|
36
|
-
}
|
|
37
|
-
toArray() {
|
|
38
|
-
return this.heap.toArray().map(n => n.value);
|
|
39
|
-
}
|
|
40
|
-
}
|