min-heap-typed 1.50.1 → 1.50.3
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/dist/data-structures/base/iterable-base.d.ts +120 -9
- package/dist/data-structures/base/iterable-base.js +143 -7
- package/dist/data-structures/binary-tree/avl-tree.d.ts +72 -47
- package/dist/data-structures/binary-tree/avl-tree.js +101 -72
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/data-structures/binary-tree/bst.d.ts +92 -79
- package/dist/data-structures/binary-tree/bst.js +68 -76
- package/dist/data-structures/binary-tree/rb-tree.d.ts +127 -57
- package/dist/data-structures/binary-tree/rb-tree.js +152 -99
- package/dist/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +72 -58
- package/dist/data-structures/binary-tree/tree-multimap.js +102 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -78
- package/dist/data-structures/graph/abstract-graph.js +3 -189
- package/dist/data-structures/graph/directed-graph.d.ts +73 -0
- package/dist/data-structures/graph/directed-graph.js +131 -0
- package/dist/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/data-structures/graph/map-graph.js +14 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +76 -7
- package/dist/data-structures/graph/undirected-graph.js +151 -18
- package/dist/data-structures/hash/hash-map.d.ts +254 -28
- package/dist/data-structures/hash/hash-map.js +347 -78
- package/dist/data-structures/heap/heap.d.ts +95 -25
- package/dist/data-structures/heap/heap.js +95 -26
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
- package/dist/data-structures/linked-list/doubly-linked-list.js +141 -77
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +154 -106
- package/dist/data-structures/linked-list/singly-linked-list.js +164 -115
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/data-structures/matrix/matrix.js +50 -11
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/data-structures/queue/deque.d.ts +139 -35
- package/dist/data-structures/queue/deque.js +200 -62
- package/dist/data-structures/queue/queue.d.ts +103 -49
- package/dist/data-structures/queue/queue.js +111 -49
- package/dist/data-structures/stack/stack.d.ts +51 -21
- package/dist/data-structures/stack/stack.js +58 -22
- package/dist/data-structures/tree/tree.d.ts +57 -3
- package/dist/data-structures/tree/tree.js +77 -11
- package/dist/data-structures/trie/trie.d.ts +135 -34
- package/dist/data-structures/trie/trie.js +153 -33
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +184 -19
- package/src/data-structures/binary-tree/avl-tree.ts +134 -100
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +127 -136
- package/src/data-structures/binary-tree/rb-tree.ts +199 -166
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
- package/src/data-structures/graph/abstract-graph.ts +4 -211
- package/src/data-structures/graph/directed-graph.ts +152 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +171 -19
- package/src/data-structures/hash/hash-map.ts +389 -96
- package/src/data-structures/heap/heap.ts +97 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
- package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +225 -70
- package/src/data-structures/queue/queue.ts +118 -49
- package/src/data-structures/stack/stack.ts +63 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +173 -38
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
|
@@ -12,10 +12,46 @@ import { IterableElementBase } from '../base';
|
|
|
12
12
|
* and a flag indicating whether it's the end of a word.
|
|
13
13
|
*/
|
|
14
14
|
export declare class TrieNode {
|
|
15
|
-
key: string;
|
|
16
|
-
children: Map<string, TrieNode>;
|
|
17
|
-
isEnd: boolean;
|
|
18
15
|
constructor(key: string);
|
|
16
|
+
protected _key: string;
|
|
17
|
+
/**
|
|
18
|
+
* The function returns the value of the protected variable _key.
|
|
19
|
+
* @returns The value of the `_key` property, which is a string.
|
|
20
|
+
*/
|
|
21
|
+
get key(): string;
|
|
22
|
+
/**
|
|
23
|
+
* The above function sets the value of a protected variable called "key".
|
|
24
|
+
* @param {string} value - The value parameter is a string that represents the value to be assigned
|
|
25
|
+
* to the key.
|
|
26
|
+
*/
|
|
27
|
+
set key(value: string);
|
|
28
|
+
protected _children: Map<string, TrieNode>;
|
|
29
|
+
/**
|
|
30
|
+
* The function returns the children of a TrieNode as a Map.
|
|
31
|
+
* @returns The `children` property of the TrieNode object, which is a Map containing string keys and
|
|
32
|
+
* TrieNode values.
|
|
33
|
+
*/
|
|
34
|
+
get children(): Map<string, TrieNode>;
|
|
35
|
+
/**
|
|
36
|
+
* The function sets the value of the `_children` property of a TrieNode object.
|
|
37
|
+
* @param value - The value parameter is a Map object that represents the children of a TrieNode. The
|
|
38
|
+
* keys of the map are strings, which represent the characters that are associated with each child
|
|
39
|
+
* TrieNode. The values of the map are TrieNode objects, which represent the child nodes of the
|
|
40
|
+
* current TrieNode.
|
|
41
|
+
*/
|
|
42
|
+
set children(value: Map<string, TrieNode>);
|
|
43
|
+
protected _isEnd: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The function returns a boolean value indicating whether a certain condition is met.
|
|
46
|
+
* @returns The method is returning a boolean value, specifically the value of the variable `_isEnd`.
|
|
47
|
+
*/
|
|
48
|
+
get isEnd(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The function sets the value of the "_isEnd" property.
|
|
51
|
+
* @param {boolean} value - The value parameter is a boolean value that indicates whether the current
|
|
52
|
+
* state is the end state or not.
|
|
53
|
+
*/
|
|
54
|
+
set isEnd(value: boolean);
|
|
19
55
|
}
|
|
20
56
|
/**
|
|
21
57
|
* 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
|
|
@@ -30,21 +66,39 @@ export declare class TrieNode {
|
|
|
30
66
|
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
31
67
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
32
68
|
*/
|
|
33
|
-
export declare class Trie extends IterableElementBase<string> {
|
|
69
|
+
export declare class Trie extends IterableElementBase<string, Trie> {
|
|
70
|
+
/**
|
|
71
|
+
* The constructor function for the Trie class.
|
|
72
|
+
* @param words: Iterable string Initialize the trie with a set of words
|
|
73
|
+
* @param options?: TrieOptions Allow the user to pass in options for the trie
|
|
74
|
+
* @return This
|
|
75
|
+
*/
|
|
34
76
|
constructor(words?: Iterable<string>, options?: TrieOptions);
|
|
35
77
|
protected _size: number;
|
|
78
|
+
/**
|
|
79
|
+
* The size function returns the size of the stack.
|
|
80
|
+
* @return The number of elements in the list
|
|
81
|
+
*/
|
|
36
82
|
get size(): number;
|
|
37
83
|
protected _caseSensitive: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The caseSensitive function is a getter that returns the value of the protected _caseSensitive property.
|
|
86
|
+
* @return The value of the _caseSensitive protected variable
|
|
87
|
+
*/
|
|
38
88
|
get caseSensitive(): boolean;
|
|
39
89
|
protected _root: TrieNode;
|
|
90
|
+
/**
|
|
91
|
+
* The root function returns the root node of the tree.
|
|
92
|
+
* @return The root node
|
|
93
|
+
*/
|
|
40
94
|
get root(): TrieNode;
|
|
41
95
|
/**
|
|
42
|
-
* Time Complexity: O(
|
|
43
|
-
* Space Complexity: O(
|
|
96
|
+
* Time Complexity: O(l), where l is the length of the word being added.
|
|
97
|
+
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
44
98
|
*/
|
|
45
99
|
/**
|
|
46
|
-
* Time Complexity: O(
|
|
47
|
-
* Space Complexity: O(
|
|
100
|
+
* Time Complexity: O(l), where l is the length of the word being added.
|
|
101
|
+
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
48
102
|
*
|
|
49
103
|
* Add a word to the Trie structure.
|
|
50
104
|
* @param {string} word - The word to add.
|
|
@@ -52,11 +106,11 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
52
106
|
*/
|
|
53
107
|
add(word: string): boolean;
|
|
54
108
|
/**
|
|
55
|
-
* Time Complexity: O(
|
|
109
|
+
* Time Complexity: O(l), where l is the length of the input word.
|
|
56
110
|
* Space Complexity: O(1) - Constant space.
|
|
57
111
|
*/
|
|
58
112
|
/**
|
|
59
|
-
* Time Complexity: O(
|
|
113
|
+
* Time Complexity: O(l), where l is the length of the input word.
|
|
60
114
|
* Space Complexity: O(1) - Constant space.
|
|
61
115
|
*
|
|
62
116
|
* Check if the Trie contains a given word.
|
|
@@ -65,12 +119,35 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
65
119
|
*/
|
|
66
120
|
has(word: string): boolean;
|
|
67
121
|
/**
|
|
68
|
-
* Time Complexity: O(
|
|
69
|
-
* Space Complexity: O(
|
|
122
|
+
* Time Complexity: O(1)
|
|
123
|
+
* Space Complexity: O(1)
|
|
124
|
+
*/
|
|
125
|
+
/**
|
|
126
|
+
* Time Complexity: O(1)
|
|
127
|
+
* Space Complexity: O(1)
|
|
128
|
+
*
|
|
129
|
+
* The isEmpty function checks if the size of the queue is 0.
|
|
130
|
+
* @return True if the size of the queue is 0
|
|
131
|
+
*/
|
|
132
|
+
isEmpty(): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Time Complexity: O(1)
|
|
135
|
+
* Space Complexity: O(1)
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* Time Complexity: O(1)
|
|
139
|
+
* Space Complexity: O(1)
|
|
140
|
+
*
|
|
141
|
+
* The clear function resets the size of the Trie to 0 and creates a new root TrieNode.
|
|
142
|
+
*/
|
|
143
|
+
clear(): void;
|
|
144
|
+
/**
|
|
145
|
+
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
146
|
+
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
70
147
|
*/
|
|
71
148
|
/**
|
|
72
|
-
* Time Complexity: O(
|
|
73
|
-
* Space Complexity: O(
|
|
149
|
+
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
150
|
+
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
74
151
|
*
|
|
75
152
|
* Remove a word from the Trie structure.
|
|
76
153
|
* @param{string} word - The word to delete.
|
|
@@ -78,21 +155,21 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
78
155
|
*/
|
|
79
156
|
delete(word: string): boolean;
|
|
80
157
|
/**
|
|
81
|
-
* Time Complexity: O(
|
|
158
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
82
159
|
* Space Complexity: O(1) - Constant space.
|
|
83
160
|
*/
|
|
84
161
|
/**
|
|
85
|
-
* Time Complexity: O(
|
|
162
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
86
163
|
* Space Complexity: O(1) - Constant space.
|
|
87
164
|
*
|
|
88
165
|
*/
|
|
89
166
|
getHeight(): number;
|
|
90
167
|
/**
|
|
91
|
-
* Time Complexity: O(
|
|
168
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
92
169
|
* Space Complexity: O(1) - Constant space.
|
|
93
170
|
*/
|
|
94
171
|
/**
|
|
95
|
-
* Time Complexity: O(
|
|
172
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
96
173
|
* Space Complexity: O(1) - Constant space.
|
|
97
174
|
*
|
|
98
175
|
* Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
|
|
@@ -101,11 +178,11 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
101
178
|
*/
|
|
102
179
|
hasPurePrefix(input: string): boolean;
|
|
103
180
|
/**
|
|
104
|
-
* Time Complexity: O(
|
|
181
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
105
182
|
* Space Complexity: O(1) - Constant space.
|
|
106
183
|
*/
|
|
107
184
|
/**
|
|
108
|
-
* Time Complexity: O(
|
|
185
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
109
186
|
* Space Complexity: O(1) - Constant space.
|
|
110
187
|
*
|
|
111
188
|
* Check if a given input string is a prefix of any existing word in the Trie, whether as an absolute prefix or a complete word.
|
|
@@ -114,12 +191,12 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
114
191
|
*/
|
|
115
192
|
hasPrefix(input: string): boolean;
|
|
116
193
|
/**
|
|
117
|
-
* Time Complexity: O(
|
|
118
|
-
* Space Complexity: O(
|
|
194
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
195
|
+
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
119
196
|
*/
|
|
120
197
|
/**
|
|
121
|
-
* Time Complexity: O(
|
|
122
|
-
* Space Complexity: O(
|
|
198
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
199
|
+
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
123
200
|
*
|
|
124
201
|
* Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
|
|
125
202
|
* @param {string} input - The input string representing the common prefix to check for.
|
|
@@ -127,24 +204,24 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
127
204
|
*/
|
|
128
205
|
hasCommonPrefix(input: string): boolean;
|
|
129
206
|
/**
|
|
130
|
-
* Time Complexity: O(
|
|
131
|
-
* Space Complexity: O(
|
|
207
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
208
|
+
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
132
209
|
*/
|
|
133
210
|
/**
|
|
134
|
-
* Time Complexity: O(
|
|
135
|
-
* Space Complexity: O(
|
|
211
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
212
|
+
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
136
213
|
*
|
|
137
214
|
* Get the longest common prefix among all the words stored in the Trie.
|
|
138
215
|
* @returns {string} The longest common prefix found in the Trie.
|
|
139
216
|
*/
|
|
140
217
|
getLongestCommonPrefix(): string;
|
|
141
218
|
/**
|
|
142
|
-
* Time Complexity: O(
|
|
143
|
-
* Space Complexity: O(
|
|
219
|
+
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
220
|
+
* Space Complexity: O(w * l) - The space required for the output array.
|
|
144
221
|
*/
|
|
145
222
|
/**
|
|
146
|
-
* Time Complexity: O(
|
|
147
|
-
* Space Complexity: O(
|
|
223
|
+
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
224
|
+
* Space Complexity: O(w * l) - The space required for the output array.
|
|
148
225
|
*
|
|
149
226
|
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
150
227
|
* @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
@@ -154,6 +231,19 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
154
231
|
* @returns {string[]} an array of strings.
|
|
155
232
|
*/
|
|
156
233
|
getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
|
|
234
|
+
/**
|
|
235
|
+
* Time Complexity: O(n)
|
|
236
|
+
* Space Complexity: O(n)
|
|
237
|
+
*/
|
|
238
|
+
/**
|
|
239
|
+
* Time Complexity: O(n)
|
|
240
|
+
* Space Complexity: O(n)
|
|
241
|
+
*
|
|
242
|
+
* The `clone` function returns a new instance of the Trie class with the same values and case
|
|
243
|
+
* sensitivity as the original Trie.
|
|
244
|
+
* @returns A new instance of the Trie class is being returned.
|
|
245
|
+
*/
|
|
246
|
+
clone(): Trie;
|
|
157
247
|
/**
|
|
158
248
|
* Time Complexity: O(n)
|
|
159
249
|
* Space Complexity: O(n)
|
|
@@ -191,13 +281,24 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
191
281
|
* @returns The `map` function is returning a new Trie object.
|
|
192
282
|
*/
|
|
193
283
|
map(callback: ElementCallback<string, string>, thisArg?: any): Trie;
|
|
284
|
+
/**
|
|
285
|
+
* Time Complexity: O(n)
|
|
286
|
+
* Space Complexity: O(n)
|
|
287
|
+
*/
|
|
288
|
+
/**
|
|
289
|
+
* Time Complexity: O(n)
|
|
290
|
+
* Space Complexity: O(n)
|
|
291
|
+
*
|
|
292
|
+
* The function `_getIterator` returns an iterable iterator that performs a depth-first search on a
|
|
293
|
+
* trie data structure and yields all the paths to the end nodes.
|
|
294
|
+
*/
|
|
194
295
|
protected _getIterator(): IterableIterator<string>;
|
|
195
296
|
/**
|
|
196
|
-
* Time Complexity: O(
|
|
297
|
+
* Time Complexity: O(l), where l is the length of the input string.
|
|
197
298
|
* Space Complexity: O(1) - Constant space.
|
|
198
299
|
*/
|
|
199
300
|
/**
|
|
200
|
-
* Time Complexity: O(
|
|
301
|
+
* Time Complexity: O(l), where l is the length of the input string.
|
|
201
302
|
* Space Complexity: O(1) - Constant space.
|
|
202
303
|
*
|
|
203
304
|
* @param str
|
|
@@ -8,9 +8,57 @@ const base_1 = require("../base");
|
|
|
8
8
|
*/
|
|
9
9
|
class TrieNode {
|
|
10
10
|
constructor(key) {
|
|
11
|
-
this.
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
11
|
+
this._key = key;
|
|
12
|
+
this._isEnd = false;
|
|
13
|
+
this._children = new Map();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The function returns the value of the protected variable _key.
|
|
17
|
+
* @returns The value of the `_key` property, which is a string.
|
|
18
|
+
*/
|
|
19
|
+
get key() {
|
|
20
|
+
return this._key;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The above function sets the value of a protected variable called "key".
|
|
24
|
+
* @param {string} value - The value parameter is a string that represents the value to be assigned
|
|
25
|
+
* to the key.
|
|
26
|
+
*/
|
|
27
|
+
set key(value) {
|
|
28
|
+
this._key = value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The function returns the children of a TrieNode as a Map.
|
|
32
|
+
* @returns The `children` property of the TrieNode object, which is a Map containing string keys and
|
|
33
|
+
* TrieNode values.
|
|
34
|
+
*/
|
|
35
|
+
get children() {
|
|
36
|
+
return this._children;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The function sets the value of the `_children` property of a TrieNode object.
|
|
40
|
+
* @param value - The value parameter is a Map object that represents the children of a TrieNode. The
|
|
41
|
+
* keys of the map are strings, which represent the characters that are associated with each child
|
|
42
|
+
* TrieNode. The values of the map are TrieNode objects, which represent the child nodes of the
|
|
43
|
+
* current TrieNode.
|
|
44
|
+
*/
|
|
45
|
+
set children(value) {
|
|
46
|
+
this._children = value;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The function returns a boolean value indicating whether a certain condition is met.
|
|
50
|
+
* @returns The method is returning a boolean value, specifically the value of the variable `_isEnd`.
|
|
51
|
+
*/
|
|
52
|
+
get isEnd() {
|
|
53
|
+
return this._isEnd;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The function sets the value of the "_isEnd" property.
|
|
57
|
+
* @param {boolean} value - The value parameter is a boolean value that indicates whether the current
|
|
58
|
+
* state is the end state or not.
|
|
59
|
+
*/
|
|
60
|
+
set isEnd(value) {
|
|
61
|
+
this._isEnd = value;
|
|
14
62
|
}
|
|
15
63
|
}
|
|
16
64
|
exports.TrieNode = TrieNode;
|
|
@@ -28,6 +76,12 @@ exports.TrieNode = TrieNode;
|
|
|
28
76
|
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
29
77
|
*/
|
|
30
78
|
class Trie extends base_1.IterableElementBase {
|
|
79
|
+
/**
|
|
80
|
+
* The constructor function for the Trie class.
|
|
81
|
+
* @param words: Iterable string Initialize the trie with a set of words
|
|
82
|
+
* @param options?: TrieOptions Allow the user to pass in options for the trie
|
|
83
|
+
* @return This
|
|
84
|
+
*/
|
|
31
85
|
constructor(words = [], options) {
|
|
32
86
|
super();
|
|
33
87
|
this._size = 0;
|
|
@@ -43,22 +97,34 @@ class Trie extends base_1.IterableElementBase {
|
|
|
43
97
|
this.add(word);
|
|
44
98
|
}
|
|
45
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* The size function returns the size of the stack.
|
|
102
|
+
* @return The number of elements in the list
|
|
103
|
+
*/
|
|
46
104
|
get size() {
|
|
47
105
|
return this._size;
|
|
48
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* The caseSensitive function is a getter that returns the value of the protected _caseSensitive property.
|
|
109
|
+
* @return The value of the _caseSensitive protected variable
|
|
110
|
+
*/
|
|
49
111
|
get caseSensitive() {
|
|
50
112
|
return this._caseSensitive;
|
|
51
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* The root function returns the root node of the tree.
|
|
116
|
+
* @return The root node
|
|
117
|
+
*/
|
|
52
118
|
get root() {
|
|
53
119
|
return this._root;
|
|
54
120
|
}
|
|
55
121
|
/**
|
|
56
|
-
* Time Complexity: O(
|
|
57
|
-
* Space Complexity: O(
|
|
122
|
+
* Time Complexity: O(l), where l is the length of the word being added.
|
|
123
|
+
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
58
124
|
*/
|
|
59
125
|
/**
|
|
60
|
-
* Time Complexity: O(
|
|
61
|
-
* Space Complexity: O(
|
|
126
|
+
* Time Complexity: O(l), where l is the length of the word being added.
|
|
127
|
+
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
62
128
|
*
|
|
63
129
|
* Add a word to the Trie structure.
|
|
64
130
|
* @param {string} word - The word to add.
|
|
@@ -84,11 +150,11 @@ class Trie extends base_1.IterableElementBase {
|
|
|
84
150
|
return isNewWord;
|
|
85
151
|
}
|
|
86
152
|
/**
|
|
87
|
-
* Time Complexity: O(
|
|
153
|
+
* Time Complexity: O(l), where l is the length of the input word.
|
|
88
154
|
* Space Complexity: O(1) - Constant space.
|
|
89
155
|
*/
|
|
90
156
|
/**
|
|
91
|
-
* Time Complexity: O(
|
|
157
|
+
* Time Complexity: O(l), where l is the length of the input word.
|
|
92
158
|
* Space Complexity: O(1) - Constant space.
|
|
93
159
|
*
|
|
94
160
|
* Check if the Trie contains a given word.
|
|
@@ -107,12 +173,40 @@ class Trie extends base_1.IterableElementBase {
|
|
|
107
173
|
return cur.isEnd;
|
|
108
174
|
}
|
|
109
175
|
/**
|
|
110
|
-
* Time Complexity: O(
|
|
111
|
-
* Space Complexity: O(
|
|
176
|
+
* Time Complexity: O(1)
|
|
177
|
+
* Space Complexity: O(1)
|
|
112
178
|
*/
|
|
113
179
|
/**
|
|
114
|
-
* Time Complexity: O(
|
|
115
|
-
* Space Complexity: O(
|
|
180
|
+
* Time Complexity: O(1)
|
|
181
|
+
* Space Complexity: O(1)
|
|
182
|
+
*
|
|
183
|
+
* The isEmpty function checks if the size of the queue is 0.
|
|
184
|
+
* @return True if the size of the queue is 0
|
|
185
|
+
*/
|
|
186
|
+
isEmpty() {
|
|
187
|
+
return this.size === 0;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Time Complexity: O(1)
|
|
191
|
+
* Space Complexity: O(1)
|
|
192
|
+
*/
|
|
193
|
+
/**
|
|
194
|
+
* Time Complexity: O(1)
|
|
195
|
+
* Space Complexity: O(1)
|
|
196
|
+
*
|
|
197
|
+
* The clear function resets the size of the Trie to 0 and creates a new root TrieNode.
|
|
198
|
+
*/
|
|
199
|
+
clear() {
|
|
200
|
+
this._size = 0;
|
|
201
|
+
this._root = new TrieNode('');
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
205
|
+
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
206
|
+
*/
|
|
207
|
+
/**
|
|
208
|
+
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
209
|
+
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
116
210
|
*
|
|
117
211
|
* Remove a word from the Trie structure.
|
|
118
212
|
* @param{string} word - The word to delete.
|
|
@@ -154,11 +248,11 @@ class Trie extends base_1.IterableElementBase {
|
|
|
154
248
|
return isDeleted;
|
|
155
249
|
}
|
|
156
250
|
/**
|
|
157
|
-
* Time Complexity: O(
|
|
251
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
158
252
|
* Space Complexity: O(1) - Constant space.
|
|
159
253
|
*/
|
|
160
254
|
/**
|
|
161
|
-
* Time Complexity: O(
|
|
255
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
162
256
|
* Space Complexity: O(1) - Constant space.
|
|
163
257
|
*
|
|
164
258
|
*/
|
|
@@ -182,11 +276,11 @@ class Trie extends base_1.IterableElementBase {
|
|
|
182
276
|
return maxDepth;
|
|
183
277
|
}
|
|
184
278
|
/**
|
|
185
|
-
* Time Complexity: O(
|
|
279
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
186
280
|
* Space Complexity: O(1) - Constant space.
|
|
187
281
|
*/
|
|
188
282
|
/**
|
|
189
|
-
* Time Complexity: O(
|
|
283
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
190
284
|
* Space Complexity: O(1) - Constant space.
|
|
191
285
|
*
|
|
192
286
|
* Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
|
|
@@ -205,11 +299,11 @@ class Trie extends base_1.IterableElementBase {
|
|
|
205
299
|
return !cur.isEnd;
|
|
206
300
|
}
|
|
207
301
|
/**
|
|
208
|
-
* Time Complexity: O(
|
|
302
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
209
303
|
* Space Complexity: O(1) - Constant space.
|
|
210
304
|
*/
|
|
211
305
|
/**
|
|
212
|
-
* Time Complexity: O(
|
|
306
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
213
307
|
* Space Complexity: O(1) - Constant space.
|
|
214
308
|
*
|
|
215
309
|
* Check if a given input string is a prefix of any existing word in the Trie, whether as an absolute prefix or a complete word.
|
|
@@ -228,12 +322,12 @@ class Trie extends base_1.IterableElementBase {
|
|
|
228
322
|
return true;
|
|
229
323
|
}
|
|
230
324
|
/**
|
|
231
|
-
* Time Complexity: O(
|
|
232
|
-
* Space Complexity: O(
|
|
325
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
326
|
+
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
233
327
|
*/
|
|
234
328
|
/**
|
|
235
|
-
* Time Complexity: O(
|
|
236
|
-
* Space Complexity: O(
|
|
329
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
330
|
+
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
237
331
|
*
|
|
238
332
|
* Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
|
|
239
333
|
* @param {string} input - The input string representing the common prefix to check for.
|
|
@@ -257,12 +351,12 @@ class Trie extends base_1.IterableElementBase {
|
|
|
257
351
|
return commonPre === input;
|
|
258
352
|
}
|
|
259
353
|
/**
|
|
260
|
-
* Time Complexity: O(
|
|
261
|
-
* Space Complexity: O(
|
|
354
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
355
|
+
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
262
356
|
*/
|
|
263
357
|
/**
|
|
264
|
-
* Time Complexity: O(
|
|
265
|
-
* Space Complexity: O(
|
|
358
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
359
|
+
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
266
360
|
*
|
|
267
361
|
* Get the longest common prefix among all the words stored in the Trie.
|
|
268
362
|
* @returns {string} The longest common prefix found in the Trie.
|
|
@@ -282,12 +376,12 @@ class Trie extends base_1.IterableElementBase {
|
|
|
282
376
|
return commonPre;
|
|
283
377
|
}
|
|
284
378
|
/**
|
|
285
|
-
* Time Complexity: O(
|
|
286
|
-
* Space Complexity: O(
|
|
379
|
+
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
380
|
+
* Space Complexity: O(w * l) - The space required for the output array.
|
|
287
381
|
*/
|
|
288
382
|
/**
|
|
289
|
-
* Time Complexity: O(
|
|
290
|
-
* Space Complexity: O(
|
|
383
|
+
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
384
|
+
* Space Complexity: O(w * l) - The space required for the output array.
|
|
291
385
|
*
|
|
292
386
|
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
293
387
|
* @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
@@ -326,6 +420,21 @@ class Trie extends base_1.IterableElementBase {
|
|
|
326
420
|
dfs(startNode, prefix);
|
|
327
421
|
return words;
|
|
328
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* Time Complexity: O(n)
|
|
425
|
+
* Space Complexity: O(n)
|
|
426
|
+
*/
|
|
427
|
+
/**
|
|
428
|
+
* Time Complexity: O(n)
|
|
429
|
+
* Space Complexity: O(n)
|
|
430
|
+
*
|
|
431
|
+
* The `clone` function returns a new instance of the Trie class with the same values and case
|
|
432
|
+
* sensitivity as the original Trie.
|
|
433
|
+
* @returns A new instance of the Trie class is being returned.
|
|
434
|
+
*/
|
|
435
|
+
clone() {
|
|
436
|
+
return new Trie(this.values(), { caseSensitive: this.caseSensitive });
|
|
437
|
+
}
|
|
329
438
|
/**
|
|
330
439
|
* Time Complexity: O(n)
|
|
331
440
|
* Space Complexity: O(n)
|
|
@@ -381,6 +490,17 @@ class Trie extends base_1.IterableElementBase {
|
|
|
381
490
|
}
|
|
382
491
|
return newTrie;
|
|
383
492
|
}
|
|
493
|
+
/**
|
|
494
|
+
* Time Complexity: O(n)
|
|
495
|
+
* Space Complexity: O(n)
|
|
496
|
+
*/
|
|
497
|
+
/**
|
|
498
|
+
* Time Complexity: O(n)
|
|
499
|
+
* Space Complexity: O(n)
|
|
500
|
+
*
|
|
501
|
+
* The function `_getIterator` returns an iterable iterator that performs a depth-first search on a
|
|
502
|
+
* trie data structure and yields all the paths to the end nodes.
|
|
503
|
+
*/
|
|
384
504
|
*_getIterator() {
|
|
385
505
|
function* _dfs(node, path) {
|
|
386
506
|
if (node.isEnd) {
|
|
@@ -393,11 +513,11 @@ class Trie extends base_1.IterableElementBase {
|
|
|
393
513
|
yield* _dfs(this.root, '');
|
|
394
514
|
}
|
|
395
515
|
/**
|
|
396
|
-
* Time Complexity: O(
|
|
516
|
+
* Time Complexity: O(l), where l is the length of the input string.
|
|
397
517
|
* Space Complexity: O(1) - Constant space.
|
|
398
518
|
*/
|
|
399
519
|
/**
|
|
400
|
-
* Time Complexity: O(
|
|
520
|
+
* Time Complexity: O(l), where l is the length of the input string.
|
|
401
521
|
* Space Complexity: O(1) - Constant space.
|
|
402
522
|
*
|
|
403
523
|
* @param str
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
2
|
import { IterationType } from "../../common";
|
|
3
3
|
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
-
export type BinaryTreeNested<K, V,
|
|
4
|
+
export type BinaryTreeNested<K, V, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, BinaryTree<K, V, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
export type BinaryTreeOptions<K> = {
|
|
6
6
|
iterationType?: IterationType;
|
|
7
7
|
extractor?: (key: K) => number;
|
|
@@ -4,13 +4,14 @@ export type HashMapLinkedNode<K, V> = {
|
|
|
4
4
|
next: HashMapLinkedNode<K, V>;
|
|
5
5
|
prev: HashMapLinkedNode<K, V>;
|
|
6
6
|
};
|
|
7
|
-
export type LinkedHashMapOptions<K> = {
|
|
7
|
+
export type LinkedHashMapOptions<K, V, R> = {
|
|
8
8
|
hashFn?: (key: K) => string;
|
|
9
9
|
objHashFn?: (key: K) => object;
|
|
10
|
+
toEntryFn?: (rawElement: R) => [K, V];
|
|
10
11
|
};
|
|
11
|
-
export type HashMapOptions<K, V,
|
|
12
|
+
export type HashMapOptions<K, V, R> = {
|
|
12
13
|
hashFn?: (key: K) => string;
|
|
13
|
-
toEntryFn?: (rawElement:
|
|
14
|
+
toEntryFn?: (rawElement: R) => [K, V];
|
|
14
15
|
};
|
|
15
16
|
export type HashMapStoreItem<K, V> = {
|
|
16
17
|
key: K;
|
|
@@ -5,3 +5,4 @@ export type Thunk = () => ReturnType<ToThunkFn> & {
|
|
|
5
5
|
export type TrlFn = (...args: any[]) => any;
|
|
6
6
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
7
7
|
export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
8
|
+
export type Any = string | number | boolean | object | null | undefined | symbol;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "min-heap-typed",
|
|
3
|
-
"version": "1.50.
|
|
3
|
+
"version": "1.50.3",
|
|
4
4
|
"description": "Min Heap. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -132,6 +132,6 @@
|
|
|
132
132
|
"typescript": "^4.9.5"
|
|
133
133
|
},
|
|
134
134
|
"dependencies": {
|
|
135
|
-
"data-structure-typed": "^1.50.
|
|
135
|
+
"data-structure-typed": "^1.50.3"
|
|
136
136
|
}
|
|
137
137
|
}
|