min-heap-typed 1.50.2 → 1.50.4
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 +6 -0
- package/dist/data-structures/binary-tree/{tree-multimap.d.ts → avl-tree-multi-map.d.ts} +43 -10
- package/dist/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +49 -11
- package/dist/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/data-structures/binary-tree/avl-tree.js +33 -1
- 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 +1 -1
- package/dist/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/data-structures/binary-tree/bst.js +51 -20
- package/dist/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/data-structures/binary-tree/index.js +2 -1
- package/dist/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/data-structures/binary-tree/rb-tree.js +90 -24
- 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-multi-map.d.ts +200 -0
- package/dist/data-structures/binary-tree/tree-multi-map.js +399 -0
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/data-structures/graph/abstract-graph.js +0 -189
- package/dist/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/data-structures/graph/directed-graph.js +105 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/data-structures/graph/undirected-graph.js +126 -18
- package/dist/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/data-structures/hash/hash-map.js +196 -62
- package/dist/data-structures/heap/heap.d.ts +29 -19
- package/dist/data-structures/heap/heap.js +29 -20
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/data-structures/linked-list/doubly-linked-list.js +83 -25
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/data-structures/linked-list/singly-linked-list.js +34 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/data-structures/matrix/matrix.js +1 -1
- 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 +95 -21
- package/dist/data-structures/queue/deque.js +100 -16
- package/dist/data-structures/queue/queue.d.ts +65 -45
- package/dist/data-structures/queue/queue.js +65 -45
- package/dist/data-structures/stack/stack.d.ts +36 -22
- package/dist/data-structures/stack/stack.js +36 -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 +100 -36
- package/dist/data-structures/trie/trie.js +115 -36
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/index.js +2 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +5 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +2 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/{tree-multimap.ts → avl-tree-multi-map.ts} +59 -20
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +51 -19
- package/src/data-structures/binary-tree/index.ts +2 -1
- package/src/data-structures/binary-tree/rb-tree.ts +99 -28
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multi-map.ts +463 -0
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- 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 +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +8 -0
- package/src/types/data-structures/binary-tree/index.ts +2 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +8 -0
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +0 -5
- package/src/types/data-structures/binary-tree/tree-multimap.ts +0 -8
- /package/dist/types/data-structures/binary-tree/{tree-multimap.js → avl-tree-multi-map.js} +0 -0
|
@@ -1,25 +1,99 @@
|
|
|
1
1
|
export class TreeNode<V = any> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The constructor function initializes a TreeNode object with a key, optional value, and optional
|
|
4
|
+
* children.
|
|
5
|
+
* @param {string} key - A string representing the key of the tree node.
|
|
6
|
+
* @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
|
|
7
|
+
* value associated with the node. If no value is provided, it defaults to `undefined`.
|
|
8
|
+
* @param {TreeNode<V>[]} [children] - The `children` parameter is an optional array of `TreeNode<V>`
|
|
9
|
+
* objects. It represents the child nodes of the current node. If no children are provided, the
|
|
10
|
+
* default value is an empty array.
|
|
11
|
+
*/
|
|
6
12
|
constructor(key: string, value?: V, children?: TreeNode<V>[]) {
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
13
|
+
this._key = key;
|
|
14
|
+
this._value = value || undefined;
|
|
15
|
+
this._children = children || [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
protected _key: string;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The function returns the value of the protected variable _key.
|
|
22
|
+
* @returns The value of the `_key` property, which is a string.
|
|
23
|
+
*/
|
|
24
|
+
get key(): string {
|
|
25
|
+
return this._key;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The above function sets the value of a protected variable called "key".
|
|
30
|
+
* @param {string} value - The value parameter is a string that represents the value to be assigned
|
|
31
|
+
* to the key.
|
|
32
|
+
*/
|
|
33
|
+
set key(value: string) {
|
|
34
|
+
this._key = value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected _value?: V | undefined;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The function returns the value stored in a variable, or undefined if the variable is empty.
|
|
41
|
+
* @returns The value of the variable `_value` is being returned.
|
|
42
|
+
*/
|
|
43
|
+
get value(): V | undefined {
|
|
44
|
+
return this._value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The function sets the value of a variable.
|
|
49
|
+
* @param {V | undefined} value - The parameter "value" is of type "V | undefined", which means it
|
|
50
|
+
* can accept a value of type "V" or it can be undefined.
|
|
51
|
+
*/
|
|
52
|
+
set value(value: V | undefined) {
|
|
53
|
+
this._value = value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
protected _children?: TreeNode<V>[] | undefined;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The function returns an array of TreeNode objects or undefined.
|
|
60
|
+
* @returns The `children` property is being returned. It is of type `TreeNode<V>[] | undefined`,
|
|
61
|
+
* which means it can either be an array of `TreeNode<V>` objects or `undefined`.
|
|
62
|
+
*/
|
|
63
|
+
get children(): TreeNode<V>[] | undefined {
|
|
64
|
+
return this._children;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The function sets the value of the children property of a TreeNode object.
|
|
69
|
+
* @param {TreeNode<V>[] | undefined} value - The value parameter is of type TreeNode<V>[] |
|
|
70
|
+
* undefined. This means that it can accept an array of TreeNode objects or undefined.
|
|
71
|
+
*/
|
|
72
|
+
set children(value: TreeNode<V>[] | undefined) {
|
|
73
|
+
this._children = value;
|
|
10
74
|
}
|
|
11
75
|
|
|
76
|
+
/**
|
|
77
|
+
* The function `addChildren` adds one or more child nodes to the current node.
|
|
78
|
+
* @param {TreeNode<V> | TreeNode<V>[]} children - The `children` parameter can be either a single
|
|
79
|
+
* `TreeNode<V>` object or an array of `TreeNode<V>` objects.
|
|
80
|
+
*/
|
|
12
81
|
addChildren(children: TreeNode<V> | TreeNode<V>[]) {
|
|
13
|
-
if (!this.
|
|
14
|
-
this.
|
|
82
|
+
if (!this._children) {
|
|
83
|
+
this._children = [];
|
|
15
84
|
}
|
|
16
85
|
if (children instanceof TreeNode) {
|
|
17
|
-
this.
|
|
86
|
+
this._children.push(children);
|
|
18
87
|
} else {
|
|
19
|
-
this.
|
|
88
|
+
this._children = this._children.concat(children);
|
|
20
89
|
}
|
|
21
90
|
}
|
|
22
91
|
|
|
92
|
+
/**
|
|
93
|
+
* The function `getHeight()` calculates the maximum depth of a tree structure by performing a
|
|
94
|
+
* breadth-first search.
|
|
95
|
+
* @returns the maximum depth or height of the tree.
|
|
96
|
+
*/
|
|
23
97
|
getHeight() {
|
|
24
98
|
let maxDepth = 0;
|
|
25
99
|
if (this) {
|
|
@@ -27,10 +101,10 @@ export class TreeNode<V = any> {
|
|
|
27
101
|
if (level > maxDepth) {
|
|
28
102
|
maxDepth = level;
|
|
29
103
|
}
|
|
30
|
-
const {
|
|
31
|
-
if (
|
|
32
|
-
for (let i = 0, len =
|
|
33
|
-
bfs(
|
|
104
|
+
const { _children } = node;
|
|
105
|
+
if (_children) {
|
|
106
|
+
for (let i = 0, len = _children.length; i < len; i++) {
|
|
107
|
+
bfs(_children[i], level + 1);
|
|
34
108
|
}
|
|
35
109
|
}
|
|
36
110
|
};
|
|
@@ -13,14 +13,70 @@ import { IterableElementBase } from '../base';
|
|
|
13
13
|
* and a flag indicating whether it's the end of a word.
|
|
14
14
|
*/
|
|
15
15
|
export class TrieNode {
|
|
16
|
-
key: string;
|
|
17
|
-
children: Map<string, TrieNode>;
|
|
18
|
-
isEnd: boolean;
|
|
19
|
-
|
|
20
16
|
constructor(key: string) {
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
this.
|
|
17
|
+
this._key = key;
|
|
18
|
+
this._isEnd = false;
|
|
19
|
+
this._children = new Map<string, TrieNode>();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
protected _key: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The function returns the value of the protected variable _key.
|
|
26
|
+
* @returns The value of the `_key` property, which is a string.
|
|
27
|
+
*/
|
|
28
|
+
get key(): string {
|
|
29
|
+
return this._key;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The above function sets the value of a protected variable called "key".
|
|
34
|
+
* @param {string} value - The value parameter is a string that represents the value to be assigned
|
|
35
|
+
* to the key.
|
|
36
|
+
*/
|
|
37
|
+
set key(value: string) {
|
|
38
|
+
this._key = value;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
protected _children: Map<string, TrieNode>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The function returns the children of a TrieNode as a Map.
|
|
45
|
+
* @returns The `children` property of the TrieNode object, which is a Map containing string keys and
|
|
46
|
+
* TrieNode values.
|
|
47
|
+
*/
|
|
48
|
+
get children(): Map<string, TrieNode> {
|
|
49
|
+
return this._children;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The function sets the value of the `_children` property of a TrieNode object.
|
|
54
|
+
* @param value - The value parameter is a Map object that represents the children of a TrieNode. The
|
|
55
|
+
* keys of the map are strings, which represent the characters that are associated with each child
|
|
56
|
+
* TrieNode. The values of the map are TrieNode objects, which represent the child nodes of the
|
|
57
|
+
* current TrieNode.
|
|
58
|
+
*/
|
|
59
|
+
set children(value: Map<string, TrieNode>) {
|
|
60
|
+
this._children = value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected _isEnd: boolean;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The function returns a boolean value indicating whether a certain condition is met.
|
|
67
|
+
* @returns The method is returning a boolean value, specifically the value of the variable `_isEnd`.
|
|
68
|
+
*/
|
|
69
|
+
get isEnd(): boolean {
|
|
70
|
+
return this._isEnd;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The function sets the value of the "_isEnd" property.
|
|
75
|
+
* @param {boolean} value - The value parameter is a boolean value that indicates whether the current
|
|
76
|
+
* state is the end state or not.
|
|
77
|
+
*/
|
|
78
|
+
set isEnd(value: boolean) {
|
|
79
|
+
this._isEnd = value;
|
|
24
80
|
}
|
|
25
81
|
}
|
|
26
82
|
|
|
@@ -68,9 +124,8 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
68
124
|
protected _caseSensitive: boolean = true;
|
|
69
125
|
|
|
70
126
|
/**
|
|
71
|
-
* The caseSensitive function is a getter that returns the value of the
|
|
72
|
-
*
|
|
73
|
-
* @return The value of the _casesensitive private variable
|
|
127
|
+
* The caseSensitive function is a getter that returns the value of the protected _caseSensitive property.
|
|
128
|
+
* @return The value of the _caseSensitive protected variable
|
|
74
129
|
*/
|
|
75
130
|
get caseSensitive(): boolean {
|
|
76
131
|
return this._caseSensitive;
|
|
@@ -87,13 +142,13 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
87
142
|
}
|
|
88
143
|
|
|
89
144
|
/**
|
|
90
|
-
* Time Complexity: O(
|
|
91
|
-
* Space Complexity: O(
|
|
145
|
+
* Time Complexity: O(l), where l is the length of the word being added.
|
|
146
|
+
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
92
147
|
*/
|
|
93
148
|
|
|
94
149
|
/**
|
|
95
|
-
* Time Complexity: O(
|
|
96
|
-
* Space Complexity: O(
|
|
150
|
+
* Time Complexity: O(l), where l is the length of the word being added.
|
|
151
|
+
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
97
152
|
*
|
|
98
153
|
* Add a word to the Trie structure.
|
|
99
154
|
* @param {string} word - The word to add.
|
|
@@ -120,12 +175,12 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
120
175
|
}
|
|
121
176
|
|
|
122
177
|
/**
|
|
123
|
-
* Time Complexity: O(
|
|
178
|
+
* Time Complexity: O(l), where l is the length of the input word.
|
|
124
179
|
* Space Complexity: O(1) - Constant space.
|
|
125
180
|
*/
|
|
126
181
|
|
|
127
182
|
/**
|
|
128
|
-
* Time Complexity: O(
|
|
183
|
+
* Time Complexity: O(l), where l is the length of the input word.
|
|
129
184
|
* Space Complexity: O(1) - Constant space.
|
|
130
185
|
*
|
|
131
186
|
* Check if the Trie contains a given word.
|
|
@@ -144,6 +199,14 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
144
199
|
}
|
|
145
200
|
|
|
146
201
|
/**
|
|
202
|
+
* Time Complexity: O(1)
|
|
203
|
+
* Space Complexity: O(1)
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Time Complexity: O(1)
|
|
208
|
+
* Space Complexity: O(1)
|
|
209
|
+
*
|
|
147
210
|
* The isEmpty function checks if the size of the queue is 0.
|
|
148
211
|
* @return True if the size of the queue is 0
|
|
149
212
|
*/
|
|
@@ -152,13 +215,29 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
152
215
|
}
|
|
153
216
|
|
|
154
217
|
/**
|
|
155
|
-
* Time Complexity: O(
|
|
156
|
-
* Space Complexity: O(
|
|
218
|
+
* Time Complexity: O(1)
|
|
219
|
+
* Space Complexity: O(1)
|
|
157
220
|
*/
|
|
158
221
|
|
|
159
222
|
/**
|
|
160
|
-
* Time Complexity: O(
|
|
161
|
-
* Space Complexity: O(
|
|
223
|
+
* Time Complexity: O(1)
|
|
224
|
+
* Space Complexity: O(1)
|
|
225
|
+
*
|
|
226
|
+
* The clear function resets the size of the Trie to 0 and creates a new root TrieNode.
|
|
227
|
+
*/
|
|
228
|
+
clear(): void {
|
|
229
|
+
this._size = 0;
|
|
230
|
+
this._root = new TrieNode('');
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
235
|
+
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
236
|
+
*/
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
240
|
+
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
162
241
|
*
|
|
163
242
|
* Remove a word from the Trie structure.
|
|
164
243
|
* @param{string} word - The word to delete.
|
|
@@ -201,12 +280,12 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
201
280
|
}
|
|
202
281
|
|
|
203
282
|
/**
|
|
204
|
-
* Time Complexity: O(
|
|
283
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
205
284
|
* Space Complexity: O(1) - Constant space.
|
|
206
285
|
*/
|
|
207
286
|
|
|
208
287
|
/**
|
|
209
|
-
* Time Complexity: O(
|
|
288
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
210
289
|
* Space Complexity: O(1) - Constant space.
|
|
211
290
|
*
|
|
212
291
|
*/
|
|
@@ -231,12 +310,12 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
231
310
|
}
|
|
232
311
|
|
|
233
312
|
/**
|
|
234
|
-
* Time Complexity: O(
|
|
313
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
235
314
|
* Space Complexity: O(1) - Constant space.
|
|
236
315
|
*/
|
|
237
316
|
|
|
238
317
|
/**
|
|
239
|
-
* Time Complexity: O(
|
|
318
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
240
319
|
* Space Complexity: O(1) - Constant space.
|
|
241
320
|
*
|
|
242
321
|
* Check if a given input string has an absolute prefix in the Trie, meaning it's not a complete word.
|
|
@@ -255,12 +334,12 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
255
334
|
}
|
|
256
335
|
|
|
257
336
|
/**
|
|
258
|
-
* Time Complexity: O(
|
|
337
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
259
338
|
* Space Complexity: O(1) - Constant space.
|
|
260
339
|
*/
|
|
261
340
|
|
|
262
341
|
/**
|
|
263
|
-
* Time Complexity: O(
|
|
342
|
+
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
264
343
|
* Space Complexity: O(1) - Constant space.
|
|
265
344
|
*
|
|
266
345
|
* 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.
|
|
@@ -279,13 +358,13 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
279
358
|
}
|
|
280
359
|
|
|
281
360
|
/**
|
|
282
|
-
* Time Complexity: O(
|
|
283
|
-
* Space Complexity: O(
|
|
361
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
362
|
+
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
284
363
|
*/
|
|
285
364
|
|
|
286
365
|
/**
|
|
287
|
-
* Time Complexity: O(
|
|
288
|
-
* Space Complexity: O(
|
|
366
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
367
|
+
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
289
368
|
*
|
|
290
369
|
* Check if the input string is a common prefix in the Trie, meaning it's a prefix shared by all words in the Trie.
|
|
291
370
|
* @param {string} input - The input string representing the common prefix to check for.
|
|
@@ -306,13 +385,13 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
306
385
|
}
|
|
307
386
|
|
|
308
387
|
/**
|
|
309
|
-
* Time Complexity: O(
|
|
310
|
-
* Space Complexity: O(
|
|
388
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
389
|
+
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
311
390
|
*/
|
|
312
391
|
|
|
313
392
|
/**
|
|
314
|
-
* Time Complexity: O(
|
|
315
|
-
* Space Complexity: O(
|
|
393
|
+
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
394
|
+
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
316
395
|
*
|
|
317
396
|
* Get the longest common prefix among all the words stored in the Trie.
|
|
318
397
|
* @returns {string} The longest common prefix found in the Trie.
|
|
@@ -330,13 +409,13 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
330
409
|
}
|
|
331
410
|
|
|
332
411
|
/**
|
|
333
|
-
* Time Complexity: O(
|
|
334
|
-
* Space Complexity: O(
|
|
412
|
+
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
413
|
+
* Space Complexity: O(w * l) - The space required for the output array.
|
|
335
414
|
*/
|
|
336
415
|
|
|
337
416
|
/**
|
|
338
|
-
* Time Complexity: O(
|
|
339
|
-
* Space Complexity: O(
|
|
417
|
+
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
418
|
+
* Space Complexity: O(w * l) - The space required for the output array.
|
|
340
419
|
*
|
|
341
420
|
* The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
|
|
342
421
|
* @param {string} prefix - The `prefix` parameter is a string that represents the prefix that we want to search for in the
|
|
@@ -454,6 +533,18 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
454
533
|
return newTrie;
|
|
455
534
|
}
|
|
456
535
|
|
|
536
|
+
/**
|
|
537
|
+
* Time Complexity: O(n)
|
|
538
|
+
* Space Complexity: O(n)
|
|
539
|
+
*/
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Time Complexity: O(n)
|
|
543
|
+
* Space Complexity: O(n)
|
|
544
|
+
*
|
|
545
|
+
* The function `_getIterator` returns an iterable iterator that performs a depth-first search on a
|
|
546
|
+
* trie data structure and yields all the paths to the end nodes.
|
|
547
|
+
*/
|
|
457
548
|
protected* _getIterator(): IterableIterator<string> {
|
|
458
549
|
function* _dfs(node: TrieNode, path: string): IterableIterator<string> {
|
|
459
550
|
if (node.isEnd) {
|
|
@@ -468,12 +559,12 @@ export class Trie extends IterableElementBase<string, Trie> {
|
|
|
468
559
|
}
|
|
469
560
|
|
|
470
561
|
/**
|
|
471
|
-
* Time Complexity: O(
|
|
562
|
+
* Time Complexity: O(l), where l is the length of the input string.
|
|
472
563
|
* Space Complexity: O(1) - Constant space.
|
|
473
564
|
*/
|
|
474
565
|
|
|
475
566
|
/**
|
|
476
|
-
* Time Complexity: O(
|
|
567
|
+
* Time Complexity: O(l), where l is the length of the input string.
|
|
477
568
|
* Space Complexity: O(1) - Constant space.
|
|
478
569
|
*
|
|
479
570
|
* @param str
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../data-structures';
|
|
2
|
+
import type { AVLTreeOptions } from './avl-tree';
|
|
3
|
+
|
|
4
|
+
export type AVLTreeMultiMapNodeNested<K, V> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
|
+
|
|
6
|
+
export type AVLTreeMultiMapNested<K, V, N extends AVLTreeMultiMapNode<K, V, N>> = AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, AVLTreeMultiMap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
|
+
|
|
8
|
+
export type AVLTreeMultiMapOptions<K> = AVLTreeOptions<K> & {}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TreeMultiMap, TreeMultiMapNode } from '../../../data-structures';
|
|
2
|
+
import type { RBTreeOptions } from './rb-tree';
|
|
3
|
+
|
|
4
|
+
export type TreeMultiMapNodeNested<K, V> = TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, TreeMultiMapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
|
+
|
|
6
|
+
export type TreeMultiMapNested<K, V, N extends TreeMultiMapNode<K, V, N>> = TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, TreeMultiMap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
|
+
|
|
8
|
+
export type TreeMultiMapOptions<K> = RBTreeOptions<K> & {}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { TreeMultimap, TreeMultimapNode } from '../../../data-structures';
|
|
2
|
-
import type { AVLTreeOptions } from './avl-tree';
|
|
3
|
-
export type TreeMultimapNodeNested<K, V> = TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
|
-
export type TreeMultimapNested<K, V, N extends TreeMultimapNode<K, V, N>> = TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
|
-
export type TreeMultimapOptions<K> = AVLTreeOptions<K> & {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { TreeMultimap, TreeMultimapNode } from '../../../data-structures';
|
|
2
|
-
import type { AVLTreeOptions } from './avl-tree';
|
|
3
|
-
|
|
4
|
-
export type TreeMultimapNodeNested<K, V> = TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
|
-
|
|
6
|
-
export type TreeMultimapNested<K, V, N extends TreeMultimapNode<K, V, N>> = TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
|
-
|
|
8
|
-
export type TreeMultimapOptions<K> = AVLTreeOptions<K> & {}
|
|
File without changes
|