data-structure-typed 2.6.0 → 2.6.2

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 (160) hide show
  1. package/.github/workflows/ci.yml +7 -2
  2. package/.github/workflows/release-package.yml +9 -2
  3. package/CHANGELOG.md +9 -1
  4. package/dist/cjs/binary-tree.cjs +2927 -23688
  5. package/dist/cjs/graph.cjs +845 -2634
  6. package/dist/cjs/hash.cjs +185 -616
  7. package/dist/cjs/heap.cjs +266 -818
  8. package/dist/cjs/index.cjs +5116 -31358
  9. package/dist/cjs/linked-list.cjs +644 -2615
  10. package/dist/cjs/matrix.cjs +220 -535
  11. package/dist/cjs/priority-queue.cjs +266 -818
  12. package/dist/cjs/queue.cjs +637 -2343
  13. package/dist/cjs/stack.cjs +124 -530
  14. package/dist/cjs/trie.cjs +145 -592
  15. package/dist/cjs-legacy/binary-tree.cjs +4352 -25113
  16. package/dist/cjs-legacy/graph.cjs +847 -2636
  17. package/dist/cjs-legacy/hash.cjs +181 -612
  18. package/dist/cjs-legacy/heap.cjs +266 -818
  19. package/dist/cjs-legacy/index.cjs +6657 -32899
  20. package/dist/cjs-legacy/linked-list.cjs +640 -2611
  21. package/dist/cjs-legacy/matrix.cjs +220 -535
  22. package/dist/cjs-legacy/priority-queue.cjs +266 -818
  23. package/dist/cjs-legacy/queue.cjs +634 -2340
  24. package/dist/cjs-legacy/stack.cjs +124 -530
  25. package/dist/cjs-legacy/trie.cjs +145 -592
  26. package/dist/esm/binary-tree.mjs +2927 -23688
  27. package/dist/esm/graph.mjs +845 -2634
  28. package/dist/esm/hash.mjs +185 -616
  29. package/dist/esm/heap.mjs +266 -818
  30. package/dist/esm/index.mjs +5116 -31358
  31. package/dist/esm/linked-list.mjs +644 -2615
  32. package/dist/esm/matrix.mjs +220 -535
  33. package/dist/esm/priority-queue.mjs +266 -818
  34. package/dist/esm/queue.mjs +637 -2343
  35. package/dist/esm/stack.mjs +124 -530
  36. package/dist/esm/trie.mjs +145 -592
  37. package/dist/esm-legacy/binary-tree.mjs +4352 -25113
  38. package/dist/esm-legacy/graph.mjs +847 -2636
  39. package/dist/esm-legacy/hash.mjs +181 -612
  40. package/dist/esm-legacy/heap.mjs +266 -818
  41. package/dist/esm-legacy/index.mjs +6657 -32899
  42. package/dist/esm-legacy/linked-list.mjs +640 -2611
  43. package/dist/esm-legacy/matrix.mjs +220 -535
  44. package/dist/esm-legacy/priority-queue.mjs +266 -818
  45. package/dist/esm-legacy/queue.mjs +634 -2340
  46. package/dist/esm-legacy/stack.mjs +124 -530
  47. package/dist/esm-legacy/trie.mjs +145 -592
  48. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +29 -500
  49. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +38 -563
  50. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +230 -1212
  51. package/dist/types/data-structures/binary-tree/bst.d.ts +124 -1063
  52. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +99 -854
  53. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +62 -314
  54. package/dist/types/data-structures/binary-tree/tree-map.d.ts +366 -5057
  55. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +277 -4885
  56. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +253 -3929
  57. package/dist/types/data-structures/binary-tree/tree-set.d.ts +261 -4782
  58. package/dist/types/data-structures/graph/abstract-graph.d.ts +44 -44
  59. package/dist/types/data-structures/graph/directed-graph.d.ts +130 -527
  60. package/dist/types/data-structures/graph/undirected-graph.d.ts +125 -482
  61. package/dist/types/data-structures/hash/hash-map.d.ts +132 -562
  62. package/dist/types/data-structures/heap/heap.d.ts +194 -746
  63. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +120 -809
  64. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -733
  65. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +193 -863
  66. package/dist/types/data-structures/matrix/matrix.d.ts +159 -474
  67. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -6
  68. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +6 -11
  69. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  70. package/dist/types/data-structures/queue/deque.d.ts +196 -804
  71. package/dist/types/data-structures/queue/queue.d.ts +99 -585
  72. package/dist/types/data-structures/stack/stack.d.ts +75 -481
  73. package/dist/types/data-structures/trie/trie.d.ts +98 -584
  74. package/dist/umd/data-structure-typed.js +6580 -32822
  75. package/dist/umd/data-structure-typed.min.js +3 -3
  76. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +162 -215
  77. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +9 -9
  78. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +47 -47
  79. package/docs-site-docusaurus/docs/api/classes/BST.md +155 -208
  80. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +7 -7
  81. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +13 -29
  82. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +104 -158
  83. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
  84. package/docs-site-docusaurus/docs/api/classes/Deque.md +253 -101
  85. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +60 -80
  86. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +244 -114
  87. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +6 -6
  88. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
  89. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
  90. package/docs-site-docusaurus/docs/api/classes/HashMap.md +52 -48
  91. package/docs-site-docusaurus/docs/api/classes/Heap.md +119 -64
  92. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +84 -14
  93. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +138 -34
  94. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +149 -41
  95. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +23 -23
  96. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +172 -92
  97. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +60 -80
  98. package/docs-site-docusaurus/docs/api/classes/Matrix.md +57 -52
  99. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +117 -62
  100. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +120 -70
  101. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +117 -62
  102. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +125 -75
  103. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +119 -64
  104. package/docs-site-docusaurus/docs/api/classes/Queue.md +158 -74
  105. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +171 -225
  106. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -22
  107. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +172 -94
  108. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +4 -4
  109. package/docs-site-docusaurus/docs/api/classes/SkipList.md +98 -75
  110. package/docs-site-docusaurus/docs/api/classes/Stack.md +112 -50
  111. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +104 -129
  112. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +90 -121
  113. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +298 -107
  114. package/docs-site-docusaurus/docs/api/classes/Trie.md +116 -58
  115. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
  116. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +59 -77
  117. package/package.json +45 -46
  118. package/src/common/error.ts +15 -32
  119. package/src/common/index.ts +0 -3
  120. package/src/data-structures/base/iterable-element-base.ts +0 -3
  121. package/src/data-structures/base/linear-base.ts +2 -36
  122. package/src/data-structures/binary-tree/avl-tree.ts +31 -529
  123. package/src/data-structures/binary-tree/binary-indexed-tree.ts +47 -572
  124. package/src/data-structures/binary-tree/binary-tree.ts +326 -1311
  125. package/src/data-structures/binary-tree/bst.ts +158 -1082
  126. package/src/data-structures/binary-tree/red-black-tree.ts +451 -1290
  127. package/src/data-structures/binary-tree/segment-tree.ts +73 -351
  128. package/src/data-structures/binary-tree/tree-map.ts +462 -5124
  129. package/src/data-structures/binary-tree/tree-multi-map.ts +302 -4914
  130. package/src/data-structures/binary-tree/tree-multi-set.ts +299 -3983
  131. package/src/data-structures/binary-tree/tree-set.ts +338 -4836
  132. package/src/data-structures/graph/abstract-graph.ts +98 -167
  133. package/src/data-structures/graph/directed-graph.ts +137 -562
  134. package/src/data-structures/graph/map-graph.ts +0 -3
  135. package/src/data-structures/graph/undirected-graph.ts +132 -511
  136. package/src/data-structures/hash/hash-map.ts +154 -582
  137. package/src/data-structures/heap/heap.ts +200 -795
  138. package/src/data-structures/linked-list/doubly-linked-list.ts +121 -865
  139. package/src/data-structures/linked-list/singly-linked-list.ts +122 -794
  140. package/src/data-structures/linked-list/skip-linked-list.ts +211 -918
  141. package/src/data-structures/matrix/matrix.ts +179 -518
  142. package/src/data-structures/matrix/navigator.ts +0 -1
  143. package/src/data-structures/priority-queue/max-priority-queue.ts +1 -6
  144. package/src/data-structures/priority-queue/min-priority-queue.ts +6 -11
  145. package/src/data-structures/priority-queue/priority-queue.ts +1 -2
  146. package/src/data-structures/queue/deque.ts +214 -882
  147. package/src/data-structures/queue/queue.ts +102 -625
  148. package/src/data-structures/stack/stack.ts +76 -505
  149. package/src/data-structures/trie/trie.ts +98 -628
  150. package/src/types/common.ts +0 -10
  151. package/src/types/data-structures/binary-tree/bst.ts +0 -7
  152. package/src/types/data-structures/binary-tree/red-black-tree.ts +0 -1
  153. package/src/types/data-structures/graph/abstract-graph.ts +0 -2
  154. package/src/types/data-structures/hash/hash-map.ts +0 -3
  155. package/src/types/data-structures/hash/index.ts +0 -1
  156. package/src/types/data-structures/matrix/navigator.ts +0 -2
  157. package/src/types/utils/utils.ts +0 -7
  158. package/src/types/utils/validate-type.ts +0 -7
  159. package/src/utils/number.ts +0 -2
  160. package/src/utils/utils.ts +0 -5
@@ -245,6 +245,13 @@ export declare class BSTNode<K = any, V = any> {
245
245
  * console.log(findLCA(20, 30)); // 25;
246
246
  */
247
247
  export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implements IBinaryTree<K, V, R> {
248
+ protected _enableOrderStatistic: boolean;
249
+ /**
250
+ * The comparator function used to determine the order of keys in the tree.
251
+
252
+ * @remarks Time O(1) Space O(1)
253
+ */
254
+ protected readonly _comparator: Comparator<K>;
248
255
  /**
249
256
  * Creates an instance of BST.
250
257
  * @remarks Time O(N log N) or O(N^2) depending on `isBalanceAdd` in `addMany` and input order. Space O(N).
@@ -254,7 +261,6 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
254
261
  */
255
262
  constructor(keysNodesEntriesOrRaws?: Iterable<K | BSTNode | [K | null | undefined, V | undefined] | null | undefined | R>, options?: BSTOptions<K, V, R>);
256
263
  protected _root?: BSTNode<K, V>;
257
- protected _enableOrderStatistic: boolean;
258
264
  /**
259
265
  * Gets the root node of the tree.
260
266
  * @remarks Time O(1)
@@ -262,12 +268,6 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
262
268
  * @returns The root node.
263
269
  */
264
270
  get root(): OptNode<BSTNode<K, V>>;
265
- /**
266
- * The comparator function used to determine the order of keys in the tree.
267
-
268
- * @remarks Time O(1) Space O(1)
269
- */
270
- protected readonly _comparator: Comparator<K>;
271
271
  /**
272
272
  * Gets the comparator function used by the tree.
273
273
  * @remarks Time O(1)
@@ -310,275 +310,36 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
310
310
  */
311
311
  isValidKey(key: unknown): key is K;
312
312
  /**
313
- * Depth-first search traversal
314
-
315
-
316
-
317
-
318
-
319
-
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
-
328
-
329
-
330
-
331
-
332
-
333
-
334
-
335
-
336
-
337
-
338
-
339
-
340
-
341
-
342
-
343
-
344
-
345
-
346
-
347
-
348
-
349
-
350
-
351
-
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
-
360
-
361
-
362
-
363
-
364
-
365
-
366
-
367
-
368
-
369
-
370
-
371
-
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
-
398
- * @example
399
- * // Depth-first traversal
400
- * const bst = new BST<number>([5, 3, 7, 1, 4]);
401
- * const inOrder = bst.dfs(node => node.key, 'IN');
402
- * console.log(inOrder); // [1, 3, 4, 5, 7];
403
- */
313
+ * Depth-first search traversal
314
+ * @example
315
+ * // Depth-first traversal
316
+ * const bst = new BST<number>([5, 3, 7, 1, 4]);
317
+ * const inOrder = bst.dfs(node => node.key, 'IN');
318
+ * console.log(inOrder); // [1, 3, 4, 5, 7];
319
+ */
404
320
  dfs(): (K | undefined)[];
405
321
  dfs<C extends NodeCallback<BSTNode<K, V>>>(callback: C, pattern?: DFSOrderPattern, onlyOne?: boolean, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
406
322
  /**
407
- * BinaryTree level-order traversal
408
-
409
-
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
-
422
-
423
-
424
-
425
-
426
-
427
-
428
-
429
-
430
-
431
-
432
-
433
-
434
-
435
-
436
-
437
-
438
-
439
-
440
-
441
-
442
-
443
-
444
-
445
-
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-
459
-
460
-
461
-
462
-
463
-
464
-
465
-
466
-
467
-
468
-
469
-
470
-
471
-
472
-
473
-
474
-
475
-
476
-
477
-
478
-
479
-
480
-
481
-
482
-
483
-
484
- * @example
485
- * // Breadth-first traversal
486
- * const bst = new BST<number>([5, 3, 7]);
487
- * const result = bst.bfs(node => node.key);
488
- * console.log(result.length); // 3;
489
- */
323
+ * BinaryTree level-order traversal
324
+ * @example
325
+ * // Breadth-first traversal
326
+ * const bst = new BST<number>([5, 3, 7]);
327
+ * const result = bst.bfs(node => node.key);
328
+ * console.log(result.length); // 3;
329
+ */
490
330
  bfs(): (K | undefined)[];
491
331
  bfs<C extends NodeCallback<BSTNode<K, V>>>(callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
492
332
  /**
493
- * Level-order grouping
494
-
495
-
496
-
497
-
498
-
499
-
500
-
501
-
502
-
503
-
504
-
505
-
506
-
507
-
508
-
509
-
510
-
511
-
512
-
513
-
514
-
515
-
516
-
517
-
518
-
519
-
520
-
521
-
522
-
523
-
524
-
525
-
526
-
527
-
528
-
529
-
530
-
531
-
532
-
533
-
534
-
535
-
536
-
537
-
538
-
539
-
540
-
541
-
542
-
543
-
544
-
545
-
546
-
547
-
548
-
549
-
550
-
551
-
552
-
553
-
554
-
555
-
556
-
557
-
558
-
559
-
560
-
561
-
562
-
563
-
564
-
565
-
566
-
567
-
568
-
569
-
570
-
571
-
572
-
573
- * @example
574
- * // Level-order grouping
575
- * const bst = new BST<number>([5, 3, 7, 1, 4]);
576
- * const levels = bst.listLevels(node => node.key);
577
- * console.log(levels); // toBeInstanceOf;
578
- * console.log(levels[0].length); // 1; // root level has 1 node
579
- * const allKeys = levels.flat().sort((a, b) => a - b);
580
- * console.log(allKeys); // [1, 3, 4, 5, 7];
581
- */
333
+ * Level-order grouping
334
+ * @example
335
+ * // Level-order grouping
336
+ * const bst = new BST<number>([5, 3, 7, 1, 4]);
337
+ * const levels = bst.listLevels(node => node.key);
338
+ * console.log(levels); // toBeInstanceOf;
339
+ * console.log(levels[0].length); // 1; // root level has 1 node
340
+ * const allKeys = levels.flat().sort((a, b) => a - b);
341
+ * console.log(allKeys); // [1, 3, 4, 5, 7];
342
+ */
582
343
  listLevels(): (K | undefined)[][];
583
344
  listLevels<C extends NodeCallback<BSTNode<K, V>>>(callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[][];
584
345
  /**
@@ -589,228 +350,40 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
589
350
  * @param [startNode=this._root] - The node to start the search from.
590
351
  * @param [iterationType=this.iterationType] - The traversal method.
591
352
  * @returns The first matching node, or undefined if not found.
592
-
593
-
594
-
595
-
596
-
597
-
598
-
599
-
600
-
601
-
602
-
603
-
604
-
605
-
606
-
607
-
608
-
609
-
610
-
611
-
612
-
613
-
614
-
615
-
616
-
617
-
618
-
619
-
620
-
621
-
622
-
623
-
624
-
625
-
626
-
627
-
628
-
629
-
630
-
631
-
632
-
633
-
634
-
635
-
636
-
637
-
638
-
639
-
640
-
641
-
642
-
643
-
644
-
645
-
646
-
647
-
648
-
649
-
650
-
651
-
652
-
653
-
654
-
655
-
656
-
657
-
658
-
659
-
660
-
661
-
662
-
663
-
664
-
665
-
666
-
667
-
668
-
669
-
670
-
671
-
672
-
673
- * @example
674
- * // Get node object by key
675
- * const bst = new BST<number, string>([[5, 'root'], [3, 'left'], [7, 'right']]);
676
- * const node = bst.getNode(3);
677
- * console.log(node?.key); // 3;
678
- * console.log(node?.value); // 'left';
353
+ * @example
354
+ * // Get node object by key
355
+ * const bst = new BST<number, string>([
356
+ * [5, 'root'],
357
+ * [3, 'left'],
358
+ * [7, 'right']
359
+ * ]);
360
+ * const node = bst.getNode(3);
361
+ * console.log(node?.key); // 3;
362
+ * console.log(node?.value); // 'left';
679
363
  */
680
364
  getNode(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>, startNode?: BSTNOptKeyOrNode<K, BSTNode<K, V>>, iterationType?: IterationType): OptNode<BSTNode<K, V>>;
681
365
  /**
682
- * Search nodes by predicate
683
-
684
-
685
-
686
-
687
-
688
-
689
-
690
-
691
-
692
-
693
-
694
-
695
-
696
-
697
-
698
-
699
-
700
-
701
-
702
-
703
-
704
-
705
-
706
-
707
-
708
-
709
-
710
-
711
-
712
-
713
-
714
-
715
-
716
-
717
-
718
-
719
-
720
-
721
-
722
-
723
-
724
-
725
-
726
-
727
-
728
-
729
-
730
-
731
-
732
-
733
-
734
-
735
-
736
-
737
-
738
-
739
-
740
-
741
-
742
-
743
-
744
-
745
-
746
-
747
-
748
-
749
-
750
-
751
-
752
-
753
-
754
-
755
-
756
-
757
- * @example
758
- * // Search nodes by predicate
759
- * const bst = new BST<number, string>([[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd']]);
760
- * const found = bst.search(node => node.key > 2, true);
761
- * console.log(found.length); // >= 1;
762
- */
366
+ * Search nodes by predicate
367
+ * @example
368
+ * // Search nodes by predicate
369
+ * const bst = new BST<number, string>([
370
+ * [1, 'a'],
371
+ * [2, 'b'],
372
+ * [3, 'c'],
373
+ * [4, 'd']
374
+ * ]);
375
+ * const found = bst.search(node => node.key > 2, true);
376
+ * console.log(found.length); // >= 1;
377
+ */
763
378
  search(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne?: boolean): (K | undefined)[];
764
379
  search<C extends NodeCallback<BSTNode<K, V>>>(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>> | Range<K>, onlyOne: boolean, callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
765
380
  /**
766
- * Find all keys in a range
767
-
768
-
769
-
770
-
771
-
772
-
773
-
774
-
775
-
776
-
777
-
778
-
779
-
780
-
781
-
782
-
783
-
784
-
785
-
786
-
787
-
788
-
789
-
790
-
791
-
792
-
793
-
794
-
795
-
796
-
797
-
798
-
799
-
800
-
801
-
802
-
803
-
804
-
805
-
806
-
807
-
808
-
809
- * @example
810
- * // Find all keys in a range
811
- * const bst = new BST<number>([10, 20, 30, 40, 50]);
812
- * console.log(bst.rangeSearch([15, 35])); // [20, 30];
813
- */
381
+ * Find all keys in a range
382
+ * @example
383
+ * // Find all keys in a range
384
+ * const bst = new BST<number>([10, 20, 30, 40, 50]);
385
+ * console.log(bst.rangeSearch([15, 35])); // [20, 30];
386
+ */
814
387
  rangeSearch(range: Range<K> | [K, K]): (K | undefined)[];
815
388
  rangeSearch<C extends NodeCallback<BSTNode<K, V>>>(range: Range<K> | [K, K], callback: C, startNode?: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, iterationType?: IterationType): ReturnType<C>[];
816
389
  /**
@@ -820,12 +393,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
820
393
  *
821
394
  * @param k - The 0-based position in tree order (0 = first element).
822
395
  * @returns The key at position k, or `undefined` if out of bounds.
823
- * @example
824
- * // Order-statistic on BST
825
- * const tree = new BST<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
826
- * console.log(tree.getByRank(0)); // 10;
827
- * console.log(tree.getByRank(4)); // 50;
828
- * console.log(tree.getRank(30)); // 2;
396
+ * @example
397
+ * // Order-statistic on BST
398
+ * const tree = new BST<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
399
+ * console.log(tree.getByRank(0)); // 10;
400
+ * console.log(tree.getByRank(4)); // 50;
401
+ * console.log(tree.getRank(30)); // 2;
829
402
  */
830
403
  getByRank(k: number): K | undefined;
831
404
  /**
@@ -883,130 +456,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
883
456
  * @param keyNodeOrEntry - The key, node, or entry to set.
884
457
  * @param [value] - The value, if providing just a key.
885
458
  * @returns True if the addition was successful, false otherwise.
886
-
887
-
888
-
889
-
890
-
891
-
892
-
893
-
894
-
895
-
896
-
897
-
898
-
899
-
900
-
901
-
902
-
903
-
904
-
905
-
906
-
907
-
908
-
909
-
910
-
911
-
912
-
913
-
914
-
915
-
916
-
917
-
918
-
919
-
920
-
921
-
922
-
923
-
924
-
925
-
926
-
927
-
928
-
929
-
930
-
931
-
932
-
933
-
934
-
935
-
936
-
937
-
938
-
939
-
940
-
941
-
942
-
943
-
944
-
945
-
946
-
947
-
948
-
949
-
950
-
951
-
952
-
953
-
954
-
955
-
956
-
957
-
958
-
959
-
960
-
961
-
962
-
963
-
964
-
965
-
966
-
967
-
968
-
969
-
970
-
971
-
972
-
973
-
974
-
975
-
976
-
977
-
978
-
979
-
980
-
981
-
982
-
983
-
984
-
985
-
986
-
987
-
988
-
989
-
990
-
991
-
992
-
993
-
994
-
995
-
996
-
997
-
998
-
999
-
1000
-
1001
-
1002
-
1003
-
1004
- * @example
1005
- * // Set a key-value pair
1006
- * const bst = new BST<number, string>();
1007
- * bst.set(1, 'one');
1008
- * bst.set(2, 'two');
1009
- * console.log(bst.get(1)); // 'one';
459
+ * @example
460
+ * // Set a key-value pair
461
+ * const bst = new BST<number, string>();
462
+ * bst.set(1, 'one');
463
+ * bst.set(2, 'two');
464
+ * console.log(bst.get(1)); // 'one';
1010
465
  */
1011
466
  set(keyNodeOrEntry: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V): boolean;
1012
467
  /**
@@ -1020,85 +475,16 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
1020
475
  * @param [isBalanceAdd=true] - If true, builds a balanced tree from the items.
1021
476
  * @param [iterationType=this.iterationType] - The traversal method for balanced set (recursive or iterative).
1022
477
  * @returns An array of booleans indicating the success of each individual `set` operation.
1023
-
1024
-
1025
-
1026
-
1027
-
1028
-
1029
-
1030
-
1031
-
1032
-
1033
-
1034
-
1035
-
1036
-
1037
-
1038
-
1039
-
1040
-
1041
-
1042
-
1043
-
1044
-
1045
-
1046
-
1047
-
1048
-
1049
-
1050
-
1051
-
1052
-
1053
-
1054
-
1055
-
1056
-
1057
-
1058
-
1059
-
1060
-
1061
-
1062
-
1063
-
1064
-
1065
-
1066
-
1067
-
1068
-
1069
-
1070
-
1071
-
1072
-
1073
-
1074
-
1075
-
1076
-
1077
-
1078
-
1079
-
1080
-
1081
-
1082
-
1083
-
1084
-
1085
-
1086
-
1087
-
1088
-
1089
-
1090
-
1091
-
1092
-
1093
-
1094
-
1095
-
1096
- * @example
1097
- * // Set multiple key-value pairs
1098
- * const bst = new BST<number, string>();
1099
- * bst.setMany([[1, 'a'], [2, 'b'], [3, 'c']]);
1100
- * console.log(bst.size); // 3;
1101
- * console.log(bst.get(2)); // 'b';
478
+ * @example
479
+ * // Set multiple key-value pairs
480
+ * const bst = new BST<number, string>();
481
+ * bst.setMany([
482
+ * [1, 'a'],
483
+ * [2, 'b'],
484
+ * [3, 'c']
485
+ * ]);
486
+ * console.log(bst.size); // 3;
487
+ * console.log(bst.get(2)); // 'b';
1102
488
  */
1103
489
  setMany(keysNodesEntriesOrRaws: Iterable<R | BTNRep<K, V, BSTNode<K, V>>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): boolean[];
1104
490
  /**
@@ -1106,54 +492,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
1106
492
  * Equivalent to Java TreeMap.ceiling.
1107
493
  * Time Complexity: O(log n) average, O(h) worst case.
1108
494
  * Space Complexity: O(h) for recursion, O(1) for iteration.
1109
-
1110
-
1111
-
1112
-
1113
-
1114
-
1115
-
1116
-
1117
-
1118
-
1119
-
1120
-
1121
-
1122
-
1123
-
1124
-
1125
-
1126
-
1127
-
1128
-
1129
-
1130
-
1131
-
1132
-
1133
-
1134
-
1135
-
1136
-
1137
-
1138
-
1139
-
1140
-
1141
-
1142
-
1143
-
1144
-
1145
-
1146
-
1147
-
1148
-
1149
-
1150
-
1151
- * @example
1152
- * // Find the least key ≥ target
1153
- * const bst = new BST<number>([10, 20, 30, 40, 50]);
1154
- * console.log(bst.ceiling(25)); // 30;
1155
- * console.log(bst.ceiling(30)); // 30;
1156
- * console.log(bst.ceiling(55)); // undefined;
495
+ * @example
496
+ * // Find the least key ≥ target
497
+ * const bst = new BST<number>([10, 20, 30, 40, 50]);
498
+ * console.log(bst.ceiling(25)); // 30;
499
+ * console.log(bst.ceiling(30)); // 30;
500
+ * console.log(bst.ceiling(55)); // undefined;
1157
501
  */
1158
502
  ceiling(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): K | undefined;
1159
503
  /**
@@ -1167,53 +511,11 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
1167
511
  * Equivalent to Java TreeMap.higher.
1168
512
  * Time Complexity: O(log n) average, O(h) worst case.
1169
513
  * Space Complexity: O(h) for recursion, O(1) for iteration.
1170
-
1171
-
1172
-
1173
-
1174
-
1175
-
1176
-
1177
-
1178
-
1179
-
1180
-
1181
-
1182
-
1183
-
1184
-
1185
-
1186
-
1187
-
1188
-
1189
-
1190
-
1191
-
1192
-
1193
-
1194
-
1195
-
1196
-
1197
-
1198
-
1199
-
1200
-
1201
-
1202
-
1203
-
1204
-
1205
-
1206
-
1207
-
1208
-
1209
-
1210
-
1211
-
1212
- * @example
1213
- * // Find the least key strictly > target
1214
- * const bst = new BST<number>([10, 20, 30, 40]);
1215
- * console.log(bst.higher(20)); // 30;
1216
- * console.log(bst.higher(40)); // undefined;
514
+ * @example
515
+ * // Find the least key strictly > target
516
+ * const bst = new BST<number>([10, 20, 30, 40]);
517
+ * console.log(bst.higher(20)); // 30;
518
+ * console.log(bst.higher(40)); // undefined;
1217
519
  */
1218
520
  higher(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): K | undefined;
1219
521
  /**
@@ -1227,54 +529,12 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
1227
529
  * Equivalent to Java TreeMap.floor.
1228
530
  * Time Complexity: O(log n) average, O(h) worst case.
1229
531
  * Space Complexity: O(h) for recursion, O(1) for iteration.
1230
-
1231
-
1232
-
1233
-
1234
-
1235
-
1236
-
1237
-
1238
-
1239
-
1240
-
1241
-
1242
-
1243
-
1244
-
1245
-
1246
-
1247
-
1248
-
1249
-
1250
-
1251
-
1252
-
1253
-
1254
-
1255
-
1256
-
1257
-
1258
-
1259
-
1260
-
1261
-
1262
-
1263
-
1264
-
1265
-
1266
-
1267
-
1268
-
1269
-
1270
-
1271
-
1272
- * @example
1273
- * // Find the greatest key ≤ target
1274
- * const bst = new BST<number>([10, 20, 30, 40, 50]);
1275
- * console.log(bst.floor(25)); // 20;
1276
- * console.log(bst.floor(10)); // 10;
1277
- * console.log(bst.floor(5)); // undefined;
532
+ * @example
533
+ * // Find the greatest key ≤ target
534
+ * const bst = new BST<number>([10, 20, 30, 40, 50]);
535
+ * console.log(bst.floor(25)); // 20;
536
+ * console.log(bst.floor(10)); // 10;
537
+ * console.log(bst.floor(5)); // undefined;
1278
538
  */
1279
539
  floor(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): K | undefined;
1280
540
  /**
@@ -1288,53 +548,11 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
1288
548
  * Equivalent to Java TreeMap.lower.
1289
549
  * Time Complexity: O(log n) average, O(h) worst case.
1290
550
  * Space Complexity: O(h) for recursion, O(1) for iteration.
1291
-
1292
-
1293
-
1294
-
1295
-
1296
-
1297
-
1298
-
1299
-
1300
-
1301
-
1302
-
1303
-
1304
-
1305
-
1306
-
1307
-
1308
-
1309
-
1310
-
1311
-
1312
-
1313
-
1314
-
1315
-
1316
-
1317
-
1318
-
1319
-
1320
-
1321
-
1322
-
1323
-
1324
-
1325
-
1326
-
1327
-
1328
-
1329
-
1330
-
1331
-
1332
-
1333
- * @example
1334
- * // Find the greatest key strictly < target
1335
- * const bst = new BST<number>([10, 20, 30, 40]);
1336
- * console.log(bst.lower(30)); // 20;
1337
- * console.log(bst.lower(10)); // undefined;
551
+ * @example
552
+ * // Find the greatest key strictly < target
553
+ * const bst = new BST<number>([10, 20, 30, 40]);
554
+ * console.log(bst.lower(30)); // 20;
555
+ * console.log(bst.lower(10)); // undefined;
1338
556
  */
1339
557
  lower(keyNodeEntryOrPredicate: K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>): K | undefined;
1340
558
  /**
@@ -1351,54 +569,14 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
1351
569
  *
1352
570
  * @param [iterationType=this.iterationType] - The traversal method for the initial node export.
1353
571
  * @returns True if successful, false if the tree was empty.
1354
-
1355
-
1356
-
1357
-
1358
-
1359
-
1360
-
1361
-
1362
-
1363
-
1364
-
1365
-
1366
-
1367
-
1368
-
1369
-
1370
-
1371
-
1372
-
1373
-
1374
-
1375
-
1376
-
1377
-
1378
-
1379
-
1380
-
1381
-
1382
-
1383
-
1384
-
1385
-
1386
-
1387
-
1388
-
1389
-
1390
-
1391
-
1392
-
1393
-
1394
- * @example
1395
- * // Rebalance the tree
1396
- * const bst = new BST<number>();
1397
- * // Insert in sorted order (worst case for BST)
1398
- * for (let i = 1; i <= 7; i++) bst.add(i);
1399
- * console.log(bst.isAVLBalanced()); // false;
1400
- * bst.perfectlyBalance();
1401
- * console.log(bst.isAVLBalanced()); // true;
572
+ * @example
573
+ * // Rebalance the tree
574
+ * const bst = new BST<number>();
575
+ * // Insert in sorted order (worst case for BST)
576
+ * for (let i = 1; i <= 7; i++) bst.add(i);
577
+ * console.log(bst.isAVLBalanced()); // false;
578
+ * bst.perfectlyBalance();
579
+ * console.log(bst.isAVLBalanced()); // true;
1402
580
  */
1403
581
  perfectlyBalance(iterationType?: IterationType): boolean;
1404
582
  /**
@@ -1407,50 +585,10 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
1407
585
  *
1408
586
  * @param [iterationType=this.iterationType] - The traversal method.
1409
587
  * @returns True if the tree is AVL balanced, false otherwise.
1410
-
1411
-
1412
-
1413
-
1414
-
1415
-
1416
-
1417
-
1418
-
1419
-
1420
-
1421
-
1422
-
1423
-
1424
-
1425
-
1426
-
1427
-
1428
-
1429
-
1430
-
1431
-
1432
-
1433
-
1434
-
1435
-
1436
-
1437
-
1438
-
1439
-
1440
-
1441
-
1442
-
1443
-
1444
-
1445
-
1446
-
1447
-
1448
-
1449
-
1450
- * @example
1451
- * // Check if tree is height-balanced
1452
- * const bst = new BST<number>([3, 1, 5, 2, 4]);
1453
- * console.log(bst.isAVLBalanced()); // true;
588
+ * @example
589
+ * // Check if tree is height-balanced
590
+ * const bst = new BST<number>([3, 1, 5, 2, 4]);
591
+ * console.log(bst.isAVLBalanced()); // true;
1454
592
  */
1455
593
  isAVLBalanced(iterationType?: IterationType): boolean;
1456
594
  /**
@@ -1465,92 +603,15 @@ export declare class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R>
1465
603
  * @param [options] - Options for the new BST.
1466
604
  * @param [thisArg] - `this` context for the callback.
1467
605
  * @returns A new, mapped BST.
1468
-
1469
-
1470
-
1471
-
1472
-
1473
-
1474
-
1475
-
1476
-
1477
-
1478
-
1479
-
1480
-
1481
-
1482
-
1483
-
1484
-
1485
-
1486
-
1487
-
1488
-
1489
-
1490
-
1491
-
1492
-
1493
-
1494
-
1495
-
1496
-
1497
-
1498
-
1499
-
1500
-
1501
-
1502
-
1503
-
1504
-
1505
-
1506
-
1507
-
1508
-
1509
-
1510
-
1511
-
1512
-
1513
-
1514
-
1515
-
1516
-
1517
-
1518
-
1519
-
1520
-
1521
-
1522
-
1523
-
1524
-
1525
-
1526
-
1527
-
1528
-
1529
-
1530
-
1531
-
1532
-
1533
-
1534
-
1535
-
1536
-
1537
-
1538
-
1539
-
1540
-
1541
-
1542
-
1543
-
1544
-
1545
-
1546
-
1547
-
1548
-
1549
- * @example
1550
- * // Transform to new tree
1551
- * const bst = new BST<number, number>([[1, 10], [2, 20], [3, 30]]);
1552
- * const doubled = bst.map((value, key) => [key, (value ?? 0) * 2] as [number, number]);
1553
- * console.log([...doubled.values()]); // [20, 40, 60];
606
+ * @example
607
+ * // Transform to new tree
608
+ * const bst = new BST<number, number>([
609
+ * [1, 10],
610
+ * [2, 20],
611
+ * [3, 30]
612
+ * ]);
613
+ * const doubled = bst.map((value, key) => [key, (value ?? 0) * 2] as [number, number]);
614
+ * console.log([...doubled.values()]); // [20, 40, 60];
1554
615
  */
1555
616
  map<MK = K, MV = V, MR = any>(callback: EntryCallback<K, V | undefined, [MK, MV]>, options?: Partial<BSTOptions<MK, MV, MR>>, thisArg?: unknown): BST<MK, MV, MR>;
1556
617
  /**