deque-typed 2.5.2 → 2.6.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 (63) hide show
  1. package/dist/cjs/index.cjs +223 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +223 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +223 -0
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +223 -0
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  10. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/umd/deque-typed.js +223 -0
  35. package/dist/umd/deque-typed.js.map +1 -1
  36. package/dist/umd/deque-typed.min.js +1 -1
  37. package/dist/umd/deque-typed.min.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/data-structures/base/iterable-element-base.ts +32 -0
  40. package/src/data-structures/base/linear-base.ts +11 -0
  41. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  43. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  44. package/src/data-structures/binary-tree/bst.ts +173 -7
  45. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  46. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  47. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  48. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  49. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  50. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  51. package/src/data-structures/graph/directed-graph.ts +71 -1
  52. package/src/data-structures/graph/undirected-graph.ts +64 -1
  53. package/src/data-structures/hash/hash-map.ts +100 -12
  54. package/src/data-structures/heap/heap.ts +149 -19
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  56. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  57. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  58. package/src/data-structures/matrix/matrix.ts +56 -0
  59. package/src/data-structures/queue/deque.ts +187 -0
  60. package/src/data-structures/queue/queue.ts +109 -0
  61. package/src/data-structures/stack/stack.ts +75 -5
  62. package/src/data-structures/trie/trie.ts +84 -0
  63. package/src/interfaces/binary-tree.ts +1 -9
@@ -245,6 +245,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
245
245
 
246
246
 
247
247
 
248
+
249
+
250
+
251
+
252
+
253
+
254
+
248
255
 
249
256
 
250
257
 
@@ -299,6 +306,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
299
306
 
300
307
 
301
308
 
309
+
310
+
311
+
312
+
313
+
314
+
315
+
302
316
 
303
317
 
304
318
 
@@ -348,6 +362,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
348
362
 
349
363
 
350
364
 
365
+
366
+
367
+
368
+
369
+
370
+
371
+
351
372
 
352
373
 
353
374
 
@@ -393,6 +414,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
393
414
 
394
415
 
395
416
 
417
+
418
+
419
+
420
+
421
+
422
+
423
+
396
424
 
397
425
 
398
426
 
@@ -437,6 +465,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
437
465
 
438
466
 
439
467
 
468
+
469
+
470
+
471
+
472
+
473
+
474
+
440
475
 
441
476
 
442
477
 
@@ -484,6 +519,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
484
519
 
485
520
 
486
521
 
522
+
523
+
524
+
525
+
526
+
527
+
528
+
487
529
 
488
530
 
489
531
 
@@ -556,6 +598,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
556
598
 
557
599
 
558
600
 
601
+
602
+
603
+
604
+
605
+
606
+
607
+
559
608
 
560
609
 
561
610
 
@@ -611,6 +660,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
611
660
 
612
661
 
613
662
 
663
+
664
+
665
+
666
+
667
+
668
+
669
+
614
670
 
615
671
 
616
672
 
@@ -660,6 +716,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
660
716
 
661
717
 
662
718
 
719
+
720
+
721
+
722
+
723
+
724
+
725
+
663
726
 
664
727
 
665
728
 
@@ -709,6 +772,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
709
772
 
710
773
 
711
774
 
775
+
776
+
777
+
778
+
779
+
780
+
781
+
712
782
 
713
783
 
714
784
 
@@ -755,6 +825,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
755
825
 
756
826
 
757
827
 
828
+
829
+
830
+
831
+
832
+
833
+
834
+
758
835
 
759
836
 
760
837
 
@@ -796,6 +873,13 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
796
873
 
797
874
 
798
875
 
876
+
877
+
878
+
879
+
880
+
881
+
882
+
799
883
 
800
884
 
801
885
 
@@ -1,5 +1,5 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
- import type { BinaryTreeDeleteResult, BinaryTreeOptions, BTNRep, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNodeOrNull, ReduceEntryCallback, ToEntryFn } from '../types';
2
+ import type { BinaryTreeOptions, BTNRep, DFSOrderPattern, EntryCallback, IterationType, NodeCallback, NodePredicate, OptNodeOrNull, ReduceEntryCallback, ToEntryFn } from '../types';
3
3
  /**
4
4
  * Public, implementation-agnostic binary tree API.
5
5
  * K = key, V = value, R = raw/record used with toEntryFn (optional).
@@ -19,7 +19,7 @@ export interface IBinaryTree<K = any, V = any, R = any> {
19
19
  add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
20
20
  set(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, BinaryTreeNode<K, V>>, value?: V, count?: number): boolean;
21
21
  addMany(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): boolean[];
22
- delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
22
+ delete(keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>): boolean;
23
23
  clear(): void;
24
24
  isEmpty(): boolean;
25
25
  get(keyNodeEntryOrPredicate: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, startNode?: K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): V | undefined;
@@ -56,5 +56,4 @@ export interface IBinaryTree<K = any, V = any, R = any> {
56
56
  filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this;
57
57
  map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BinaryTreeOptions<MK, MV, MR>>, thisArg?: unknown): IBinaryTree<MK, MV, MR>;
58
58
  merge(anotherTree: IBinaryTree<K, V, R>): void;
59
- refill(keysNodesEntriesOrRaws: Iterable<K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, values?: Iterable<V | undefined>): void;
60
59
  }
@@ -238,6 +238,35 @@ var dequeTyped = (() => {
238
238
  for (const ele of this) if (ele === element) return true;
239
239
  return false;
240
240
  }
241
+ /**
242
+ * Check whether a value exists (Array-compatible alias for `has`).
243
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
244
+ * @param element - Element to search for (uses `===`).
245
+ * @returns `true` if found.
246
+ */
247
+ includes(element) {
248
+ return this.has(element);
249
+ }
250
+ /**
251
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
252
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
253
+ */
254
+ *entries() {
255
+ let index = 0;
256
+ for (const value of this) {
257
+ yield [index++, value];
258
+ }
259
+ }
260
+ /**
261
+ * Return an iterator of numeric indices (Array-compatible).
262
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
263
+ */
264
+ *keys() {
265
+ let index = 0;
266
+ for (const _ of this) {
267
+ yield index++;
268
+ }
269
+ }
241
270
  /**
242
271
  * Reduces all elements to a single accumulated value.
243
272
  *
@@ -497,6 +526,16 @@ var dequeTyped = (() => {
497
526
  }
498
527
  return this;
499
528
  }
529
+ /**
530
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
531
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
532
+ * @returns A new reversed instance.
533
+ */
534
+ toReversed() {
535
+ const cloned = this.clone();
536
+ cloned.reverse();
537
+ return cloned;
538
+ }
500
539
  };
501
540
 
502
541
  // src/data-structures/queue/deque.ts
@@ -655,8 +694,39 @@ var dequeTyped = (() => {
655
694
 
656
695
 
657
696
 
697
+
698
+
699
+
658
700
 
659
701
 
702
+
703
+
704
+ * @example
705
+ * // Deque peek at both ends
706
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
707
+ *
708
+ * // Get first element without removing
709
+ * const first = deque.at(0);
710
+ * console.log(first); // 10;
711
+ *
712
+ * // Get last element without removing
713
+ * const last = deque.at(deque.length - 1);
714
+ * console.log(last); // 50;
715
+ *
716
+ * // Length unchanged
717
+ * console.log(deque.length); // 5;
718
+ */
719
+ /**
720
+ * Peek at the front element without removing it (alias for `first`).
721
+ * @remarks Time O(1), Space O(1)
722
+ * @returns Front element or undefined.
723
+ */
724
+ peek() {
725
+ return this.first;
726
+ }
727
+ /**
728
+ * Deque peek at both ends
729
+
660
730
 
661
731
 
662
732
  * @example
@@ -709,6 +779,13 @@ var dequeTyped = (() => {
709
779
 
710
780
 
711
781
 
782
+
783
+
784
+
785
+
786
+
787
+
788
+
712
789
 
713
790
 
714
791
 
@@ -772,6 +849,13 @@ var dequeTyped = (() => {
772
849
 
773
850
 
774
851
 
852
+
853
+
854
+
855
+
856
+
857
+
858
+
775
859
 
776
860
 
777
861
 
@@ -848,6 +932,13 @@ var dequeTyped = (() => {
848
932
 
849
933
 
850
934
 
935
+
936
+
937
+
938
+
939
+
940
+
941
+
851
942
 
852
943
 
853
944
 
@@ -911,6 +1002,13 @@ var dequeTyped = (() => {
911
1002
 
912
1003
 
913
1004
 
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
914
1012
 
915
1013
 
916
1014
 
@@ -975,6 +1073,13 @@ var dequeTyped = (() => {
975
1073
 
976
1074
 
977
1075
 
1076
+
1077
+
1078
+
1079
+
1080
+
1081
+
1082
+
978
1083
 
979
1084
 
980
1085
 
@@ -1080,6 +1185,13 @@ var dequeTyped = (() => {
1080
1185
 
1081
1186
 
1082
1187
 
1188
+
1189
+
1190
+
1191
+
1192
+
1193
+
1194
+
1083
1195
 
1084
1196
 
1085
1197
 
@@ -1125,6 +1237,13 @@ var dequeTyped = (() => {
1125
1237
 
1126
1238
 
1127
1239
 
1240
+
1241
+
1242
+
1243
+
1244
+
1245
+
1246
+
1128
1247
 
1129
1248
 
1130
1249
 
@@ -1174,6 +1293,13 @@ var dequeTyped = (() => {
1174
1293
 
1175
1294
 
1176
1295
 
1296
+
1297
+
1298
+
1299
+
1300
+
1301
+
1302
+
1177
1303
 
1178
1304
 
1179
1305
 
@@ -1374,6 +1500,13 @@ var dequeTyped = (() => {
1374
1500
 
1375
1501
 
1376
1502
 
1503
+
1504
+
1505
+
1506
+
1507
+
1508
+
1509
+
1377
1510
 
1378
1511
 
1379
1512
 
@@ -1464,10 +1597,72 @@ var dequeTyped = (() => {
1464
1597
 
1465
1598
 
1466
1599
 
1600
+
1601
+
1602
+
1603
+
1467
1604
 
1468
1605
 
1469
1606
 
1470
1607
 
1608
+
1609
+ * @example
1610
+ * // Deque for...of iteration and reverse
1611
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
1612
+ *
1613
+ * // Iterate forward
1614
+ * const forward: string[] = [];
1615
+ * for (const item of deque) {
1616
+ * forward.push(item);
1617
+ * }
1618
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
1619
+ *
1620
+ * // Reverse the deque
1621
+ * deque.reverse();
1622
+ * const backward: string[] = [];
1623
+ * for (const item of deque) {
1624
+ * backward.push(item);
1625
+ * }
1626
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
1627
+ */
1628
+ /**
1629
+ * Find the last value matching a predicate (scans back-to-front).
1630
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1631
+ * @param predicate - Function called with (value, index, deque).
1632
+ * @returns Matching value or undefined.
1633
+ * @example
1634
+ * // Find last matching value
1635
+ * const d = new Deque([1, 2, 3, 4, 5]);
1636
+ * console.log(d.findLast(v => v > 2)); // 5;
1637
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
1638
+ */
1639
+ findLast(predicate) {
1640
+ for (let i = this.length - 1; i >= 0; i--) {
1641
+ const val = this.at(i);
1642
+ if (predicate(val, i, this)) return val;
1643
+ }
1644
+ return void 0;
1645
+ }
1646
+ /**
1647
+ * Find the index of the last value matching a predicate (scans back-to-front).
1648
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1649
+ * @param predicate - Function called with (value, index, deque).
1650
+ * @returns Matching index, or -1 if not found.
1651
+ * @example
1652
+ * // Find last matching index
1653
+ * const d = new Deque([10, 20, 30, 20, 10]);
1654
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
1655
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
1656
+ */
1657
+ findLastIndex(predicate) {
1658
+ for (let i = this.length - 1; i >= 0; i--) {
1659
+ if (predicate(this.at(i), i, this)) return i;
1660
+ }
1661
+ return -1;
1662
+ }
1663
+ /**
1664
+ * Deque for...of iteration and reverse
1665
+
1471
1666
 
1472
1667
  * @example
1473
1668
  * // Deque for...of iteration and reverse
@@ -1573,6 +1768,13 @@ var dequeTyped = (() => {
1573
1768
 
1574
1769
 
1575
1770
 
1771
+
1772
+
1773
+
1774
+
1775
+
1776
+
1777
+
1576
1778
 
1577
1779
 
1578
1780
 
@@ -1644,6 +1846,13 @@ var dequeTyped = (() => {
1644
1846
 
1645
1847
 
1646
1848
 
1849
+
1850
+
1851
+
1852
+
1853
+
1854
+
1855
+
1647
1856
 
1648
1857
 
1649
1858
 
@@ -1698,6 +1907,13 @@ var dequeTyped = (() => {
1698
1907
 
1699
1908
 
1700
1909
 
1910
+
1911
+
1912
+
1913
+
1914
+
1915
+
1916
+
1701
1917
 
1702
1918
 
1703
1919
 
@@ -1772,6 +1988,13 @@ var dequeTyped = (() => {
1772
1988
 
1773
1989
 
1774
1990
 
1991
+
1992
+
1993
+
1994
+
1995
+
1996
+
1997
+
1775
1998
 
1776
1999
 
1777
2000