priority-queue-typed 2.1.2 → 2.2.1
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 +72 -65
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +1082 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +72 -65
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +1071 -0
- package/dist/esm-legacy/index.mjs.map +1 -0
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +61 -5
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +58 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +59 -4
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +66 -3
- package/dist/types/types/data-structures/base/base.d.ts +1 -1
- package/package.json +20 -2
- package/src/data-structures/base/iterable-entry-base.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-counter.ts +103 -12
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
- package/src/data-structures/binary-tree/avl-tree.ts +109 -16
- package/src/data-structures/binary-tree/binary-tree.ts +3 -2
- package/src/data-structures/binary-tree/bst.ts +104 -12
- package/src/data-structures/binary-tree/red-black-tree.ts +110 -19
- package/src/data-structures/binary-tree/tree-counter.ts +102 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +124 -12
- package/src/data-structures/graph/abstract-graph.ts +8 -8
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- package/src/data-structures/hash/hash-map.ts +4 -4
- package/src/types/data-structures/base/base.ts +1 -1
- package/tsup.node.config.js +40 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
5
4
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
5
|
|
|
8
6
|
// src/data-structures/base/iterable-element-base.ts
|
|
9
|
-
var
|
|
7
|
+
var IterableElementBase = class {
|
|
8
|
+
static {
|
|
9
|
+
__name(this, "IterableElementBase");
|
|
10
|
+
}
|
|
10
11
|
/**
|
|
11
12
|
* Create a new iterable base.
|
|
12
13
|
*
|
|
@@ -17,19 +18,19 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
17
18
|
* Time O(1), Space O(1).
|
|
18
19
|
*/
|
|
19
20
|
constructor(options) {
|
|
20
|
-
/**
|
|
21
|
-
* The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
22
|
-
*
|
|
23
|
-
* @remarks
|
|
24
|
-
* Time O(1), Space O(1).
|
|
25
|
-
*/
|
|
26
|
-
__publicField(this, "_toElementFn");
|
|
27
21
|
if (options) {
|
|
28
22
|
const { toElementFn } = options;
|
|
29
23
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
30
24
|
else if (toElementFn) throw new TypeError("toElementFn must be a function type");
|
|
31
25
|
}
|
|
32
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* The converter used to transform a raw element (`R`) into a public element (`E`).
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* Time O(1), Space O(1).
|
|
32
|
+
*/
|
|
33
|
+
_toElementFn;
|
|
33
34
|
/**
|
|
34
35
|
* Exposes the current `toElementFn`, if configured.
|
|
35
36
|
*
|
|
@@ -224,11 +225,13 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
224
225
|
console.log(this.toVisual());
|
|
225
226
|
}
|
|
226
227
|
};
|
|
227
|
-
__name(_IterableElementBase, "IterableElementBase");
|
|
228
|
-
var IterableElementBase = _IterableElementBase;
|
|
229
228
|
|
|
230
229
|
// src/data-structures/heap/heap.ts
|
|
231
|
-
var
|
|
230
|
+
var Heap = class _Heap extends IterableElementBase {
|
|
231
|
+
static {
|
|
232
|
+
__name(this, "Heap");
|
|
233
|
+
}
|
|
234
|
+
_equals = Object.is;
|
|
232
235
|
/**
|
|
233
236
|
* Create a Heap and optionally bulk-insert elements.
|
|
234
237
|
* @remarks Time O(N), Space O(N)
|
|
@@ -238,23 +241,13 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
238
241
|
*/
|
|
239
242
|
constructor(elements = [], options) {
|
|
240
243
|
super(options);
|
|
241
|
-
__publicField(this, "_equals", Object.is);
|
|
242
|
-
__publicField(this, "_elements", []);
|
|
243
|
-
__publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
|
|
244
|
-
if (typeof a === "object" || typeof b === "object") {
|
|
245
|
-
throw TypeError("When comparing object types, define a custom comparator in options.");
|
|
246
|
-
}
|
|
247
|
-
if (a > b) return 1;
|
|
248
|
-
if (a < b) return -1;
|
|
249
|
-
return 0;
|
|
250
|
-
}, "_DEFAULT_COMPARATOR"));
|
|
251
|
-
__publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
|
|
252
244
|
if (options) {
|
|
253
245
|
const { comparator } = options;
|
|
254
246
|
if (comparator) this._comparator = comparator;
|
|
255
247
|
}
|
|
256
248
|
this.addMany(elements);
|
|
257
249
|
}
|
|
250
|
+
_elements = [];
|
|
258
251
|
/**
|
|
259
252
|
* Get the backing array of the heap.
|
|
260
253
|
* @remarks Time O(1), Space O(1)
|
|
@@ -277,8 +270,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
277
270
|
* @returns Last element or undefined.
|
|
278
271
|
*/
|
|
279
272
|
get leaf() {
|
|
280
|
-
|
|
281
|
-
return (_a = this.elements[this.size - 1]) != null ? _a : void 0;
|
|
273
|
+
return this.elements[this.size - 1] ?? void 0;
|
|
282
274
|
}
|
|
283
275
|
/**
|
|
284
276
|
* Create a heap of the same class from an iterable.
|
|
@@ -551,7 +543,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
551
543
|
* @returns A new heap with mapped elements.
|
|
552
544
|
*/
|
|
553
545
|
map(callback, options, thisArg) {
|
|
554
|
-
const { comparator, toElementFn, ...rest } = options
|
|
546
|
+
const { comparator, toElementFn, ...rest } = options ?? {};
|
|
555
547
|
if (!comparator) throw new TypeError("Heap.map requires options.comparator for EM");
|
|
556
548
|
const out = this._createLike([], { ...rest, comparator, toElementFn });
|
|
557
549
|
let i = 0;
|
|
@@ -577,6 +569,15 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
577
569
|
}
|
|
578
570
|
return out;
|
|
579
571
|
}
|
|
572
|
+
_DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
|
|
573
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
574
|
+
throw TypeError("When comparing object types, define a custom comparator in options.");
|
|
575
|
+
}
|
|
576
|
+
if (a > b) return 1;
|
|
577
|
+
if (a < b) return -1;
|
|
578
|
+
return 0;
|
|
579
|
+
}, "_DEFAULT_COMPARATOR");
|
|
580
|
+
_comparator = this._DEFAULT_COMPARATOR;
|
|
580
581
|
/**
|
|
581
582
|
* Get the comparator used to order elements.
|
|
582
583
|
* @remarks Time O(1), Space O(1)
|
|
@@ -630,7 +631,7 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
630
631
|
*/
|
|
631
632
|
_createInstance(options) {
|
|
632
633
|
const Ctor = this.constructor;
|
|
633
|
-
const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options
|
|
634
|
+
const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
|
|
634
635
|
return next;
|
|
635
636
|
}
|
|
636
637
|
/**
|
|
@@ -658,25 +659,27 @@ var _Heap = class _Heap extends IterableElementBase {
|
|
|
658
659
|
return this._createLike([], options);
|
|
659
660
|
}
|
|
660
661
|
};
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
662
|
+
var FibonacciHeapNode = class {
|
|
663
|
+
static {
|
|
664
|
+
__name(this, "FibonacciHeapNode");
|
|
665
|
+
}
|
|
666
|
+
element;
|
|
667
|
+
degree;
|
|
668
|
+
left;
|
|
669
|
+
right;
|
|
670
|
+
child;
|
|
671
|
+
parent;
|
|
672
|
+
marked;
|
|
664
673
|
constructor(element, degree = 0) {
|
|
665
|
-
__publicField(this, "element");
|
|
666
|
-
__publicField(this, "degree");
|
|
667
|
-
__publicField(this, "left");
|
|
668
|
-
__publicField(this, "right");
|
|
669
|
-
__publicField(this, "child");
|
|
670
|
-
__publicField(this, "parent");
|
|
671
|
-
__publicField(this, "marked");
|
|
672
674
|
this.element = element;
|
|
673
675
|
this.degree = degree;
|
|
674
676
|
this.marked = false;
|
|
675
677
|
}
|
|
676
678
|
};
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
679
|
+
var FibonacciHeap = class {
|
|
680
|
+
static {
|
|
681
|
+
__name(this, "FibonacciHeap");
|
|
682
|
+
}
|
|
680
683
|
/**
|
|
681
684
|
* Create a FibonacciHeap.
|
|
682
685
|
* @remarks Time O(1), Space O(1)
|
|
@@ -684,14 +687,11 @@ var _FibonacciHeap = class _FibonacciHeap {
|
|
|
684
687
|
* @returns New FibonacciHeap instance.
|
|
685
688
|
*/
|
|
686
689
|
constructor(comparator) {
|
|
687
|
-
__publicField(this, "_root");
|
|
688
|
-
__publicField(this, "_size", 0);
|
|
689
|
-
__publicField(this, "_min");
|
|
690
|
-
__publicField(this, "_comparator");
|
|
691
690
|
this.clear();
|
|
692
691
|
this._comparator = comparator || this._defaultComparator;
|
|
693
692
|
if (typeof this.comparator !== "function") throw new Error("FibonacciHeap: comparator must be a function.");
|
|
694
693
|
}
|
|
694
|
+
_root;
|
|
695
695
|
/**
|
|
696
696
|
* Get the circular root list head.
|
|
697
697
|
* @remarks Time O(1), Space O(1)
|
|
@@ -700,9 +700,11 @@ var _FibonacciHeap = class _FibonacciHeap {
|
|
|
700
700
|
get root() {
|
|
701
701
|
return this._root;
|
|
702
702
|
}
|
|
703
|
+
_size = 0;
|
|
703
704
|
get size() {
|
|
704
705
|
return this._size;
|
|
705
706
|
}
|
|
707
|
+
_min;
|
|
706
708
|
/**
|
|
707
709
|
* Get the current minimum node.
|
|
708
710
|
* @remarks Time O(1), Space O(1)
|
|
@@ -711,6 +713,7 @@ var _FibonacciHeap = class _FibonacciHeap {
|
|
|
711
713
|
get min() {
|
|
712
714
|
return this._min;
|
|
713
715
|
}
|
|
716
|
+
_comparator;
|
|
714
717
|
get comparator() {
|
|
715
718
|
return this._comparator;
|
|
716
719
|
}
|
|
@@ -887,11 +890,12 @@ var _FibonacciHeap = class _FibonacciHeap {
|
|
|
887
890
|
}
|
|
888
891
|
}
|
|
889
892
|
};
|
|
890
|
-
__name(_FibonacciHeap, "FibonacciHeap");
|
|
891
|
-
var FibonacciHeap = _FibonacciHeap;
|
|
892
893
|
|
|
893
894
|
// src/data-structures/heap/max-heap.ts
|
|
894
|
-
var
|
|
895
|
+
var MaxHeap = class extends Heap {
|
|
896
|
+
static {
|
|
897
|
+
__name(this, "MaxHeap");
|
|
898
|
+
}
|
|
895
899
|
/**
|
|
896
900
|
* Create a max-heap. For objects, supply a custom comparator.
|
|
897
901
|
* @param elements Optional initial elements.
|
|
@@ -913,11 +917,12 @@ var _MaxHeap = class _MaxHeap extends Heap {
|
|
|
913
917
|
});
|
|
914
918
|
}
|
|
915
919
|
};
|
|
916
|
-
__name(_MaxHeap, "MaxHeap");
|
|
917
|
-
var MaxHeap = _MaxHeap;
|
|
918
920
|
|
|
919
921
|
// src/data-structures/heap/min-heap.ts
|
|
920
|
-
var
|
|
922
|
+
var MinHeap = class extends Heap {
|
|
923
|
+
static {
|
|
924
|
+
__name(this, "MinHeap");
|
|
925
|
+
}
|
|
921
926
|
/**
|
|
922
927
|
* Create a min-heap.
|
|
923
928
|
* @param elements Optional initial elements.
|
|
@@ -927,20 +932,22 @@ var _MinHeap = class _MinHeap extends Heap {
|
|
|
927
932
|
super(elements, options);
|
|
928
933
|
}
|
|
929
934
|
};
|
|
930
|
-
__name(_MinHeap, "MinHeap");
|
|
931
|
-
var MinHeap = _MinHeap;
|
|
932
935
|
|
|
933
936
|
// src/data-structures/priority-queue/priority-queue.ts
|
|
934
|
-
var
|
|
937
|
+
var PriorityQueue = class extends Heap {
|
|
938
|
+
static {
|
|
939
|
+
__name(this, "PriorityQueue");
|
|
940
|
+
}
|
|
935
941
|
constructor(elements = [], options) {
|
|
936
942
|
super(elements, options);
|
|
937
943
|
}
|
|
938
944
|
};
|
|
939
|
-
__name(_PriorityQueue, "PriorityQueue");
|
|
940
|
-
var PriorityQueue = _PriorityQueue;
|
|
941
945
|
|
|
942
946
|
// src/data-structures/priority-queue/min-priority-queue.ts
|
|
943
|
-
var
|
|
947
|
+
var MinPriorityQueue = class extends PriorityQueue {
|
|
948
|
+
static {
|
|
949
|
+
__name(this, "MinPriorityQueue");
|
|
950
|
+
}
|
|
944
951
|
/**
|
|
945
952
|
* Creates a min-priority queue.
|
|
946
953
|
* @param elements Optional initial elements to insert.
|
|
@@ -951,11 +958,12 @@ var _MinPriorityQueue = class _MinPriorityQueue extends PriorityQueue {
|
|
|
951
958
|
super(elements, options);
|
|
952
959
|
}
|
|
953
960
|
};
|
|
954
|
-
__name(_MinPriorityQueue, "MinPriorityQueue");
|
|
955
|
-
var MinPriorityQueue = _MinPriorityQueue;
|
|
956
961
|
|
|
957
962
|
// src/data-structures/priority-queue/max-priority-queue.ts
|
|
958
|
-
var
|
|
963
|
+
var MaxPriorityQueue = class extends PriorityQueue {
|
|
964
|
+
static {
|
|
965
|
+
__name(this, "MaxPriorityQueue");
|
|
966
|
+
}
|
|
959
967
|
/**
|
|
960
968
|
* Creates a max-priority queue.
|
|
961
969
|
* @param elements Optional initial elements to insert.
|
|
@@ -979,8 +987,6 @@ var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
|
|
|
979
987
|
});
|
|
980
988
|
}
|
|
981
989
|
};
|
|
982
|
-
__name(_MaxPriorityQueue, "MaxPriorityQueue");
|
|
983
|
-
var MaxPriorityQueue = _MaxPriorityQueue;
|
|
984
990
|
|
|
985
991
|
// src/utils/utils.ts
|
|
986
992
|
function isPrimitiveComparable(value) {
|
|
@@ -1022,7 +1028,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
|
1022
1028
|
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
1023
1029
|
return DFSOperation2;
|
|
1024
1030
|
})(DFSOperation || {});
|
|
1025
|
-
var
|
|
1031
|
+
var Range = class {
|
|
1026
1032
|
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
1027
1033
|
this.low = low;
|
|
1028
1034
|
this.high = high;
|
|
@@ -1031,6 +1037,9 @@ var _Range = class _Range {
|
|
|
1031
1037
|
if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
|
|
1032
1038
|
if (low > high) throw new RangeError("low must be less than or equal to high");
|
|
1033
1039
|
}
|
|
1040
|
+
static {
|
|
1041
|
+
__name(this, "Range");
|
|
1042
|
+
}
|
|
1034
1043
|
// Determine whether a key is within the range
|
|
1035
1044
|
isInRange(key, comparator) {
|
|
1036
1045
|
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
@@ -1038,8 +1047,6 @@ var _Range = class _Range {
|
|
|
1038
1047
|
return lowCheck && highCheck;
|
|
1039
1048
|
}
|
|
1040
1049
|
};
|
|
1041
|
-
__name(_Range, "Range");
|
|
1042
|
-
var Range = _Range;
|
|
1043
1050
|
/**
|
|
1044
1051
|
* data-structure-typed
|
|
1045
1052
|
*
|