data-structure-typed 1.49.5 → 1.49.6
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 +14 -23
- package/benchmark/report.html +14 -23
- package/benchmark/report.json +163 -256
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +55 -49
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +153 -130
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +192 -149
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +83 -71
- package/dist/cjs/data-structures/binary-tree/bst.js +113 -89
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +62 -59
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +46 -39
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +58 -51
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/common.d.ts +3 -3
- package/dist/cjs/types/common.js +2 -2
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +55 -49
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +153 -130
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +192 -149
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +83 -71
- package/dist/mjs/data-structures/binary-tree/bst.js +113 -89
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +62 -59
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +46 -39
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +58 -51
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/common.d.ts +3 -3
- package/dist/mjs/types/common.js +2 -2
- package/dist/umd/data-structure-typed.js +497 -419
- 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/binary-tree/avl-tree.ts +58 -53
- package/src/data-structures/binary-tree/binary-tree.ts +253 -205
- package/src/data-structures/binary-tree/bst.ts +125 -104
- package/src/data-structures/binary-tree/rb-tree.ts +66 -64
- package/src/data-structures/binary-tree/tree-multimap.ts +62 -56
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +3 -3
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -12
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +37 -0
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +6 -16
- package/test/performance/data-structures/binary-tree/bst.test.ts +5 -13
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +5 -15
- package/test/performance/data-structures/comparison/comparison.test.ts +13 -36
- package/test/performance/data-structures/graph/directed-graph.test.ts +3 -14
- package/test/performance/data-structures/hash/hash-map.test.ts +11 -34
- package/test/performance/data-structures/heap/heap.test.ts +5 -18
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -2
- package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +2 -4
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +4 -14
- package/test/performance/data-structures/queue/queue.test.ts +8 -25
- package/test/performance/data-structures/stack/stack.test.ts +6 -18
- package/test/performance/data-structures/trie/trie.test.ts +2 -6
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +6 -5
- package/test/unit/data-structures/binary-tree/bst.test.ts +17 -1
- package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
- package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
- package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
|
@@ -24,11 +24,11 @@ exports.TreeMultimapNode = TreeMultimapNode;
|
|
|
24
24
|
* The only distinction between a TreeMultimap and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
|
|
25
25
|
*/
|
|
26
26
|
class TreeMultimap extends avl_tree_1.AVLTree {
|
|
27
|
-
constructor(
|
|
27
|
+
constructor(nodes, options) {
|
|
28
28
|
super([], options);
|
|
29
29
|
this._count = 0;
|
|
30
|
-
if (
|
|
31
|
-
this.addMany(
|
|
30
|
+
if (nodes)
|
|
31
|
+
this.addMany(nodes);
|
|
32
32
|
}
|
|
33
33
|
// TODO the _count is not accurate after nodes count modified
|
|
34
34
|
get count() {
|
|
@@ -52,26 +52,8 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
52
52
|
return new TreeMultimap([], Object.assign({ iterationType: this.iterationType, variant: this.variant }, options));
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
* The function
|
|
56
|
-
* @param
|
|
57
|
-
* @returns a boolean value indicating whether the exemplar is an instance of the TreeMultimapNode
|
|
58
|
-
* class.
|
|
59
|
-
*/
|
|
60
|
-
isNode(exemplar) {
|
|
61
|
-
return exemplar instanceof TreeMultimapNode;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
65
|
-
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
66
|
-
* data type.
|
|
67
|
-
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
68
|
-
*/
|
|
69
|
-
isNotNodeInstance(potentialKey) {
|
|
70
|
-
return !(potentialKey instanceof TreeMultimapNode);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
74
|
-
* @param exemplar - The `exemplar` parameter is of type `BTNExemplar<K, V, N>`, which means it
|
|
55
|
+
* The function `exemplarToNode` converts an keyOrNodeOrEntry object into a node object.
|
|
56
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`, which means it
|
|
75
57
|
* can be one of the following:
|
|
76
58
|
* @param {V} [value] - The `value` parameter is an optional argument that represents the value
|
|
77
59
|
* associated with the node. It is of type `V`, which can be any data type. If no value is provided,
|
|
@@ -80,16 +62,16 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
80
62
|
* times the value should be added to the node. If not provided, it defaults to 1.
|
|
81
63
|
* @returns a node of type `N` or `undefined`.
|
|
82
64
|
*/
|
|
83
|
-
exemplarToNode(
|
|
65
|
+
exemplarToNode(keyOrNodeOrEntry, value, count = 1) {
|
|
84
66
|
let node;
|
|
85
|
-
if (
|
|
67
|
+
if (keyOrNodeOrEntry === undefined || keyOrNodeOrEntry === null) {
|
|
86
68
|
return;
|
|
87
69
|
}
|
|
88
|
-
else if (this.isNode(
|
|
89
|
-
node =
|
|
70
|
+
else if (this.isNode(keyOrNodeOrEntry)) {
|
|
71
|
+
node = keyOrNodeOrEntry;
|
|
90
72
|
}
|
|
91
|
-
else if (this.isEntry(
|
|
92
|
-
const [key, value] =
|
|
73
|
+
else if (this.isEntry(keyOrNodeOrEntry)) {
|
|
74
|
+
const [key, value] = keyOrNodeOrEntry;
|
|
93
75
|
if (key === undefined || key === null) {
|
|
94
76
|
return;
|
|
95
77
|
}
|
|
@@ -97,8 +79,8 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
97
79
|
node = this.createNode(key, value, count);
|
|
98
80
|
}
|
|
99
81
|
}
|
|
100
|
-
else if (this.isNotNodeInstance(
|
|
101
|
-
node = this.createNode(
|
|
82
|
+
else if (this.isNotNodeInstance(keyOrNodeOrEntry)) {
|
|
83
|
+
node = this.createNode(keyOrNodeOrEntry, value, count);
|
|
102
84
|
}
|
|
103
85
|
else {
|
|
104
86
|
return;
|
|
@@ -106,12 +88,31 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
106
88
|
return node;
|
|
107
89
|
}
|
|
108
90
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
91
|
+
* The function checks if an keyOrNodeOrEntry is an instance of the TreeMultimapNode class.
|
|
92
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
|
|
93
|
+
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the TreeMultimapNode
|
|
94
|
+
* class.
|
|
111
95
|
*/
|
|
96
|
+
isNode(keyOrNodeOrEntry) {
|
|
97
|
+
return keyOrNodeOrEntry instanceof TreeMultimapNode;
|
|
98
|
+
}
|
|
112
99
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
100
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
101
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
102
|
+
* data type.
|
|
103
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
104
|
+
*/
|
|
105
|
+
isNotNodeInstance(potentialKey) {
|
|
106
|
+
return !(potentialKey instanceof TreeMultimapNode);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Time Complexity: O(log n)
|
|
110
|
+
* Space Complexity: O(1)
|
|
111
|
+
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
|
|
112
|
+
*/
|
|
113
|
+
/**
|
|
114
|
+
* Time Complexity: O(log n)
|
|
115
|
+
* Space Complexity: O(1)
|
|
115
116
|
*
|
|
116
117
|
* The function overrides the add method of a binary tree node and adds a new node to the tree.
|
|
117
118
|
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
|
|
@@ -128,21 +129,22 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
128
129
|
add(keyOrNodeOrEntry, value, count = 1) {
|
|
129
130
|
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value, count);
|
|
130
131
|
if (newNode === undefined)
|
|
131
|
-
return;
|
|
132
|
+
return false;
|
|
132
133
|
const orgNodeCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
|
|
133
134
|
const inserted = super.add(newNode);
|
|
134
135
|
if (inserted) {
|
|
135
136
|
this._count += orgNodeCount;
|
|
136
137
|
}
|
|
137
|
-
return
|
|
138
|
+
return true;
|
|
138
139
|
}
|
|
139
140
|
/**
|
|
140
|
-
* Time Complexity: O(k log n)
|
|
141
|
-
* Space Complexity: O(1)
|
|
141
|
+
* Time Complexity: O(k log n)
|
|
142
|
+
* Space Complexity: O(1)
|
|
143
|
+
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
|
|
142
144
|
*/
|
|
143
145
|
/**
|
|
144
|
-
* Time Complexity: O(k log n)
|
|
145
|
-
* Space Complexity: O(1)
|
|
146
|
+
* Time Complexity: O(k log n)
|
|
147
|
+
* Space Complexity: O(1)
|
|
146
148
|
*
|
|
147
149
|
* The function overrides the addMany method to add multiple keys, nodes, or entries to a data
|
|
148
150
|
* structure.
|
|
@@ -154,12 +156,13 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
154
156
|
return super.addMany(keysOrNodesOrEntries);
|
|
155
157
|
}
|
|
156
158
|
/**
|
|
157
|
-
* Time Complexity: O(
|
|
158
|
-
* Space Complexity: O(
|
|
159
|
+
* Time Complexity: O(n log n)
|
|
160
|
+
* Space Complexity: O(n)
|
|
161
|
+
* logarithmic time for each insertion, where "n" is the number of nodes in the tree. This is because the method calls the add method for each node. linear space, as it creates an array to store the sorted nodes.
|
|
159
162
|
*/
|
|
160
163
|
/**
|
|
161
|
-
* Time Complexity: O(n log n)
|
|
162
|
-
* Space Complexity: O(n)
|
|
164
|
+
* Time Complexity: O(n log n)
|
|
165
|
+
* Space Complexity: O(n)
|
|
163
166
|
*
|
|
164
167
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
165
168
|
* tree using either a recursive or iterative approach.
|
|
@@ -205,12 +208,13 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
205
208
|
}
|
|
206
209
|
}
|
|
207
210
|
/**
|
|
208
|
-
* Time Complexity: O(k log n)
|
|
209
|
-
* Space Complexity: O(1)
|
|
211
|
+
* Time Complexity: O(k log n)
|
|
212
|
+
* Space Complexity: O(1)
|
|
213
|
+
* logarithmic time for each insertion, where "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted. This is because the method iterates through the keys and calls the add method for each. constant space, as it doesn't use additional data structures that scale with input size.
|
|
210
214
|
*/
|
|
211
215
|
/**
|
|
212
|
-
* Time Complexity: O(log n)
|
|
213
|
-
* Space Complexity: O(1)
|
|
216
|
+
* Time Complexity: O(k log n)
|
|
217
|
+
* Space Complexity: O(1)
|
|
214
218
|
*
|
|
215
219
|
* The `delete` function in TypeScript is used to remove a node from a binary tree, taking into
|
|
216
220
|
* account the count of the node and balancing the tree if necessary.
|
|
@@ -286,10 +290,13 @@ class TreeMultimap extends avl_tree_1.AVLTree {
|
|
|
286
290
|
return deletedResult;
|
|
287
291
|
}
|
|
288
292
|
/**
|
|
289
|
-
* Time Complexity: O(
|
|
290
|
-
* Space Complexity: O(
|
|
293
|
+
* Time Complexity: O(1)
|
|
294
|
+
* Space Complexity: O(1)
|
|
291
295
|
*/
|
|
292
296
|
/**
|
|
297
|
+
* Time Complexity: O(1)
|
|
298
|
+
* Space Complexity: O(1)
|
|
299
|
+
*
|
|
293
300
|
* The clear() function clears the contents of a data structure and sets the count to zero.
|
|
294
301
|
*/
|
|
295
302
|
clear() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tree-multimap.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multimap.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"tree-multimap.js","sourceRoot":"","sources":["../../../../src/data-structures/binary-tree/tree-multimap.ts"],"names":[],"mappings":";;;AAgBA,uCAA4D;AAE5D,yCAAkD;AAElD,MAAa,gBAIX,SAAQ,sBAAoB;IAG5B;;;;;;;;;OASG;IACH,YAAY,GAAM,EAAE,KAAS,EAAE,KAAK,GAAG,CAAC;QACtC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AArBD,4CAqBC;AAED;;GAEG;AACH,MAAa,YAMX,SAAQ,kBAAsB;IAE9B,YAAY,KAA2C,EAAE,OAAyC;QAChG,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAIb,WAAM,GAAG,CAAC,CAAC;QAHjB,IAAI,KAAK;YAAE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAID,6DAA6D;IAC7D,IAAI,KAAK;QACP,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAClD,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;;;;;;;OAQG;IACM,UAAU,CAAC,GAAM,EAAE,KAAS,EAAE,KAAc;QACnD,OAAO,IAAI,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAM,CAAC;IACtD,CAAC;IAEQ,UAAU,CAAC,OAAgC;QAClD,OAAO,IAAI,YAAY,CAAgB,EAAE,kBACvC,aAAa,EAAE,IAAI,CAAC,aAAa,EACjC,OAAO,EAAE,IAAI,CAAC,OAAO,IAClB,OAAO,EACF,CAAC;IACb,CAAC;IAED;;;;;;;;;;OAU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,CAAC,MAAM,CAAC;YACnC,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAES,YAAY,CAAC,OAAU,EAAE,OAAU;QAC3C,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;AAzWD,oCAyWC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback,
|
|
2
|
+
import { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNCallback, KeyOrNodeOrEntry } 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<
|
|
6
|
+
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V, count?: number): boolean;
|
|
7
|
+
addMany(nodes: Iterable<KeyOrNodeOrEntry<K, V, N>>, values?: Iterable<V | undefined>): boolean[];
|
|
8
8
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BinaryTreeDeleteResult<N>[];
|
|
9
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare enum BSTVariant {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
STANDARD = "STANDARD",
|
|
3
|
+
INVERSE = "INVERSE"
|
|
4
4
|
}
|
|
5
5
|
export declare enum CP {
|
|
6
6
|
lt = "lt",
|
|
@@ -44,7 +44,7 @@ export type BinaryTreePrintOptions = {
|
|
|
44
44
|
};
|
|
45
45
|
export type BTNEntry<K, V> = [K | null | undefined, V | undefined];
|
|
46
46
|
export type BTNKeyOrNode<K, N> = K | null | undefined | N;
|
|
47
|
-
export type
|
|
47
|
+
export type KeyOrNodeOrEntry<K, V, N> = BTNEntry<K, V> | BTNKeyOrNode<K, N>;
|
|
48
48
|
export type BTNodePureKeyOrNode<K, N> = K | N;
|
|
49
49
|
export type BTNodePureExemplar<K, V, N> = [K, V | undefined] | BTNodePureKeyOrNode<K, N>;
|
|
50
50
|
export type BSTNKeyOrNode<K, N> = K | undefined | N;
|
package/dist/cjs/types/common.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.FamilyPosition = exports.IterationType = exports.CP = exports.BSTVariant = void 0;
|
|
4
4
|
var BSTVariant;
|
|
5
5
|
(function (BSTVariant) {
|
|
6
|
-
BSTVariant["
|
|
7
|
-
BSTVariant["
|
|
6
|
+
BSTVariant["STANDARD"] = "STANDARD";
|
|
7
|
+
BSTVariant["INVERSE"] = "INVERSE";
|
|
8
8
|
})(BSTVariant || (exports.BSTVariant = BSTVariant = {}));
|
|
9
9
|
var CP;
|
|
10
10
|
(function (CP) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/types/common.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/types/common.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,mCAAqB,CAAA;IACrB,iCAAmB,CAAA;AACrB,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB;AAED,IAAY,EAIX;AAJD,WAAY,EAAE;IACZ,eAAS,CAAA;IACT,eAAS,CAAA;IACT,eAAS,CAAA;AACX,CAAC,EAJW,EAAE,kBAAF,EAAE,QAIb;AAED;;;;;GAKG;AACH,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,wCAAuB,CAAA;IACvB,wCAAuB,CAAA;AACzB,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAED,IAAY,cAQX;AARD,WAAY,cAAc;IACxB,+BAAa,CAAA;IACb,+BAAa,CAAA;IACb,iCAAe,CAAA;IACf,yCAAuB,CAAA;IACvB,2CAAyB,CAAA;IACzB,uCAAqB,CAAA;IACrB,uCAAqB,CAAA;AACvB,CAAC,EARW,cAAc,8BAAd,cAAc,QAQzB"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback,
|
|
9
|
+
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry } from '../../types';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
|
|
12
12
|
height: number;
|
|
@@ -23,15 +23,15 @@ export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N
|
|
|
23
23
|
*/
|
|
24
24
|
export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>> extends BST<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
|
|
25
25
|
/**
|
|
26
|
-
* The constructor function initializes an AVLTree object with optional
|
|
27
|
-
* @param [
|
|
28
|
-
* objects. It represents a collection of
|
|
26
|
+
* The constructor function initializes an AVLTree object with optional nodes and options.
|
|
27
|
+
* @param [nodes] - The `nodes` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
|
|
28
|
+
* objects. It represents a collection of nodes that will be added to the AVL tree during
|
|
29
29
|
* initialization.
|
|
30
30
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
31
31
|
* behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
|
|
32
32
|
* provide only a subset of the properties defined in the `AVLTreeOptions` interface.
|
|
33
33
|
*/
|
|
34
|
-
constructor(
|
|
34
|
+
constructor(nodes?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: Partial<AVLTreeOptions<K>>);
|
|
35
35
|
/**
|
|
36
36
|
* The function creates a new AVL tree node with the specified key and value.
|
|
37
37
|
* @param {K} key - The key parameter is the key value that will be associated with
|
|
@@ -51,25 +51,26 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
51
51
|
*/
|
|
52
52
|
createTree(options?: AVLTreeOptions<K>): TREE;
|
|
53
53
|
/**
|
|
54
|
-
* The function checks if an
|
|
55
|
-
* @param
|
|
56
|
-
* @returns a boolean value indicating whether the
|
|
54
|
+
* The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
|
|
55
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
|
|
56
|
+
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
|
|
57
57
|
*/
|
|
58
|
-
isNode(
|
|
58
|
+
isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
|
|
59
59
|
/**
|
|
60
60
|
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
61
61
|
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
62
62
|
* data type.
|
|
63
63
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
64
64
|
*/
|
|
65
|
-
isNotNodeInstance(potentialKey:
|
|
65
|
+
isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K;
|
|
66
66
|
/**
|
|
67
|
-
* Time Complexity: O(log n)
|
|
68
|
-
* Space Complexity: O(1)
|
|
67
|
+
* Time Complexity: O(log n)
|
|
68
|
+
* Space Complexity: O(1)
|
|
69
|
+
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
|
|
69
70
|
*/
|
|
70
71
|
/**
|
|
71
|
-
* Time Complexity: O(log n)
|
|
72
|
-
* Space Complexity: O(1)
|
|
72
|
+
* Time Complexity: O(log n)
|
|
73
|
+
* Space Complexity: O(1)
|
|
73
74
|
*
|
|
74
75
|
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
75
76
|
* a new node.
|
|
@@ -79,14 +80,14 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
79
80
|
* being added to the binary tree.
|
|
80
81
|
* @returns The method is returning either the inserted node or undefined.
|
|
81
82
|
*/
|
|
82
|
-
add(keyOrNodeOrEntry:
|
|
83
|
+
add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
|
|
83
84
|
/**
|
|
84
|
-
* Time Complexity: O(log n)
|
|
85
|
-
* Space Complexity: O(1)
|
|
85
|
+
* Time Complexity: O(log n)
|
|
86
|
+
* Space Complexity: O(1)
|
|
86
87
|
*/
|
|
87
88
|
/**
|
|
88
|
-
* Time Complexity: O(log n)
|
|
89
|
-
* Space Complexity: O(1)
|
|
89
|
+
* Time Complexity: O(log n)
|
|
90
|
+
* Space Complexity: O(1)
|
|
90
91
|
*
|
|
91
92
|
* The function overrides the delete method of a binary tree, performs the deletion, and then
|
|
92
93
|
* balances the tree if necessary.
|
|
@@ -112,12 +113,13 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
112
113
|
*/
|
|
113
114
|
protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
|
|
114
115
|
/**
|
|
115
|
-
* Time Complexity: O(1)
|
|
116
|
-
* Space Complexity: O(1)
|
|
116
|
+
* Time Complexity: O(1)
|
|
117
|
+
* Space Complexity: O(1)
|
|
118
|
+
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
|
|
117
119
|
*/
|
|
118
120
|
/**
|
|
119
|
-
* Time Complexity: O(1)
|
|
120
|
-
* Space Complexity: O(1)
|
|
121
|
+
* Time Complexity: O(1)
|
|
122
|
+
* Space Complexity: O(1)
|
|
121
123
|
*
|
|
122
124
|
* The function calculates the balance factor of a node in a binary tree.
|
|
123
125
|
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
@@ -126,12 +128,13 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
126
128
|
*/
|
|
127
129
|
protected _balanceFactor(node: N): number;
|
|
128
130
|
/**
|
|
129
|
-
* Time Complexity: O(1)
|
|
130
|
-
* Space Complexity: O(1)
|
|
131
|
+
* Time Complexity: O(1)
|
|
132
|
+
* Space Complexity: O(1)
|
|
133
|
+
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
|
|
131
134
|
*/
|
|
132
135
|
/**
|
|
133
|
-
* Time Complexity: O(1)
|
|
134
|
-
* Space Complexity: O(1)
|
|
136
|
+
* Time Complexity: O(1)
|
|
137
|
+
* Space Complexity: O(1)
|
|
135
138
|
*
|
|
136
139
|
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
137
140
|
* right children.
|
|
@@ -139,62 +142,64 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
|
|
|
139
142
|
*/
|
|
140
143
|
protected _updateHeight(node: N): void;
|
|
141
144
|
/**
|
|
142
|
-
* Time Complexity: O(log n)
|
|
143
|
-
* Space Complexity: O(1)
|
|
145
|
+
* Time Complexity: O(log n)
|
|
146
|
+
* Space Complexity: O(1)
|
|
147
|
+
* logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
|
|
144
148
|
*/
|
|
145
149
|
/**
|
|
146
|
-
* Time Complexity: O(log n)
|
|
147
|
-
* Space Complexity: O(1)
|
|
150
|
+
* Time Complexity: O(log n)
|
|
151
|
+
* Space Complexity: O(1)
|
|
148
152
|
*
|
|
149
153
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
150
154
|
* to restore balance in an AVL tree after inserting a node.
|
|
151
155
|
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
152
156
|
* AVL tree that needs to be balanced.
|
|
153
157
|
*/
|
|
154
|
-
protected _balancePath(node: N): void;
|
|
158
|
+
protected _balancePath(node: KeyOrNodeOrEntry<K, V, N>): void;
|
|
155
159
|
/**
|
|
156
|
-
* Time Complexity: O(1)
|
|
157
|
-
* Space Complexity: O(1)
|
|
160
|
+
* Time Complexity: O(1)
|
|
161
|
+
* Space Complexity: O(1)
|
|
162
|
+
* constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
|
|
158
163
|
*/
|
|
159
164
|
/**
|
|
160
|
-
* Time Complexity: O(1)
|
|
161
|
-
* Space Complexity: O(1)
|
|
165
|
+
* Time Complexity: O(1)
|
|
166
|
+
* Space Complexity: O(1)
|
|
162
167
|
*
|
|
163
168
|
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
164
169
|
* @param {N} A - A is a node in a binary tree.
|
|
165
170
|
*/
|
|
166
171
|
protected _balanceLL(A: N): void;
|
|
167
172
|
/**
|
|
168
|
-
* Time Complexity: O(1)
|
|
169
|
-
* Space Complexity: O(1)
|
|
173
|
+
* Time Complexity: O(1)
|
|
174
|
+
* Space Complexity: O(1)
|
|
170
175
|
*/
|
|
171
176
|
/**
|
|
172
|
-
* Time Complexity: O(1)
|
|
173
|
-
* Space Complexity: O(1)
|
|
177
|
+
* Time Complexity: O(1)
|
|
178
|
+
* Space Complexity: O(1)
|
|
174
179
|
*
|
|
175
180
|
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
176
181
|
* @param {N} A - A is a node in a binary tree.
|
|
177
182
|
*/
|
|
178
183
|
protected _balanceLR(A: N): void;
|
|
179
184
|
/**
|
|
180
|
-
* Time Complexity: O(1)
|
|
181
|
-
* Space Complexity: O(1)
|
|
185
|
+
* Time Complexity: O(1)
|
|
186
|
+
* Space Complexity: O(1)
|
|
182
187
|
*/
|
|
183
188
|
/**
|
|
184
|
-
* Time Complexity: O(1)
|
|
185
|
-
* Space Complexity: O(1)
|
|
189
|
+
* Time Complexity: O(1)
|
|
190
|
+
* Space Complexity: O(1)
|
|
186
191
|
*
|
|
187
192
|
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
188
193
|
* @param {N} A - A is a node in a binary tree.
|
|
189
194
|
*/
|
|
190
195
|
protected _balanceRR(A: N): void;
|
|
191
196
|
/**
|
|
192
|
-
* Time Complexity: O(1)
|
|
193
|
-
* Space Complexity: O(1)
|
|
197
|
+
* Time Complexity: O(1)
|
|
198
|
+
* Space Complexity: O(1)
|
|
194
199
|
*/
|
|
195
200
|
/**
|
|
196
|
-
* Time Complexity: O(1)
|
|
197
|
-
* Space Complexity: O(1)
|
|
201
|
+
* Time Complexity: O(1)
|
|
202
|
+
* Space Complexity: O(1)
|
|
198
203
|
*
|
|
199
204
|
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
200
205
|
* @param {N} A - A is a node in a binary tree.
|