singly-linked-list-typed 2.1.2 → 2.2.0

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 (27) hide show
  1. package/dist/cjs/index.cjs +48 -45
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +1384 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -0
  5. package/dist/esm/index.mjs +48 -45
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +1379 -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 +58 -4
  12. package/dist/types/data-structures/binary-tree/bst.d.ts +57 -3
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +58 -4
  14. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +57 -3
  15. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +65 -3
  16. package/package.json +20 -2
  17. package/src/data-structures/binary-tree/avl-tree-counter.ts +102 -11
  18. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +115 -11
  19. package/src/data-structures/binary-tree/avl-tree.ts +105 -14
  20. package/src/data-structures/binary-tree/bst.ts +102 -11
  21. package/src/data-structures/binary-tree/red-black-tree.ts +108 -18
  22. package/src/data-structures/binary-tree/tree-counter.ts +101 -10
  23. package/src/data-structures/binary-tree/tree-multi-map.ts +122 -11
  24. package/src/data-structures/graph/abstract-graph.ts +5 -5
  25. package/src/data-structures/graph/directed-graph.ts +5 -5
  26. package/src/data-structures/graph/undirected-graph.ts +5 -5
  27. 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,22 +225,22 @@ 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/base/linear-base.ts
231
- var _LinkedListNode = class _LinkedListNode {
230
+ var LinkedListNode = class {
231
+ static {
232
+ __name(this, "LinkedListNode");
233
+ }
232
234
  /**
233
235
  * Initialize a node.
234
236
  * @param value - Element value.
235
237
  * @remarks Time O(1), Space O(1)
236
238
  */
237
239
  constructor(value) {
238
- __publicField(this, "_value");
239
- __publicField(this, "_next");
240
240
  this._value = value;
241
241
  this._next = void 0;
242
242
  }
243
+ _value;
243
244
  /**
244
245
  * Element payload getter.
245
246
  * @returns Element value.
@@ -256,6 +257,7 @@ var _LinkedListNode = class _LinkedListNode {
256
257
  set value(value) {
257
258
  this._value = value;
258
259
  }
260
+ _next;
259
261
  /**
260
262
  * Next node getter.
261
263
  * @returns Next node or `undefined`.
@@ -273,9 +275,10 @@ var _LinkedListNode = class _LinkedListNode {
273
275
  this._next = value;
274
276
  }
275
277
  };
276
- __name(_LinkedListNode, "LinkedListNode");
277
- var LinkedListNode = _LinkedListNode;
278
- var _LinearBase = class _LinearBase extends IterableElementBase {
278
+ var LinearBase = class _LinearBase extends IterableElementBase {
279
+ static {
280
+ __name(this, "LinearBase");
281
+ }
279
282
  /**
280
283
  * Construct a linear container with runtime options.
281
284
  * @param options - `{ maxLen?, ... }` bounds/behavior options.
@@ -283,12 +286,12 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
283
286
  */
284
287
  constructor(options) {
285
288
  super(options);
286
- __publicField(this, "_maxLen", -1);
287
289
  if (options) {
288
290
  const { maxLen } = options;
289
291
  if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
290
292
  }
291
293
  }
294
+ _maxLen = -1;
292
295
  /**
293
296
  * Upper bound for length (if positive), or `-1` when unbounded.
294
297
  * @returns Maximum allowed length.
@@ -421,7 +424,7 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
421
424
  return array;
422
425
  }
423
426
  reduceRight(callbackfn, initialValue) {
424
- let accumulator = initialValue != null ? initialValue : 0;
427
+ let accumulator = initialValue ?? 0;
425
428
  for (let i = this.length - 1; i >= 0; i--) {
426
429
  accumulator = callbackfn(accumulator, this.at(i), i, this);
427
430
  }
@@ -463,9 +466,10 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
463
466
  return this;
464
467
  }
465
468
  };
466
- __name(_LinearBase, "LinearBase");
467
- var LinearBase = _LinearBase;
468
- var _LinearLinkedBase = class _LinearLinkedBase extends LinearBase {
469
+ var LinearLinkedBase = class extends LinearBase {
470
+ static {
471
+ __name(this, "LinearLinkedBase");
472
+ }
469
473
  constructor(options) {
470
474
  super(options);
471
475
  if (options) {
@@ -595,7 +599,7 @@ var _LinearLinkedBase = class _LinearLinkedBase extends LinearBase {
595
599
  return removedList;
596
600
  }
597
601
  reduceRight(callbackfn, initialValue) {
598
- let accumulator = initialValue != null ? initialValue : 0;
602
+ let accumulator = initialValue ?? 0;
599
603
  let index = this.length - 1;
600
604
  for (const item of this._getReverseIterator()) {
601
605
  accumulator = callbackfn(accumulator, item, index--, this);
@@ -603,11 +607,12 @@ var _LinearLinkedBase = class _LinearLinkedBase extends LinearBase {
603
607
  return accumulator;
604
608
  }
605
609
  };
606
- __name(_LinearLinkedBase, "LinearLinkedBase");
607
- var LinearLinkedBase = _LinearLinkedBase;
608
610
 
609
611
  // src/data-structures/linked-list/singly-linked-list.ts
610
- var _SinglyLinkedListNode = class _SinglyLinkedListNode extends LinkedListNode {
612
+ var SinglyLinkedListNode = class extends LinkedListNode {
613
+ static {
614
+ __name(this, "SinglyLinkedListNode");
615
+ }
611
616
  /**
612
617
  * Create a list node.
613
618
  * @remarks Time O(1), Space O(1)
@@ -616,10 +621,10 @@ var _SinglyLinkedListNode = class _SinglyLinkedListNode extends LinkedListNode {
616
621
  */
617
622
  constructor(value) {
618
623
  super(value);
619
- __publicField(this, "_next");
620
624
  this._value = value;
621
625
  this._next = void 0;
622
626
  }
627
+ _next;
623
628
  /**
624
629
  * Get the next node.
625
630
  * @remarks Time O(1), Space O(1)
@@ -638,9 +643,11 @@ var _SinglyLinkedListNode = class _SinglyLinkedListNode extends LinkedListNode {
638
643
  this._next = value;
639
644
  }
640
645
  };
641
- __name(_SinglyLinkedListNode, "SinglyLinkedListNode");
642
- var SinglyLinkedListNode = _SinglyLinkedListNode;
643
- var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
646
+ var SinglyLinkedList = class extends LinearLinkedBase {
647
+ static {
648
+ __name(this, "SinglyLinkedList");
649
+ }
650
+ _equals = Object.is;
644
651
  /**
645
652
  * Create a SinglyLinkedList and optionally bulk-insert elements.
646
653
  * @remarks Time O(N), Space O(N)
@@ -650,12 +657,9 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
650
657
  */
651
658
  constructor(elements = [], options) {
652
659
  super(options);
653
- __publicField(this, "_equals", Object.is);
654
- __publicField(this, "_head");
655
- __publicField(this, "_tail");
656
- __publicField(this, "_length", 0);
657
660
  this.pushMany(elements);
658
661
  }
662
+ _head;
659
663
  /**
660
664
  * Get the head node.
661
665
  * @remarks Time O(1), Space O(1)
@@ -664,6 +668,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
664
668
  get head() {
665
669
  return this._head;
666
670
  }
671
+ _tail;
667
672
  /**
668
673
  * Get the tail node.
669
674
  * @remarks Time O(1), Space O(1)
@@ -672,6 +677,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
672
677
  get tail() {
673
678
  return this._tail;
674
679
  }
680
+ _length = 0;
675
681
  /**
676
682
  * Get the number of elements.
677
683
  * @remarks Time O(1), Space O(1)
@@ -686,8 +692,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
686
692
  * @returns First element or undefined.
687
693
  */
688
694
  get first() {
689
- var _a;
690
- return (_a = this.head) == null ? void 0 : _a.value;
695
+ return this.head?.value;
691
696
  }
692
697
  /**
693
698
  * Get the last element value.
@@ -695,8 +700,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
695
700
  * @returns Last element or undefined.
696
701
  */
697
702
  get last() {
698
- var _a;
699
- return (_a = this.tail) == null ? void 0 : _a.value;
703
+ return this.tail?.value;
700
704
  }
701
705
  /**
702
706
  * Create a new list from an iterable of elements.
@@ -1175,7 +1179,7 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1175
1179
  * @returns A new SinglyLinkedList with mapped values.
1176
1180
  */
1177
1181
  map(callback, options, thisArg) {
1178
- const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
1182
+ const out = this._createLike([], { ...options ?? {}, maxLen: this._maxLen });
1179
1183
  let index = 0;
1180
1184
  for (const value of this) out.push(callback.call(thisArg, value, index++, this));
1181
1185
  return out;
@@ -1300,8 +1304,6 @@ var _SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1300
1304
  return this._createLike([], options);
1301
1305
  }
1302
1306
  };
1303
- __name(_SinglyLinkedList, "SinglyLinkedList");
1304
- var SinglyLinkedList = _SinglyLinkedList;
1305
1307
  function elementOrPredicate(input, equals) {
1306
1308
  if (input instanceof SinglyLinkedListNode) return (node) => node === input;
1307
1309
  if (typeof input === "function") return input;
@@ -1350,7 +1352,7 @@ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1350
1352
  DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1351
1353
  return DFSOperation2;
1352
1354
  })(DFSOperation || {});
1353
- var _Range = class _Range {
1355
+ var Range = class {
1354
1356
  constructor(low, high, includeLow = true, includeHigh = true) {
1355
1357
  this.low = low;
1356
1358
  this.high = high;
@@ -1359,6 +1361,9 @@ var _Range = class _Range {
1359
1361
  if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
1360
1362
  if (low > high) throw new RangeError("low must be less than or equal to high");
1361
1363
  }
1364
+ static {
1365
+ __name(this, "Range");
1366
+ }
1362
1367
  // Determine whether a key is within the range
1363
1368
  isInRange(key, comparator) {
1364
1369
  const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
@@ -1366,8 +1371,6 @@ var _Range = class _Range {
1366
1371
  return lowCheck && highCheck;
1367
1372
  }
1368
1373
  };
1369
- __name(_Range, "Range");
1370
- var Range = _Range;
1371
1374
  /**
1372
1375
  * data-structure-typed
1373
1376
  *