typescript-dsa-stl 2.8.0 → 2.9.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.
package/README.md CHANGED
@@ -18,7 +18,7 @@ STL-style data structures and algorithms for TypeScript: **Vector**, **Stack**,
18
18
  | [Collections](#collections) | Deque, nested vectors, multi-map / multi-set |
19
19
  | [Segment trees](#segment-trees) | Overview, variants, and examples (one section) |
20
20
  | [Graph algorithms](#graph-algorithms) | Adjacency lists, BFS/DFS, topological sort, components, MST, shortest paths |
21
- | [String algorithms](#string-algorithms) | KMP, Rabin–Karp, rolling hash |
21
+ | [String algorithms](#string-algorithms) | KMP, Rabin–Karp, Trie, rolling hash |
22
22
  | [For maintainers](#for-maintainers) | Build and publish |
23
23
  | [License](#license) | MIT |
24
24
 
@@ -49,6 +49,7 @@ import {
49
49
  topologicalSortIndegree,
50
50
  KnuthMorrisPratt,
51
51
  RabinKarp,
52
+ Trie,
52
53
  StringRollingHash,
53
54
  } from 'typescript-dsa-stl/algorithms';
54
55
  import { clamp, range } from 'typescript-dsa-stl/utils';
@@ -166,7 +167,7 @@ range(0, 5); // [0, 1, 2, 3, 4]
166
167
  | Area | Exports |
167
168
  |------|---------|
168
169
  | **Collections** | `Vector`, `Stack`, `Queue`, `Deque`, `List`, `ListNode`, `PriorityQueue`, `OrderedMap`, `UnorderedMap`, `OrderedSet`, `UnorderedSet`, `OrderedMultiMap`, `OrderedMultiSet`, `GeneralSegmentTree`, `SegmentTree`, `SegmentTreeSum`, `SegmentTreeMin`, `SegmentTreeMax`, `LazySegmentTreeSum`, `WeightedEdge`, `AdjacencyList`, `WeightedAdjacencyList`, `createAdjacencyList`, `createWeightedAdjacencyList`, `addEdge`, `deleteEdge` |
169
- | **Algorithms** | `sort`, `find`, `findIndex`, `transform`, `filter`, `reduce`, `reverse`, `unique`, `binarySearch`, `lowerBound`, `upperBound`, `min`, `max`, `partition`, `DisjointSetUnion`, `KnuthMorrisPratt`, `RabinKarp`, `RABIN_KARP_DEFAULT_MODS`, `StringRollingHash`, `breadthFirstSearch`, `depthFirstSearch`, `topologicalSortStack`, `topologicalSortIndegree`, `connectedComponents`, `kruskalMST`, `dijkstra`, `reconstructPath` |
170
+ | **Algorithms** | `sort`, `find`, `findIndex`, `transform`, `filter`, `reduce`, `reverse`, `unique`, `binarySearch`, `lowerBound`, `upperBound`, `min`, `max`, `partition`, `DisjointSetUnion`, `KnuthMorrisPratt`, `RabinKarp`, `Trie`, `RABIN_KARP_DEFAULT_MODS`, `StringRollingHash`, `breadthFirstSearch`, `depthFirstSearch`, `topologicalSortStack`, `topologicalSortIndegree`, `connectedComponents`, `kruskalMST`, `dijkstra`, `reconstructPath` |
170
171
  | **Utils** | `clamp`, `range`, `noop`, `identity`, `swap` |
171
172
  | **Types** | `Comparator`, `Predicate`, `UnaryFn`, `Reducer`, `IterableLike`, `toArray`, `RabinKarpTripleMods`, `WeightedUndirectedEdge`, `TopologicalSortResult`, `GeneralSegmentTreeConfig`, `SegmentCombine`, `SegmentMerge`, `SegmentLeafBuild` |
172
173
 
@@ -174,7 +175,7 @@ range(0, 5); // [0, 1, 2, 3, 4]
174
175
 
175
176
  ```ts
176
177
  import { Vector, Stack, Queue, Deque } from 'typescript-dsa-stl/collections';
177
- import { sort, binarySearch, breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, KnuthMorrisPratt, RabinKarp, StringRollingHash } from 'typescript-dsa-stl/algorithms';
178
+ import { sort, binarySearch, breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, KnuthMorrisPratt, RabinKarp, Trie, StringRollingHash } from 'typescript-dsa-stl/algorithms';
178
179
  import { clamp, range } from 'typescript-dsa-stl/utils';
179
180
  import type { Comparator } from 'typescript-dsa-stl/types';
180
181
  ```
@@ -890,9 +891,9 @@ console.log(path); // [0, 1, 2, 4]
890
891
 
891
892
  ## String algorithms
892
893
 
893
- ### Knuth–Morris–Pratt (KMP), Rabin–Karp, and string rolling hash
894
+ ### Knuth–Morris–Pratt (KMP), Rabin–Karp, Trie, and string rolling hash
894
895
 
895
- All three work on **UTF-16 code units** (same as `String` indexing). They solve **different jobs**: KMP and Rabin–Karp are **pattern matchers** (list all start indices of a pattern in a text). `StringRollingHash` is a **substring-hash tool** on a **fixed** string—you combine it with your own logic (equality checks, binary search, etc.).
896
+ All four work on **UTF-16 code units** (same as `String` indexing). KMP and Rabin–Karp are **pattern matchers** (list all start indices of a pattern in a text). `Trie` is a **prefix tree** for fast dictionary operations (`insert`, exact word lookup, prefix lookup, deletion). `StringRollingHash` is a **substring-hash tool** on a **fixed** string—you combine it with your own logic (equality checks, binary search, etc.).
896
897
 
897
898
  #### When to use which
898
899
 
@@ -900,16 +901,18 @@ All three work on **UTF-16 code units** (same as `String` indexing). They solve
900
901
  |------|--------|-----|
901
902
  | **Find every occurrence** of **one pattern** in **one text**, with **worst-case** O(n + m), **no hashing**, predictable behaviour | **KnuthMorrisPratt** | LPS table; only character comparisons; no modular arithmetic. |
902
903
  | **Find every occurrence** of a pattern using a **sliding window** and **hashes** (triple moduli + final verify) | **RabinKarp** | Same asymptotic average case; good when you think in rolling hashes or batch **same-length** patterns. |
904
+ | **Maintain a dynamic dictionary** of words and answer **exact / prefix** queries efficiently | **Trie** | Insert/search/prefix in O(L) where L is key length; natural fit for autocomplete and prefix filtering. |
903
905
  | **Many O(1) hash queries** on **substrings of one string** you already hold (compare two ranges, palindrome / LCP style checks, rolling checks without slicing) | **StringRollingHash** | O(n) preprocess, O(1) per `substringHash`; **not** a drop-in “find all matches” API—use KMP or Rabin–Karp for that. |
904
906
 
905
907
  **Concrete situations**
906
908
 
907
909
  - **Use KMP** when you need a **guaranteed** linear scan (interviews, strict time bounds, large alphabets), or the pattern is **reused** across many searches (`new KnuthMorrisPratt(pattern)` once, `.search(text)` many times).
908
910
  - **Use Rabin–Karp** when a **rolling hash** model fits (e.g. one long stream, one pattern), or you later generalize to **several patterns of the same length** (compare each pattern’s triple hash to each window hash). Triple hashing keeps false hash positives negligible; **verification** still guarantees correct indices.
911
+ - **Use `Trie`** when your workload is dictionary-like: store many words once, then do repeated `search(word)` and `startsWith(prefix)` checks in **O(L)**.
909
912
  - **Use `StringRollingHash`** when the problem is **“hash of s[l..r)”** many times on **one** `s`—e.g. check `s[i..i+k) === s[j..j+k)` via hash equality (then confirm if needed), or algorithms that **binary search** on length using substring hashes. For **only** “list all starts of P in T”, pick **KMP** or **Rabin–Karp** instead of building substring hashes by hand.
910
913
 
911
914
  ```ts
912
- import { KnuthMorrisPratt, RabinKarp, StringRollingHash } from 'typescript-dsa-stl';
915
+ import { KnuthMorrisPratt, RabinKarp, Trie, StringRollingHash } from 'typescript-dsa-stl';
913
916
 
914
917
  // A) Pattern fixed, searched in many buffers — build KMP once, call .search() repeatedly (LPS reused).
915
918
  const multiDoc = new KnuthMorrisPratt('ERROR');
@@ -921,7 +924,15 @@ const hay = '...long text...';
921
924
  KnuthMorrisPratt.findOccurrences(hay, 'needle');
922
925
  new RabinKarp('needle').search(hay);
923
926
 
924
- // C) Same static string, many range-equality checks rolling hash (not for “find all pattern starts” by itself).
927
+ // C) Dictionary/prefix queriesTrie.
928
+ const trie = new Trie();
929
+ trie.insert('apple');
930
+ trie.insert('app');
931
+ trie.search('app'); // true
932
+ trie.startsWith('appl'); // true
933
+ trie.delete('app'); // true
934
+
935
+ // D) Same static string, many range-equality checks — rolling hash (not for “find all pattern starts” by itself).
925
936
  const s = 'banana';
926
937
  const rh = new StringRollingHash(s);
927
938
  // Does s[1..4) equal s[3..6)? (both length 3)
@@ -937,8 +948,9 @@ const maybe = rh.substringHash(1, 3) === rh.substringHash(3, 3); // then compare
937
948
  ```ts
938
949
  import {
939
950
  KnuthMorrisPratt,
940
- StringRollingHash,
941
951
  RabinKarp,
952
+ Trie,
953
+ StringRollingHash,
942
954
  RABIN_KARP_DEFAULT_MODS,
943
955
  } from 'typescript-dsa-stl';
944
956
 
@@ -975,6 +987,16 @@ console.log(RabinKarp.findOccurrences('aaaa', 'aa')); // [0, 1, 2]
975
987
  // Empty pattern: no matches
976
988
  console.log(new RabinKarp('').search('text')); // []
977
989
 
990
+ // --- Trie: dictionary and prefix queries ---
991
+ const trie = new Trie();
992
+ trie.insert('apple');
993
+ trie.insert('app');
994
+ console.log(trie.search('app')); // true
995
+ console.log(trie.search('ap')); // false
996
+ console.log(trie.startsWith('ap')); // true
997
+ console.log(trie.delete('app')); // true
998
+ console.log(trie.search('app')); // false
999
+
978
1000
  // --- String rolling hash: default base 131, mod 1_000_000_007 (both configurable) ---
979
1001
  const rh = new StringRollingHash('hello');
980
1002
  // Internally: prefix[] and pow[] so substring hashes are O(1)
@@ -3,6 +3,7 @@ export { DisjointSetUnion } from './disjointSetUnion.js';
3
3
  export { KnuthMorrisPratt } from './kmp.js';
4
4
  export { StringRollingHash } from './stringHashing.js';
5
5
  export { RabinKarp, RABIN_KARP_DEFAULT_MODS } from './rabinKarp.js';
6
+ export { Trie } from './trie.js';
6
7
  export type { RabinKarpTripleMods } from './rabinKarp.js';
7
8
  export type { WeightedUndirectedEdge, TopologicalSortResult } from './graph.js';
8
9
  export { breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './graph.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC"}
@@ -3,5 +3,6 @@ export { DisjointSetUnion } from './disjointSetUnion.js';
3
3
  export { KnuthMorrisPratt } from './kmp.js';
4
4
  export { StringRollingHash } from './stringHashing.js';
5
5
  export { RabinKarp, RABIN_KARP_DEFAULT_MODS } from './rabinKarp.js';
6
+ export { Trie } from './trie.js';
6
7
  export { breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './graph.js';
7
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAGpE,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/algorithms/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,GACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,YAAY,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Trie (prefix tree) for UTF-16 strings.
3
+ * Supports insert/search/prefix checks and word removal.
4
+ */
5
+ export declare class Trie {
6
+ private readonly root;
7
+ constructor();
8
+ /** Insert a word into the trie. */
9
+ insert(word: string): void;
10
+ /** Returns true if the exact word exists in the trie. */
11
+ search(word: string): boolean;
12
+ /** Returns true if there is any inserted word with this prefix. */
13
+ startsWith(prefix: string): boolean;
14
+ /**
15
+ * Remove one exact word from the trie.
16
+ * Returns true when the word existed and was removed.
17
+ */
18
+ delete(word: string): boolean;
19
+ /** Returns true when no words have been inserted. */
20
+ isEmpty(): boolean;
21
+ private findNode;
22
+ }
23
+ //# sourceMappingURL=trie.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trie.d.ts","sourceRoot":"","sources":["../../src/algorithms/trie.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,qBAAa,IAAI;IACf,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAW;;IAMhC,mCAAmC;IACnC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAc1B,yDAAyD;IACzD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAK7B,mEAAmE;IACnE,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAInC;;;OAGG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAwB7B,qDAAqD;IACrD,OAAO,IAAI,OAAO;IAIlB,OAAO,CAAC,QAAQ;CASjB"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Trie (prefix tree) for UTF-16 strings.
3
+ * Supports insert/search/prefix checks and word removal.
4
+ */
5
+ class TrieNode {
6
+ constructor() {
7
+ this.children = new Map();
8
+ this.isWord = false;
9
+ }
10
+ }
11
+ export class Trie {
12
+ constructor() {
13
+ this.root = new TrieNode();
14
+ }
15
+ /** Insert a word into the trie. */
16
+ insert(word) {
17
+ let node = this.root;
18
+ for (let i = 0; i < word.length; i++) {
19
+ const ch = word[i];
20
+ let next = node.children.get(ch);
21
+ if (!next) {
22
+ next = new TrieNode();
23
+ node.children.set(ch, next);
24
+ }
25
+ node = next;
26
+ }
27
+ node.isWord = true;
28
+ }
29
+ /** Returns true if the exact word exists in the trie. */
30
+ search(word) {
31
+ const node = this.findNode(word);
32
+ return node !== undefined && node.isWord;
33
+ }
34
+ /** Returns true if there is any inserted word with this prefix. */
35
+ startsWith(prefix) {
36
+ return this.findNode(prefix) !== undefined;
37
+ }
38
+ /**
39
+ * Remove one exact word from the trie.
40
+ * Returns true when the word existed and was removed.
41
+ */
42
+ delete(word) {
43
+ const path = [];
44
+ let node = this.root;
45
+ for (let i = 0; i < word.length; i++) {
46
+ const ch = word[i];
47
+ const next = node.children.get(ch);
48
+ if (!next)
49
+ return false;
50
+ path.push({ parent: node, ch, node: next });
51
+ node = next;
52
+ }
53
+ if (!node.isWord)
54
+ return false;
55
+ node.isWord = false;
56
+ // Prune nodes that are no longer needed.
57
+ for (let i = path.length - 1; i >= 0; i--) {
58
+ const segment = path[i];
59
+ if (segment.node.isWord || segment.node.children.size > 0)
60
+ break;
61
+ segment.parent.children.delete(segment.ch);
62
+ }
63
+ return true;
64
+ }
65
+ /** Returns true when no words have been inserted. */
66
+ isEmpty() {
67
+ return this.root.children.size === 0;
68
+ }
69
+ findNode(path) {
70
+ let node = this.root;
71
+ for (let i = 0; i < path.length; i++) {
72
+ const next = node.children.get(path[i]);
73
+ if (!next)
74
+ return undefined;
75
+ node = next;
76
+ }
77
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AAY;QAC3B,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;QACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACrC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC;YACzC,IAAI,CAAC,IAAI;gBAAE,OAAO,SAAS,CAAC;YAC5B,IAAI,GAAG,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  */
8
8
  export { Vector, Stack, Queue, Deque, List, ListNode, PriorityQueue, OrderedMap, UnorderedMap, OrderedSet, UnorderedSet, OrderedMultiSet, OrderedMultiMap, addEdge, deleteEdge, createAdjacencyList, createWeightedAdjacencyList, GeneralSegmentTree, SegmentTree, SegmentTreeSum, SegmentTreeMin, SegmentTreeMax, LazySegmentTreeSum, } from './collections/index.js';
9
9
  export type { WeightedEdge, AdjacencyList, WeightedAdjacencyList, GeneralSegmentTreeConfig, SegmentCombine, SegmentLeafBuild, SegmentMerge, } from './collections/index.js';
10
- export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, DisjointSetUnion, KnuthMorrisPratt, StringRollingHash, RabinKarp, RABIN_KARP_DEFAULT_MODS, breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './algorithms/index.js';
10
+ export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, DisjointSetUnion, KnuthMorrisPratt, StringRollingHash, RabinKarp, Trie, RABIN_KARP_DEFAULT_MODS, breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './algorithms/index.js';
11
11
  export type { WeightedUndirectedEdge, RabinKarpTripleMods, TopologicalSortResult, } from './algorithms/index.js';
12
12
  export { clamp, range, noop, identity, swap } from './utils/index.js';
13
13
  export type { Comparator, Predicate, UnaryFn, Reducer, IterableLike } from './types/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACtE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,YAAY,EACZ,aAAa,EACb,qBAAqB,EACrB,wBAAwB,EACxB,cAAc,EACd,gBAAgB,EAChB,YAAY,GACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,IAAI,EACJ,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACtE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * import { Vector, Stack, Queue, List, sort, binarySearch, clamp } from 'typescript-dsa-stl';
7
7
  */
8
8
  export { Vector, Stack, Queue, Deque, List, ListNode, PriorityQueue, OrderedMap, UnorderedMap, OrderedSet, UnorderedSet, OrderedMultiSet, OrderedMultiMap, addEdge, deleteEdge, createAdjacencyList, createWeightedAdjacencyList, GeneralSegmentTree, SegmentTree, SegmentTreeSum, SegmentTreeMin, SegmentTreeMax, LazySegmentTreeSum, } from './collections/index.js';
9
- export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, DisjointSetUnion, KnuthMorrisPratt, StringRollingHash, RabinKarp, RABIN_KARP_DEFAULT_MODS, breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './algorithms/index.js';
9
+ export { sort, find, findIndex, transform, filter, reduce, reverse, unique, binarySearch, lowerBound, upperBound, min, max, partition, DisjointSetUnion, KnuthMorrisPratt, StringRollingHash, RabinKarp, Trie, RABIN_KARP_DEFAULT_MODS, breadthFirstSearch, depthFirstSearch, topologicalSortStack, topologicalSortIndegree, connectedComponents, dijkstra, reconstructPath, kruskalMST, } from './algorithms/index.js';
10
10
  export { clamp, range, noop, identity, swap } from './utils/index.js';
11
11
  export { toArray } from './types/index.js';
12
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAUhC,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EACL,MAAM,EACN,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,EACf,OAAO,EACP,UAAU,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,cAAc,EACd,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAUhC,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,GAAG,EACH,GAAG,EACH,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,IAAI,EACJ,uBAAuB,EACvB,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,EACR,eAAe,EACf,UAAU,GACX,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typescript-dsa-stl",
3
- "version": "2.8.0",
3
+ "version": "2.9.0",
4
4
  "description": "STL-style data structures and algorithms for TypeScript: Vector, Stack, Queue, Deque (double-ended queue), List, PriorityQueue, Map, Set, sort, binarySearch, graph utilities. Use like C++ STL.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",