max-heap-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 +56 -53
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +998 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +56 -53
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +991 -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,8 +917,6 @@ 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/utils/utils.ts
|
|
920
922
|
function isPrimitiveComparable(value) {
|
|
@@ -956,7 +958,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
|
956
958
|
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
957
959
|
return DFSOperation2;
|
|
958
960
|
})(DFSOperation || {});
|
|
959
|
-
var
|
|
961
|
+
var Range = class {
|
|
960
962
|
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
961
963
|
this.low = low;
|
|
962
964
|
this.high = high;
|
|
@@ -965,6 +967,9 @@ var _Range = class _Range {
|
|
|
965
967
|
if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
|
|
966
968
|
if (low > high) throw new RangeError("low must be less than or equal to high");
|
|
967
969
|
}
|
|
970
|
+
static {
|
|
971
|
+
__name(this, "Range");
|
|
972
|
+
}
|
|
968
973
|
// Determine whether a key is within the range
|
|
969
974
|
isInRange(key, comparator) {
|
|
970
975
|
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
@@ -972,8 +977,6 @@ var _Range = class _Range {
|
|
|
972
977
|
return lowCheck && highCheck;
|
|
973
978
|
}
|
|
974
979
|
};
|
|
975
|
-
__name(_Range, "Range");
|
|
976
|
-
var Range = _Range;
|
|
977
980
|
/**
|
|
978
981
|
* data-structure-typed
|
|
979
982
|
*
|