graph-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 (37) hide show
  1. package/dist/cjs/index.cjs +143 -138
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +3288 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -0
  5. package/dist/esm/index.mjs +143 -138
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +3273 -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/dist/umd/graph-typed.js +7 -7
  19. package/dist/umd/graph-typed.js.map +1 -1
  20. package/dist/umd/graph-typed.min.js +1 -1
  21. package/dist/umd/graph-typed.min.js.map +1 -1
  22. package/package.json +20 -2
  23. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  24. package/src/data-structures/binary-tree/avl-tree-counter.ts +103 -12
  25. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
  26. package/src/data-structures/binary-tree/avl-tree.ts +109 -16
  27. package/src/data-structures/binary-tree/binary-tree.ts +3 -2
  28. package/src/data-structures/binary-tree/bst.ts +104 -12
  29. package/src/data-structures/binary-tree/red-black-tree.ts +110 -19
  30. package/src/data-structures/binary-tree/tree-counter.ts +102 -11
  31. package/src/data-structures/binary-tree/tree-multi-map.ts +124 -12
  32. package/src/data-structures/graph/abstract-graph.ts +8 -8
  33. package/src/data-structures/graph/directed-graph.ts +5 -5
  34. package/src/data-structures/graph/undirected-graph.ts +5 -5
  35. package/src/data-structures/hash/hash-map.ts +4 -4
  36. package/src/types/data-structures/base/base.ts +1 -1
  37. package/tsup.node.config.js +40 -6
@@ -1,7 +1,5 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
3
 
6
4
  // src/utils/utils.ts
7
5
  var uuidV4 = /* @__PURE__ */ __name(function() {
@@ -57,7 +55,10 @@ function isComparable(value, isForceObjectComparable = false) {
57
55
  __name(isComparable, "isComparable");
58
56
 
59
57
  // src/data-structures/base/iterable-entry-base.ts
60
- var _IterableEntryBase = class _IterableEntryBase {
58
+ var IterableEntryBase = class {
59
+ static {
60
+ __name(this, "IterableEntryBase");
61
+ }
61
62
  /**
62
63
  * Default iterator yielding `[key, value]` entries.
63
64
  * @returns Iterator of `[K, V]`.
@@ -106,7 +107,7 @@ var _IterableEntryBase = class _IterableEntryBase {
106
107
  every(predicate, thisArg) {
107
108
  let index = 0;
108
109
  for (const item of this) {
109
- if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
110
+ if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
110
111
  return false;
111
112
  }
112
113
  }
@@ -122,7 +123,7 @@ var _IterableEntryBase = class _IterableEntryBase {
122
123
  some(predicate, thisArg) {
123
124
  let index = 0;
124
125
  for (const item of this) {
125
- if (predicate.call(thisArg, item[0], item[1], index++, this)) {
126
+ if (predicate.call(thisArg, item[1], item[0], index++, this)) {
126
127
  return true;
127
128
  }
128
129
  }
@@ -138,7 +139,7 @@ var _IterableEntryBase = class _IterableEntryBase {
138
139
  let index = 0;
139
140
  for (const item of this) {
140
141
  const [key, value] = item;
141
- callbackfn.call(thisArg, key, value, index++, this);
142
+ callbackfn.call(thisArg, value, key, index++, this);
142
143
  }
143
144
  }
144
145
  /**
@@ -152,7 +153,7 @@ var _IterableEntryBase = class _IterableEntryBase {
152
153
  let index = 0;
153
154
  for (const item of this) {
154
155
  const [key, value] = item;
155
- if (callbackfn.call(thisArg, key, value, index++, this)) return item;
156
+ if (callbackfn.call(thisArg, value, key, index++, this)) return item;
156
157
  }
157
158
  return;
158
159
  }
@@ -226,11 +227,12 @@ var _IterableEntryBase = class _IterableEntryBase {
226
227
  console.log(this.toVisual());
227
228
  }
228
229
  };
229
- __name(_IterableEntryBase, "IterableEntryBase");
230
- var IterableEntryBase = _IterableEntryBase;
231
230
 
232
231
  // src/data-structures/base/iterable-element-base.ts
233
- var _IterableElementBase = class _IterableElementBase {
232
+ var IterableElementBase = class {
233
+ static {
234
+ __name(this, "IterableElementBase");
235
+ }
234
236
  /**
235
237
  * Create a new iterable base.
236
238
  *
@@ -241,19 +243,19 @@ var _IterableElementBase = class _IterableElementBase {
241
243
  * Time O(1), Space O(1).
242
244
  */
243
245
  constructor(options) {
244
- /**
245
- * The converter used to transform a raw element (`R`) into a public element (`E`).
246
- *
247
- * @remarks
248
- * Time O(1), Space O(1).
249
- */
250
- __publicField(this, "_toElementFn");
251
246
  if (options) {
252
247
  const { toElementFn } = options;
253
248
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
254
249
  else if (toElementFn) throw new TypeError("toElementFn must be a function type");
255
250
  }
256
251
  }
252
+ /**
253
+ * The converter used to transform a raw element (`R`) into a public element (`E`).
254
+ *
255
+ * @remarks
256
+ * Time O(1), Space O(1).
257
+ */
258
+ _toElementFn;
257
259
  /**
258
260
  * Exposes the current `toElementFn`, if configured.
259
261
  *
@@ -448,11 +450,13 @@ var _IterableElementBase = class _IterableElementBase {
448
450
  console.log(this.toVisual());
449
451
  }
450
452
  };
451
- __name(_IterableElementBase, "IterableElementBase");
452
- var IterableElementBase = _IterableElementBase;
453
453
 
454
454
  // src/data-structures/heap/heap.ts
455
- var _Heap = class _Heap extends IterableElementBase {
455
+ var Heap = class _Heap extends IterableElementBase {
456
+ static {
457
+ __name(this, "Heap");
458
+ }
459
+ _equals = Object.is;
456
460
  /**
457
461
  * Create a Heap and optionally bulk-insert elements.
458
462
  * @remarks Time O(N), Space O(N)
@@ -462,23 +466,13 @@ var _Heap = class _Heap extends IterableElementBase {
462
466
  */
463
467
  constructor(elements = [], options) {
464
468
  super(options);
465
- __publicField(this, "_equals", Object.is);
466
- __publicField(this, "_elements", []);
467
- __publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
468
- if (typeof a === "object" || typeof b === "object") {
469
- throw TypeError("When comparing object types, define a custom comparator in options.");
470
- }
471
- if (a > b) return 1;
472
- if (a < b) return -1;
473
- return 0;
474
- }, "_DEFAULT_COMPARATOR"));
475
- __publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
476
469
  if (options) {
477
470
  const { comparator } = options;
478
471
  if (comparator) this._comparator = comparator;
479
472
  }
480
473
  this.addMany(elements);
481
474
  }
475
+ _elements = [];
482
476
  /**
483
477
  * Get the backing array of the heap.
484
478
  * @remarks Time O(1), Space O(1)
@@ -501,8 +495,7 @@ var _Heap = class _Heap extends IterableElementBase {
501
495
  * @returns Last element or undefined.
502
496
  */
503
497
  get leaf() {
504
- var _a;
505
- return (_a = this.elements[this.size - 1]) != null ? _a : void 0;
498
+ return this.elements[this.size - 1] ?? void 0;
506
499
  }
507
500
  /**
508
501
  * Create a heap of the same class from an iterable.
@@ -775,7 +768,7 @@ var _Heap = class _Heap extends IterableElementBase {
775
768
  * @returns A new heap with mapped elements.
776
769
  */
777
770
  map(callback, options, thisArg) {
778
- const { comparator, toElementFn, ...rest } = options != null ? options : {};
771
+ const { comparator, toElementFn, ...rest } = options ?? {};
779
772
  if (!comparator) throw new TypeError("Heap.map requires options.comparator for EM");
780
773
  const out = this._createLike([], { ...rest, comparator, toElementFn });
781
774
  let i = 0;
@@ -801,6 +794,15 @@ var _Heap = class _Heap extends IterableElementBase {
801
794
  }
802
795
  return out;
803
796
  }
797
+ _DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
798
+ if (typeof a === "object" || typeof b === "object") {
799
+ throw TypeError("When comparing object types, define a custom comparator in options.");
800
+ }
801
+ if (a > b) return 1;
802
+ if (a < b) return -1;
803
+ return 0;
804
+ }, "_DEFAULT_COMPARATOR");
805
+ _comparator = this._DEFAULT_COMPARATOR;
804
806
  /**
805
807
  * Get the comparator used to order elements.
806
808
  * @remarks Time O(1), Space O(1)
@@ -854,7 +856,7 @@ var _Heap = class _Heap extends IterableElementBase {
854
856
  */
855
857
  _createInstance(options) {
856
858
  const Ctor = this.constructor;
857
- const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options != null ? options : {} });
859
+ const next = new Ctor([], { comparator: this.comparator, toElementFn: this.toElementFn, ...options ?? {} });
858
860
  return next;
859
861
  }
860
862
  /**
@@ -882,11 +884,12 @@ var _Heap = class _Heap extends IterableElementBase {
882
884
  return this._createLike([], options);
883
885
  }
884
886
  };
885
- __name(_Heap, "Heap");
886
- var Heap = _Heap;
887
887
 
888
888
  // src/data-structures/base/linear-base.ts
889
- var _LinearBase = class _LinearBase extends IterableElementBase {
889
+ var LinearBase = class _LinearBase extends IterableElementBase {
890
+ static {
891
+ __name(this, "LinearBase");
892
+ }
890
893
  /**
891
894
  * Construct a linear container with runtime options.
892
895
  * @param options - `{ maxLen?, ... }` bounds/behavior options.
@@ -894,12 +897,12 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
894
897
  */
895
898
  constructor(options) {
896
899
  super(options);
897
- __publicField(this, "_maxLen", -1);
898
900
  if (options) {
899
901
  const { maxLen } = options;
900
902
  if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
901
903
  }
902
904
  }
905
+ _maxLen = -1;
903
906
  /**
904
907
  * Upper bound for length (if positive), or `-1` when unbounded.
905
908
  * @returns Maximum allowed length.
@@ -1032,7 +1035,7 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
1032
1035
  return array;
1033
1036
  }
1034
1037
  reduceRight(callbackfn, initialValue) {
1035
- let accumulator = initialValue != null ? initialValue : 0;
1038
+ let accumulator = initialValue ?? 0;
1036
1039
  for (let i = this.length - 1; i >= 0; i--) {
1037
1040
  accumulator = callbackfn(accumulator, this.at(i), i, this);
1038
1041
  }
@@ -1074,11 +1077,12 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
1074
1077
  return this;
1075
1078
  }
1076
1079
  };
1077
- __name(_LinearBase, "LinearBase");
1078
- var LinearBase = _LinearBase;
1079
1080
 
1080
1081
  // src/data-structures/queue/queue.ts
1081
- var _Queue = class _Queue extends LinearBase {
1082
+ var Queue = class _Queue extends LinearBase {
1083
+ static {
1084
+ __name(this, "Queue");
1085
+ }
1082
1086
  /**
1083
1087
  * Create a Queue and optionally bulk-insert elements.
1084
1088
  * @remarks Time O(N), Space O(N)
@@ -1088,15 +1092,13 @@ var _Queue = class _Queue extends LinearBase {
1088
1092
  */
1089
1093
  constructor(elements = [], options) {
1090
1094
  super(options);
1091
- __publicField(this, "_elements", []);
1092
- __publicField(this, "_offset", 0);
1093
- __publicField(this, "_autoCompactRatio", 0.5);
1094
1095
  if (options) {
1095
1096
  const { autoCompactRatio = 0.5 } = options;
1096
1097
  this._autoCompactRatio = autoCompactRatio;
1097
1098
  }
1098
1099
  this.pushMany(elements);
1099
1100
  }
1101
+ _elements = [];
1100
1102
  /**
1101
1103
  * Get the underlying array buffer.
1102
1104
  * @remarks Time O(1), Space O(1)
@@ -1105,6 +1107,7 @@ var _Queue = class _Queue extends LinearBase {
1105
1107
  get elements() {
1106
1108
  return this._elements;
1107
1109
  }
1110
+ _offset = 0;
1108
1111
  /**
1109
1112
  * Get the current start offset into the array.
1110
1113
  * @remarks Time O(1), Space O(1)
@@ -1113,6 +1116,7 @@ var _Queue = class _Queue extends LinearBase {
1113
1116
  get offset() {
1114
1117
  return this._offset;
1115
1118
  }
1119
+ _autoCompactRatio = 0.5;
1116
1120
  /**
1117
1121
  * Get the compaction threshold (offset/size).
1118
1122
  * @remarks Time O(1), Space O(1)
@@ -1357,11 +1361,10 @@ var _Queue = class _Queue extends LinearBase {
1357
1361
  * @returns A new Queue with mapped elements.
1358
1362
  */
1359
1363
  map(callback, options, thisArg) {
1360
- var _a, _b;
1361
1364
  const out = new this.constructor([], {
1362
- toElementFn: options == null ? void 0 : options.toElementFn,
1363
- maxLen: (_a = options == null ? void 0 : options.maxLen) != null ? _a : this._maxLen,
1364
- autoCompactRatio: (_b = options == null ? void 0 : options.autoCompactRatio) != null ? _b : this._autoCompactRatio
1365
+ toElementFn: options?.toElementFn,
1366
+ maxLen: options?.maxLen ?? this._maxLen,
1367
+ autoCompactRatio: options?.autoCompactRatio ?? this._autoCompactRatio
1365
1368
  });
1366
1369
  let index = 0;
1367
1370
  for (const v of this)
@@ -1376,14 +1379,13 @@ var _Queue = class _Queue extends LinearBase {
1376
1379
  * @returns A new queue with mapped elements (same element type).
1377
1380
  */
1378
1381
  mapSame(callback, thisArg) {
1379
- var _a;
1380
1382
  const Ctor = this.constructor;
1381
1383
  const out = new Ctor([], {
1382
1384
  toElementFn: this.toElementFn,
1383
1385
  maxLen: this._maxLen,
1384
1386
  autoCompactRatio: this._autoCompactRatio
1385
1387
  });
1386
- (_a = out._setAutoCompactRatio) == null ? void 0 : _a.call(out, this._autoCompactRatio);
1388
+ out._setAutoCompactRatio?.(this._autoCompactRatio);
1387
1389
  let index = 0;
1388
1390
  for (const v of this) {
1389
1391
  const mv = thisArg === void 0 ? callback(v, index++, this) : callback.call(thisArg, v, index++, this);
@@ -1443,36 +1445,39 @@ var _Queue = class _Queue extends LinearBase {
1443
1445
  return new Ctor(elements, options);
1444
1446
  }
1445
1447
  };
1446
- __name(_Queue, "Queue");
1447
- var Queue = _Queue;
1448
1448
 
1449
1449
  // src/data-structures/graph/abstract-graph.ts
1450
- var _AbstractVertex = class _AbstractVertex {
1450
+ var AbstractVertex = class {
1451
+ static {
1452
+ __name(this, "AbstractVertex");
1453
+ }
1454
+ key;
1455
+ value;
1451
1456
  constructor(key, value) {
1452
- __publicField(this, "key");
1453
- __publicField(this, "value");
1454
1457
  this.key = key;
1455
1458
  this.value = value;
1456
1459
  }
1457
1460
  };
1458
- __name(_AbstractVertex, "AbstractVertex");
1459
- var AbstractVertex = _AbstractVertex;
1460
- var _AbstractEdge = class _AbstractEdge {
1461
+ var AbstractEdge = class {
1462
+ static {
1463
+ __name(this, "AbstractEdge");
1464
+ }
1465
+ value;
1466
+ weight;
1461
1467
  constructor(weight, value) {
1462
- __publicField(this, "value");
1463
- __publicField(this, "weight");
1464
- __publicField(this, "_hashCode");
1465
1468
  this.weight = weight !== void 0 ? weight : 1;
1466
1469
  this.value = value;
1467
1470
  this._hashCode = uuidV4();
1468
1471
  }
1472
+ _hashCode;
1469
1473
  get hashCode() {
1470
1474
  return this._hashCode;
1471
1475
  }
1472
1476
  };
1473
- __name(_AbstractEdge, "AbstractEdge");
1474
- var AbstractEdge = _AbstractEdge;
1475
- var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
1477
+ var AbstractGraph = class extends IterableEntryBase {
1478
+ static {
1479
+ __name(this, "AbstractGraph");
1480
+ }
1476
1481
  /**
1477
1482
  * Construct a graph with runtime defaults.
1478
1483
  * @param options - `GraphOptions<V>` in `options.graph` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
@@ -1480,14 +1485,14 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
1480
1485
  */
1481
1486
  constructor(options) {
1482
1487
  super();
1483
- __publicField(this, "_options", { defaultEdgeWeight: 1 });
1484
- __publicField(this, "_vertexMap", /* @__PURE__ */ new Map());
1485
- const graph = options == null ? void 0 : options.graph;
1486
- this._options = { defaultEdgeWeight: 1, ...graph != null ? graph : {} };
1488
+ const graph = options?.graph;
1489
+ this._options = { defaultEdgeWeight: 1, ...graph ?? {} };
1487
1490
  }
1491
+ _options = { defaultEdgeWeight: 1 };
1488
1492
  get options() {
1489
1493
  return this._options;
1490
1494
  }
1495
+ _vertexMap = /* @__PURE__ */ new Map();
1491
1496
  get vertexMap() {
1492
1497
  return this._vertexMap;
1493
1498
  }
@@ -1645,10 +1650,9 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
1645
1650
  * @remarks Time O(L), Space O(1) where L is path length
1646
1651
  */
1647
1652
  getPathSumWeight(path) {
1648
- var _a;
1649
1653
  let sum = 0;
1650
1654
  for (let i = 0; i < path.length; i++) {
1651
- sum += ((_a = this.getEdge(path[i], path[i + 1])) == null ? void 0 : _a.weight) || 0;
1655
+ sum += this.getEdge(path[i], path[i + 1])?.weight || 0;
1652
1656
  }
1653
1657
  return sum;
1654
1658
  }
@@ -1710,7 +1714,6 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
1710
1714
  * @remarks Time O((V + E) log V) weighted / O(V + E) unweighted, Space O(V + E)
1711
1715
  */
1712
1716
  getMinPathBetween(v1, v2, isWeight, isDFS = false) {
1713
- var _a, _b;
1714
1717
  if (isWeight === void 0) isWeight = false;
1715
1718
  if (isWeight) {
1716
1719
  if (isDFS) {
@@ -1728,7 +1731,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
1728
1731
  }
1729
1732
  return allPaths[minIndex] || void 0;
1730
1733
  } else {
1731
- return (_b = (_a = this.dijkstra(v1, v2, true, true)) == null ? void 0 : _a.minPath) != null ? _b : [];
1734
+ return this.dijkstra(v1, v2, true, true)?.minPath ?? [];
1732
1735
  }
1733
1736
  } else {
1734
1737
  let minPath = [];
@@ -1857,7 +1860,6 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
1857
1860
  return { distMap, preMap, seen, paths, minDist, minPath };
1858
1861
  }
1859
1862
  dijkstra(src, dest = void 0, getMinDist = false, genPaths = false) {
1860
- var _a;
1861
1863
  let minDist = Number.MAX_SAFE_INTEGER;
1862
1864
  let minDest = void 0;
1863
1865
  let minPath = [];
@@ -1895,8 +1897,8 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
1895
1897
  }, "getPaths");
1896
1898
  while (heap.size > 0) {
1897
1899
  const curHeapNode = heap.poll();
1898
- const dist = curHeapNode == null ? void 0 : curHeapNode.key;
1899
- const cur = curHeapNode == null ? void 0 : curHeapNode.value;
1900
+ const dist = curHeapNode?.key;
1901
+ const cur = curHeapNode?.value;
1900
1902
  if (dist !== void 0) {
1901
1903
  if (cur) {
1902
1904
  seen.add(cur);
@@ -1912,7 +1914,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
1912
1914
  const neighbors = this.getNeighbors(cur);
1913
1915
  for (const neighbor of neighbors) {
1914
1916
  if (!seen.has(neighbor)) {
1915
- const weight = (_a = this.getEdge(cur, neighbor)) == null ? void 0 : _a.weight;
1917
+ const weight = this.getEdge(cur, neighbor)?.weight;
1916
1918
  if (typeof weight === "number") {
1917
1919
  const distSrcToNeighbor = distMap.get(neighbor);
1918
1920
  if (distSrcToNeighbor !== void 0) {
@@ -2035,7 +2037,6 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
2035
2037
  * @remarks Time O(V^3), Space O(V^2)
2036
2038
  */
2037
2039
  floydWarshall() {
2038
- var _a;
2039
2040
  const idAndVertices = [...this._vertexMap];
2040
2041
  const n = idAndVertices.length;
2041
2042
  const costs = [];
@@ -2049,7 +2050,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
2049
2050
  }
2050
2051
  for (let i = 0; i < n; i++) {
2051
2052
  for (let j = 0; j < n; j++) {
2052
- costs[i][j] = ((_a = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])) == null ? void 0 : _a.weight) || Number.MAX_SAFE_INTEGER;
2053
+ costs[i][j] = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])?.weight || Number.MAX_SAFE_INTEGER;
2053
2054
  }
2054
2055
  }
2055
2056
  for (let k = 0; k < n; k++) {
@@ -2113,7 +2114,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
2113
2114
  const filtered = [];
2114
2115
  let index = 0;
2115
2116
  for (const [key, value] of this) {
2116
- if (predicate.call(thisArg, key, value, index, this)) {
2117
+ if (predicate.call(thisArg, value, key, index, this)) {
2117
2118
  filtered.push([key, value]);
2118
2119
  }
2119
2120
  index++;
@@ -2128,7 +2129,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
2128
2129
  const filtered = [];
2129
2130
  let index = 0;
2130
2131
  for (const [key, value] of this) {
2131
- if (predicate.call(thisArg, key, value, index, this)) {
2132
+ if (predicate.call(thisArg, value, key, index, this)) {
2132
2133
  filtered.push([key, value]);
2133
2134
  }
2134
2135
  index++;
@@ -2139,7 +2140,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
2139
2140
  const mapped = [];
2140
2141
  let index = 0;
2141
2142
  for (const [key, value] of this) {
2142
- mapped.push(callback.call(thisArg, key, value, index, this));
2143
+ mapped.push(callback.call(thisArg, value, key, index, this));
2143
2144
  index++;
2144
2145
  }
2145
2146
  return mapped;
@@ -2192,7 +2193,7 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
2192
2193
  _createInstance(_options) {
2193
2194
  const Ctor = this.constructor;
2194
2195
  const instance = new Ctor();
2195
- const graph = _options == null ? void 0 : _options.graph;
2196
+ const graph = _options?.graph;
2196
2197
  if (graph) instance._options = { ...instance._options, ...graph };
2197
2198
  else instance._options = { ...instance._options, ...this._options };
2198
2199
  return instance;
@@ -2271,29 +2272,32 @@ var _AbstractGraph = class _AbstractGraph extends IterableEntryBase {
2271
2272
  return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
2272
2273
  }
2273
2274
  };
2274
- __name(_AbstractGraph, "AbstractGraph");
2275
- var AbstractGraph = _AbstractGraph;
2276
2275
 
2277
2276
  // src/data-structures/graph/directed-graph.ts
2278
- var _DirectedVertex = class _DirectedVertex extends AbstractVertex {
2277
+ var DirectedVertex = class extends AbstractVertex {
2278
+ static {
2279
+ __name(this, "DirectedVertex");
2280
+ }
2279
2281
  constructor(key, value) {
2280
2282
  super(key, value);
2281
2283
  }
2282
2284
  };
2283
- __name(_DirectedVertex, "DirectedVertex");
2284
- var DirectedVertex = _DirectedVertex;
2285
- var _DirectedEdge = class _DirectedEdge extends AbstractEdge {
2285
+ var DirectedEdge = class extends AbstractEdge {
2286
+ static {
2287
+ __name(this, "DirectedEdge");
2288
+ }
2289
+ src;
2290
+ dest;
2286
2291
  constructor(src, dest, weight, value) {
2287
2292
  super(weight, value);
2288
- __publicField(this, "src");
2289
- __publicField(this, "dest");
2290
2293
  this.src = src;
2291
2294
  this.dest = dest;
2292
2295
  }
2293
2296
  };
2294
- __name(_DirectedEdge, "DirectedEdge");
2295
- var DirectedEdge = _DirectedEdge;
2296
- var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
2297
+ var DirectedGraph = class _DirectedGraph extends AbstractGraph {
2298
+ static {
2299
+ __name(this, "DirectedGraph");
2300
+ }
2297
2301
  /**
2298
2302
  * Construct a directed graph with runtime defaults.
2299
2303
  * @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
@@ -2301,15 +2305,15 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
2301
2305
  */
2302
2306
  constructor(options) {
2303
2307
  super(options);
2304
- __publicField(this, "_outEdgeMap", /* @__PURE__ */ new Map());
2305
- __publicField(this, "_inEdgeMap", /* @__PURE__ */ new Map());
2306
2308
  }
2309
+ _outEdgeMap = /* @__PURE__ */ new Map();
2307
2310
  get outEdgeMap() {
2308
2311
  return this._outEdgeMap;
2309
2312
  }
2310
2313
  set outEdgeMap(v) {
2311
2314
  this._outEdgeMap = v;
2312
2315
  }
2316
+ _inEdgeMap = /* @__PURE__ */ new Map();
2313
2317
  get inEdgeMap() {
2314
2318
  return this._inEdgeMap;
2315
2319
  }
@@ -2362,8 +2366,7 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
2362
2366
  * @remarks Time O(1), Space O(1)
2363
2367
  */
2364
2368
  createEdge(src, dest, weight, value) {
2365
- var _a;
2366
- return new DirectedEdge(src, dest, (_a = weight != null ? weight : this.options.defaultEdgeWeight) != null ? _a : 1, value);
2369
+ return new DirectedEdge(src, dest, weight ?? this.options.defaultEdgeWeight ?? 1, value);
2367
2370
  }
2368
2371
  /**
2369
2372
  * Get the unique edge from `src` to `dest`, if present.
@@ -2434,7 +2437,7 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
2434
2437
  if (src && dest) {
2435
2438
  const srcOutEdges = this._outEdgeMap.get(src);
2436
2439
  if (srcOutEdges && srcOutEdges.length > 0) {
2437
- arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === (dest == null ? void 0 : dest.key));
2440
+ arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === dest?.key);
2438
2441
  }
2439
2442
  const destInEdges = this._inEdgeMap.get(dest);
2440
2443
  if (destInEdges && destInEdges.length > 0) {
@@ -2556,7 +2559,7 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
2556
2559
  * @remarks Time O(V + E), Space O(V)
2557
2560
  */
2558
2561
  topologicalSort(propertyName) {
2559
- propertyName = propertyName != null ? propertyName : "key";
2562
+ propertyName = propertyName ?? "key";
2560
2563
  const statusMap = /* @__PURE__ */ new Map();
2561
2564
  for (const entry of this.vertexMap) {
2562
2565
  statusMap.set(entry[1], 0);
@@ -2749,27 +2752,30 @@ var _DirectedGraph = class _DirectedGraph extends AbstractGraph {
2749
2752
  }
2750
2753
  }
2751
2754
  };
2752
- __name(_DirectedGraph, "DirectedGraph");
2753
- var DirectedGraph = _DirectedGraph;
2754
2755
 
2755
2756
  // src/data-structures/graph/undirected-graph.ts
2756
- var _UndirectedVertex = class _UndirectedVertex extends AbstractVertex {
2757
+ var UndirectedVertex = class extends AbstractVertex {
2758
+ static {
2759
+ __name(this, "UndirectedVertex");
2760
+ }
2757
2761
  constructor(key, value) {
2758
2762
  super(key, value);
2759
2763
  }
2760
2764
  };
2761
- __name(_UndirectedVertex, "UndirectedVertex");
2762
- var UndirectedVertex = _UndirectedVertex;
2763
- var _UndirectedEdge = class _UndirectedEdge extends AbstractEdge {
2765
+ var UndirectedEdge = class extends AbstractEdge {
2766
+ static {
2767
+ __name(this, "UndirectedEdge");
2768
+ }
2769
+ endpoints;
2764
2770
  constructor(v1, v2, weight, value) {
2765
2771
  super(weight, value);
2766
- __publicField(this, "endpoints");
2767
2772
  this.endpoints = [v1, v2];
2768
2773
  }
2769
2774
  };
2770
- __name(_UndirectedEdge, "UndirectedEdge");
2771
- var UndirectedEdge = _UndirectedEdge;
2772
- var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
2775
+ var UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
2776
+ static {
2777
+ __name(this, "UndirectedGraph");
2778
+ }
2773
2779
  /**
2774
2780
  * Construct an undirected graph with runtime defaults.
2775
2781
  * @param options - `GraphOptions<V>` (e.g. `vertexValueInitializer`, `defaultEdgeWeight`).
@@ -2777,9 +2783,9 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
2777
2783
  */
2778
2784
  constructor(options) {
2779
2785
  super(options);
2780
- __publicField(this, "_edgeMap");
2781
2786
  this._edgeMap = /* @__PURE__ */ new Map();
2782
2787
  }
2788
+ _edgeMap;
2783
2789
  get edgeMap() {
2784
2790
  return this._edgeMap;
2785
2791
  }
@@ -2832,8 +2838,7 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
2832
2838
  * @remarks Time O(1), Space O(1)
2833
2839
  */
2834
2840
  createEdge(v1, v2, weight, value) {
2835
- var _a;
2836
- return new UndirectedEdge(v1, v2, (_a = weight != null ? weight : this.options.defaultEdgeWeight) != null ? _a : 1, value);
2841
+ return new UndirectedEdge(v1, v2, weight ?? this.options.defaultEdgeWeight ?? 1, value);
2837
2842
  }
2838
2843
  /**
2839
2844
  * Get an undirected edge between two vertices, if present.
@@ -2843,13 +2848,12 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
2843
2848
  * @remarks Time O(1) avg, Space O(1)
2844
2849
  */
2845
2850
  getEdge(v1, v2) {
2846
- var _a;
2847
2851
  let edgeMap = [];
2848
2852
  if (v1 !== void 0 && v2 !== void 0) {
2849
2853
  const vertex1 = this._getVertex(v1);
2850
2854
  const vertex2 = this._getVertex(v2);
2851
2855
  if (vertex1 && vertex2) {
2852
- edgeMap = (_a = this._edgeMap.get(vertex1)) == null ? void 0 : _a.filter((e) => e.endpoints.includes(vertex2.key));
2856
+ edgeMap = this._edgeMap.get(vertex1)?.filter((e) => e.endpoints.includes(vertex2.key));
2853
2857
  }
2854
2858
  }
2855
2859
  return edgeMap ? edgeMap[0] || void 0 : void 0;
@@ -2942,10 +2946,9 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
2942
2946
  * @remarks Time O(1) avg, Space O(1)
2943
2947
  */
2944
2948
  degreeOf(vertexOrKey) {
2945
- var _a;
2946
2949
  const vertex = this._getVertex(vertexOrKey);
2947
2950
  if (vertex) {
2948
- return ((_a = this._edgeMap.get(vertex)) == null ? void 0 : _a.length) || 0;
2951
+ return this._edgeMap.get(vertex)?.length || 0;
2949
2952
  } else {
2950
2953
  return 0;
2951
2954
  }
@@ -3138,29 +3141,32 @@ var _UndirectedGraph = class _UndirectedGraph extends AbstractGraph {
3138
3141
  return true;
3139
3142
  }
3140
3143
  };
3141
- __name(_UndirectedGraph, "UndirectedGraph");
3142
- var UndirectedGraph = _UndirectedGraph;
3143
3144
 
3144
3145
  // src/data-structures/graph/map-graph.ts
3145
- var _MapVertex = class _MapVertex extends DirectedVertex {
3146
+ var MapVertex = class extends DirectedVertex {
3147
+ static {
3148
+ __name(this, "MapVertex");
3149
+ }
3150
+ lat;
3151
+ long;
3146
3152
  constructor(key, value, lat, long) {
3147
3153
  super(key, value);
3148
- __publicField(this, "lat");
3149
- __publicField(this, "long");
3150
3154
  this.lat = lat;
3151
3155
  this.long = long;
3152
3156
  }
3153
3157
  };
3154
- __name(_MapVertex, "MapVertex");
3155
- var MapVertex = _MapVertex;
3156
- var _MapEdge = class _MapEdge extends DirectedEdge {
3158
+ var MapEdge = class extends DirectedEdge {
3159
+ static {
3160
+ __name(this, "MapEdge");
3161
+ }
3157
3162
  constructor(src, dest, weight, value) {
3158
3163
  super(src, dest, weight, value);
3159
3164
  }
3160
3165
  };
3161
- __name(_MapEdge, "MapEdge");
3162
- var MapEdge = _MapEdge;
3163
- var _MapGraph = class _MapGraph extends DirectedGraph {
3166
+ var MapGraph = class _MapGraph extends DirectedGraph {
3167
+ static {
3168
+ __name(this, "MapGraph");
3169
+ }
3164
3170
  /**
3165
3171
  * Construct a MapGraph.
3166
3172
  * @param originCoord - Origin coordinate `[lat, long]` used as default.
@@ -3169,14 +3175,14 @@ var _MapGraph = class _MapGraph extends DirectedGraph {
3169
3175
  */
3170
3176
  constructor(originCoord, bottomRight) {
3171
3177
  super();
3172
- __publicField(this, "_originCoord", [0, 0]);
3173
- __publicField(this, "_bottomRight");
3174
3178
  this._originCoord = originCoord;
3175
3179
  this._bottomRight = bottomRight;
3176
3180
  }
3181
+ _originCoord = [0, 0];
3177
3182
  get originCoord() {
3178
3183
  return this._originCoord;
3179
3184
  }
3185
+ _bottomRight;
3180
3186
  get bottomRight() {
3181
3187
  return this._bottomRight;
3182
3188
  }
@@ -3228,13 +3234,11 @@ var _MapGraph = class _MapGraph extends DirectedGraph {
3228
3234
  */
3229
3235
  _createInstance(options) {
3230
3236
  const { originCoord, bottomRight } = options || {};
3231
- const oc = originCoord != null ? originCoord : this.originCoord;
3232
- const br = bottomRight != null ? bottomRight : this.bottomRight;
3237
+ const oc = originCoord ?? this.originCoord;
3238
+ const br = bottomRight ?? this.bottomRight;
3233
3239
  return new _MapGraph(oc, br);
3234
3240
  }
3235
3241
  };
3236
- __name(_MapGraph, "MapGraph");
3237
- var MapGraph = _MapGraph;
3238
3242
 
3239
3243
  // src/common/index.ts
3240
3244
  var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
@@ -3242,7 +3246,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
3242
3246
  DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
3243
3247
  return DFSOperation2;
3244
3248
  })(DFSOperation || {});
3245
- var _Range = class _Range {
3249
+ var Range = class {
3246
3250
  constructor(low, high, includeLow = true, includeHigh = true) {
3247
3251
  this.low = low;
3248
3252
  this.high = high;
@@ -3251,6 +3255,9 @@ var _Range = class _Range {
3251
3255
  if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
3252
3256
  if (low > high) throw new RangeError("low must be less than or equal to high");
3253
3257
  }
3258
+ static {
3259
+ __name(this, "Range");
3260
+ }
3254
3261
  // Determine whether a key is within the range
3255
3262
  isInRange(key, comparator) {
3256
3263
  const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
@@ -3258,8 +3265,6 @@ var _Range = class _Range {
3258
3265
  return lowCheck && highCheck;
3259
3266
  }
3260
3267
  };
3261
- __name(_Range, "Range");
3262
- var Range = _Range;
3263
3268
  /**
3264
3269
  * data-structure-typed
3265
3270
  *