undirected-graph-typed 1.52.4 → 1.52.5
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-element-base.d.ts +1 -37
- package/dist/data-structures/base/iterable-element-base.js +1 -37
- package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/data-structures/binary-tree/binary-tree.js +299 -331
- package/dist/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/data-structures/binary-tree/bst.js +12 -44
- package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/data-structures/graph/abstract-graph.js +0 -75
- package/dist/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/data-structures/graph/directed-graph.js +0 -98
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/data-structures/graph/undirected-graph.js +0 -50
- package/dist/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/data-structures/hash/hash-map.js +27 -111
- package/dist/data-structures/heap/heap.d.ts +0 -32
- package/dist/data-structures/heap/heap.js +0 -32
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/data-structures/queue/deque.d.ts +1 -98
- package/dist/data-structures/queue/deque.js +3 -99
- package/dist/data-structures/queue/queue.d.ts +1 -54
- package/dist/data-structures/queue/queue.js +0 -53
- package/dist/data-structures/stack/stack.d.ts +1 -34
- package/dist/data-structures/stack/stack.js +1 -34
- package/dist/data-structures/tree/tree.js +2 -1
- package/dist/data-structures/trie/trie.d.ts +0 -64
- package/dist/data-structures/trie/trie.js +0 -64
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/types/utils/utils.d.ts +13 -12
- package/dist/utils/number.d.ts +13 -0
- package/dist/utils/number.js +13 -0
- package/dist/utils/utils.d.ts +125 -3
- package/dist/utils/utils.js +177 -21
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +329 -358
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +29 -133
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +1 -68
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
|
@@ -52,10 +52,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
52
52
|
get size() {
|
|
53
53
|
return this.elements.length - this.offset;
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Time Complexity: O(1)
|
|
57
|
-
* Space Complexity: O(1)
|
|
58
|
-
*/
|
|
59
55
|
/**
|
|
60
56
|
* Time Complexity: O(1)
|
|
61
57
|
* Space Complexity: O(1)
|
|
@@ -67,10 +63,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
67
63
|
get first() {
|
|
68
64
|
return this.size > 0 ? this.elements[this.offset] : undefined;
|
|
69
65
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Time Complexity: O(1)
|
|
72
|
-
* Space Complexity: O(1)
|
|
73
|
-
*/
|
|
74
66
|
/**
|
|
75
67
|
* Time Complexity: O(1)
|
|
76
68
|
* Space Complexity: O(1)
|
|
@@ -97,10 +89,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
97
89
|
set autoCompactRatio(v) {
|
|
98
90
|
this._autoCompactRatio = v;
|
|
99
91
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Time Complexity: O(n)
|
|
102
|
-
* Space Complexity: O(n)
|
|
103
|
-
*/
|
|
104
92
|
/**
|
|
105
93
|
* Time Complexity: O(n)
|
|
106
94
|
* Space Complexity: O(n)
|
|
@@ -114,10 +102,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
114
102
|
static fromArray(elements) {
|
|
115
103
|
return new Queue(elements);
|
|
116
104
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Time Complexity: O(1)
|
|
119
|
-
* Space Complexity: O(1)
|
|
120
|
-
*/
|
|
121
105
|
/**
|
|
122
106
|
* Time Complexity: O(1)
|
|
123
107
|
* Space Complexity: O(1)
|
|
@@ -130,10 +114,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
130
114
|
this.elements.push(element);
|
|
131
115
|
return true;
|
|
132
116
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Time Complexity: O(1)
|
|
135
|
-
* Space Complexity: O(1)
|
|
136
|
-
*/
|
|
137
117
|
/**
|
|
138
118
|
* Time Complexity: O(1)
|
|
139
119
|
* Space Complexity: O(1)
|
|
@@ -169,10 +149,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
169
149
|
const spliced = this.elements.splice(index, 1);
|
|
170
150
|
return spliced.length === 1;
|
|
171
151
|
}
|
|
172
|
-
/**
|
|
173
|
-
* Time Complexity: O(1)
|
|
174
|
-
* Space Complexity: O(1)
|
|
175
|
-
*/
|
|
176
152
|
/**
|
|
177
153
|
* Time Complexity: O(1)
|
|
178
154
|
* Space Complexity: O(1)
|
|
@@ -182,10 +158,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
182
158
|
at(index) {
|
|
183
159
|
return this.elements[index + this._offset];
|
|
184
160
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Time Complexity: O(1)
|
|
187
|
-
* Space Complexity: O(1)
|
|
188
|
-
*/
|
|
189
161
|
/**
|
|
190
162
|
* Time Complexity: O(1)
|
|
191
163
|
* Space Complexity: O(1)
|
|
@@ -196,10 +168,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
196
168
|
isEmpty() {
|
|
197
169
|
return this.size === 0;
|
|
198
170
|
}
|
|
199
|
-
/**
|
|
200
|
-
* Time Complexity: O(1)
|
|
201
|
-
* Space Complexity: O(n)
|
|
202
|
-
*/
|
|
203
171
|
/**
|
|
204
172
|
* Time Complexity: O(1)
|
|
205
173
|
* Space Complexity: O(n)
|
|
@@ -210,10 +178,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
210
178
|
toArray() {
|
|
211
179
|
return this.elements.slice(this.offset);
|
|
212
180
|
}
|
|
213
|
-
/**
|
|
214
|
-
* Time Complexity: O(1)
|
|
215
|
-
* Space Complexity: O(1)
|
|
216
|
-
*/
|
|
217
181
|
/**
|
|
218
182
|
* Time Complexity: O(1)
|
|
219
183
|
* Space Complexity: O(1)
|
|
@@ -234,11 +198,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
234
198
|
this._offset = 0;
|
|
235
199
|
return true;
|
|
236
200
|
}
|
|
237
|
-
/**
|
|
238
|
-
* Time Complexity: O(n)
|
|
239
|
-
* Space Complexity: O(n)
|
|
240
|
-
* where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
|
|
241
|
-
*/
|
|
242
201
|
/**
|
|
243
202
|
* Time Complexity: O(n)
|
|
244
203
|
* Space Complexity: O(n)
|
|
@@ -249,10 +208,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
249
208
|
clone() {
|
|
250
209
|
return new Queue(this.elements.slice(this.offset), { toElementFn: this.toElementFn });
|
|
251
210
|
}
|
|
252
|
-
/**
|
|
253
|
-
* Time Complexity: O(n)
|
|
254
|
-
* Space Complexity: O(n)
|
|
255
|
-
*/
|
|
256
211
|
/**
|
|
257
212
|
* Time Complexity: O(n)
|
|
258
213
|
* Space Complexity: O(n)
|
|
@@ -293,10 +248,6 @@ class Queue extends base_1.IterableElementBase {
|
|
|
293
248
|
}
|
|
294
249
|
return newDeque;
|
|
295
250
|
}
|
|
296
|
-
/**
|
|
297
|
-
* Time Complexity: O(n)
|
|
298
|
-
* Space Complexity: O(n)
|
|
299
|
-
*/
|
|
300
251
|
/**
|
|
301
252
|
* Time Complexity: O(n)
|
|
302
253
|
* Space Complexity: O(n)
|
|
@@ -317,10 +268,6 @@ exports.Queue = Queue;
|
|
|
317
268
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
318
269
|
*/
|
|
319
270
|
class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
320
|
-
/**
|
|
321
|
-
* Time Complexity: O(n)
|
|
322
|
-
* Space Complexity: O(n)
|
|
323
|
-
*/
|
|
324
271
|
/**
|
|
325
272
|
* Time Complexity: O(n)
|
|
326
273
|
* Space Complexity: O(n)
|
|
@@ -47,10 +47,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
47
47
|
* @returns A boolean value indicating whether the `_elements` array is empty or not.
|
|
48
48
|
*/
|
|
49
49
|
isEmpty(): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Time Complexity: O(1)
|
|
52
|
-
* Space Complexity: O(1)
|
|
53
|
-
*/
|
|
54
50
|
/**
|
|
55
51
|
* Time Complexity: O(1)
|
|
56
52
|
* Space Complexity: O(1)
|
|
@@ -59,10 +55,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
59
55
|
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
60
56
|
*/
|
|
61
57
|
peek(): E | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* Time Complexity: O(1)
|
|
64
|
-
* Space Complexity: O(1)
|
|
65
|
-
*/
|
|
66
58
|
/**
|
|
67
59
|
* Time Complexity: O(1)
|
|
68
60
|
* Space Complexity: O(1)
|
|
@@ -72,10 +64,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
72
64
|
* @returns The `push` method is returning the updated `Stack<E>` object.
|
|
73
65
|
*/
|
|
74
66
|
push(element: E): boolean;
|
|
75
|
-
/**
|
|
76
|
-
* Time Complexity: O(1)
|
|
77
|
-
* Space Complexity: O(1)
|
|
78
|
-
*/
|
|
79
67
|
/**
|
|
80
68
|
* Time Complexity: O(1)
|
|
81
69
|
* Space Complexity: O(1)
|
|
@@ -97,10 +85,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
97
85
|
* @return A boolean value
|
|
98
86
|
*/
|
|
99
87
|
deleteAt(index: number): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Time Complexity: O(n)
|
|
102
|
-
* Space Complexity: O(n)
|
|
103
|
-
*/
|
|
104
88
|
/**
|
|
105
89
|
* Time Complexity: O(n)
|
|
106
90
|
* Space Complexity: O(n)
|
|
@@ -109,10 +93,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
109
93
|
* @returns An array of type E.
|
|
110
94
|
*/
|
|
111
95
|
toArray(): E[];
|
|
112
|
-
/**
|
|
113
|
-
* Time Complexity: O(1)
|
|
114
|
-
* Space Complexity: O(1)
|
|
115
|
-
*/
|
|
116
96
|
/**
|
|
117
97
|
* Time Complexity: O(1)
|
|
118
98
|
* Space Complexity: O(1)
|
|
@@ -120,10 +100,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
120
100
|
* The clear function clears the elements array.
|
|
121
101
|
*/
|
|
122
102
|
clear(): void;
|
|
123
|
-
/**
|
|
124
|
-
* Time Complexity: O(n)
|
|
125
|
-
* Space Complexity: O(n)
|
|
126
|
-
*/
|
|
127
103
|
/**
|
|
128
104
|
* Time Complexity: O(n)
|
|
129
105
|
* Space Complexity: O(n)
|
|
@@ -132,10 +108,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
132
108
|
* @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
|
|
133
109
|
*/
|
|
134
110
|
clone(): Stack<E, R>;
|
|
135
|
-
/**
|
|
136
|
-
* Time Complexity: O(n)
|
|
137
|
-
* Space Complexity: O(n)
|
|
138
|
-
*/
|
|
139
111
|
/**
|
|
140
112
|
* Time Complexity: O(n)
|
|
141
113
|
* Space Complexity: O(n)
|
|
@@ -156,8 +128,7 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
156
128
|
/**
|
|
157
129
|
* Time Complexity: O(n)
|
|
158
130
|
* Space Complexity: O(n)
|
|
159
|
-
|
|
160
|
-
/**
|
|
131
|
+
*
|
|
161
132
|
* The `map` function takes a callback function and applies it to each element in the stack,
|
|
162
133
|
* returning a new stack with the results.
|
|
163
134
|
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
@@ -172,10 +143,6 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R, S
|
|
|
172
143
|
* @returns a new Stack object with elements of type EM and raw elements of type RM.
|
|
173
144
|
*/
|
|
174
145
|
map<EM, RM>(callback: ElementCallback<E, R, EM, Stack<E, R>>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): Stack<EM, RM>;
|
|
175
|
-
/**
|
|
176
|
-
* Time Complexity: O(n)
|
|
177
|
-
* Space Complexity: O(n)
|
|
178
|
-
*/
|
|
179
146
|
/**
|
|
180
147
|
* Time Complexity: O(n)
|
|
181
148
|
* Space Complexity: O(n)
|
|
@@ -62,10 +62,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
62
62
|
isEmpty() {
|
|
63
63
|
return this.elements.length === 0;
|
|
64
64
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Time Complexity: O(1)
|
|
67
|
-
* Space Complexity: O(1)
|
|
68
|
-
*/
|
|
69
65
|
/**
|
|
70
66
|
* Time Complexity: O(1)
|
|
71
67
|
* Space Complexity: O(1)
|
|
@@ -78,10 +74,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
78
74
|
return undefined;
|
|
79
75
|
return this.elements[this.elements.length - 1];
|
|
80
76
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Time Complexity: O(1)
|
|
83
|
-
* Space Complexity: O(1)
|
|
84
|
-
*/
|
|
85
77
|
/**
|
|
86
78
|
* Time Complexity: O(1)
|
|
87
79
|
* Space Complexity: O(1)
|
|
@@ -94,10 +86,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
94
86
|
this.elements.push(element);
|
|
95
87
|
return true;
|
|
96
88
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Time Complexity: O(1)
|
|
99
|
-
* Space Complexity: O(1)
|
|
100
|
-
*/
|
|
101
89
|
/**
|
|
102
90
|
* Time Complexity: O(1)
|
|
103
91
|
* Space Complexity: O(1)
|
|
@@ -129,10 +117,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
129
117
|
const spliced = this.elements.splice(index, 1);
|
|
130
118
|
return spliced.length === 1;
|
|
131
119
|
}
|
|
132
|
-
/**
|
|
133
|
-
* Time Complexity: O(n)
|
|
134
|
-
* Space Complexity: O(n)
|
|
135
|
-
*/
|
|
136
120
|
/**
|
|
137
121
|
* Time Complexity: O(n)
|
|
138
122
|
* Space Complexity: O(n)
|
|
@@ -143,10 +127,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
143
127
|
toArray() {
|
|
144
128
|
return this.elements.slice();
|
|
145
129
|
}
|
|
146
|
-
/**
|
|
147
|
-
* Time Complexity: O(1)
|
|
148
|
-
* Space Complexity: O(1)
|
|
149
|
-
*/
|
|
150
130
|
/**
|
|
151
131
|
* Time Complexity: O(1)
|
|
152
132
|
* Space Complexity: O(1)
|
|
@@ -156,10 +136,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
156
136
|
clear() {
|
|
157
137
|
this._elements = [];
|
|
158
138
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Time Complexity: O(n)
|
|
161
|
-
* Space Complexity: O(n)
|
|
162
|
-
*/
|
|
163
139
|
/**
|
|
164
140
|
* Time Complexity: O(n)
|
|
165
141
|
* Space Complexity: O(n)
|
|
@@ -170,10 +146,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
170
146
|
clone() {
|
|
171
147
|
return new Stack(this, { toElementFn: this.toElementFn });
|
|
172
148
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Time Complexity: O(n)
|
|
175
|
-
* Space Complexity: O(n)
|
|
176
|
-
*/
|
|
177
149
|
/**
|
|
178
150
|
* Time Complexity: O(n)
|
|
179
151
|
* Space Complexity: O(n)
|
|
@@ -204,8 +176,7 @@ class Stack extends base_1.IterableElementBase {
|
|
|
204
176
|
/**
|
|
205
177
|
* Time Complexity: O(n)
|
|
206
178
|
* Space Complexity: O(n)
|
|
207
|
-
|
|
208
|
-
/**
|
|
179
|
+
*
|
|
209
180
|
* The `map` function takes a callback function and applies it to each element in the stack,
|
|
210
181
|
* returning a new stack with the results.
|
|
211
182
|
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
@@ -228,10 +199,6 @@ class Stack extends base_1.IterableElementBase {
|
|
|
228
199
|
}
|
|
229
200
|
return newStack;
|
|
230
201
|
}
|
|
231
|
-
/**
|
|
232
|
-
* Time Complexity: O(n)
|
|
233
|
-
* Space Complexity: O(n)
|
|
234
|
-
*/
|
|
235
202
|
/**
|
|
236
203
|
* Time Complexity: O(n)
|
|
237
204
|
* Space Complexity: O(n)
|
|
@@ -15,7 +15,8 @@ class TreeNode {
|
|
|
15
15
|
constructor(key, value, children) {
|
|
16
16
|
this._key = key;
|
|
17
17
|
this._value = value || undefined;
|
|
18
|
-
|
|
18
|
+
if (children)
|
|
19
|
+
this._children = children;
|
|
19
20
|
}
|
|
20
21
|
/**
|
|
21
22
|
* The function returns the value of the protected variable _key.
|
|
@@ -92,10 +92,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
92
92
|
* @return The root node
|
|
93
93
|
*/
|
|
94
94
|
get root(): TrieNode;
|
|
95
|
-
/**
|
|
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.
|
|
98
|
-
*/
|
|
99
95
|
/**
|
|
100
96
|
* Time Complexity: O(l), where l is the length of the word being added.
|
|
101
97
|
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
@@ -105,10 +101,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
105
101
|
* @returns {boolean} True if the word was successfully added.
|
|
106
102
|
*/
|
|
107
103
|
add(word: string): boolean;
|
|
108
|
-
/**
|
|
109
|
-
* Time Complexity: O(l), where l is the length of the input word.
|
|
110
|
-
* Space Complexity: O(1) - Constant space.
|
|
111
|
-
*/
|
|
112
104
|
/**
|
|
113
105
|
* Time Complexity: O(l), where l is the length of the input word.
|
|
114
106
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -118,10 +110,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
118
110
|
* @returns {boolean} True if the word is present in the Trie.
|
|
119
111
|
*/
|
|
120
112
|
has(word: string): boolean;
|
|
121
|
-
/**
|
|
122
|
-
* Time Complexity: O(1)
|
|
123
|
-
* Space Complexity: O(1)
|
|
124
|
-
*/
|
|
125
113
|
/**
|
|
126
114
|
* Time Complexity: O(1)
|
|
127
115
|
* Space Complexity: O(1)
|
|
@@ -130,10 +118,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
130
118
|
* @return True if the size of the queue is 0
|
|
131
119
|
*/
|
|
132
120
|
isEmpty(): boolean;
|
|
133
|
-
/**
|
|
134
|
-
* Time Complexity: O(1)
|
|
135
|
-
* Space Complexity: O(1)
|
|
136
|
-
*/
|
|
137
121
|
/**
|
|
138
122
|
* Time Complexity: O(1)
|
|
139
123
|
* Space Complexity: O(1)
|
|
@@ -141,10 +125,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
141
125
|
* The clear function resets the size of the Trie to 0 and creates a new root TrieNode.
|
|
142
126
|
*/
|
|
143
127
|
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.
|
|
147
|
-
*/
|
|
148
128
|
/**
|
|
149
129
|
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
150
130
|
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
@@ -154,20 +134,12 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
154
134
|
* @returns {boolean} True if the word was successfully removed.
|
|
155
135
|
*/
|
|
156
136
|
delete(word: string): boolean;
|
|
157
|
-
/**
|
|
158
|
-
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
159
|
-
* Space Complexity: O(1) - Constant space.
|
|
160
|
-
*/
|
|
161
137
|
/**
|
|
162
138
|
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
163
139
|
* Space Complexity: O(1) - Constant space.
|
|
164
140
|
*
|
|
165
141
|
*/
|
|
166
142
|
getHeight(): number;
|
|
167
|
-
/**
|
|
168
|
-
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
169
|
-
* Space Complexity: O(1) - Constant space.
|
|
170
|
-
*/
|
|
171
143
|
/**
|
|
172
144
|
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
173
145
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -177,10 +149,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
177
149
|
* @returns {boolean} True if it's an absolute prefix in the Trie.
|
|
178
150
|
*/
|
|
179
151
|
hasPurePrefix(input: string): boolean;
|
|
180
|
-
/**
|
|
181
|
-
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
182
|
-
* Space Complexity: O(1) - Constant space.
|
|
183
|
-
*/
|
|
184
152
|
/**
|
|
185
153
|
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
186
154
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -190,10 +158,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
190
158
|
* @returns {boolean} True if it's a prefix in the Trie.
|
|
191
159
|
*/
|
|
192
160
|
hasPrefix(input: string): boolean;
|
|
193
|
-
/**
|
|
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.
|
|
196
|
-
*/
|
|
197
161
|
/**
|
|
198
162
|
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
199
163
|
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
@@ -203,10 +167,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
203
167
|
* @returns {boolean} True if it's a common prefix in the Trie.
|
|
204
168
|
*/
|
|
205
169
|
hasCommonPrefix(input: string): boolean;
|
|
206
|
-
/**
|
|
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.
|
|
209
|
-
*/
|
|
210
170
|
/**
|
|
211
171
|
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
212
172
|
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
@@ -215,10 +175,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
215
175
|
* @returns {string} The longest common prefix found in the Trie.
|
|
216
176
|
*/
|
|
217
177
|
getLongestCommonPrefix(): string;
|
|
218
|
-
/**
|
|
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.
|
|
221
|
-
*/
|
|
222
178
|
/**
|
|
223
179
|
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
224
180
|
* Space Complexity: O(w * l) - The space required for the output array.
|
|
@@ -231,10 +187,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
231
187
|
* @returns {string[]} an array of strings.
|
|
232
188
|
*/
|
|
233
189
|
getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
|
|
234
|
-
/**
|
|
235
|
-
* Time Complexity: O(n)
|
|
236
|
-
* Space Complexity: O(n)
|
|
237
|
-
*/
|
|
238
190
|
/**
|
|
239
191
|
* Time Complexity: O(n)
|
|
240
192
|
* Space Complexity: O(n)
|
|
@@ -244,10 +196,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
244
196
|
* @returns A new instance of the Trie class is being returned.
|
|
245
197
|
*/
|
|
246
198
|
clone(): Trie<R>;
|
|
247
|
-
/**
|
|
248
|
-
* Time Complexity: O(n)
|
|
249
|
-
* Space Complexity: O(n)
|
|
250
|
-
*/
|
|
251
199
|
/**
|
|
252
200
|
* Time Complexity: O(n)
|
|
253
201
|
* Space Complexity: O(n)
|
|
@@ -263,10 +211,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
263
211
|
* @returns The `filter` method is returning an array of strings (`string[]`).
|
|
264
212
|
*/
|
|
265
213
|
filter(predicate: ElementCallback<string, R, boolean, Trie<R>>, thisArg?: any): Trie<R>;
|
|
266
|
-
/**
|
|
267
|
-
* Time Complexity: O(n)
|
|
268
|
-
* Space Complexity: O(n)
|
|
269
|
-
*/
|
|
270
214
|
/**
|
|
271
215
|
* Time Complexity: O(n)
|
|
272
216
|
* Space Complexity: O(n)
|
|
@@ -286,10 +230,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
286
230
|
* @returns a new Trie object.
|
|
287
231
|
*/
|
|
288
232
|
map<RM>(callback: ElementCallback<string, R, string, Trie<R>>, toElementFn?: (rawElement: RM) => string, thisArg?: any): Trie<RM>;
|
|
289
|
-
/**
|
|
290
|
-
* Time Complexity: O(n)
|
|
291
|
-
* Space Complexity: O(n)
|
|
292
|
-
*/
|
|
293
233
|
/**
|
|
294
234
|
* Time Complexity: O(n)
|
|
295
235
|
* Space Complexity: O(n)
|
|
@@ -298,10 +238,6 @@ export declare class Trie<R = any> extends IterableElementBase<string, R, Trie<R
|
|
|
298
238
|
* trie data structure and yields all the paths to the end nodes.
|
|
299
239
|
*/
|
|
300
240
|
protected _getIterator(): IterableIterator<string>;
|
|
301
|
-
/**
|
|
302
|
-
* Time Complexity: O(l), where l is the length of the input string.
|
|
303
|
-
* Space Complexity: O(1) - Constant space.
|
|
304
|
-
*/
|
|
305
241
|
/**
|
|
306
242
|
* Time Complexity: O(l), where l is the length of the input string.
|
|
307
243
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -124,10 +124,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
124
124
|
get root() {
|
|
125
125
|
return this._root;
|
|
126
126
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Time Complexity: O(l), where l is the length of the word being added.
|
|
129
|
-
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
130
|
-
*/
|
|
131
127
|
/**
|
|
132
128
|
* Time Complexity: O(l), where l is the length of the word being added.
|
|
133
129
|
* Space Complexity: O(l) - Each character in the word adds a TrieNode.
|
|
@@ -155,10 +151,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
155
151
|
}
|
|
156
152
|
return isNewWord;
|
|
157
153
|
}
|
|
158
|
-
/**
|
|
159
|
-
* Time Complexity: O(l), where l is the length of the input word.
|
|
160
|
-
* Space Complexity: O(1) - Constant space.
|
|
161
|
-
*/
|
|
162
154
|
/**
|
|
163
155
|
* Time Complexity: O(l), where l is the length of the input word.
|
|
164
156
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -178,10 +170,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
178
170
|
}
|
|
179
171
|
return cur.isEnd;
|
|
180
172
|
}
|
|
181
|
-
/**
|
|
182
|
-
* Time Complexity: O(1)
|
|
183
|
-
* Space Complexity: O(1)
|
|
184
|
-
*/
|
|
185
173
|
/**
|
|
186
174
|
* Time Complexity: O(1)
|
|
187
175
|
* Space Complexity: O(1)
|
|
@@ -192,10 +180,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
192
180
|
isEmpty() {
|
|
193
181
|
return this.size === 0;
|
|
194
182
|
}
|
|
195
|
-
/**
|
|
196
|
-
* Time Complexity: O(1)
|
|
197
|
-
* Space Complexity: O(1)
|
|
198
|
-
*/
|
|
199
183
|
/**
|
|
200
184
|
* Time Complexity: O(1)
|
|
201
185
|
* Space Complexity: O(1)
|
|
@@ -206,10 +190,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
206
190
|
this._size = 0;
|
|
207
191
|
this._root = new TrieNode('');
|
|
208
192
|
}
|
|
209
|
-
/**
|
|
210
|
-
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
211
|
-
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
212
|
-
*/
|
|
213
193
|
/**
|
|
214
194
|
* Time Complexity: O(l), where l is the length of the word being deleted.
|
|
215
195
|
* Space Complexity: O(n) - Due to the recursive DFS approach.
|
|
@@ -253,10 +233,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
253
233
|
}
|
|
254
234
|
return isDeleted;
|
|
255
235
|
}
|
|
256
|
-
/**
|
|
257
|
-
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
258
|
-
* Space Complexity: O(1) - Constant space.
|
|
259
|
-
*/
|
|
260
236
|
/**
|
|
261
237
|
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
262
238
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -281,10 +257,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
281
257
|
}
|
|
282
258
|
return maxDepth;
|
|
283
259
|
}
|
|
284
|
-
/**
|
|
285
|
-
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
286
|
-
* Space Complexity: O(1) - Constant space.
|
|
287
|
-
*/
|
|
288
260
|
/**
|
|
289
261
|
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
290
262
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -304,10 +276,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
304
276
|
}
|
|
305
277
|
return !cur.isEnd;
|
|
306
278
|
}
|
|
307
|
-
/**
|
|
308
|
-
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
309
|
-
* Space Complexity: O(1) - Constant space.
|
|
310
|
-
*/
|
|
311
279
|
/**
|
|
312
280
|
* Time Complexity: O(l), where l is the length of the input prefix.
|
|
313
281
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -327,10 +295,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
327
295
|
}
|
|
328
296
|
return true;
|
|
329
297
|
}
|
|
330
|
-
/**
|
|
331
|
-
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
332
|
-
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
333
|
-
*/
|
|
334
298
|
/**
|
|
335
299
|
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
336
300
|
* Space Complexity: O(l), where l is the length of the input prefix.
|
|
@@ -356,10 +320,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
356
320
|
dfs(this.root);
|
|
357
321
|
return commonPre === input;
|
|
358
322
|
}
|
|
359
|
-
/**
|
|
360
|
-
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
361
|
-
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
362
|
-
*/
|
|
363
323
|
/**
|
|
364
324
|
* Time Complexity: O(n), where n is the total number of nodes in the trie.
|
|
365
325
|
* Space Complexity: O(l), where l is the length of the longest common prefix.
|
|
@@ -381,10 +341,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
381
341
|
dfs(this.root);
|
|
382
342
|
return commonPre;
|
|
383
343
|
}
|
|
384
|
-
/**
|
|
385
|
-
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
386
|
-
* Space Complexity: O(w * l) - The space required for the output array.
|
|
387
|
-
*/
|
|
388
344
|
/**
|
|
389
345
|
* Time Complexity: O(w * l), where w is the number of words retrieved, and l is the average length of the words.
|
|
390
346
|
* Space Complexity: O(w * l) - The space required for the output array.
|
|
@@ -431,10 +387,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
431
387
|
dfs(startNode, prefix);
|
|
432
388
|
return words;
|
|
433
389
|
}
|
|
434
|
-
/**
|
|
435
|
-
* Time Complexity: O(n)
|
|
436
|
-
* Space Complexity: O(n)
|
|
437
|
-
*/
|
|
438
390
|
/**
|
|
439
391
|
* Time Complexity: O(n)
|
|
440
392
|
* Space Complexity: O(n)
|
|
@@ -446,10 +398,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
446
398
|
clone() {
|
|
447
399
|
return new Trie(this, { caseSensitive: this.caseSensitive, toElementFn: this.toElementFn });
|
|
448
400
|
}
|
|
449
|
-
/**
|
|
450
|
-
* Time Complexity: O(n)
|
|
451
|
-
* Space Complexity: O(n)
|
|
452
|
-
*/
|
|
453
401
|
/**
|
|
454
402
|
* Time Complexity: O(n)
|
|
455
403
|
* Space Complexity: O(n)
|
|
@@ -475,10 +423,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
475
423
|
}
|
|
476
424
|
return results;
|
|
477
425
|
}
|
|
478
|
-
/**
|
|
479
|
-
* Time Complexity: O(n)
|
|
480
|
-
* Space Complexity: O(n)
|
|
481
|
-
*/
|
|
482
426
|
/**
|
|
483
427
|
* Time Complexity: O(n)
|
|
484
428
|
* Space Complexity: O(n)
|
|
@@ -506,10 +450,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
506
450
|
}
|
|
507
451
|
return newTrie;
|
|
508
452
|
}
|
|
509
|
-
/**
|
|
510
|
-
* Time Complexity: O(n)
|
|
511
|
-
* Space Complexity: O(n)
|
|
512
|
-
*/
|
|
513
453
|
/**
|
|
514
454
|
* Time Complexity: O(n)
|
|
515
455
|
* Space Complexity: O(n)
|
|
@@ -528,10 +468,6 @@ class Trie extends base_1.IterableElementBase {
|
|
|
528
468
|
}
|
|
529
469
|
yield* _dfs(this.root, '');
|
|
530
470
|
}
|
|
531
|
-
/**
|
|
532
|
-
* Time Complexity: O(l), where l is the length of the input string.
|
|
533
|
-
* Space Complexity: O(1) - Constant space.
|
|
534
|
-
*/
|
|
535
471
|
/**
|
|
536
472
|
* Time Complexity: O(l), where l is the length of the input string.
|
|
537
473
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -23,3 +23,11 @@ export type BinaryTreeDeleteResult<NODE> = {
|
|
|
23
23
|
needBalanced: OptBTNOrNull<NODE>;
|
|
24
24
|
};
|
|
25
25
|
export type BTNCallback<NODE, D = any> = (node: NODE) => D;
|
|
26
|
+
export declare enum DFSOperation {
|
|
27
|
+
VISIT = 0,
|
|
28
|
+
PROCESS = 1
|
|
29
|
+
}
|
|
30
|
+
export type DFSStackItem<NODE> = {
|
|
31
|
+
opt: DFSOperation;
|
|
32
|
+
node: OptBTNOrNull<NODE>;
|
|
33
|
+
};
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DFSOperation = void 0;
|
|
4
|
+
var DFSOperation;
|
|
5
|
+
(function (DFSOperation) {
|
|
6
|
+
DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
|
|
7
|
+
DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS";
|
|
8
|
+
})(DFSOperation = exports.DFSOperation || (exports.DFSOperation = {}));
|