directed-graph-typed 1.48.0 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/data-structures/base/index.d.ts +1 -0
- package/dist/data-structures/base/index.js +17 -0
- package/dist/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/data-structures/base/iterable-base.js +312 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +28 -19
- package/dist/data-structures/binary-tree/avl-tree.js +22 -11
- package/dist/data-structures/binary-tree/binary-tree.d.ts +158 -152
- package/dist/data-structures/binary-tree/binary-tree.js +241 -215
- package/dist/data-structures/binary-tree/bst.d.ts +64 -48
- package/dist/data-structures/binary-tree/bst.js +94 -65
- package/dist/data-structures/binary-tree/rb-tree.d.ts +39 -39
- package/dist/data-structures/binary-tree/rb-tree.js +42 -49
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +60 -34
- package/dist/data-structures/binary-tree/tree-multimap.js +59 -27
- package/dist/data-structures/graph/abstract-graph.d.ts +92 -53
- package/dist/data-structures/graph/abstract-graph.js +130 -103
- package/dist/data-structures/graph/directed-graph.d.ts +70 -52
- package/dist/data-structures/graph/directed-graph.js +111 -65
- package/dist/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/data-structures/graph/map-graph.js +8 -8
- package/dist/data-structures/graph/undirected-graph.d.ts +51 -32
- package/dist/data-structures/graph/undirected-graph.js +117 -54
- package/dist/data-structures/hash/hash-map.d.ts +160 -44
- package/dist/data-structures/hash/hash-map.js +314 -82
- package/dist/data-structures/heap/heap.d.ts +50 -7
- package/dist/data-structures/heap/heap.js +60 -30
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +42 -55
- package/dist/data-structures/linked-list/doubly-linked-list.js +50 -77
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +36 -55
- package/dist/data-structures/linked-list/singly-linked-list.js +44 -77
- package/dist/data-structures/queue/deque.d.ts +35 -167
- package/dist/data-structures/queue/deque.js +43 -249
- package/dist/data-structures/queue/queue.d.ts +49 -48
- package/dist/data-structures/queue/queue.js +69 -82
- package/dist/data-structures/stack/stack.d.ts +43 -10
- package/dist/data-structures/stack/stack.js +50 -31
- package/dist/data-structures/trie/trie.d.ts +41 -6
- package/dist/data-structures/trie/trie.js +53 -32
- package/dist/interfaces/binary-tree.d.ts +6 -6
- package/dist/types/common.d.ts +11 -8
- package/dist/types/common.js +6 -1
- package/dist/types/data-structures/base/base.d.ts +5 -0
- package/dist/types/data-structures/base/base.js +2 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/index.js +17 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -0
- package/dist/types/data-structures/index.d.ts +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-base.ts +329 -0
- package/src/data-structures/binary-tree/avl-tree.ts +37 -25
- package/src/data-structures/binary-tree/binary-tree.ts +336 -296
- package/src/data-structures/binary-tree/bst.ts +135 -89
- package/src/data-structures/binary-tree/rb-tree.ts +60 -69
- package/src/data-structures/binary-tree/tree-multimap.ts +86 -49
- package/src/data-structures/graph/abstract-graph.ts +136 -104
- package/src/data-structures/graph/directed-graph.ts +114 -65
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +124 -56
- package/src/data-structures/hash/hash-map.ts +335 -84
- package/src/data-structures/heap/heap.ts +63 -36
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +54 -83
- package/src/data-structures/linked-list/singly-linked-list.ts +49 -84
- package/src/data-structures/queue/deque.ts +43 -275
- package/src/data-structures/queue/queue.ts +71 -86
- package/src/data-structures/stack/stack.ts +53 -34
- package/src/data-structures/trie/trie.ts +58 -35
- package/src/interfaces/binary-tree.ts +5 -6
- package/src/types/common.ts +11 -8
- package/src/types/data-structures/base/base.ts +6 -0
- package/src/types/data-structures/base/index.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
- package/src/types/data-structures/hash/hash-map.ts +2 -0
- package/src/types/data-structures/heap/heap.ts +1 -1
- package/src/types/data-structures/index.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { IterableElementBase } from "../base";
|
|
2
|
+
import { ElementCallback } from "../../types";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* @license MIT
|
|
3
6
|
* @copyright Tyler Zeng <zrwusa@gmail.com>
|
|
4
7
|
* @class
|
|
5
8
|
*/
|
|
6
|
-
export class Stack<E = any> {
|
|
9
|
+
export class Stack<E = any> extends IterableElementBase<E> {
|
|
7
10
|
/**
|
|
8
11
|
* The constructor initializes an array of elements, which can be provided as an optional parameter.
|
|
9
12
|
* @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
|
|
@@ -11,6 +14,7 @@ export class Stack<E = any> {
|
|
|
11
14
|
* is provided and is an array, it is assigned to the `_elements
|
|
12
15
|
*/
|
|
13
16
|
constructor(elements?: Iterable<E>) {
|
|
17
|
+
super();
|
|
14
18
|
this._elements = [];
|
|
15
19
|
if (elements) {
|
|
16
20
|
for (const el of elements) {
|
|
@@ -154,33 +158,31 @@ export class Stack<E = any> {
|
|
|
154
158
|
}
|
|
155
159
|
|
|
156
160
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
161
|
+
* Time Complexity: O(n)
|
|
162
|
+
* Space Complexity: O(n)
|
|
159
163
|
*/
|
|
160
|
-
* [Symbol.iterator]() {
|
|
161
|
-
for (let i = 0; i < this.elements.length; i++) {
|
|
162
|
-
yield this.elements[i];
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
164
|
|
|
166
165
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
166
|
+
* Time Complexity: O(n)
|
|
167
|
+
* Space Complexity: O(n)
|
|
168
|
+
*
|
|
169
|
+
* The `filter` function creates a new stack containing elements from the original stack that satisfy
|
|
170
|
+
* a given predicate function.
|
|
171
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
172
|
+
* the current element being iterated over, the index of the current element, and the stack itself.
|
|
173
|
+
* It should return a boolean value indicating whether the element should be included in the filtered
|
|
174
|
+
* stack or not.
|
|
175
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
176
|
+
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
177
|
+
* passed as the `this` value to the `predicate` function. If `thisArg` is
|
|
178
|
+
* @returns The `filter` method is returning a new `Stack` object that contains the elements that
|
|
179
|
+
* satisfy the given predicate function.
|
|
180
|
+
*/
|
|
181
|
+
filter(predicate: ElementCallback<E, boolean>, thisArg?: any): Stack<E> {
|
|
180
182
|
const newStack = new Stack<E>();
|
|
181
183
|
let index = 0;
|
|
182
184
|
for (const el of this) {
|
|
183
|
-
if (predicate(el, index, this)) {
|
|
185
|
+
if (predicate.call(thisArg, el, index, this)) {
|
|
184
186
|
newStack.push(el);
|
|
185
187
|
}
|
|
186
188
|
index++;
|
|
@@ -188,28 +190,45 @@ export class Stack<E = any> {
|
|
|
188
190
|
return newStack;
|
|
189
191
|
}
|
|
190
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Time Complexity: O(n)
|
|
195
|
+
* Space Complexity: O(n)
|
|
196
|
+
*/
|
|
191
197
|
|
|
192
|
-
|
|
198
|
+
/**
|
|
199
|
+
* Time Complexity: O(n)
|
|
200
|
+
* Space Complexity: O(n)
|
|
201
|
+
*
|
|
202
|
+
* The `map` function takes a callback function and applies it to each element in the stack,
|
|
203
|
+
* returning a new stack with the results.
|
|
204
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
205
|
+
* the stack. It takes three arguments:
|
|
206
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
207
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
208
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
209
|
+
* @returns The `map` method is returning a new `Stack` object.
|
|
210
|
+
*/
|
|
211
|
+
map<T>(callback: ElementCallback<E, T>, thisArg?: any): Stack<T> {
|
|
193
212
|
const newStack = new Stack<T>();
|
|
194
213
|
let index = 0;
|
|
195
214
|
for (const el of this) {
|
|
196
|
-
newStack.push(callback(el, index, this));
|
|
215
|
+
newStack.push(callback.call(thisArg, el, index, this));
|
|
197
216
|
index++;
|
|
198
217
|
}
|
|
199
218
|
return newStack;
|
|
200
219
|
}
|
|
201
220
|
|
|
202
|
-
reduce<T>(callback: (accumulator: T, element: E, index: number, stack: this) => T, initialValue: T): T {
|
|
203
|
-
let accumulator = initialValue;
|
|
204
|
-
let index = 0;
|
|
205
|
-
for (const el of this) {
|
|
206
|
-
accumulator = callback(accumulator, el, index, this);
|
|
207
|
-
index++;
|
|
208
|
-
}
|
|
209
|
-
return accumulator;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
221
|
print(): void {
|
|
213
222
|
console.log([...this]);
|
|
214
223
|
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Custom iterator for the Stack class.
|
|
227
|
+
* @returns An iterator object.
|
|
228
|
+
*/
|
|
229
|
+
protected* _getIterator() {
|
|
230
|
+
for (let i = 0; i < this.elements.length; i++) {
|
|
231
|
+
yield this.elements[i];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
215
234
|
}
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { IterableElementBase } from "../base";
|
|
10
|
+
import { ElementCallback } from "../../types";
|
|
11
|
+
|
|
9
12
|
/**
|
|
10
13
|
* TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
|
|
11
14
|
* and a flag indicating whether it's the end of a word.
|
|
@@ -25,8 +28,9 @@ export class TrieNode {
|
|
|
25
28
|
/**
|
|
26
29
|
* Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
|
|
27
30
|
*/
|
|
28
|
-
export class Trie {
|
|
31
|
+
export class Trie extends IterableElementBase<string> {
|
|
29
32
|
constructor(words?: string[], caseSensitive = true) {
|
|
33
|
+
super();
|
|
30
34
|
this._root = new TrieNode('');
|
|
31
35
|
this._caseSensitive = caseSensitive;
|
|
32
36
|
this._size = 0;
|
|
@@ -339,32 +343,30 @@ export class Trie {
|
|
|
339
343
|
return words;
|
|
340
344
|
}
|
|
341
345
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
for (const [char, childNode] of node.children) {
|
|
348
|
-
yield* _dfs(childNode, path + char);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
yield* _dfs(this.root, '');
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
forEach(callback: (word: string, index: number, trie: this) => void): void {
|
|
356
|
-
let index = 0;
|
|
357
|
-
for (const word of this) {
|
|
358
|
-
callback(word, index, this);
|
|
359
|
-
index++;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
346
|
+
/**
|
|
347
|
+
* Time Complexity: O(n)
|
|
348
|
+
* Space Complexity: O(n)
|
|
349
|
+
*/
|
|
362
350
|
|
|
363
|
-
|
|
351
|
+
/**
|
|
352
|
+
* Time Complexity: O(n)
|
|
353
|
+
* Space Complexity: O(n)
|
|
354
|
+
*
|
|
355
|
+
* The `filter` function takes a predicate function and returns a new array containing all the
|
|
356
|
+
* elements for which the predicate function returns true.
|
|
357
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
358
|
+
* `word`, `index`, and `this`. It should return a boolean value indicating whether the current
|
|
359
|
+
* element should be included in the filtered results or not.
|
|
360
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
|
|
361
|
+
* specify the value of `this` within the `predicate` function. It is used when you want to bind a
|
|
362
|
+
* specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
|
|
363
|
+
* @returns The `filter` method is returning an array of strings (`string[]`).
|
|
364
|
+
*/
|
|
365
|
+
filter(predicate: ElementCallback<string, boolean>, thisArg?: any): string[] {
|
|
364
366
|
const results: string[] = [];
|
|
365
367
|
let index = 0;
|
|
366
368
|
for (const word of this) {
|
|
367
|
-
if (predicate(word, index, this)) {
|
|
369
|
+
if (predicate.call(thisArg, word, index, this)) {
|
|
368
370
|
results.push(word);
|
|
369
371
|
}
|
|
370
372
|
index++;
|
|
@@ -372,30 +374,51 @@ export class Trie {
|
|
|
372
374
|
return results;
|
|
373
375
|
}
|
|
374
376
|
|
|
375
|
-
|
|
377
|
+
/**
|
|
378
|
+
* Time Complexity: O(n)
|
|
379
|
+
* Space Complexity: O(n)
|
|
380
|
+
*/
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Time Complexity: O(n)
|
|
384
|
+
* Space Complexity: O(n)
|
|
385
|
+
*
|
|
386
|
+
* The `map` function creates a new Trie by applying a callback function to each element in the Trie.
|
|
387
|
+
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
388
|
+
* Trie. It takes three arguments: the current element in the Trie, the index of the current element,
|
|
389
|
+
* and the Trie itself. The callback function should return a new value for the element.
|
|
390
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
391
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
392
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
393
|
+
* @returns The `map` function is returning a new Trie object.
|
|
394
|
+
*/
|
|
395
|
+
map(callback: ElementCallback<string, string>, thisArg?: any): Trie {
|
|
376
396
|
const newTrie = new Trie();
|
|
377
397
|
let index = 0;
|
|
378
398
|
for (const word of this) {
|
|
379
|
-
newTrie.add(callback(word, index, this));
|
|
399
|
+
newTrie.add(callback.call(thisArg, word, index, this));
|
|
380
400
|
index++;
|
|
381
401
|
}
|
|
382
402
|
return newTrie;
|
|
383
403
|
}
|
|
384
404
|
|
|
385
|
-
reduce<T>(callback: (accumulator: T, word: string, index: number, trie: this) => T, initialValue: T): T {
|
|
386
|
-
let accumulator = initialValue;
|
|
387
|
-
let index = 0;
|
|
388
|
-
for (const word of this) {
|
|
389
|
-
accumulator = callback(accumulator, word, index, this);
|
|
390
|
-
index++;
|
|
391
|
-
}
|
|
392
|
-
return accumulator;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
405
|
print() {
|
|
396
406
|
console.log([...this]);
|
|
397
407
|
}
|
|
398
408
|
|
|
409
|
+
protected* _getIterator(): IterableIterator<string> {
|
|
410
|
+
function* _dfs(node: TrieNode, path: string): IterableIterator<string> {
|
|
411
|
+
if (node.isEnd) {
|
|
412
|
+
yield path;
|
|
413
|
+
}
|
|
414
|
+
for (const [char, childNode] of node.children) {
|
|
415
|
+
yield* _dfs(childNode, path + char);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
yield* _dfs(this.root, '');
|
|
420
|
+
}
|
|
421
|
+
|
|
399
422
|
/**
|
|
400
423
|
* Time Complexity: O(M), where M is the length of the input string.
|
|
401
424
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -5,18 +5,17 @@ import {
|
|
|
5
5
|
BinaryTreeOptions,
|
|
6
6
|
BiTreeDeleteResult,
|
|
7
7
|
BTNCallback,
|
|
8
|
-
BTNKey,
|
|
9
8
|
BTNodeExemplar,
|
|
10
9
|
} from '../types';
|
|
11
10
|
|
|
12
|
-
export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>, TREE extends BinaryTree<V, N, TREE> = BinaryTreeNested<V, N>> {
|
|
13
|
-
createNode(key:
|
|
11
|
+
export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V, N> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, N, TREE> = BinaryTreeNested<K, V, N>> {
|
|
12
|
+
createNode(key: K, value?: N['value']): N;
|
|
14
13
|
|
|
15
|
-
createTree(options?: Partial<BinaryTreeOptions
|
|
14
|
+
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
16
15
|
|
|
17
|
-
add(keyOrNodeOrEntry: BTNodeExemplar<V, N>, count?: number): N | null | undefined;
|
|
16
|
+
add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
|
|
18
17
|
|
|
19
|
-
addMany(nodes: Iterable<BTNodeExemplar<V, N
|
|
18
|
+
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
|
|
20
19
|
|
|
21
20
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
|
|
22
21
|
}
|
package/src/types/common.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
export type Comparator<K> = (a: K, b: K) => number;
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export enum BSTVariant {
|
|
4
|
+
MIN = 'MIN',
|
|
5
|
+
MAX = 'MAX',
|
|
6
|
+
}
|
|
4
7
|
|
|
5
8
|
export type DFSOrderPattern = 'pre' | 'in' | 'post';
|
|
6
9
|
|
|
@@ -24,14 +27,14 @@ export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLeng
|
|
|
24
27
|
|
|
25
28
|
export type BinaryTreePrintOptions = { isShowUndefined?: boolean, isShowNull?: boolean, isShowRedBlackNIL?: boolean }
|
|
26
29
|
|
|
27
|
-
export type BTNodeEntry<
|
|
30
|
+
export type BTNodeEntry<K, V> = [K | null | undefined, V | undefined];
|
|
28
31
|
|
|
29
|
-
export type BTNodeKeyOrNode<N> =
|
|
32
|
+
export type BTNodeKeyOrNode<K, N> = K | null | undefined | N;
|
|
30
33
|
|
|
31
|
-
export type BTNodeExemplar<
|
|
34
|
+
export type BTNodeExemplar<K, V, N> = BTNodeEntry<K, V> | BTNodeKeyOrNode<K, N>
|
|
32
35
|
|
|
33
|
-
export type BTNodePureExemplar<
|
|
36
|
+
export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>
|
|
34
37
|
|
|
35
|
-
export type BTNodePureKeyOrNode<N> =
|
|
38
|
+
export type BTNodePureKeyOrNode<K, N> = K | N;
|
|
36
39
|
|
|
37
|
-
export type BSTNodeKeyOrNode<N> =
|
|
40
|
+
export type BSTNodeKeyOrNode<K, N> = K | undefined | N;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IterableElementBase, IterableEntryBase } from "../../../data-structures";
|
|
2
|
+
|
|
3
|
+
export type EntryCallback<K, V, R> = (value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
|
|
4
|
+
export type ElementCallback<V, R> = (element: V, index: number, container: IterableElementBase<V>) => R;
|
|
5
|
+
export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
|
|
6
|
+
export type ReduceElementCallback<V, R> = (accumulator: R, element: V, index: number, container: IterableElementBase<V>) => R;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './base';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AVLTree, AVLTreeNode } from '../../../data-structures';
|
|
2
2
|
import { BSTOptions } from './bst';
|
|
3
3
|
|
|
4
|
-
export type AVLTreeNodeNested<
|
|
4
|
+
export type AVLTreeNodeNested<K, V> = AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, AVLTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
5
5
|
|
|
6
|
-
export type AVLTreeNested<
|
|
6
|
+
export type AVLTreeNested<K, V, N extends AVLTreeNode<K, V, N>> = AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, AVLTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
export type AVLTreeOptions = BSTOptions & {};
|
|
9
|
+
export type AVLTreeOptions<K> = BSTOptions<K> & {};
|
|
@@ -22,14 +22,15 @@ export enum FamilyPosition {
|
|
|
22
22
|
MAL_NODE = 'MAL_NODE'
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export type BTNKey = number;
|
|
26
|
-
|
|
27
25
|
export type BiTreeDeleteResult<N> = { deleted: N | null | undefined; needBalanced: N | null | undefined };
|
|
28
26
|
|
|
29
|
-
export type BinaryTreeNodeNested<
|
|
27
|
+
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
30
28
|
|
|
31
|
-
export type BinaryTreeNested<
|
|
29
|
+
export type BinaryTreeNested<K, V, N extends BinaryTreeNode<K, V, N>> = BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, BinaryTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
32
30
|
|
|
33
|
-
export type BinaryTreeOptions = {
|
|
31
|
+
export type BinaryTreeOptions<K> = {
|
|
32
|
+
iterationType: IterationType,
|
|
33
|
+
extractor: (key: K) => number
|
|
34
|
+
}
|
|
34
35
|
|
|
35
36
|
export type NodeDisplayLayout = [string[], number, number, number];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BST, BSTNode } from '../../../data-structures';
|
|
2
|
-
import type { BinaryTreeOptions
|
|
3
|
-
import {
|
|
2
|
+
import type { BinaryTreeOptions } from './binary-tree';
|
|
3
|
+
import { BSTVariant } from "../../common";
|
|
4
4
|
|
|
5
5
|
// prettier-ignore
|
|
6
|
-
export type BSTNodeNested<
|
|
6
|
+
export type BSTNodeNested<K, V> = BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, BSTNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
7
|
|
|
8
|
-
export type BSTNested<
|
|
8
|
+
export type BSTNested<K, V, N extends BSTNode<K, V, N>> = BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, BST<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
9
9
|
|
|
10
|
-
export type BSTOptions = BinaryTreeOptions & {
|
|
11
|
-
|
|
10
|
+
export type BSTOptions<K> = BinaryTreeOptions<K> & {
|
|
11
|
+
variant: BSTVariant
|
|
12
12
|
}
|
|
@@ -3,8 +3,8 @@ import { BSTOptions } from "./bst";
|
|
|
3
3
|
|
|
4
4
|
export enum RBTNColor { RED = 1, BLACK = 0}
|
|
5
5
|
|
|
6
|
-
export type RedBlackTreeNodeNested<
|
|
6
|
+
export type RedBlackTreeNodeNested<K, V> = RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, RedBlackTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
7
7
|
|
|
8
|
-
export type RedBlackTreeNested<
|
|
8
|
+
export type RedBlackTreeNested<K, V, N extends RedBlackTreeNode<K, V, N>> = RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, RedBlackTree<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
9
9
|
|
|
10
|
-
export type RBTreeOptions = BSTOptions & {};
|
|
10
|
+
export type RBTreeOptions<K> = BSTOptions<K> & {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TreeMultimap, TreeMultimapNode } from '../../../data-structures';
|
|
2
2
|
import { AVLTreeOptions } from './avl-tree';
|
|
3
3
|
|
|
4
|
-
export type TreeMultimapNodeNested<
|
|
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
5
|
|
|
6
|
-
export type TreeMultimapNested<
|
|
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
7
|
|
|
8
|
-
export type TreeMultimapOptions = Omit<AVLTreeOptions
|
|
8
|
+
export type TreeMultimapOptions<K> = Omit<AVLTreeOptions<K>, 'isMergeDuplicatedNodeByKey'> & {}
|