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