data-structure-typed 1.48.1 → 1.48.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +24 -18
  3. package/benchmark/report.html +16 -16
  4. package/benchmark/report.json +172 -172
  5. package/dist/cjs/data-structures/base/index.d.ts +1 -0
  6. package/dist/cjs/data-structures/base/index.js +18 -0
  7. package/dist/cjs/data-structures/base/index.js.map +1 -0
  8. package/dist/cjs/data-structures/base/iterable-base.d.ts +232 -0
  9. package/dist/cjs/data-structures/base/iterable-base.js +313 -0
  10. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -0
  11. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
  12. package/dist/cjs/data-structures/binary-tree/avl-tree.js +7 -7
  13. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +121 -152
  15. package/dist/cjs/data-structures/binary-tree/binary-tree.js +140 -182
  16. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/bst.d.ts +28 -47
  18. package/dist/cjs/data-structures/binary-tree/bst.js +54 -57
  19. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +15 -15
  21. package/dist/cjs/data-structures/binary-tree/rb-tree.js +7 -7
  22. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
  24. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +11 -11
  25. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +44 -6
  27. package/dist/cjs/data-structures/graph/abstract-graph.js +50 -27
  28. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/hash/hash-map.d.ts +59 -100
  30. package/dist/cjs/data-structures/hash/hash-map.js +69 -173
  31. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/heap.d.ts +50 -7
  33. package/dist/cjs/data-structures/heap/heap.js +60 -30
  34. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  35. package/dist/cjs/data-structures/index.d.ts +1 -0
  36. package/dist/cjs/data-structures/index.js +1 -0
  37. package/dist/cjs/data-structures/index.js.map +1 -1
  38. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
  39. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +46 -73
  40. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  41. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +32 -51
  42. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +40 -73
  43. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  44. package/dist/cjs/data-structures/queue/deque.d.ts +29 -51
  45. package/dist/cjs/data-structures/queue/deque.js +36 -71
  46. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  47. package/dist/cjs/data-structures/queue/queue.d.ts +49 -48
  48. package/dist/cjs/data-structures/queue/queue.js +69 -82
  49. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  50. package/dist/cjs/data-structures/stack/stack.d.ts +43 -10
  51. package/dist/cjs/data-structures/stack/stack.js +50 -31
  52. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  53. package/dist/cjs/data-structures/trie/trie.d.ts +41 -6
  54. package/dist/cjs/data-structures/trie/trie.js +53 -32
  55. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  56. package/dist/cjs/interfaces/binary-tree.d.ts +6 -6
  57. package/dist/cjs/types/common.d.ts +11 -8
  58. package/dist/cjs/types/common.js +6 -1
  59. package/dist/cjs/types/common.js.map +1 -1
  60. package/dist/cjs/types/data-structures/base/base.d.ts +5 -0
  61. package/dist/cjs/types/data-structures/base/base.js +3 -0
  62. package/dist/cjs/types/data-structures/base/base.js.map +1 -0
  63. package/dist/cjs/types/data-structures/base/index.d.ts +1 -0
  64. package/dist/cjs/types/data-structures/base/index.js +18 -0
  65. package/dist/cjs/types/data-structures/base/index.js.map +1 -0
  66. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
  67. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
  68. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +6 -6
  69. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
  70. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
  71. package/dist/cjs/types/data-structures/index.d.ts +1 -0
  72. package/dist/cjs/types/data-structures/index.js +1 -0
  73. package/dist/cjs/types/data-structures/index.js.map +1 -1
  74. package/dist/mjs/data-structures/base/index.d.ts +1 -0
  75. package/dist/mjs/data-structures/base/index.js +1 -0
  76. package/dist/mjs/data-structures/base/iterable-base.d.ts +232 -0
  77. package/dist/mjs/data-structures/base/iterable-base.js +307 -0
  78. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
  79. package/dist/mjs/data-structures/binary-tree/avl-tree.js +7 -7
  80. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +121 -152
  81. package/dist/mjs/data-structures/binary-tree/binary-tree.js +140 -182
  82. package/dist/mjs/data-structures/binary-tree/bst.d.ts +28 -47
  83. package/dist/mjs/data-structures/binary-tree/bst.js +55 -57
  84. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +15 -15
  85. package/dist/mjs/data-structures/binary-tree/rb-tree.js +7 -7
  86. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
  87. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +11 -11
  88. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +44 -6
  89. package/dist/mjs/data-structures/graph/abstract-graph.js +52 -27
  90. package/dist/mjs/data-structures/hash/hash-map.d.ts +59 -100
  91. package/dist/mjs/data-structures/hash/hash-map.js +69 -173
  92. package/dist/mjs/data-structures/heap/heap.d.ts +50 -7
  93. package/dist/mjs/data-structures/heap/heap.js +60 -30
  94. package/dist/mjs/data-structures/index.d.ts +1 -0
  95. package/dist/mjs/data-structures/index.js +1 -0
  96. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
  97. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +46 -73
  98. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +32 -51
  99. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +40 -73
  100. package/dist/mjs/data-structures/queue/deque.d.ts +29 -51
  101. package/dist/mjs/data-structures/queue/deque.js +36 -71
  102. package/dist/mjs/data-structures/queue/queue.d.ts +49 -48
  103. package/dist/mjs/data-structures/queue/queue.js +66 -79
  104. package/dist/mjs/data-structures/stack/stack.d.ts +43 -10
  105. package/dist/mjs/data-structures/stack/stack.js +50 -31
  106. package/dist/mjs/data-structures/trie/trie.d.ts +41 -6
  107. package/dist/mjs/data-structures/trie/trie.js +53 -32
  108. package/dist/mjs/interfaces/binary-tree.d.ts +6 -6
  109. package/dist/mjs/types/common.d.ts +11 -8
  110. package/dist/mjs/types/common.js +5 -0
  111. package/dist/mjs/types/data-structures/base/base.d.ts +5 -0
  112. package/dist/mjs/types/data-structures/base/base.js +1 -0
  113. package/dist/mjs/types/data-structures/base/index.d.ts +1 -0
  114. package/dist/mjs/types/data-structures/base/index.js +1 -0
  115. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
  116. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
  117. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +6 -6
  118. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
  119. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
  120. package/dist/mjs/types/data-structures/index.d.ts +1 -0
  121. package/dist/mjs/types/data-structures/index.js +1 -0
  122. package/dist/umd/data-structure-typed.js +991 -848
  123. package/dist/umd/data-structure-typed.min.js +2 -2
  124. package/dist/umd/data-structure-typed.min.js.map +1 -1
  125. package/package.json +2 -2
  126. package/src/data-structures/base/index.ts +1 -0
  127. package/src/data-structures/base/iterable-base.ts +329 -0
  128. package/src/data-structures/binary-tree/avl-tree.ts +20 -21
  129. package/src/data-structures/binary-tree/binary-tree.ts +222 -267
  130. package/src/data-structures/binary-tree/bst.ts +86 -82
  131. package/src/data-structures/binary-tree/rb-tree.ts +25 -26
  132. package/src/data-structures/binary-tree/tree-multimap.ts +30 -35
  133. package/src/data-structures/graph/abstract-graph.ts +55 -28
  134. package/src/data-structures/hash/hash-map.ts +76 -185
  135. package/src/data-structures/heap/heap.ts +63 -36
  136. package/src/data-structures/index.ts +1 -0
  137. package/src/data-structures/linked-list/doubly-linked-list.ts +50 -79
  138. package/src/data-structures/linked-list/singly-linked-list.ts +45 -80
  139. package/src/data-structures/queue/deque.ts +40 -82
  140. package/src/data-structures/queue/queue.ts +72 -87
  141. package/src/data-structures/stack/stack.ts +53 -34
  142. package/src/data-structures/trie/trie.ts +58 -35
  143. package/src/interfaces/binary-tree.ts +5 -6
  144. package/src/types/common.ts +11 -8
  145. package/src/types/data-structures/base/base.ts +6 -0
  146. package/src/types/data-structures/base/index.ts +1 -0
  147. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
  148. package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
  149. package/src/types/data-structures/binary-tree/bst.ts +6 -6
  150. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
  151. package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
  152. package/src/types/data-structures/index.ts +1 -0
  153. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +13 -13
  154. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +16 -16
  155. package/test/unit/data-structures/binary-tree/bst.test.ts +20 -19
  156. package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
  157. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +9 -9
  158. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +15 -15
  159. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  160. package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
  161. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +28 -0
  162. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +25 -0
  163. package/test/unit/data-structures/queue/deque.test.ts +25 -0
  164. package/test/unit/unrestricted-interconversion.test.ts +1 -1
@@ -1,9 +1,11 @@
1
+ import { IterableElementBase } from "../base";
2
+ import { ElementCallback } from "../../types";
1
3
  /**
2
4
  * @license MIT
3
5
  * @copyright Tyler Zeng <zrwusa@gmail.com>
4
6
  * @class
5
7
  */
6
- export declare class Stack<E = any> {
8
+ export declare class Stack<E = any> extends IterableElementBase<E> {
7
9
  /**
8
10
  * The constructor initializes an array of elements, which can be provided as an optional parameter.
9
11
  * @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
@@ -104,17 +106,48 @@ export declare class Stack<E = any> {
104
106
  */
105
107
  clone(): Stack<E>;
106
108
  /**
107
- * Custom iterator for the Stack class.
108
- * @returns An iterator object.
109
+ * Time Complexity: O(n)
110
+ * Space Complexity: O(n)
109
111
  */
110
- [Symbol.iterator](): Generator<E, void, unknown>;
111
112
  /**
112
- * Applies a function to each element of the stack.
113
- * @param {function(E): void} callback - A function to apply to each element.
113
+ * Time Complexity: O(n)
114
+ * Space Complexity: O(n)
115
+ *
116
+ * The `filter` function creates a new stack containing elements from the original stack that satisfy
117
+ * a given predicate function.
118
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
119
+ * the current element being iterated over, the index of the current element, and the stack itself.
120
+ * It should return a boolean value indicating whether the element should be included in the filtered
121
+ * stack or not.
122
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
123
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
124
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
125
+ * @returns The `filter` method is returning a new `Stack` object that contains the elements that
126
+ * satisfy the given predicate function.
127
+ */
128
+ filter(predicate: ElementCallback<E, boolean>, thisArg?: any): Stack<E>;
129
+ /**
130
+ * Time Complexity: O(n)
131
+ * Space Complexity: O(n)
114
132
  */
115
- forEach(callback: (element: E, index: number, stack: this) => void): void;
116
- filter(predicate: (element: E, index: number, stack: this) => boolean): Stack<E>;
117
- map<T>(callback: (element: E, index: number, stack: this) => T): Stack<T>;
118
- reduce<T>(callback: (accumulator: T, element: E, index: number, stack: this) => T, initialValue: T): T;
133
+ /**
134
+ * Time Complexity: O(n)
135
+ * Space Complexity: O(n)
136
+ *
137
+ * The `map` function takes a callback function and applies it to each element in the stack,
138
+ * returning a new stack with the results.
139
+ * @param callback - The `callback` parameter is a function that will be called for each element in
140
+ * the stack. It takes three arguments:
141
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
142
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
143
+ * passed as the `this` value to the `callback` function. If `thisArg` is
144
+ * @returns The `map` method is returning a new `Stack` object.
145
+ */
146
+ map<T>(callback: ElementCallback<E, T>, thisArg?: any): Stack<T>;
119
147
  print(): void;
148
+ /**
149
+ * Custom iterator for the Stack class.
150
+ * @returns An iterator object.
151
+ */
152
+ protected _getIterator(): Generator<E, void, unknown>;
120
153
  }
@@ -1,9 +1,10 @@
1
+ import { IterableElementBase } from "../base";
1
2
  /**
2
3
  * @license MIT
3
4
  * @copyright Tyler Zeng <zrwusa@gmail.com>
4
5
  * @class
5
6
  */
6
- export class Stack {
7
+ export class Stack extends IterableElementBase {
7
8
  /**
8
9
  * The constructor initializes an array of elements, which can be provided as an optional parameter.
9
10
  * @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
@@ -11,6 +12,7 @@ export class Stack {
11
12
  * is provided and is an array, it is assigned to the `_elements
12
13
  */
13
14
  constructor(elements) {
15
+ super();
14
16
  this._elements = [];
15
17
  if (elements) {
16
18
  for (const el of elements) {
@@ -136,55 +138,72 @@ export class Stack {
136
138
  return new Stack(this.elements.slice());
137
139
  }
138
140
  /**
139
- * Custom iterator for the Stack class.
140
- * @returns An iterator object.
141
+ * Time Complexity: O(n)
142
+ * Space Complexity: O(n)
141
143
  */
142
- *[Symbol.iterator]() {
143
- for (let i = 0; i < this.elements.length; i++) {
144
- yield this.elements[i];
145
- }
146
- }
147
144
  /**
148
- * Applies a function to each element of the stack.
149
- * @param {function(E): void} callback - A function to apply to each element.
150
- */
151
- forEach(callback) {
152
- let index = 0;
153
- for (const el of this) {
154
- callback(el, index, this);
155
- index++;
156
- }
157
- }
158
- filter(predicate) {
145
+ * Time Complexity: O(n)
146
+ * Space Complexity: O(n)
147
+ *
148
+ * The `filter` function creates a new stack containing elements from the original stack that satisfy
149
+ * a given predicate function.
150
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
151
+ * the current element being iterated over, the index of the current element, and the stack itself.
152
+ * It should return a boolean value indicating whether the element should be included in the filtered
153
+ * stack or not.
154
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
155
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
156
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
157
+ * @returns The `filter` method is returning a new `Stack` object that contains the elements that
158
+ * satisfy the given predicate function.
159
+ */
160
+ filter(predicate, thisArg) {
159
161
  const newStack = new Stack();
160
162
  let index = 0;
161
163
  for (const el of this) {
162
- if (predicate(el, index, this)) {
164
+ if (predicate.call(thisArg, el, index, this)) {
163
165
  newStack.push(el);
164
166
  }
165
167
  index++;
166
168
  }
167
169
  return newStack;
168
170
  }
169
- map(callback) {
171
+ /**
172
+ * Time Complexity: O(n)
173
+ * Space Complexity: O(n)
174
+ */
175
+ /**
176
+ * Time Complexity: O(n)
177
+ * Space Complexity: O(n)
178
+ *
179
+ * The `map` function takes a callback function and applies it to each element in the stack,
180
+ * returning a new stack with the results.
181
+ * @param callback - The `callback` parameter is a function that will be called for each element in
182
+ * the stack. It takes three arguments:
183
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
184
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
185
+ * passed as the `this` value to the `callback` function. If `thisArg` is
186
+ * @returns The `map` method is returning a new `Stack` object.
187
+ */
188
+ map(callback, thisArg) {
170
189
  const newStack = new Stack();
171
190
  let index = 0;
172
191
  for (const el of this) {
173
- newStack.push(callback(el, index, this));
192
+ newStack.push(callback.call(thisArg, el, index, this));
174
193
  index++;
175
194
  }
176
195
  return newStack;
177
196
  }
178
- reduce(callback, initialValue) {
179
- let accumulator = initialValue;
180
- let index = 0;
181
- for (const el of this) {
182
- accumulator = callback(accumulator, el, index, this);
183
- index++;
184
- }
185
- return accumulator;
186
- }
187
197
  print() {
188
198
  console.log([...this]);
189
199
  }
200
+ /**
201
+ * Custom iterator for the Stack class.
202
+ * @returns An iterator object.
203
+ */
204
+ *_getIterator() {
205
+ for (let i = 0; i < this.elements.length; i++) {
206
+ yield this.elements[i];
207
+ }
208
+ }
190
209
  }
@@ -5,6 +5,8 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
+ import { IterableElementBase } from "../base";
9
+ import { ElementCallback } from "../../types";
8
10
  /**
9
11
  * TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
10
12
  * and a flag indicating whether it's the end of a word.
@@ -18,7 +20,7 @@ export declare class TrieNode {
18
20
  /**
19
21
  * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
20
22
  */
21
- export declare class Trie {
23
+ export declare class Trie extends IterableElementBase<string> {
22
24
  constructor(words?: string[], caseSensitive?: boolean);
23
25
  protected _size: number;
24
26
  get size(): number;
@@ -142,12 +144,45 @@ export declare class Trie {
142
144
  * @returns {string[]} an array of strings.
143
145
  */
144
146
  getWords(prefix?: string, max?: number, isAllWhenEmptyPrefix?: boolean): string[];
145
- [Symbol.iterator](): IterableIterator<string>;
146
- forEach(callback: (word: string, index: number, trie: this) => void): void;
147
- filter(predicate: (word: string, index: number, trie: this) => boolean): string[];
148
- map(callback: (word: string, index: number, trie: this) => string): Trie;
149
- reduce<T>(callback: (accumulator: T, word: string, index: number, trie: this) => T, initialValue: T): T;
147
+ /**
148
+ * Time Complexity: O(n)
149
+ * Space Complexity: O(n)
150
+ */
151
+ /**
152
+ * Time Complexity: O(n)
153
+ * Space Complexity: O(n)
154
+ *
155
+ * The `filter` function takes a predicate function and returns a new array containing all the
156
+ * elements for which the predicate function returns true.
157
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
158
+ * `word`, `index`, and `this`. It should return a boolean value indicating whether the current
159
+ * element should be included in the filtered results or not.
160
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
161
+ * specify the value of `this` within the `predicate` function. It is used when you want to bind a
162
+ * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
163
+ * @returns The `filter` method is returning an array of strings (`string[]`).
164
+ */
165
+ filter(predicate: ElementCallback<string, boolean>, thisArg?: any): string[];
166
+ /**
167
+ * Time Complexity: O(n)
168
+ * Space Complexity: O(n)
169
+ */
170
+ /**
171
+ * Time Complexity: O(n)
172
+ * Space Complexity: O(n)
173
+ *
174
+ * The `map` function creates a new Trie by applying a callback function to each element in the Trie.
175
+ * @param callback - The callback parameter is a function that will be called for each element in the
176
+ * Trie. It takes three arguments: the current element in the Trie, the index of the current element,
177
+ * and the Trie itself. The callback function should return a new value for the element.
178
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
179
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
180
+ * passed as the `this` value to the `callback` function. If `thisArg` is
181
+ * @returns The `map` function is returning a new Trie object.
182
+ */
183
+ map(callback: ElementCallback<string, string>, thisArg?: any): Trie;
150
184
  print(): void;
185
+ protected _getIterator(): IterableIterator<string>;
151
186
  /**
152
187
  * Time Complexity: O(M), where M is the length of the input string.
153
188
  * Space Complexity: O(1) - Constant space.
@@ -5,6 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
+ import { IterableElementBase } from "../base";
8
9
  /**
9
10
  * TrieNode represents a node in the Trie data structure. It holds a character key, a map of children nodes,
10
11
  * and a flag indicating whether it's the end of a word.
@@ -22,8 +23,9 @@ export class TrieNode {
22
23
  /**
23
24
  * Trie represents a Trie data structure. It provides basic Trie operations and additional methods.
24
25
  */
25
- export class Trie {
26
+ export class Trie extends IterableElementBase {
26
27
  constructor(words, caseSensitive = true) {
28
+ super();
27
29
  this._root = new TrieNode('');
28
30
  this._caseSensitive = caseSensitive;
29
31
  this._size = 0;
@@ -319,56 +321,75 @@ export class Trie {
319
321
  dfs(startNode, prefix);
320
322
  return words;
321
323
  }
322
- *[Symbol.iterator]() {
323
- function* _dfs(node, path) {
324
- if (node.isEnd) {
325
- yield path;
326
- }
327
- for (const [char, childNode] of node.children) {
328
- yield* _dfs(childNode, path + char);
329
- }
330
- }
331
- yield* _dfs(this.root, '');
332
- }
333
- forEach(callback) {
334
- let index = 0;
335
- for (const word of this) {
336
- callback(word, index, this);
337
- index++;
338
- }
339
- }
340
- filter(predicate) {
324
+ /**
325
+ * Time Complexity: O(n)
326
+ * Space Complexity: O(n)
327
+ */
328
+ /**
329
+ * Time Complexity: O(n)
330
+ * Space Complexity: O(n)
331
+ *
332
+ * The `filter` function takes a predicate function and returns a new array containing all the
333
+ * elements for which the predicate function returns true.
334
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
335
+ * `word`, `index`, and `this`. It should return a boolean value indicating whether the current
336
+ * element should be included in the filtered results or not.
337
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
338
+ * specify the value of `this` within the `predicate` function. It is used when you want to bind a
339
+ * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
340
+ * @returns The `filter` method is returning an array of strings (`string[]`).
341
+ */
342
+ filter(predicate, thisArg) {
341
343
  const results = [];
342
344
  let index = 0;
343
345
  for (const word of this) {
344
- if (predicate(word, index, this)) {
346
+ if (predicate.call(thisArg, word, index, this)) {
345
347
  results.push(word);
346
348
  }
347
349
  index++;
348
350
  }
349
351
  return results;
350
352
  }
351
- map(callback) {
353
+ /**
354
+ * Time Complexity: O(n)
355
+ * Space Complexity: O(n)
356
+ */
357
+ /**
358
+ * Time Complexity: O(n)
359
+ * Space Complexity: O(n)
360
+ *
361
+ * The `map` function creates a new Trie by applying a callback function to each element in the Trie.
362
+ * @param callback - The callback parameter is a function that will be called for each element in the
363
+ * Trie. It takes three arguments: the current element in the Trie, the index of the current element,
364
+ * and the Trie itself. The callback function should return a new value for the element.
365
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
366
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
367
+ * passed as the `this` value to the `callback` function. If `thisArg` is
368
+ * @returns The `map` function is returning a new Trie object.
369
+ */
370
+ map(callback, thisArg) {
352
371
  const newTrie = new Trie();
353
372
  let index = 0;
354
373
  for (const word of this) {
355
- newTrie.add(callback(word, index, this));
374
+ newTrie.add(callback.call(thisArg, word, index, this));
356
375
  index++;
357
376
  }
358
377
  return newTrie;
359
378
  }
360
- reduce(callback, initialValue) {
361
- let accumulator = initialValue;
362
- let index = 0;
363
- for (const word of this) {
364
- accumulator = callback(accumulator, word, index, this);
365
- index++;
366
- }
367
- return accumulator;
368
- }
369
379
  print() {
370
380
  console.log([...this]);
371
381
  }
382
+ *_getIterator() {
383
+ function* _dfs(node, path) {
384
+ if (node.isEnd) {
385
+ yield path;
386
+ }
387
+ for (const [char, childNode] of node.children) {
388
+ yield* _dfs(childNode, path + char);
389
+ }
390
+ }
391
+ yield* _dfs(this.root, '');
392
+ }
372
393
  /**
373
394
  * Time Complexity: O(M), where M is the length of the input string.
374
395
  * Space Complexity: O(1) - Constant space.
@@ -1,9 +1,9 @@
1
1
  import { BinaryTree, BinaryTreeNode } from '../data-structures';
2
- import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BiTreeDeleteResult, BTNCallback, BTNKey, BTNodeExemplar } from '../types';
3
- export interface IBinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNodeNested<V>, TREE extends BinaryTree<V, N, TREE> = BinaryTreeNested<V, N>> {
4
- createNode(key: BTNKey, value?: N['value']): N;
5
- createTree(options?: Partial<BinaryTreeOptions>): TREE;
6
- add(keyOrNodeOrEntry: BTNodeExemplar<V, N>, count?: number): N | null | undefined;
7
- addMany(nodes: Iterable<BTNodeExemplar<V, N>>): (N | null | undefined)[];
2
+ import { BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BiTreeDeleteResult, BTNCallback, BTNodeExemplar } from '../types';
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
+ createNode(key: K, value?: N['value']): N;
5
+ createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
6
+ add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, count?: number): N | null | undefined;
7
+ addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>): (N | null | undefined)[];
8
8
  delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
9
9
  }
@@ -1,5 +1,8 @@
1
- import { BTNKey } from "./data-structures";
2
- export type Comparator<T> = (a: T, b: T) => number;
1
+ export type Comparator<K> = (a: K, b: K) => number;
2
+ export declare enum BSTVariant {
3
+ MIN = "MIN",
4
+ MAX = "MAX"
5
+ }
3
6
  export type DFSOrderPattern = 'pre' | 'in' | 'post';
4
7
  export type BTNCallback<N, D = any> = (node: N) => D;
5
8
  export declare enum CP {
@@ -19,9 +22,9 @@ export type BinaryTreePrintOptions = {
19
22
  isShowNull?: boolean;
20
23
  isShowRedBlackNIL?: boolean;
21
24
  };
22
- export type BTNodeEntry<T> = [BTNKey | null | undefined, T | undefined];
23
- export type BTNodeKeyOrNode<N> = BTNKey | null | undefined | N;
24
- export type BTNodeExemplar<T, N> = BTNodeEntry<T> | BTNodeKeyOrNode<N>;
25
- export type BTNodePureExemplar<T, N> = [BTNKey, T | undefined] | BTNodePureKeyOrNode<N>;
26
- export type BTNodePureKeyOrNode<N> = BTNKey | N;
27
- export type BSTNodeKeyOrNode<N> = BTNKey | undefined | N;
25
+ export type BTNodeEntry<K, V> = [K | null | undefined, V | undefined];
26
+ export type BTNodeKeyOrNode<K, N> = K | null | undefined | N;
27
+ export type BTNodeExemplar<K, V, N> = BTNodeEntry<K, V> | BTNodeKeyOrNode<K, N>;
28
+ export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
29
+ export type BTNodePureKeyOrNode<K, N> = K | N;
30
+ export type BSTNodeKeyOrNode<K, N> = K | undefined | N;
@@ -1,3 +1,8 @@
1
+ export var BSTVariant;
2
+ (function (BSTVariant) {
3
+ BSTVariant["MIN"] = "MIN";
4
+ BSTVariant["MAX"] = "MAX";
5
+ })(BSTVariant || (BSTVariant = {}));
1
6
  export var CP;
2
7
  (function (CP) {
3
8
  CP["lt"] = "lt";
@@ -0,0 +1,5 @@
1
+ import { IterableElementBase, IterablePairBase } from "../../../data-structures";
2
+ export type PairCallback<K, V, R> = (value: V, key: K, index: number, container: IterablePairBase<K, V>) => R;
3
+ export type ElementCallback<V, R> = (element: V, index: number, container: IterableElementBase<V>) => R;
4
+ export type ReducePairCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, container: IterablePairBase<K, V>) => R;
5
+ export type ReduceElementCallback<V, R> = (accumulator: R, element: V, index: number, container: IterableElementBase<V>) => R;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './base';
@@ -0,0 +1 @@
1
+ export * from './base';
@@ -1,5 +1,5 @@
1
1
  import { AVLTree, AVLTreeNode } from '../../../data-structures';
2
2
  import { BSTOptions } from './bst';
3
- export type AVLTreeNodeNested<T> = AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, AVLTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
- export type AVLTreeNested<T, N extends AVLTreeNode<T, N>> = AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, AVLTree<T, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
- export type AVLTreeOptions = BSTOptions & {};
3
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
+ export type AVLTreeOptions<K> = BSTOptions<K> & {};
@@ -18,14 +18,14 @@ export declare enum FamilyPosition {
18
18
  ISOLATED = "ISOLATED",
19
19
  MAL_NODE = "MAL_NODE"
20
20
  }
21
- export type BTNKey = number;
22
21
  export type BiTreeDeleteResult<N> = {
23
22
  deleted: N | null | undefined;
24
23
  needBalanced: N | null | undefined;
25
24
  };
26
- export type BinaryTreeNodeNested<T> = BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, BinaryTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
27
- export type BinaryTreeNested<T, N extends BinaryTreeNode<T, N>> = BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, BinaryTree<T, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
28
- export type BinaryTreeOptions = {
25
+ 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
+ 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
+ export type BinaryTreeOptions<K> = {
29
28
  iterationType: IterationType;
29
+ extractor: (key: K) => number;
30
30
  };
31
31
  export type NodeDisplayLayout = [string[], number, number, number];
@@ -1,8 +1,8 @@
1
1
  import { BST, BSTNode } from '../../../data-structures';
2
- import type { BinaryTreeOptions, BTNKey } from './binary-tree';
3
- import { Comparator } from "../../common";
4
- export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
- export type BSTNested<T, N extends BSTNode<T, N>> = BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, BST<T, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
6
- export type BSTOptions = BinaryTreeOptions & {
7
- comparator: Comparator<BTNKey>;
2
+ import type { BinaryTreeOptions } from './binary-tree';
3
+ import { BSTVariant } from "../../common";
4
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
6
+ export type BSTOptions<K> = BinaryTreeOptions<K> & {
7
+ variant: BSTVariant;
8
8
  };
@@ -4,6 +4,6 @@ export declare enum RBTNColor {
4
4
  RED = 1,
5
5
  BLACK = 0
6
6
  }
7
- export type RedBlackTreeNodeNested<T> = RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, RedBlackTreeNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
8
- export type RedBlackTreeNested<T, N extends RedBlackTreeNode<T, N>> = RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, RedBlackTree<T, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
9
- export type RBTreeOptions = BSTOptions & {};
7
+ 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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
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
+ export type RBTreeOptions<K> = BSTOptions<K> & {};
@@ -1,5 +1,5 @@
1
1
  import { TreeMultimap, TreeMultimapNode } from '../../../data-structures';
2
2
  import { AVLTreeOptions } from './avl-tree';
3
- export type TreeMultimapNodeNested<T> = TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, TreeMultimapNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
- export type TreeMultimapNested<T, N extends TreeMultimapNode<T, N>> = TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, TreeMultimap<T, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
- export type TreeMultimapOptions = Omit<AVLTreeOptions, 'isMergeDuplicatedNodeByKey'> & {};
3
+ export type TreeMultimapNodeNested<K, V> = TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, TreeMultimapNode<K, V, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
4
+ export type TreeMultimapNested<K, V, N extends TreeMultimapNode<K, V, N>> = TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, TreeMultimap<K, V, N, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
5
+ export type TreeMultimapOptions<K> = Omit<AVLTreeOptions<K>, 'isMergeDuplicatedNodeByKey'> & {};
@@ -9,3 +9,4 @@ export * from './queue';
9
9
  export * from './stack';
10
10
  export * from './tree';
11
11
  export * from './trie';
12
+ export * from './base';
@@ -9,3 +9,4 @@ export * from './queue';
9
9
  export * from './stack';
10
10
  export * from './tree';
11
11
  export * from './trie';
12
+ export * from './base';