data-structure-typed 1.52.8 → 1.53.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/CHANGELOG.md +1 -1
- package/README.md +13 -13
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +151 -151
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +22 -22
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +64 -47
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +20 -20
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +28 -26
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +240 -141
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +395 -269
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +56 -56
- package/dist/cjs/data-structures/binary-tree/bst.js +114 -91
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +13 -13
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +35 -31
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +22 -23
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +59 -48
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.js +3 -3
- package/dist/cjs/interfaces/binary-tree.d.ts +5 -5
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +13 -13
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +22 -22
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +64 -46
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +20 -20
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +28 -25
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +240 -141
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +395 -268
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +56 -56
- package/dist/mjs/data-structures/binary-tree/bst.js +114 -89
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +13 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +35 -30
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +22 -23
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +59 -47
- package/dist/mjs/data-structures/trie/trie.js +3 -3
- package/dist/mjs/interfaces/binary-tree.d.ts +5 -5
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +13 -13
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -3
- package/dist/umd/data-structure-typed.js +617 -482
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +60 -55
- package/src/data-structures/binary-tree/avl-tree.ts +31 -35
- package/src/data-structures/binary-tree/binary-tree.ts +461 -385
- package/src/data-structures/binary-tree/bst.ts +155 -128
- package/src/data-structures/binary-tree/rb-tree.ts +37 -39
- package/src/data-structures/binary-tree/tree-multi-map.ts +57 -60
- package/src/data-structures/trie/trie.ts +3 -3
- package/src/interfaces/binary-tree.ts +6 -6
- package/src/types/data-structures/binary-tree/binary-tree.ts +14 -15
- package/src/types/data-structures/binary-tree/bst.ts +4 -4
- package/test/integration/bst.test.ts +2 -2
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +1 -1
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +2 -2
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +1 -1
- package/test/performance/data-structures/binary-tree/bst.test.ts +1 -1
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +113 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +107 -1
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +169 -26
- package/test/unit/data-structures/binary-tree/bst.test.ts +326 -21
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +139 -1
|
@@ -40,18 +40,18 @@ exports.TreeMultiMapNode = TreeMultiMapNode;
|
|
|
40
40
|
class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
41
41
|
/**
|
|
42
42
|
* The constructor function initializes a TreeMultiMap object with optional initial data.
|
|
43
|
-
* @param
|
|
43
|
+
* @param keysNodesEntriesOrRaws - The parameter `keysNodesEntriesOrRaws` is an
|
|
44
44
|
* iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
|
|
45
45
|
* TreeMultiMap with initial data.
|
|
46
46
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
47
47
|
* behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
|
|
48
48
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
49
49
|
*/
|
|
50
|
-
constructor(
|
|
50
|
+
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
51
51
|
super([], options);
|
|
52
52
|
this._count = 0;
|
|
53
|
-
if (
|
|
54
|
-
this.addMany(
|
|
53
|
+
if (keysNodesEntriesOrRaws)
|
|
54
|
+
this.addMany(keysNodesEntriesOrRaws);
|
|
55
55
|
}
|
|
56
56
|
// TODO the _count is not accurate after nodes count modified
|
|
57
57
|
/**
|
|
@@ -99,13 +99,13 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
99
99
|
* existing `iterationType` property. The returned value is casted as `TREE`.
|
|
100
100
|
*/
|
|
101
101
|
createTree(options) {
|
|
102
|
-
return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
|
|
102
|
+
return new TreeMultiMap([], Object.assign({ iterationType: this.iterationType, isMapMode: this._isMapMode, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
|
-
* The function `
|
|
105
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
106
106
|
* node based on the input.
|
|
107
|
-
* @param {
|
|
108
|
-
* `
|
|
107
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
108
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
109
109
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
110
110
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
111
111
|
* an existing node.
|
|
@@ -113,36 +113,38 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
113
113
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
114
114
|
* @returns either a NODE object or undefined.
|
|
115
115
|
*/
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
return;
|
|
119
|
-
if (this.isNode(
|
|
120
|
-
return
|
|
121
|
-
if (this.isEntry(
|
|
122
|
-
const [key, entryValue] =
|
|
116
|
+
keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
|
|
117
|
+
if (keyNodeEntryOrRaw === undefined || keyNodeEntryOrRaw === null)
|
|
118
|
+
return [undefined, undefined];
|
|
119
|
+
if (this.isNode(keyNodeEntryOrRaw))
|
|
120
|
+
return [keyNodeEntryOrRaw, value];
|
|
121
|
+
if (this.isEntry(keyNodeEntryOrRaw)) {
|
|
122
|
+
const [key, entryValue] = keyNodeEntryOrRaw;
|
|
123
123
|
if (key === undefined || key === null)
|
|
124
|
-
return;
|
|
124
|
+
return [undefined, undefined];
|
|
125
|
+
const finalValue = value !== null && value !== void 0 ? value : entryValue;
|
|
125
126
|
if (this.isKey(key))
|
|
126
|
-
return this.createNode(key,
|
|
127
|
+
return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
|
|
127
128
|
}
|
|
128
129
|
if (this._toEntryFn) {
|
|
129
|
-
const [key, entryValue] = this._toEntryFn(
|
|
130
|
+
const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
|
|
131
|
+
const finalValue = value !== null && value !== void 0 ? value : entryValue;
|
|
130
132
|
if (this.isKey(key))
|
|
131
|
-
return this.createNode(key,
|
|
133
|
+
return [this.createNode(key, finalValue, 'BLACK', count), finalValue];
|
|
132
134
|
}
|
|
133
|
-
if (this.isKey(
|
|
134
|
-
return this.createNode(
|
|
135
|
-
return;
|
|
135
|
+
if (this.isKey(keyNodeEntryOrRaw))
|
|
136
|
+
return [this.createNode(keyNodeEntryOrRaw, value, 'BLACK', count), value];
|
|
137
|
+
return [undefined, undefined];
|
|
136
138
|
}
|
|
137
139
|
/**
|
|
138
140
|
* The function checks if the input is an instance of the TreeMultiMapNode class.
|
|
139
|
-
* @param {
|
|
140
|
-
* `
|
|
141
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
141
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
142
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
143
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
|
|
142
144
|
* an instance of the `TreeMultiMapNode` class.
|
|
143
145
|
*/
|
|
144
|
-
isNode(
|
|
145
|
-
return
|
|
146
|
+
isNode(keyNodeEntryOrRaw) {
|
|
147
|
+
return keyNodeEntryOrRaw instanceof TreeMultiMapNode;
|
|
146
148
|
}
|
|
147
149
|
/**
|
|
148
150
|
* Time Complexity: O(log n)
|
|
@@ -150,8 +152,8 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
150
152
|
*
|
|
151
153
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
152
154
|
* the count and returning a boolean indicating success.
|
|
153
|
-
* @param {
|
|
154
|
-
* `
|
|
155
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
156
|
+
* `keyNodeEntryOrRaw` parameter can accept one of the following types:
|
|
155
157
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
156
158
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
157
159
|
* @param [count=1] - The `count` parameter represents the number of times the key-value pair should
|
|
@@ -160,10 +162,10 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
160
162
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
161
163
|
* was successful, and false otherwise.
|
|
162
164
|
*/
|
|
163
|
-
add(
|
|
164
|
-
const newNode = this.
|
|
165
|
+
add(keyNodeEntryOrRaw, value, count = 1) {
|
|
166
|
+
const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
|
|
165
167
|
const orgCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
|
|
166
|
-
const isSuccessAdded = super.add(newNode);
|
|
168
|
+
const isSuccessAdded = super.add(newNode, newValue);
|
|
167
169
|
if (isSuccessAdded) {
|
|
168
170
|
this._count += orgCount;
|
|
169
171
|
return true;
|
|
@@ -178,25 +180,24 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
178
180
|
*
|
|
179
181
|
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
180
182
|
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
181
|
-
* @param {
|
|
183
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
|
|
182
184
|
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
183
|
-
* should be deleted from the binary tree. It can be a key, a node, an entry
|
|
184
|
-
* function.
|
|
185
|
+
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
185
186
|
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
186
187
|
* boolean flag that determines whether to ignore the count of nodes when performing deletion. If
|
|
187
188
|
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
188
189
|
* `ignoreCount` is `false
|
|
189
190
|
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<NODE>` objects.
|
|
190
191
|
*/
|
|
191
|
-
delete(
|
|
192
|
-
if (
|
|
192
|
+
delete(keyNodeEntryOrRaw, ignoreCount = false) {
|
|
193
|
+
if (keyNodeEntryOrRaw === null)
|
|
193
194
|
return [];
|
|
194
195
|
const results = [];
|
|
195
196
|
let nodeToDelete;
|
|
196
|
-
if (this.
|
|
197
|
-
nodeToDelete = this.getNode(
|
|
197
|
+
if (this._isPredicate(keyNodeEntryOrRaw))
|
|
198
|
+
nodeToDelete = this.getNode(keyNodeEntryOrRaw);
|
|
198
199
|
else
|
|
199
|
-
nodeToDelete = this.isRealNode(
|
|
200
|
+
nodeToDelete = this.isRealNode(keyNodeEntryOrRaw) ? keyNodeEntryOrRaw : this.getNode(keyNodeEntryOrRaw);
|
|
200
201
|
if (!nodeToDelete) {
|
|
201
202
|
return results;
|
|
202
203
|
}
|
|
@@ -314,7 +315,10 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
314
315
|
return;
|
|
315
316
|
const m = l + Math.floor((r - l) / 2);
|
|
316
317
|
const midNode = sorted[m];
|
|
317
|
-
this.
|
|
318
|
+
if (this._isMapMode)
|
|
319
|
+
this.add(midNode.key, undefined, midNode.count);
|
|
320
|
+
else
|
|
321
|
+
this.add(midNode.key, midNode.value, midNode.count);
|
|
318
322
|
buildBalanceBST(l, m - 1);
|
|
319
323
|
buildBalanceBST(m + 1, r);
|
|
320
324
|
};
|
|
@@ -330,7 +334,10 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
330
334
|
if (l <= r) {
|
|
331
335
|
const m = l + Math.floor((r - l) / 2);
|
|
332
336
|
const midNode = sorted[m];
|
|
333
|
-
this.
|
|
337
|
+
if (this._isMapMode)
|
|
338
|
+
this.add(midNode.key, undefined, midNode.count);
|
|
339
|
+
else
|
|
340
|
+
this.add(midNode.key, midNode.value, midNode.count);
|
|
334
341
|
stack.push([m + 1, r]);
|
|
335
342
|
stack.push([l, m - 1]);
|
|
336
343
|
}
|
|
@@ -348,7 +355,9 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
348
355
|
*/
|
|
349
356
|
clone() {
|
|
350
357
|
const cloned = this.createTree();
|
|
351
|
-
this.bfs(node => cloned.add(node.key,
|
|
358
|
+
this.bfs(node => cloned.add(node.key, undefined, node.count));
|
|
359
|
+
if (this._isMapMode)
|
|
360
|
+
cloned._store = this._store;
|
|
352
361
|
return cloned;
|
|
353
362
|
}
|
|
354
363
|
/**
|
|
@@ -357,10 +366,10 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
357
366
|
*
|
|
358
367
|
* The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
|
|
359
368
|
* in a binary search tree.
|
|
360
|
-
* @param {R |
|
|
369
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
361
370
|
* that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
|
|
362
|
-
* instance of the `
|
|
363
|
-
* @param {R |
|
|
371
|
+
* instance of the `BSTNOptKeyOrNode<K, NODE>` class.
|
|
372
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
364
373
|
* node where the properties will be swapped with the source node.
|
|
365
374
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
366
375
|
* If either `srcNode` or `destNode` is undefined, it returns undefined.
|
|
@@ -374,11 +383,13 @@ class TreeMultiMap extends rb_tree_1.RedBlackTree {
|
|
|
374
383
|
if (tempNode) {
|
|
375
384
|
tempNode.color = color;
|
|
376
385
|
destNode.key = srcNode.key;
|
|
377
|
-
|
|
386
|
+
if (!this._isMapMode)
|
|
387
|
+
destNode.value = srcNode.value;
|
|
378
388
|
destNode.count = srcNode.count;
|
|
379
389
|
destNode.color = srcNode.color;
|
|
380
390
|
srcNode.key = tempNode.key;
|
|
381
|
-
|
|
391
|
+
if (!this._isMapMode)
|
|
392
|
+
srcNode.value = tempNode.value;
|
|
382
393
|
srcNode.count = tempNode.count;
|
|
383
394
|
srcNode.color = tempNode.color;
|
|
384
395
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-multi-map.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multi-map.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"tree-multi-map.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multi-map.ts"],"names":[],"mappings":";;;AAmBA,uCAA2D;AAE3D,MAAa,gBAIX,SAAQ,0BAA4B;IACpC;;;;;;;;;;;OAWG;IACH,YAAY,GAAM,EAAE,KAAS,EAAE,KAAK,GAAG,CAAC,EAAE,QAAmB,OAAO;QAClE,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAIjB,WAAM,GAAW,CAAC,CAAC;QAH3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAID;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,IAAI,KAAK,CAAC,KAAa;QACrB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;CACF;AAxCD,4CAwCC;AAED,MAAa,YAOX,SAAQ,sBAAiC;IAGzC;;;;;;;;OAQG;IACH,YAAY,yBAAuD,EAAE,EAAE,OAAsC;QAC3G,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAIX,WAAM,GAAG,CAAC,CAAC;QAHnB,IAAI,sBAAsB;YAAE,IAAI,CAAC,OAAO,CAAC,sBA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AG,OAAO,CAAC,KAAK,CAAC;gBAC/B,QAAQ,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;gBAE/B,OAAO,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC;gBAC3B,IAAI,CAAC,IAAI,CAAC,UAAU;oBAAE,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;gBACrD,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;gBAC/B,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;YACjC,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;;;;;OAUG;IACgB,YAAY,CAAC,OAAa,EAAE,OAAa;QAC1D,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC9C,OAAO,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF;AArZD,oCAqZC"}
|
|
@@ -239,9 +239,9 @@ class Trie extends base_1.IterableElementBase {
|
|
|
239
239
|
*
|
|
240
240
|
*/
|
|
241
241
|
getHeight() {
|
|
242
|
-
const
|
|
242
|
+
const startNode = this.root;
|
|
243
243
|
let maxDepth = 0;
|
|
244
|
-
if (
|
|
244
|
+
if (startNode) {
|
|
245
245
|
const bfs = (node, level) => {
|
|
246
246
|
if (level > maxDepth) {
|
|
247
247
|
maxDepth = level;
|
|
@@ -253,7 +253,7 @@ class Trie extends base_1.IterableElementBase {
|
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
};
|
|
256
|
-
bfs(
|
|
256
|
+
bfs(startNode, 0);
|
|
257
257
|
}
|
|
258
258
|
return maxDepth;
|
|
259
259
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions,
|
|
3
|
-
export interface IBinaryTree<K = any, V = any, R =
|
|
2
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNRep, NodePredicate } from '../types';
|
|
3
|
+
export interface IBinaryTree<K = any, V = any, R = object, NODE extends BinaryTreeNode<K, V, NODE> = BinaryTreeNodeNested<K, V>, TREE extends BinaryTree<K, V, R, NODE, TREE> = BinaryTreeNested<K, V, R, NODE>> {
|
|
4
4
|
createNode(key: K, value?: NODE['value']): NODE;
|
|
5
5
|
createTree(options?: Partial<BinaryTreeOptions<K, V, R>>): TREE;
|
|
6
|
-
add(keyOrNodeOrEntryOrRawElement:
|
|
7
|
-
addMany(nodes: Iterable<
|
|
8
|
-
delete(predicate: R |
|
|
6
|
+
add(keyOrNodeOrEntryOrRawElement: BTNRep<K, V, NODE>, value?: V, count?: number): boolean;
|
|
7
|
+
addMany(nodes: Iterable<BTNRep<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
8
|
+
delete(predicate: R | BTNRep<K, V, NODE> | NodePredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
|
|
9
9
|
}
|
|
@@ -3,29 +3,29 @@ import { IterationType, OptValue } from '../../common';
|
|
|
3
3
|
import { DFSOperation } from '../../../constants';
|
|
4
4
|
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
5
|
export type BinaryTreeNested<K, V, R, NODE extends BinaryTreeNode<K, V, NODE>> = BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, BinaryTree<K, V, R, NODE, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
6
|
+
export type ToEntryFn<K, V, R> = (rawElement: R) => BTNEntry<K, V>;
|
|
6
7
|
export type BinaryTreeOptions<K, V, R> = {
|
|
7
8
|
iterationType?: IterationType;
|
|
8
|
-
toEntryFn?:
|
|
9
|
+
toEntryFn?: ToEntryFn<K, V, R>;
|
|
10
|
+
isMapMode?: boolean;
|
|
9
11
|
};
|
|
10
12
|
export type BinaryTreePrintOptions = {
|
|
11
13
|
isShowUndefined?: boolean;
|
|
12
14
|
isShowNull?: boolean;
|
|
13
15
|
isShowRedBlackNIL?: boolean;
|
|
14
16
|
};
|
|
15
|
-
export type
|
|
16
|
-
export type
|
|
17
|
-
export type BTNEntry<K, V> = [
|
|
18
|
-
export type
|
|
19
|
-
export type
|
|
20
|
-
export type BTNPureKeyOrNode<K, NODE> = K | NODE;
|
|
21
|
-
export type BTNPureKeyOrNodeOrEntry<K, V, NODE> = [K, OptValue<V>] | BTNPureKeyOrNode<K, NODE>;
|
|
17
|
+
export type OptNodeOrNull<NODE> = NODE | null | undefined;
|
|
18
|
+
export type BTNOptKeyOrNull<K> = K | null | undefined;
|
|
19
|
+
export type BTNEntry<K, V> = [BTNOptKeyOrNull<K>, OptValue<V>];
|
|
20
|
+
export type BTNOptKeyNodeOrNull<K, NODE> = BTNOptKeyOrNull<K> | NODE;
|
|
21
|
+
export type BTNRep<K, V, NODE> = BTNEntry<K, V> | BTNOptKeyNodeOrNull<K, NODE>;
|
|
22
22
|
export type BinaryTreeDeleteResult<NODE> = {
|
|
23
|
-
deleted:
|
|
24
|
-
needBalanced:
|
|
23
|
+
deleted: OptNodeOrNull<NODE>;
|
|
24
|
+
needBalanced: OptNodeOrNull<NODE>;
|
|
25
25
|
};
|
|
26
|
-
export type
|
|
27
|
-
export type
|
|
26
|
+
export type NodeCallback<NODE, D = any> = (node: NODE) => D;
|
|
27
|
+
export type NodePredicate<NODE> = (node: NODE) => boolean;
|
|
28
28
|
export type DFSStackItem<NODE> = {
|
|
29
29
|
opt: DFSOperation;
|
|
30
|
-
node:
|
|
30
|
+
node: OptNodeOrNull<NODE>;
|
|
31
31
|
};
|
|
@@ -6,6 +6,6 @@ export type BSTNested<K, V, R, NODE extends BSTNode<K, V, NODE>> = BST<K, V, R,
|
|
|
6
6
|
export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
|
|
7
7
|
comparator?: Comparator<K>;
|
|
8
8
|
};
|
|
9
|
-
export type
|
|
10
|
-
export type
|
|
11
|
-
export type
|
|
9
|
+
export type BSTNOptKey<K> = K | undefined;
|
|
10
|
+
export type OptNode<NODE> = NODE | undefined;
|
|
11
|
+
export type BSTNOptKeyOrNode<K, NODE> = BSTNOptKey<K> | NODE;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult,
|
|
8
|
+
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep, IterationType } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
11
11
|
export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
|
|
@@ -36,16 +36,16 @@ export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeM
|
|
|
36
36
|
/**
|
|
37
37
|
* The only distinction between a AVLTreeMultiMap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
38
38
|
*/
|
|
39
|
-
export declare class AVLTreeMultiMap<K = any, V = any, R =
|
|
39
|
+
export declare class AVLTreeMultiMap<K = any, V = any, R = object, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNode<K, V, AVLTreeMultiMapNodeNested<K, V>>, TREE extends AVLTreeMultiMap<K, V, R, NODE, TREE> = AVLTreeMultiMap<K, V, R, NODE, AVLTreeMultiMapNested<K, V, R, NODE>>> extends AVLTree<K, V, R, NODE, TREE> implements IBinaryTree<K, V, R, NODE, TREE> {
|
|
40
40
|
/**
|
|
41
41
|
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
42
|
-
* @param
|
|
42
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
43
43
|
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
44
44
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
45
45
|
* behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
|
|
46
46
|
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
47
47
|
*/
|
|
48
|
-
constructor(
|
|
48
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<R | BTNRep<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K, V, R>);
|
|
49
49
|
protected _count: number;
|
|
50
50
|
/**
|
|
51
51
|
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
@@ -84,17 +84,17 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
|
|
|
84
84
|
createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE;
|
|
85
85
|
/**
|
|
86
86
|
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
87
|
-
* @param {
|
|
88
|
-
* `
|
|
89
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
87
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
88
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
89
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
|
|
90
90
|
* an instance of the `AVLTreeMultiMapNode` class.
|
|
91
91
|
*/
|
|
92
|
-
isNode(
|
|
92
|
+
isNode(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R): keyNodeEntryOrRaw is NODE;
|
|
93
93
|
/**
|
|
94
|
-
* The function `
|
|
94
|
+
* The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
|
|
95
95
|
* a node object.
|
|
96
|
-
* @param {
|
|
97
|
-
* `
|
|
96
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
97
|
+
* `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
98
98
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
99
99
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
100
100
|
* value is provided, it will default to `undefined`.
|
|
@@ -102,16 +102,16 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
|
|
|
102
102
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
103
103
|
* @returns either a NODE object or undefined.
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V, count?: number): [NODE | undefined, V | undefined];
|
|
106
106
|
/**
|
|
107
107
|
* Time Complexity: O(log n)
|
|
108
108
|
* Space Complexity: O(1)
|
|
109
109
|
*
|
|
110
110
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
111
111
|
* and update the count.
|
|
112
|
-
* @param {
|
|
113
|
-
* `
|
|
114
|
-
* can also accept a value of type `
|
|
112
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
|
|
113
|
+
* `keyNodeEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
|
|
114
|
+
* can also accept a value of type `BTNRep<K, V, NODE>`, which represents a key, node,
|
|
115
115
|
* entry, or raw element
|
|
116
116
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
117
117
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -120,16 +120,16 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
|
|
|
120
120
|
* be added once. However, you can specify a different value for `count` if you want to add
|
|
121
121
|
* @returns a boolean value.
|
|
122
122
|
*/
|
|
123
|
-
add(
|
|
123
|
+
add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V, count?: number): boolean;
|
|
124
124
|
/**
|
|
125
125
|
* Time Complexity: O(log n)
|
|
126
126
|
* Space Complexity: O(1)
|
|
127
127
|
*
|
|
128
128
|
* The function overrides the delete method in a binary tree data structure, handling deletion of
|
|
129
129
|
* nodes and maintaining balance in the tree.
|
|
130
|
-
* @param {
|
|
130
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `predicate`
|
|
131
131
|
* parameter in the `delete` method is used to specify the condition for deleting a node from the
|
|
132
|
-
* binary tree. It can be a key, node,
|
|
132
|
+
* binary tree. It can be a key, node, or entry that determines which
|
|
133
133
|
* node(s) should be deleted.
|
|
134
134
|
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
135
135
|
* boolean flag that determines whether to ignore the count of the node being deleted. If
|
|
@@ -140,7 +140,7 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
|
|
|
140
140
|
* method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
|
|
141
141
|
* deleted node and whether balancing is needed in the tree.
|
|
142
142
|
*/
|
|
143
|
-
delete(
|
|
143
|
+
delete(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
|
|
144
144
|
/**
|
|
145
145
|
* Time Complexity: O(1)
|
|
146
146
|
* Space Complexity: O(1)
|
|
@@ -176,14 +176,14 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
|
|
|
176
176
|
*
|
|
177
177
|
* The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
|
|
178
178
|
* in a binary search tree.
|
|
179
|
-
* @param {R |
|
|
179
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
|
|
180
180
|
* that will be swapped with the `destNode`.
|
|
181
|
-
* @param {R |
|
|
181
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
|
|
182
182
|
* node where the properties will be swapped with the source node.
|
|
183
183
|
* @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
|
|
184
184
|
* If either `srcNode` or `destNode` is undefined, it returns `undefined`.
|
|
185
185
|
*/
|
|
186
|
-
protected _swapProperties(srcNode: R |
|
|
186
|
+
protected _swapProperties(srcNode: R | BSTNOptKeyOrNode<K, NODE>, destNode: R | BSTNOptKeyOrNode<K, NODE>): NODE | undefined;
|
|
187
187
|
/**
|
|
188
188
|
* Time Complexity: O(1)
|
|
189
189
|
* Space Complexity: O(1)
|