priority-queue-typed 2.5.0 → 2.5.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/dist/cjs/index.cjs +399 -56
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +398 -55
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +399 -57
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +398 -56
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/priority-queue-typed.js +396 -54
- package/dist/umd/priority-queue-typed.js.map +1 -1
- package/dist/umd/priority-queue-typed.min.js +1 -1
- package/dist/umd/priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +299 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
- package/src/data-structures/binary-tree/binary-tree.ts +606 -6
- package/src/data-structures/binary-tree/bst.ts +946 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
- package/src/data-structures/binary-tree/segment-tree.ts +145 -2
- package/src/data-structures/binary-tree/tree-map.ts +3423 -499
- package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
- package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
- package/src/data-structures/binary-tree/tree-set.ts +3209 -413
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +240 -0
- package/src/data-structures/graph/undirected-graph.ts +216 -0
- package/src/data-structures/hash/hash-map.ts +281 -19
- package/src/data-structures/heap/heap.ts +340 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
- package/src/data-structures/matrix/matrix.ts +202 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +365 -5
- package/src/data-structures/queue/queue.ts +288 -0
- package/src/data-structures/stack/stack.ts +240 -0
- package/src/data-structures/trie/trie.ts +295 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -33,9 +33,61 @@ var priorityQueueTyped = (() => {
|
|
|
33
33
|
MinHeap: () => MinHeap,
|
|
34
34
|
MinPriorityQueue: () => MinPriorityQueue,
|
|
35
35
|
PriorityQueue: () => PriorityQueue,
|
|
36
|
-
Range: () => Range
|
|
36
|
+
Range: () => Range,
|
|
37
|
+
raise: () => raise
|
|
37
38
|
});
|
|
38
39
|
|
|
40
|
+
// src/common/error.ts
|
|
41
|
+
function raise(ErrorClass, message) {
|
|
42
|
+
throw new ErrorClass(message);
|
|
43
|
+
}
|
|
44
|
+
var ERR = {
|
|
45
|
+
// Range / index
|
|
46
|
+
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
47
|
+
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
48
|
+
// Type / argument
|
|
49
|
+
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
50
|
+
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
51
|
+
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
52
|
+
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
53
|
+
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
54
|
+
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
55
|
+
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
56
|
+
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
57
|
+
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
58
|
+
// State / operation
|
|
59
|
+
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
60
|
+
// Matrix
|
|
61
|
+
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
62
|
+
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
63
|
+
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
64
|
+
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
65
|
+
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`,
|
|
66
|
+
// Order statistic
|
|
67
|
+
orderStatisticNotEnabled: (method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/common/index.ts
|
|
71
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
72
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
73
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
74
|
+
return DFSOperation2;
|
|
75
|
+
})(DFSOperation || {});
|
|
76
|
+
var Range = class {
|
|
77
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
78
|
+
this.low = low;
|
|
79
|
+
this.high = high;
|
|
80
|
+
this.includeLow = includeLow;
|
|
81
|
+
this.includeHigh = includeHigh;
|
|
82
|
+
}
|
|
83
|
+
// Determine whether a key is within the range
|
|
84
|
+
isInRange(key, comparator) {
|
|
85
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
86
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
87
|
+
return lowCheck && highCheck;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
39
91
|
// src/data-structures/base/iterable-element-base.ts
|
|
40
92
|
var IterableElementBase = class {
|
|
41
93
|
/**
|
|
@@ -58,7 +110,7 @@ var priorityQueueTyped = (() => {
|
|
|
58
110
|
if (options) {
|
|
59
111
|
const { toElementFn } = options;
|
|
60
112
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
61
|
-
else if (toElementFn)
|
|
113
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
62
114
|
}
|
|
63
115
|
}
|
|
64
116
|
/**
|
|
@@ -214,7 +266,7 @@ var priorityQueueTyped = (() => {
|
|
|
214
266
|
acc = initialValue;
|
|
215
267
|
} else {
|
|
216
268
|
const first = iter.next();
|
|
217
|
-
if (first.done)
|
|
269
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
218
270
|
acc = first.value;
|
|
219
271
|
index = 1;
|
|
220
272
|
}
|
|
@@ -256,52 +308,6 @@ var priorityQueueTyped = (() => {
|
|
|
256
308
|
}
|
|
257
309
|
};
|
|
258
310
|
|
|
259
|
-
// src/common/error.ts
|
|
260
|
-
var ERR = {
|
|
261
|
-
// Range / index
|
|
262
|
-
indexOutOfRange: (index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`,
|
|
263
|
-
invalidIndex: (ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`,
|
|
264
|
-
// Type / argument
|
|
265
|
-
invalidArgument: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
266
|
-
comparatorRequired: (ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`,
|
|
267
|
-
invalidKey: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
268
|
-
notAFunction: (name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`,
|
|
269
|
-
invalidEntry: (ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`,
|
|
270
|
-
invalidNaN: (ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`,
|
|
271
|
-
invalidDate: (ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`,
|
|
272
|
-
reduceEmpty: (ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`,
|
|
273
|
-
callbackReturnType: (expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`,
|
|
274
|
-
// State / operation
|
|
275
|
-
invalidOperation: (reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`,
|
|
276
|
-
// Matrix
|
|
277
|
-
matrixDimensionMismatch: (op) => `Matrix: Dimensions must be compatible for ${op}.`,
|
|
278
|
-
matrixSingular: () => "Matrix: Singular matrix, inverse does not exist.",
|
|
279
|
-
matrixNotSquare: () => "Matrix: Must be square for inversion.",
|
|
280
|
-
matrixNotRectangular: () => "Matrix: Must be rectangular for transposition.",
|
|
281
|
-
matrixRowMismatch: (expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
// src/common/index.ts
|
|
285
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
286
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
287
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
288
|
-
return DFSOperation2;
|
|
289
|
-
})(DFSOperation || {});
|
|
290
|
-
var Range = class {
|
|
291
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
292
|
-
this.low = low;
|
|
293
|
-
this.high = high;
|
|
294
|
-
this.includeLow = includeLow;
|
|
295
|
-
this.includeHigh = includeHigh;
|
|
296
|
-
}
|
|
297
|
-
// Determine whether a key is within the range
|
|
298
|
-
isInRange(key, comparator) {
|
|
299
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
300
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
301
|
-
return lowCheck && highCheck;
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
|
|
305
311
|
// src/data-structures/heap/heap.ts
|
|
306
312
|
var Heap = class _Heap extends IterableElementBase {
|
|
307
313
|
/**
|
|
@@ -317,7 +323,7 @@ var priorityQueueTyped = (() => {
|
|
|
317
323
|
__publicField(this, "_elements", []);
|
|
318
324
|
__publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
|
|
319
325
|
if (typeof a === "object" || typeof b === "object") {
|
|
320
|
-
|
|
326
|
+
raise(TypeError, ERR.comparatorRequired("Heap"));
|
|
321
327
|
}
|
|
322
328
|
if (a > b) return 1;
|
|
323
329
|
if (a < b) return -1;
|
|
@@ -353,6 +359,30 @@ var priorityQueueTyped = (() => {
|
|
|
353
359
|
|
|
354
360
|
|
|
355
361
|
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
356
386
|
* @example
|
|
357
387
|
* // Track heap capacity
|
|
358
388
|
* const heap = new Heap<number>();
|
|
@@ -416,6 +446,30 @@ var priorityQueueTyped = (() => {
|
|
|
416
446
|
|
|
417
447
|
|
|
418
448
|
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
419
473
|
* @example
|
|
420
474
|
* // basic Heap creation and add operation
|
|
421
475
|
* // Create a min heap (default)
|
|
@@ -449,6 +503,30 @@ var priorityQueueTyped = (() => {
|
|
|
449
503
|
|
|
450
504
|
|
|
451
505
|
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
452
530
|
* @example
|
|
453
531
|
* // Add multiple elements
|
|
454
532
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -484,6 +562,30 @@ var priorityQueueTyped = (() => {
|
|
|
484
562
|
|
|
485
563
|
|
|
486
564
|
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
487
589
|
* @example
|
|
488
590
|
* // Heap with custom comparator (MaxHeap behavior)
|
|
489
591
|
* interface Task {
|
|
@@ -535,6 +637,30 @@ var priorityQueueTyped = (() => {
|
|
|
535
637
|
|
|
536
638
|
|
|
537
639
|
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
538
664
|
* @example
|
|
539
665
|
* // Heap for event processing with priority
|
|
540
666
|
* interface Event {
|
|
@@ -611,6 +737,30 @@ var priorityQueueTyped = (() => {
|
|
|
611
737
|
|
|
612
738
|
|
|
613
739
|
|
|
740
|
+
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
614
764
|
* @example
|
|
615
765
|
* // Check if heap is empty
|
|
616
766
|
* const heap = new Heap<number>([], { comparator: (a, b) => a - b });
|
|
@@ -634,6 +784,30 @@ var priorityQueueTyped = (() => {
|
|
|
634
784
|
|
|
635
785
|
|
|
636
786
|
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
637
811
|
* @example
|
|
638
812
|
* // Remove all elements
|
|
639
813
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -660,6 +834,30 @@ var priorityQueueTyped = (() => {
|
|
|
660
834
|
* @returns True if found.
|
|
661
835
|
|
|
662
836
|
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
663
861
|
* @example
|
|
664
862
|
* // Check element existence
|
|
665
863
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -683,6 +881,30 @@ var priorityQueueTyped = (() => {
|
|
|
683
881
|
|
|
684
882
|
|
|
685
883
|
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
|
|
686
908
|
* @example
|
|
687
909
|
* // Remove specific element
|
|
688
910
|
* const heap = new Heap<number>([3, 1, 4, 1, 5], { comparator: (a, b) => a - b });
|
|
@@ -752,6 +974,30 @@ var priorityQueueTyped = (() => {
|
|
|
752
974
|
* @returns Array of visited elements.
|
|
753
975
|
|
|
754
976
|
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
|
|
755
1001
|
* @example
|
|
756
1002
|
* // Depth-first traversal
|
|
757
1003
|
* const heap = new Heap<number>([3, 1, 2], { comparator: (a, b) => a - b });
|
|
@@ -808,6 +1054,30 @@ var priorityQueueTyped = (() => {
|
|
|
808
1054
|
|
|
809
1055
|
|
|
810
1056
|
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
|
|
1071
|
+
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
|
|
811
1081
|
* @example
|
|
812
1082
|
* // Sort elements using heap
|
|
813
1083
|
* const heap = new Heap<number>([5, 1, 3, 2, 4]);
|
|
@@ -837,6 +1107,30 @@ var priorityQueueTyped = (() => {
|
|
|
837
1107
|
|
|
838
1108
|
|
|
839
1109
|
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
|
|
1130
|
+
|
|
1131
|
+
|
|
1132
|
+
|
|
1133
|
+
|
|
840
1134
|
* @example
|
|
841
1135
|
* // Create independent copy
|
|
842
1136
|
* const heap = new Heap<number>([3, 1, 4], { comparator: (a, b) => a - b });
|
|
@@ -865,6 +1159,30 @@ var priorityQueueTyped = (() => {
|
|
|
865
1159
|
|
|
866
1160
|
|
|
867
1161
|
|
|
1162
|
+
|
|
1163
|
+
|
|
1164
|
+
|
|
1165
|
+
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
|
|
1169
|
+
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
868
1186
|
* @example
|
|
869
1187
|
* // Filter elements
|
|
870
1188
|
* const heap = new Heap<number>([1, 2, 3, 4, 5], { comparator: (a, b) => a - b });
|
|
@@ -900,6 +1218,30 @@ var priorityQueueTyped = (() => {
|
|
|
900
1218
|
|
|
901
1219
|
|
|
902
1220
|
|
|
1221
|
+
|
|
1222
|
+
|
|
1223
|
+
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
|
|
1238
|
+
|
|
1239
|
+
|
|
1240
|
+
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
|
|
903
1245
|
* @example
|
|
904
1246
|
* // Transform elements
|
|
905
1247
|
* const heap = new Heap<number>([1, 2, 3], { comparator: (a, b) => a - b });
|
|
@@ -908,7 +1250,7 @@ var priorityQueueTyped = (() => {
|
|
|
908
1250
|
*/
|
|
909
1251
|
map(callback, options, thisArg) {
|
|
910
1252
|
const { comparator, toElementFn, ...rest } = options != null ? options : {};
|
|
911
|
-
if (!comparator)
|
|
1253
|
+
if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
|
|
912
1254
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
913
1255
|
let i = 0;
|
|
914
1256
|
for (const x of this) {
|
|
@@ -1036,7 +1378,7 @@ var priorityQueueTyped = (() => {
|
|
|
1036
1378
|
__publicField(this, "_comparator");
|
|
1037
1379
|
this.clear();
|
|
1038
1380
|
this._comparator = comparator || this._defaultComparator;
|
|
1039
|
-
if (typeof this.comparator !== "function")
|
|
1381
|
+
if (typeof this.comparator !== "function") raise(TypeError, ERR.notAFunction("comparator", "FibonacciHeap"));
|
|
1040
1382
|
}
|
|
1041
1383
|
/**
|
|
1042
1384
|
* Get the circular root list head.
|
|
@@ -1245,7 +1587,7 @@ var priorityQueueTyped = (() => {
|
|
|
1245
1587
|
super(elements, {
|
|
1246
1588
|
comparator: (a, b) => {
|
|
1247
1589
|
if (typeof a === "object" || typeof b === "object") {
|
|
1248
|
-
|
|
1590
|
+
raise(TypeError, ERR.comparatorRequired("MaxHeap"));
|
|
1249
1591
|
}
|
|
1250
1592
|
if (a < b) return 1;
|
|
1251
1593
|
if (a > b) return -1;
|
|
@@ -1301,7 +1643,7 @@ var priorityQueueTyped = (() => {
|
|
|
1301
1643
|
super(elements, {
|
|
1302
1644
|
comparator: (a, b) => {
|
|
1303
1645
|
if (typeof a === "object" || typeof b === "object") {
|
|
1304
|
-
|
|
1646
|
+
raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
|
|
1305
1647
|
}
|
|
1306
1648
|
if (a < b) return 1;
|
|
1307
1649
|
if (a > b) return -1;
|