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
@@ -410,68 +410,26 @@ var _Trie = class _Trie extends IterableElementBase {
410
410
  return this._size;
411
411
  }
412
412
  /**
413
- * Insert one word into the trie.
414
- * @remarks Time O(L), Space O(L)
415
- * @param word - Word to insert.
416
- * @returns True if the word was newly added.
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
- * @example
460
- * // basic Trie creation and add words
461
- * // Create a simple Trie with initial words
462
- * const trie = new Trie(['apple', 'app', 'apply']);
463
- *
464
- * // Verify size
465
- * console.log(trie.size); // 3;
466
- *
467
- * // Check if words exist
468
- * console.log(trie.has('apple')); // true;
469
- * console.log(trie.has('app')); // true;
470
- *
471
- * // Add a new word
472
- * trie.add('application');
473
- * console.log(trie.size); // 4;
474
- */
413
+ * Insert one word into the trie.
414
+ * @remarks Time O(L), Space O(L)
415
+ * @param word - Word to insert.
416
+ * @returns True if the word was newly added.
417
+ * @example
418
+ * // basic Trie creation and add words
419
+ * // Create a simple Trie with initial words
420
+ * const trie = new Trie(['apple', 'app', 'apply']);
421
+ *
422
+ * // Verify size
423
+ * console.log(trie.size); // 3;
424
+ *
425
+ * // Check if words exist
426
+ * console.log(trie.has('apple')); // true;
427
+ * console.log(trie.has('app')); // true;
428
+ *
429
+ * // Add a new word
430
+ * trie.add('application');
431
+ * console.log(trie.size); // 4;
432
+ */
475
433
  add(word) {
476
434
  word = this._caseProcess(word);
477
435
  let cur = this.root;
@@ -492,57 +450,18 @@ var _Trie = class _Trie extends IterableElementBase {
492
450
  return isNewWord;
493
451
  }
494
452
  /**
495
- * Insert many words from an iterable.
496
- * @remarks Time O(ΣL), Space O(ΣL)
497
- * @param words - Iterable of strings (or raw records if toElementFn is provided).
498
- * @returns Array of per-word 'added' flags.
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
- * @example
539
- * // Add multiple words
540
- * const trie = new Trie();
541
- * trie.addMany(['cat', 'car', 'card']);
542
- * console.log(trie.has('cat')); // true;
543
- * console.log(trie.has('car')); // true;
544
- * console.log(trie.size); // 3;
545
- */
453
+ * Insert many words from an iterable.
454
+ * @remarks Time O(ΣL), Space O(ΣL)
455
+ * @param words - Iterable of strings (or raw records if toElementFn is provided).
456
+ * @returns Array of per-word 'added' flags.
457
+ * @example
458
+ * // Add multiple words
459
+ * const trie = new Trie();
460
+ * trie.addMany(['cat', 'car', 'card']);
461
+ * console.log(trie.has('cat')); // true;
462
+ * console.log(trie.has('car')); // true;
463
+ * console.log(trie.size); // 3;
464
+ */
546
465
  addMany(words) {
547
466
  const ans = [];
548
467
  for (const word of words) {
@@ -555,60 +474,18 @@ var _Trie = class _Trie extends IterableElementBase {
555
474
  return ans;
556
475
  }
557
476
  /**
558
- * Check whether a word exists.
559
- * @remarks Time O(L), Space O(1)
560
- * @param word - Word to search for.
561
- * @returns True if present.
562
-
563
-
564
-
565
-
566
-
567
-
568
-
569
-
570
-
571
-
572
-
573
-
574
-
575
-
576
-
577
-
578
-
579
-
580
-
581
-
582
-
583
-
584
-
585
-
586
-
587
-
588
-
589
-
590
-
591
-
592
-
593
-
594
-
595
-
596
-
597
-
598
-
599
-
600
-
601
-
602
-
603
-
604
- * @example
605
- * // Check if a word exists
606
- * const dict = new Trie(['apple', 'app', 'application']);
607
- *
608
- * console.log(dict.has('app')); // true;
609
- * console.log(dict.has('apple')); // true;
610
- * console.log(dict.has('ap')); // false;
611
- */
477
+ * Check whether a word exists.
478
+ * @remarks Time O(L), Space O(1)
479
+ * @param word - Word to search for.
480
+ * @returns True if present.
481
+ * @example
482
+ * // Check if a word exists
483
+ * const dict = new Trie(['apple', 'app', 'application']);
484
+ *
485
+ * console.log(dict.has('app')); // true;
486
+ * console.log(dict.has('apple')); // true;
487
+ * console.log(dict.has('ap')); // false;
488
+ */
612
489
  has(word) {
613
490
  word = this._caseProcess(word);
614
491
  let cur = this.root;
@@ -620,176 +497,56 @@ var _Trie = class _Trie extends IterableElementBase {
620
497
  return cur.isEnd;
621
498
  }
622
499
  /**
623
- * Check whether the trie is empty.
624
- * @remarks Time O(1), Space O(1)
625
- * @returns True if size is 0.
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
- * @example
666
- * // Check if empty
667
- * const trie = new Trie();
668
- * console.log(trie.isEmpty()); // true;
669
- * trie.add('word');
670
- * console.log(trie.isEmpty()); // false;
671
- */
500
+ * Check whether the trie is empty.
501
+ * @remarks Time O(1), Space O(1)
502
+ * @returns True if size is 0.
503
+ * @example
504
+ * // Check if empty
505
+ * const trie = new Trie();
506
+ * console.log(trie.isEmpty()); // true;
507
+ * trie.add('word');
508
+ * console.log(trie.isEmpty()); // false;
509
+ */
672
510
  isEmpty() {
673
511
  return this._size === 0;
674
512
  }
675
513
  /**
676
- * Remove all words and reset to a fresh root.
677
- * @remarks Time O(1), Space O(1)
678
- * @returns void
679
-
680
-
681
-
682
-
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
- * @example
719
- * // Remove all words
720
- * const trie = new Trie(['a', 'b', 'c']);
721
- * trie.clear();
722
- * console.log(trie.isEmpty()); // true;
723
- */
514
+ * Remove all words and reset to a fresh root.
515
+ * @remarks Time O(1), Space O(1)
516
+ * @returns void
517
+ * @example
518
+ * // Remove all words
519
+ * const trie = new Trie(['a', 'b', 'c']);
520
+ * trie.clear();
521
+ * console.log(trie.isEmpty()); // true;
522
+ */
724
523
  clear() {
725
524
  this._size = 0;
726
525
  this._root = new TrieNode("");
727
526
  }
728
527
  /**
729
- * Delete one word if present.
730
- * @remarks Time O(L), Space O(1)
731
- * @param word - Word to delete.
732
- * @returns True if a word was removed.
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
-
758
-
759
-
760
-
761
-
762
-
763
-
764
-
765
-
766
-
767
-
768
-
769
-
770
-
771
-
772
-
773
-
774
-
775
- * @example
776
- * // Trie delete and iteration
777
- * const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
778
- *
779
- * // Delete a word
780
- * trie.delete('card');
781
- * console.log(trie.has('card')); // false;
782
- *
783
- * // Word with same prefix still exists
784
- * console.log(trie.has('care')); // true;
785
- *
786
- * // Size decreased
787
- * console.log(trie.size); // 5;
788
- *
789
- * // Iterate through all words
790
- * const allWords = [...trie];
791
- * console.log(allWords.length); // 5;
792
- */
528
+ * Delete one word if present.
529
+ * @remarks Time O(L), Space O(1)
530
+ * @param word - Word to delete.
531
+ * @returns True if a word was removed.
532
+ * @example
533
+ * // Trie delete and iteration
534
+ * const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
535
+ *
536
+ * // Delete a word
537
+ * trie.delete('card');
538
+ * console.log(trie.has('card')); // false;
539
+ *
540
+ * // Word with same prefix still exists
541
+ * console.log(trie.has('care')); // true;
542
+ *
543
+ * // Size decreased
544
+ * console.log(trie.size); // 5;
545
+ *
546
+ * // Iterate through all words
547
+ * const allWords = [...trie];
548
+ * console.log(allWords.length); // 5;
549
+ */
793
550
  delete(word) {
794
551
  word = this._caseProcess(word);
795
552
  let isDeleted = false;
@@ -865,60 +622,18 @@ var _Trie = class _Trie extends IterableElementBase {
865
622
  return !cur.isEnd;
866
623
  }
867
624
  /**
868
- * Check whether any word starts with input.
869
- * @remarks Time O(L), Space O(1)
870
- * @param input - String to test as prefix.
871
- * @returns True if input matches a path from root.
872
-
873
-
874
-
875
-
876
-
877
-
878
-
879
-
880
-
881
-
882
-
883
-
884
-
885
-
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
- * @example
915
- * // Check if a prefix exists
916
- * const trie = new Trie(['hello', 'help', 'world']);
917
- *
918
- * console.log(trie.hasPrefix('hel')); // true;
919
- * console.log(trie.hasPrefix('wor')); // true;
920
- * console.log(trie.hasPrefix('xyz')); // false;
921
- */
625
+ * Check whether any word starts with input.
626
+ * @remarks Time O(L), Space O(1)
627
+ * @param input - String to test as prefix.
628
+ * @returns True if input matches a path from root.
629
+ * @example
630
+ * // Check if a prefix exists
631
+ * const trie = new Trie(['hello', 'help', 'world']);
632
+ *
633
+ * console.log(trie.hasPrefix('hel')); // true;
634
+ * console.log(trie.hasPrefix('wor')); // true;
635
+ * console.log(trie.hasPrefix('xyz')); // false;
636
+ */
922
637
  hasPrefix(input) {
923
638
  input = this._caseProcess(input);
924
639
  let cur = this.root;
@@ -949,57 +664,15 @@ var _Trie = class _Trie extends IterableElementBase {
949
664
  return commonPre === input;
950
665
  }
951
666
  /**
952
- * Return the longest common prefix among all words.
953
- * @remarks Time O(H), Space O(1)
954
- * @returns The longest common prefix string.
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
- * @example
998
- * // Find shared prefix
999
- * const trie = new Trie(['flower', 'flow', 'flight']);
1000
- *
1001
- * console.log(trie.getLongestCommonPrefix()); // 'fl';
1002
- */
667
+ * Return the longest common prefix among all words.
668
+ * @remarks Time O(H), Space O(1)
669
+ * @returns The longest common prefix string.
670
+ * @example
671
+ * // Find shared prefix
672
+ * const trie = new Trie(['flower', 'flow', 'flight']);
673
+ *
674
+ * console.log(trie.getLongestCommonPrefix()); // 'fl';
675
+ */
1003
676
  getLongestCommonPrefix() {
1004
677
  let commonPre = "";
1005
678
  const dfs = /* @__PURE__ */ __name((cur) => {
@@ -1012,66 +685,24 @@ var _Trie = class _Trie extends IterableElementBase {
1012
685
  return commonPre;
1013
686
  }
1014
687
  /**
1015
- * Collect words under a prefix up to a maximum count.
1016
- * @remarks Time O(K·L), Space O(K·L)
1017
- * @param [prefix] - Prefix to match; default empty string for root.
1018
- * @param [max] - Maximum number of words to return; default is Number.MAX_SAFE_INTEGER.
1019
- * @param [isAllWhenEmptyPrefix] - When true, collect from root even if prefix is empty.
1020
- * @returns Array of collected words (at most max).
1021
-
1022
-
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
- * @example
1064
- * // Trie getWords and prefix search
1065
- * const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
1066
- *
1067
- * // Get all words with prefix 'app'
1068
- * const appWords = trie.getWords('app');
1069
- * console.log(appWords); // contains 'app';
1070
- * console.log(appWords); // contains 'apple';
1071
- * console.log(appWords); // contains 'apply';
1072
- * console.log(appWords); // contains 'application';
1073
- * expect(appWords).not.toContain('apricot');
1074
- */
688
+ * Collect words under a prefix up to a maximum count.
689
+ * @remarks Time O(K·L), Space O(K·L)
690
+ * @param [prefix] - Prefix to match; default empty string for root.
691
+ * @param [max] - Maximum number of words to return; default is Number.MAX_SAFE_INTEGER.
692
+ * @param [isAllWhenEmptyPrefix] - When true, collect from root even if prefix is empty.
693
+ * @returns Array of collected words (at most max).
694
+ * @example
695
+ * // Trie getWords and prefix search
696
+ * const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
697
+ *
698
+ * // Get all words with prefix 'app'
699
+ * const appWords = trie.getWords('app');
700
+ * console.log(appWords); // contains 'app';
701
+ * console.log(appWords); // contains 'apple';
702
+ * console.log(appWords); // contains 'apply';
703
+ * console.log(appWords); // contains 'application';
704
+ * expect(appWords).not.toContain('apricot');
705
+ */
1075
706
  getWords(prefix = "", max = Number.MAX_SAFE_INTEGER, isAllWhenEmptyPrefix = false) {
1076
707
  prefix = this._caseProcess(prefix);
1077
708
  const words = [];
@@ -1102,111 +733,33 @@ var _Trie = class _Trie extends IterableElementBase {
1102
733
  return words;
1103
734
  }
1104
735
  /**
1105
- * Deep clone this trie by iterating and inserting all words.
1106
- * @remarks Time O(ΣL), Space O(ΣL)
1107
- * @returns A new trie with the same words and options.
1108
-
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
- * @example
1148
- * // Create independent copy
1149
- * const trie = new Trie(['hello', 'world']);
1150
- * const copy = trie.clone();
1151
- * copy.delete('hello');
1152
- * console.log(trie.has('hello')); // true;
1153
- */
736
+ * Deep clone this trie by iterating and inserting all words.
737
+ * @remarks Time O(ΣL), Space O(ΣL)
738
+ * @returns A new trie with the same words and options.
739
+ * @example
740
+ * // Create independent copy
741
+ * const trie = new Trie(['hello', 'world']);
742
+ * const copy = trie.clone();
743
+ * copy.delete('hello');
744
+ * console.log(trie.has('hello')); // true;
745
+ */
1154
746
  clone() {
1155
747
  const next = this._createInstance();
1156
748
  for (const x of this) next.add(x);
1157
749
  return next;
1158
750
  }
1159
751
  /**
1160
- * Filter words into a new trie of the same class.
1161
- * @remarks Time O(ΣL), Space O(ΣL)
1162
- * @param predicate - Predicate (word, index, trie) → boolean to keep word.
1163
- * @param [thisArg] - Value for `this` inside the predicate.
1164
- * @returns A new trie containing words that satisfy the predicate.
1165
-
1166
-
1167
-
1168
-
1169
-
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
- * @example
1205
- * // Filter words
1206
- * const trie = new Trie(['cat', 'car', 'dog', 'card']);
1207
- * const result = trie.filter(w => w.startsWith('ca'));
1208
- * console.log(result.size); // 3;
1209
- */
752
+ * Filter words into a new trie of the same class.
753
+ * @remarks Time O(ΣL), Space O(ΣL)
754
+ * @param predicate - Predicate (word, index, trie) → boolean to keep word.
755
+ * @param [thisArg] - Value for `this` inside the predicate.
756
+ * @returns A new trie containing words that satisfy the predicate.
757
+ * @example
758
+ * // Filter words
759
+ * const trie = new Trie(['cat', 'car', 'dog', 'card']);
760
+ * const result = trie.filter(w => w.startsWith('ca'));
761
+ * console.log(result.size); // 3;
762
+ */
1210
763
  filter(predicate, thisArg) {
1211
764
  const results = this._createInstance();
1212
765
  let index = 0;