min-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.
Files changed (33) hide show
  1. package/dist/cjs/index.cjs +60 -56
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +998 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -0
  5. package/dist/esm/index.mjs +60 -56
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +990 -0
  8. package/dist/esm-legacy/index.mjs.map +1 -0
  9. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +57 -3
  10. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +65 -3
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +61 -5
  12. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  13. package/dist/types/data-structures/binary-tree/bst.d.ts +58 -3
  14. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +59 -4
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +66 -3
  17. package/dist/types/types/data-structures/base/base.d.ts +1 -1
  18. package/package.json +20 -2
  19. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  20. package/src/data-structures/binary-tree/avl-tree-counter.ts +103 -12
  21. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
  22. package/src/data-structures/binary-tree/avl-tree.ts +109 -16
  23. package/src/data-structures/binary-tree/binary-tree.ts +3 -2
  24. package/src/data-structures/binary-tree/bst.ts +104 -12
  25. package/src/data-structures/binary-tree/red-black-tree.ts +110 -19
  26. package/src/data-structures/binary-tree/tree-counter.ts +102 -11
  27. package/src/data-structures/binary-tree/tree-multi-map.ts +124 -12
  28. package/src/data-structures/graph/abstract-graph.ts +8 -8
  29. package/src/data-structures/graph/directed-graph.ts +5 -5
  30. package/src/data-structures/graph/undirected-graph.ts +5 -5
  31. package/src/data-structures/hash/hash-map.ts +4 -4
  32. package/src/types/data-structures/base/base.ts +1 -1
  33. package/tsup.node.config.js +40 -6
@@ -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 _IterableElementBase = class _IterableElementBase {
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 _Heap = class _Heap extends IterableElementBase {
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
- var _a;
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 != null ? 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 != null ? 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
- __name(_Heap, "Heap");
662
- var Heap = _Heap;
663
- var _FibonacciHeapNode = class _FibonacciHeapNode {
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
- __name(_FibonacciHeapNode, "FibonacciHeapNode");
678
- var FibonacciHeapNode = _FibonacciHeapNode;
679
- var _FibonacciHeap = class _FibonacciHeap {
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,20 +890,22 @@ 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/priority-queue/priority-queue.ts
894
- var _PriorityQueue = class _PriorityQueue extends Heap {
895
+ var PriorityQueue = class extends Heap {
896
+ static {
897
+ __name(this, "PriorityQueue");
898
+ }
895
899
  constructor(elements = [], options) {
896
900
  super(elements, options);
897
901
  }
898
902
  };
899
- __name(_PriorityQueue, "PriorityQueue");
900
- var PriorityQueue = _PriorityQueue;
901
903
 
902
904
  // src/data-structures/priority-queue/min-priority-queue.ts
903
- var _MinPriorityQueue = class _MinPriorityQueue extends PriorityQueue {
905
+ var MinPriorityQueue = class extends PriorityQueue {
906
+ static {
907
+ __name(this, "MinPriorityQueue");
908
+ }
904
909
  /**
905
910
  * Creates a min-priority queue.
906
911
  * @param elements Optional initial elements to insert.
@@ -911,8 +916,6 @@ var _MinPriorityQueue = class _MinPriorityQueue extends PriorityQueue {
911
916
  super(elements, options);
912
917
  }
913
918
  };
914
- __name(_MinPriorityQueue, "MinPriorityQueue");
915
- var MinPriorityQueue = _MinPriorityQueue;
916
919
 
917
920
  // src/utils/utils.ts
918
921
  function isPrimitiveComparable(value) {
@@ -954,7 +957,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
954
957
  DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
955
958
  return DFSOperation2;
956
959
  })(DFSOperation || {});
957
- var _Range = class _Range {
960
+ var Range = class {
958
961
  constructor(low, high, includeLow = true, includeHigh = true) {
959
962
  this.low = low;
960
963
  this.high = high;
@@ -963,6 +966,9 @@ var _Range = class _Range {
963
966
  if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
964
967
  if (low > high) throw new RangeError("low must be less than or equal to high");
965
968
  }
969
+ static {
970
+ __name(this, "Range");
971
+ }
966
972
  // Determine whether a key is within the range
967
973
  isInRange(key, comparator) {
968
974
  const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
@@ -970,8 +976,6 @@ var _Range = class _Range {
970
976
  return lowCheck && highCheck;
971
977
  }
972
978
  };
973
- __name(_Range, "Range");
974
- var Range = _Range;
975
979
  /**
976
980
  * data-structure-typed
977
981
  *