data-structure-typed 1.49.0 → 1.49.2
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/CHANGELOG.md +1 -1
- package/README.md +16 -16
- package/README_zh-CN.md +2 -2
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +457 -22
- package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/cjs/data-structures/base/iterable-base.js +21 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +3 -4
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +6 -6
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +15 -15
- package/dist/cjs/data-structures/binary-tree/bst.js +3 -3
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +5 -6
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +3 -3
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/cjs/data-structures/graph/abstract-graph.js +27 -31
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +1 -8
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js +1 -8
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +22 -10
- package/dist/cjs/data-structures/hash/hash-map.js +28 -16
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-table.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +20 -38
- package/dist/cjs/data-structures/heap/heap.js +22 -42
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/cjs/data-structures/heap/max-heap.js +10 -7
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/cjs/data-structures/heap/min-heap.js +10 -7
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +132 -136
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -49
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -7
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +76 -80
- package/dist/cjs/data-structures/queue/deque.js +106 -122
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +30 -16
- package/dist/cjs/data-structures/queue/queue.js +31 -24
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +17 -8
- package/dist/cjs/data-structures/stack/stack.js +9 -9
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +14 -5
- package/dist/cjs/data-structures/trie/trie.js +13 -13
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/cjs/types/common.d.ts +32 -8
- package/dist/cjs/types/common.js +22 -1
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -22
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/mjs/data-structures/base/iterable-base.js +21 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +10 -12
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +3 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +58 -58
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +6 -6
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +15 -15
- package/dist/mjs/data-structures/binary-tree/bst.js +3 -3
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +11 -11
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +5 -6
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +14 -14
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -3
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +9 -3
- package/dist/mjs/data-structures/graph/abstract-graph.js +27 -31
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +8 -1
- package/dist/mjs/data-structures/graph/directed-graph.js +1 -8
- package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +8 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js +1 -8
- package/dist/mjs/data-structures/hash/hash-map.d.ts +22 -10
- package/dist/mjs/data-structures/hash/hash-map.js +27 -15
- package/dist/mjs/data-structures/hash/hash-table.d.ts +2 -2
- package/dist/mjs/data-structures/heap/heap.d.ts +20 -38
- package/dist/mjs/data-structures/heap/heap.js +23 -43
- package/dist/mjs/data-structures/heap/max-heap.d.ts +11 -1
- package/dist/mjs/data-structures/heap/max-heap.js +9 -6
- package/dist/mjs/data-structures/heap/min-heap.d.ts +11 -1
- package/dist/mjs/data-structures/heap/min-heap.js +9 -6
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +95 -95
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +132 -136
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +18 -23
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -50
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +0 -7
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +1 -1
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +0 -7
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +9 -1
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +7 -6
- package/dist/mjs/data-structures/queue/deque.d.ts +76 -80
- package/dist/mjs/data-structures/queue/deque.js +106 -122
- package/dist/mjs/data-structures/queue/queue.d.ts +30 -16
- package/dist/mjs/data-structures/queue/queue.js +31 -24
- package/dist/mjs/data-structures/stack/stack.d.ts +17 -8
- package/dist/mjs/data-structures/stack/stack.js +10 -10
- package/dist/mjs/data-structures/trie/trie.d.ts +14 -5
- package/dist/mjs/data-structures/trie/trie.js +14 -14
- package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/mjs/types/common.d.ts +32 -8
- package/dist/mjs/types/common.js +21 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -24
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -21
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +533 -558
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/base/iterable-base.ts +24 -0
- package/src/data-structures/binary-tree/avl-tree.ts +14 -14
- package/src/data-structures/binary-tree/binary-tree.ts +74 -77
- package/src/data-structures/binary-tree/bst.ts +18 -17
- package/src/data-structures/binary-tree/rb-tree.ts +17 -18
- package/src/data-structures/binary-tree/tree-multimap.ts +22 -20
- package/src/data-structures/graph/abstract-graph.ts +35 -25
- package/src/data-structures/graph/directed-graph.ts +2 -2
- package/src/data-structures/graph/map-graph.ts +1 -1
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +40 -24
- package/src/data-structures/hash/hash-table.ts +3 -3
- package/src/data-structures/heap/heap.ts +33 -60
- package/src/data-structures/heap/max-heap.ts +11 -2
- package/src/data-structures/heap/min-heap.ts +11 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +147 -145
- package/src/data-structures/linked-list/singly-linked-list.ts +52 -52
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +9 -2
- package/src/data-structures/queue/deque.ts +129 -144
- package/src/data-structures/queue/queue.ts +37 -26
- package/src/data-structures/stack/stack.ts +20 -14
- package/src/data-structures/trie/trie.ts +18 -13
- package/src/interfaces/binary-tree.ts +5 -5
- package/src/types/common.ts +37 -12
- package/src/types/data-structures/binary-tree/avl-tree.ts +0 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -26
- package/src/types/data-structures/binary-tree/bst.ts +0 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
- package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
- package/test/performance/data-structures/heap/heap.test.ts +2 -2
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
- package/test/unit/data-structures/graph/directed-graph.test.ts +21 -1
- package/test/unit/data-structures/graph/undirected-graph.test.ts +39 -1
- package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +1 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
- package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
- package/test/unit/data-structures/queue/deque.test.ts +5 -5
- package/test/unit/data-structures/queue/queue.test.ts +4 -4
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { IterableElementBase } from
|
|
1
|
+
import { IterableElementBase } from '../base';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* 1. Last In, First Out (LIFO): The core characteristic of a stack is its last in, first out nature, meaning the last element added to the stack will be the first to be removed.
|
|
4
|
+
* 2. Uses: Stacks are commonly used for managing a series of tasks or elements that need to be processed in a last in, first out manner. They are widely used in various scenarios, such as in function calls in programming languages, evaluation of arithmetic expressions, and backtracking algorithms.
|
|
5
|
+
* 3. Performance: Stack operations are typically O(1) in time complexity, meaning that regardless of the stack's size, adding, removing, and viewing the top element are very fast operations.
|
|
6
|
+
* 4. Function Calls: In most modern programming languages, the records of function calls are managed through a stack. When a function is called, its record (including parameters, local variables, and return address) is 'pushed' into the stack. When the function returns, its record is 'popped' from the stack.
|
|
7
|
+
* 5. Expression Evaluation: Used for the evaluation of arithmetic or logical expressions, especially when dealing with parenthesis matching and operator precedence.
|
|
8
|
+
* 6. Backtracking Algorithms: In problems where multiple branches need to be explored but only one branch can be explored at a time, stacks can be used to save the state at each branching point.
|
|
6
9
|
*/
|
|
7
10
|
export class Stack extends IterableElementBase {
|
|
8
11
|
/**
|
|
@@ -84,7 +87,7 @@ export class Stack extends IterableElementBase {
|
|
|
84
87
|
*/
|
|
85
88
|
push(element) {
|
|
86
89
|
this.elements.push(element);
|
|
87
|
-
return
|
|
90
|
+
return true;
|
|
88
91
|
}
|
|
89
92
|
/**
|
|
90
93
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
@@ -100,8 +103,8 @@ export class Stack extends IterableElementBase {
|
|
|
100
103
|
*/
|
|
101
104
|
pop() {
|
|
102
105
|
if (this.isEmpty())
|
|
103
|
-
return
|
|
104
|
-
return this.elements.pop()
|
|
106
|
+
return;
|
|
107
|
+
return this.elements.pop();
|
|
105
108
|
}
|
|
106
109
|
/**
|
|
107
110
|
* Time Complexity: O(n)
|
|
@@ -194,9 +197,6 @@ export class Stack extends IterableElementBase {
|
|
|
194
197
|
}
|
|
195
198
|
return newStack;
|
|
196
199
|
}
|
|
197
|
-
print() {
|
|
198
|
-
console.log([...this]);
|
|
199
|
-
}
|
|
200
200
|
/**
|
|
201
201
|
* Custom iterator for the Stack class.
|
|
202
202
|
* @returns An iterator object.
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import type { ElementCallback } from '../../types';
|
|
9
|
+
import { IterableElementBase } from '../base';
|
|
10
10
|
/**
|
|
11
11
|
* TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
|
|
12
12
|
* and a flag indicating whether it's the end of a word.
|
|
@@ -18,7 +18,17 @@ export declare class TrieNode {
|
|
|
18
18
|
constructor(key: string);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
-
* Trie represents a
|
|
21
|
+
* 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
|
|
22
|
+
* 2. Child Node Relationship: Each node's children represent the strings that can be formed by adding one character to the string at the current node. For example, if a node represents the string 'ca', one of its children might represent 'cat'.
|
|
23
|
+
* 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
|
|
24
|
+
* 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
|
|
25
|
+
* 5. Autocomplete and Prediction: Trie can be used for implementing autocomplete and word prediction features, as it can quickly find all strings with a common prefix.
|
|
26
|
+
* 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
|
|
27
|
+
* 7. String Retrieval: For example, searching for a specific string in a large set of strings.
|
|
28
|
+
* 8. Autocomplete: Providing recommended words or phrases as a user types.
|
|
29
|
+
* 9. Spell Check: Checking the spelling of words.
|
|
30
|
+
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
31
|
+
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
22
32
|
*/
|
|
23
33
|
export declare class Trie extends IterableElementBase<string> {
|
|
24
34
|
constructor(words?: string[], caseSensitive?: boolean);
|
|
@@ -162,7 +172,7 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
162
172
|
* specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
|
|
163
173
|
* @returns The `filter` method is returning an array of strings (`string[]`).
|
|
164
174
|
*/
|
|
165
|
-
filter(predicate: ElementCallback<string, boolean>, thisArg?: any):
|
|
175
|
+
filter(predicate: ElementCallback<string, boolean>, thisArg?: any): Trie;
|
|
166
176
|
/**
|
|
167
177
|
* Time Complexity: O(n)
|
|
168
178
|
* Space Complexity: O(n)
|
|
@@ -181,7 +191,6 @@ export declare class Trie extends IterableElementBase<string> {
|
|
|
181
191
|
* @returns The `map` function is returning a new Trie object.
|
|
182
192
|
*/
|
|
183
193
|
map(callback: ElementCallback<string, string>, thisArg?: any): Trie;
|
|
184
|
-
print(): void;
|
|
185
194
|
protected _getIterator(): IterableIterator<string>;
|
|
186
195
|
/**
|
|
187
196
|
* Time Complexity: O(M), where M is the length of the input string.
|
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* data-structure-typed
|
|
3
|
-
*
|
|
4
|
-
* @author Tyler Zeng
|
|
5
|
-
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
-
* @license MIT License
|
|
7
|
-
*/
|
|
8
|
-
import { IterableElementBase } from "../base";
|
|
1
|
+
import { IterableElementBase } from '../base';
|
|
9
2
|
/**
|
|
10
3
|
* TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
|
|
11
4
|
* and a flag indicating whether it's the end of a word.
|
|
@@ -21,7 +14,17 @@ export class TrieNode {
|
|
|
21
14
|
}
|
|
22
15
|
}
|
|
23
16
|
/**
|
|
24
|
-
* Trie represents a
|
|
17
|
+
* 1. Node Structure: Each node in a Trie represents a string (or a part of a string). The root node typically represents an empty string.
|
|
18
|
+
* 2. Child Node Relationship: Each node's children represent the strings that can be formed by adding one character to the string at the current node. For example, if a node represents the string 'ca', one of its children might represent 'cat'.
|
|
19
|
+
* 3. Fast Retrieval: Trie allows retrieval in O(m) time complexity, where m is the length of the string to be searched.
|
|
20
|
+
* 4. Space Efficiency: Trie can store a large number of strings very space-efficiently, especially when these strings share common prefixes.
|
|
21
|
+
* 5. Autocomplete and Prediction: Trie can be used for implementing autocomplete and word prediction features, as it can quickly find all strings with a common prefix.
|
|
22
|
+
* 6. Sorting: Trie can be used to sort a set of strings in alphabetical order.
|
|
23
|
+
* 7. String Retrieval: For example, searching for a specific string in a large set of strings.
|
|
24
|
+
* 8. Autocomplete: Providing recommended words or phrases as a user types.
|
|
25
|
+
* 9. Spell Check: Checking the spelling of words.
|
|
26
|
+
* 10. IP Routing: Used in certain types of IP routing algorithms.
|
|
27
|
+
* 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data."
|
|
25
28
|
*/
|
|
26
29
|
export class Trie extends IterableElementBase {
|
|
27
30
|
constructor(words, caseSensitive = true) {
|
|
@@ -340,11 +343,11 @@ export class Trie extends IterableElementBase {
|
|
|
340
343
|
* @returns The `filter` method is returning an array of strings (`string[]`).
|
|
341
344
|
*/
|
|
342
345
|
filter(predicate, thisArg) {
|
|
343
|
-
const results =
|
|
346
|
+
const results = new Trie();
|
|
344
347
|
let index = 0;
|
|
345
348
|
for (const word of this) {
|
|
346
349
|
if (predicate.call(thisArg, word, index, this)) {
|
|
347
|
-
results.
|
|
350
|
+
results.add(word);
|
|
348
351
|
}
|
|
349
352
|
index++;
|
|
350
353
|
}
|
|
@@ -376,9 +379,6 @@ export class Trie extends IterableElementBase {
|
|
|
376
379
|
}
|
|
377
380
|
return newTrie;
|
|
378
381
|
}
|
|
379
|
-
print() {
|
|
380
|
-
console.log([...this]);
|
|
381
|
-
}
|
|
382
382
|
*_getIterator() {
|
|
383
383
|
function* _dfs(node, path) {
|
|
384
384
|
if (node.isEnd) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions,
|
|
2
|
+
import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, BTNExemplar } from '../types';
|
|
3
3
|
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>> {
|
|
4
4
|
createNode(key: K, value?: N['value']): N;
|
|
5
5
|
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
6
|
-
add(keyOrNodeOrEntry:
|
|
7
|
-
addMany(nodes: Iterable<
|
|
8
|
-
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C):
|
|
6
|
+
add(keyOrNodeOrEntry: BTNExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
|
|
7
|
+
addMany(nodes: Iterable<BTNExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
|
|
8
|
+
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<N>[];
|
|
9
9
|
}
|
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
export type Comparator<K> = (a: K, b: K) => number;
|
|
2
1
|
export declare enum BSTVariant {
|
|
3
2
|
MIN = "MIN",
|
|
4
3
|
MAX = "MAX"
|
|
5
4
|
}
|
|
6
|
-
export type DFSOrderPattern = 'pre' | 'in' | 'post';
|
|
7
|
-
export type BTNCallback<N, D = any> = (node: N) => D;
|
|
8
5
|
export declare enum CP {
|
|
9
6
|
lt = "lt",
|
|
10
7
|
eq = "eq",
|
|
11
8
|
gt = "gt"
|
|
12
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Enum representing different loop types.
|
|
12
|
+
*
|
|
13
|
+
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
14
|
+
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
15
|
+
*/
|
|
16
|
+
export declare enum IterationType {
|
|
17
|
+
ITERATIVE = "ITERATIVE",
|
|
18
|
+
RECURSIVE = "RECURSIVE"
|
|
19
|
+
}
|
|
20
|
+
export declare enum FamilyPosition {
|
|
21
|
+
ROOT = "ROOT",
|
|
22
|
+
LEFT = "LEFT",
|
|
23
|
+
RIGHT = "RIGHT",
|
|
24
|
+
ROOT_LEFT = "ROOT_LEFT",
|
|
25
|
+
ROOT_RIGHT = "ROOT_RIGHT",
|
|
26
|
+
ISOLATED = "ISOLATED",
|
|
27
|
+
MAL_NODE = "MAL_NODE"
|
|
28
|
+
}
|
|
29
|
+
export type Comparator<K> = (a: K, b: K) => number;
|
|
30
|
+
export type DFSOrderPattern = 'pre' | 'in' | 'post';
|
|
31
|
+
export type NodeDisplayLayout = [string[], number, number, number];
|
|
32
|
+
export type BTNCallback<N, D = any> = (node: N) => D;
|
|
13
33
|
export interface IterableWithSize<T> extends Iterable<T> {
|
|
14
34
|
size: number | ((...args: any[]) => number);
|
|
15
35
|
}
|
|
@@ -22,9 +42,13 @@ export type BinaryTreePrintOptions = {
|
|
|
22
42
|
isShowNull?: boolean;
|
|
23
43
|
isShowRedBlackNIL?: boolean;
|
|
24
44
|
};
|
|
25
|
-
export type
|
|
26
|
-
export type
|
|
27
|
-
export type
|
|
28
|
-
export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
|
|
45
|
+
export type BTNEntry<K, V> = [K | null | undefined, V | undefined];
|
|
46
|
+
export type BTNKeyOrNode<K, N> = K | null | undefined | N;
|
|
47
|
+
export type BTNExemplar<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>;
|
|
29
48
|
export type BTNodePureKeyOrNode<K, N> = K | N;
|
|
30
|
-
export type
|
|
49
|
+
export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
|
|
50
|
+
export type BSTNKeyOrNode<K, N> = K | undefined | N;
|
|
51
|
+
export type BinaryTreeDeleteResult<N> = {
|
|
52
|
+
deleted: N | null | undefined;
|
|
53
|
+
needBalanced: N | null | undefined;
|
|
54
|
+
};
|
package/dist/mjs/types/common.js
CHANGED
|
@@ -9,3 +9,24 @@ export var CP;
|
|
|
9
9
|
CP["eq"] = "eq";
|
|
10
10
|
CP["gt"] = "gt";
|
|
11
11
|
})(CP || (CP = {}));
|
|
12
|
+
/**
|
|
13
|
+
* Enum representing different loop types.
|
|
14
|
+
*
|
|
15
|
+
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
16
|
+
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
17
|
+
*/
|
|
18
|
+
export var IterationType;
|
|
19
|
+
(function (IterationType) {
|
|
20
|
+
IterationType["ITERATIVE"] = "ITERATIVE";
|
|
21
|
+
IterationType["RECURSIVE"] = "RECURSIVE";
|
|
22
|
+
})(IterationType || (IterationType = {}));
|
|
23
|
+
export var FamilyPosition;
|
|
24
|
+
(function (FamilyPosition) {
|
|
25
|
+
FamilyPosition["ROOT"] = "ROOT";
|
|
26
|
+
FamilyPosition["LEFT"] = "LEFT";
|
|
27
|
+
FamilyPosition["RIGHT"] = "RIGHT";
|
|
28
|
+
FamilyPosition["ROOT_LEFT"] = "ROOT_LEFT";
|
|
29
|
+
FamilyPosition["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
30
|
+
FamilyPosition["ISOLATED"] = "ISOLATED";
|
|
31
|
+
FamilyPosition["MAL_NODE"] = "MAL_NODE";
|
|
32
|
+
})(FamilyPosition || (FamilyPosition = {}));
|
|
@@ -1,31 +1,8 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
|
-
|
|
3
|
-
* Enum representing different loop types.
|
|
4
|
-
*
|
|
5
|
-
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
6
|
-
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
7
|
-
*/
|
|
8
|
-
export declare enum IterationType {
|
|
9
|
-
ITERATIVE = "ITERATIVE",
|
|
10
|
-
RECURSIVE = "RECURSIVE"
|
|
11
|
-
}
|
|
12
|
-
export declare enum FamilyPosition {
|
|
13
|
-
ROOT = "ROOT",
|
|
14
|
-
LEFT = "LEFT",
|
|
15
|
-
RIGHT = "RIGHT",
|
|
16
|
-
ROOT_LEFT = "ROOT_LEFT",
|
|
17
|
-
ROOT_RIGHT = "ROOT_RIGHT",
|
|
18
|
-
ISOLATED = "ISOLATED",
|
|
19
|
-
MAL_NODE = "MAL_NODE"
|
|
20
|
-
}
|
|
21
|
-
export type BiTreeDeleteResult<N> = {
|
|
22
|
-
deleted: N | null | undefined;
|
|
23
|
-
needBalanced: N | null | undefined;
|
|
24
|
-
};
|
|
2
|
+
import { IterationType } from "../../common";
|
|
25
3
|
export type BinaryTreeNodeNested<K, V> = BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, BinaryTreeNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
26
4
|
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
27
5
|
export type BinaryTreeOptions<K> = {
|
|
28
6
|
iterationType: IterationType;
|
|
29
7
|
extractor: (key: K) => number;
|
|
30
8
|
};
|
|
31
|
-
export type NodeDisplayLayout = [string[], number, number, number];
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Enum representing different loop types.
|
|
3
|
-
*
|
|
4
|
-
* - `iterative`: Indicates the iterative loop type (with loops that use iterations).
|
|
5
|
-
* - `recursive`: Indicates the recursive loop type (with loops that call themselves).
|
|
6
|
-
*/
|
|
7
|
-
export var IterationType;
|
|
8
|
-
(function (IterationType) {
|
|
9
|
-
IterationType["ITERATIVE"] = "ITERATIVE";
|
|
10
|
-
IterationType["RECURSIVE"] = "RECURSIVE";
|
|
11
|
-
})(IterationType || (IterationType = {}));
|
|
12
|
-
export var FamilyPosition;
|
|
13
|
-
(function (FamilyPosition) {
|
|
14
|
-
FamilyPosition["ROOT"] = "ROOT";
|
|
15
|
-
FamilyPosition["LEFT"] = "LEFT";
|
|
16
|
-
FamilyPosition["RIGHT"] = "RIGHT";
|
|
17
|
-
FamilyPosition["ROOT_LEFT"] = "ROOT_LEFT";
|
|
18
|
-
FamilyPosition["ROOT_RIGHT"] = "ROOT_RIGHT";
|
|
19
|
-
FamilyPosition["ISOLATED"] = "ISOLATED";
|
|
20
|
-
FamilyPosition["MAL_NODE"] = "MAL_NODE";
|
|
21
|
-
})(FamilyPosition || (FamilyPosition = {}));
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TreeMultimap, TreeMultimapNode } from '../../../data-structures';
|
|
2
|
-
import { AVLTreeOptions } from './avl-tree';
|
|
2
|
+
import type { AVLTreeOptions } from './avl-tree';
|
|
3
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
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
5
|
export type TreeMultimapOptions<K> = Omit<AVLTreeOptions<K>, 'isMergeDuplicatedNodeByKey'> & {};
|