binary-tree-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 +320 -55
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +320 -55
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +320 -55
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +320 -55
  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/binary-tree-typed.js +320 -55
  35. package/dist/umd/binary-tree-typed.js.map +1 -1
  36. package/dist/umd/binary-tree-typed.min.js +5 -5
  37. package/dist/umd/binary-tree-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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binary-tree-typed",
3
- "version": "2.5.2",
3
+ "version": "2.6.0",
4
4
  "description": "Binary Tree. Javascript & Typescript Data Structure.",
5
5
  "browser": "dist/umd/binary-tree-typed.min.js",
6
6
  "umd:main": "dist/umd/binary-tree-typed.min.js",
@@ -178,6 +178,6 @@
178
178
  "typescript": "^4.9.5"
179
179
  },
180
180
  "dependencies": {
181
- "data-structure-typed": "^2.5.2"
181
+ "data-structure-typed": "^2.6.0"
182
182
  }
183
183
  }
@@ -191,6 +191,38 @@ export abstract class IterableElementBase<E, R> implements Iterable<E> {
191
191
  return false;
192
192
  }
193
193
 
194
+ /**
195
+ * Check whether a value exists (Array-compatible alias for `has`).
196
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
197
+ * @param element - Element to search for (uses `===`).
198
+ * @returns `true` if found.
199
+ */
200
+ includes(element: E): boolean {
201
+ return this.has(element);
202
+ }
203
+
204
+ /**
205
+ * Return an iterator of `[index, value]` pairs (Array-compatible).
206
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
207
+ */
208
+ *entries(): IterableIterator<[number, E]> {
209
+ let index = 0;
210
+ for (const value of this) {
211
+ yield [index++, value];
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Return an iterator of numeric indices (Array-compatible).
217
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1) per step.
218
+ */
219
+ *keys(): IterableIterator<number> {
220
+ let index = 0;
221
+ for (const _ of this) {
222
+ yield index++;
223
+ }
224
+ }
225
+
194
226
  reduce(callbackfn: ReduceElementCallback<E, R>): E;
195
227
  reduce(callbackfn: ReduceElementCallback<E, R>, initialValue: E): E;
196
228
  reduce<U>(callbackfn: ReduceElementCallback<E, R, U>, initialValue: U): U;
@@ -327,6 +327,17 @@ export abstract class LinearBase<
327
327
  */
328
328
  abstract reverse(): this;
329
329
 
330
+ /**
331
+ * Return a new instance of the same type with elements in reverse order (non-mutating).
332
+ * @remarks Provided for familiarity when migrating from Array (ES2023 `toReversed`). Time O(n), Space O(n).
333
+ * @returns A new reversed instance.
334
+ */
335
+ toReversed(): this {
336
+ const cloned = this.clone();
337
+ cloned.reverse();
338
+ return cloned as this;
339
+ }
340
+
330
341
  /**
331
342
  * Append one element or node to the tail.
332
343
  * @param elementOrNode - Element or node.
@@ -9,7 +9,6 @@
9
9
  import { BST } from './bst';
10
10
  import type {
11
11
  AVLTreeOptions,
12
- BinaryTreeDeleteResult,
13
12
  BinaryTreeOptions,
14
13
  BSTNOptKeyOrNode,
15
14
  EntryCallback,
@@ -471,6 +470,34 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
471
470
 
472
471
 
473
472
 
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
474
501
 
475
502
 
476
503
 
@@ -600,6 +627,27 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
600
627
 
601
628
 
602
629
 
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
603
651
 
604
652
 
605
653
 
@@ -630,15 +678,15 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
630
678
  */
631
679
  override delete(
632
680
  keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
633
- ): BinaryTreeDeleteResult<AVLTreeNode<K, V>>[] {
634
- const deletedResults = super.delete(keyNodeOrEntry);
681
+ ): boolean {
682
+ const deletedResults = this._deleteInternal(keyNodeOrEntry);
635
683
  // After deletion, balance the path from the parent of the *physically deleted* node.
636
684
  for (const { needBalanced } of deletedResults) {
637
685
  if (needBalanced) {
638
- this._balancePath(needBalanced);
686
+ this._balancePath(needBalanced as AVLTreeNode<K, V>);
639
687
  }
640
688
  }
641
- return deletedResults;
689
+ return deletedResults.length > 0;
642
690
  }
643
691
 
644
692
  /**
@@ -693,6 +741,20 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
693
741
 
694
742
 
695
743
 
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
696
758
 
697
759
 
698
760
 
@@ -830,6 +892,27 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
830
892
 
831
893
 
832
894
 
895
+
896
+
897
+
898
+
899
+
900
+
901
+
902
+
903
+
904
+
905
+
906
+
907
+
908
+
909
+
910
+
911
+
912
+
913
+
914
+
915
+
833
916
 
834
917
 
835
918
 
@@ -103,6 +103,20 @@ export class BinaryIndexedTree implements Iterable<number> {
103
103
 
104
104
 
105
105
 
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
106
120
 
107
121
 
108
122
 
@@ -180,6 +194,20 @@ export class BinaryIndexedTree implements Iterable<number> {
180
194
 
181
195
 
182
196
 
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
183
211
 
184
212
 
185
213
 
@@ -257,6 +285,20 @@ export class BinaryIndexedTree implements Iterable<number> {
257
285
 
258
286
 
259
287
 
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
260
302
 
261
303
 
262
304
 
@@ -334,6 +376,20 @@ export class BinaryIndexedTree implements Iterable<number> {
334
376
 
335
377
 
336
378
 
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
337
393
 
338
394
 
339
395
 
@@ -409,6 +465,20 @@ export class BinaryIndexedTree implements Iterable<number> {
409
465
 
410
466
 
411
467
 
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
412
482
 
413
483
 
414
484
 
@@ -492,6 +562,20 @@ export class BinaryIndexedTree implements Iterable<number> {
492
562
 
493
563
 
494
564
 
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
495
579
 
496
580
 
497
581
 
@@ -552,6 +636,13 @@ export class BinaryIndexedTree implements Iterable<number> {
552
636
 
553
637
 
554
638
 
639
+
640
+
641
+
642
+
643
+
644
+
645
+
555
646
 
556
647
 
557
648
 
@@ -621,6 +712,13 @@ export class BinaryIndexedTree implements Iterable<number> {
621
712
 
622
713
 
623
714
 
715
+
716
+
717
+
718
+
719
+
720
+
721
+
624
722
 
625
723
 
626
724