data-structure-typed 1.52.9 → 1.53.1
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 +1 -37
- package/benchmark/report.json +24 -384
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +21 -21
- 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 +29 -27
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +186 -144
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +376 -265
- 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 +108 -78
- 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 +42 -36
- 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 +21 -21
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +59 -49
- 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 +21 -21
- 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 +29 -26
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +186 -144
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +376 -264
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +56 -56
- package/dist/mjs/data-structures/binary-tree/bst.js +108 -76
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +13 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +42 -35
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +21 -21
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +59 -48
- 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 +596 -468
- 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 -54
- package/src/data-structures/binary-tree/avl-tree.ts +32 -35
- package/src/data-structures/binary-tree/binary-tree.ts +440 -360
- package/src/data-structures/binary-tree/bst.ts +144 -113
- package/src/data-structures/binary-tree/rb-tree.ts +44 -43
- package/src/data-structures/binary-tree/tree-multi-map.ts +57 -61
- 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 +13 -14
- package/src/types/data-structures/binary-tree/bst.ts +3 -3
- package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +2 -2
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +9 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +115 -3
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +109 -4
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +183 -46
- package/test/unit/data-structures/binary-tree/bst.test.ts +340 -21
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +19 -0
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +141 -3
- package/test/utils/array.ts +15 -12
|
@@ -49,7 +49,7 @@ export class AVLTree extends BST {
|
|
|
49
49
|
/**
|
|
50
50
|
* This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
|
|
51
51
|
* entries, or raw elements.
|
|
52
|
-
* @param
|
|
52
|
+
* @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
|
|
53
53
|
* iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
|
|
54
54
|
* be used to initialize the AVLTree.
|
|
55
55
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
@@ -57,10 +57,10 @@ export class AVLTree extends BST {
|
|
|
57
57
|
* keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
|
|
58
58
|
* `nodeBuilder` (
|
|
59
59
|
*/
|
|
60
|
-
constructor(
|
|
60
|
+
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
61
61
|
super([], options);
|
|
62
|
-
if (
|
|
63
|
-
super.addMany(
|
|
62
|
+
if (keysNodesEntriesOrRaws)
|
|
63
|
+
super.addMany(keysNodesEntriesOrRaws);
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* The function creates a new AVL tree node with the given key and value.
|
|
@@ -72,7 +72,7 @@ export class AVLTree extends BST {
|
|
|
72
72
|
* type NODE.
|
|
73
73
|
*/
|
|
74
74
|
createNode(key, value) {
|
|
75
|
-
return new AVLTreeNode(key, value);
|
|
75
|
+
return new AVLTreeNode(key, this._isMapMode ? undefined : value);
|
|
76
76
|
}
|
|
77
77
|
/**
|
|
78
78
|
* The function creates a new AVL tree with the specified options and returns it.
|
|
@@ -84,6 +84,7 @@ export class AVLTree extends BST {
|
|
|
84
84
|
createTree(options) {
|
|
85
85
|
return new AVLTree([], {
|
|
86
86
|
iterationType: this.iterationType,
|
|
87
|
+
isMapMode: this._isMapMode,
|
|
87
88
|
comparator: this._comparator,
|
|
88
89
|
toEntryFn: this._toEntryFn,
|
|
89
90
|
...options
|
|
@@ -91,13 +92,13 @@ export class AVLTree extends BST {
|
|
|
91
92
|
}
|
|
92
93
|
/**
|
|
93
94
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
94
|
-
* @param {
|
|
95
|
-
* `
|
|
96
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
95
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
96
|
+
* `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
|
|
97
|
+
* @returns a boolean value indicating whether the input parameter `keyNodeEntryOrRaw` is
|
|
97
98
|
* an instance of the `AVLTreeNode` class.
|
|
98
99
|
*/
|
|
99
|
-
isNode(
|
|
100
|
-
return
|
|
100
|
+
isNode(keyNodeEntryOrRaw) {
|
|
101
|
+
return keyNodeEntryOrRaw instanceof AVLTreeNode;
|
|
101
102
|
}
|
|
102
103
|
/**
|
|
103
104
|
* Time Complexity: O(log n)
|
|
@@ -105,19 +106,19 @@ export class AVLTree extends BST {
|
|
|
105
106
|
*
|
|
106
107
|
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
107
108
|
* structure, then balances the path.
|
|
108
|
-
* @param {
|
|
109
|
-
* `
|
|
109
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
|
|
110
|
+
* `keyNodeEntryOrRaw` can accept values of type `R`, `BTNRep<K, V, NODE>`, or
|
|
110
111
|
* `RawElement`.
|
|
111
112
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
112
113
|
* the key or node being added to the data structure.
|
|
113
114
|
* @returns The method is returning a boolean value.
|
|
114
115
|
*/
|
|
115
|
-
add(
|
|
116
|
-
if (
|
|
116
|
+
add(keyNodeEntryOrRaw, value) {
|
|
117
|
+
if (keyNodeEntryOrRaw === null)
|
|
117
118
|
return false;
|
|
118
|
-
const inserted = super.add(
|
|
119
|
+
const inserted = super.add(keyNodeEntryOrRaw, value);
|
|
119
120
|
if (inserted)
|
|
120
|
-
this._balancePath(
|
|
121
|
+
this._balancePath(keyNodeEntryOrRaw);
|
|
121
122
|
return inserted;
|
|
122
123
|
}
|
|
123
124
|
/**
|
|
@@ -126,15 +127,15 @@ export class AVLTree extends BST {
|
|
|
126
127
|
*
|
|
127
128
|
* The function overrides the delete method in a TypeScript class, performs deletion, and then
|
|
128
129
|
* balances the tree if necessary.
|
|
129
|
-
* @param {
|
|
130
|
+
* @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The `keyNodeEntryOrRaw`
|
|
130
131
|
* parameter in the `override delete` method can be one of the following types:
|
|
131
132
|
* @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
|
|
132
133
|
* method from the superclass (presumably a parent class) with the provided `predicate`, which could
|
|
133
134
|
* be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
|
|
134
135
|
* `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
|
|
135
136
|
*/
|
|
136
|
-
delete(
|
|
137
|
-
const deletedResults = super.delete(
|
|
137
|
+
delete(keyNodeEntryOrRaw) {
|
|
138
|
+
const deletedResults = super.delete(keyNodeEntryOrRaw);
|
|
138
139
|
for (const { needBalanced } of deletedResults) {
|
|
139
140
|
if (needBalanced) {
|
|
140
141
|
this._balancePath(needBalanced);
|
|
@@ -148,10 +149,10 @@ export class AVLTree extends BST {
|
|
|
148
149
|
*
|
|
149
150
|
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
|
|
150
151
|
* binary search tree.
|
|
151
|
-
* @param {R |
|
|
152
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
|
|
152
153
|
* object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
|
|
153
|
-
* @param {R |
|
|
154
|
-
* `R` or an instance of `
|
|
154
|
+
* @param {R | BSTNOptKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
|
|
155
|
+
* `R` or an instance of `BSTNOptKeyOrNode<K, NODE>`.
|
|
155
156
|
* @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
|
|
156
157
|
* `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
|
|
157
158
|
*/
|
|
@@ -164,10 +165,12 @@ export class AVLTree extends BST {
|
|
|
164
165
|
if (tempNode) {
|
|
165
166
|
tempNode.height = height;
|
|
166
167
|
destNodeEnsured.key = srcNodeEnsured.key;
|
|
167
|
-
|
|
168
|
+
if (!this._isMapMode)
|
|
169
|
+
destNodeEnsured.value = srcNodeEnsured.value;
|
|
168
170
|
destNodeEnsured.height = srcNodeEnsured.height;
|
|
169
171
|
srcNodeEnsured.key = tempNode.key;
|
|
170
|
-
|
|
172
|
+
if (!this._isMapMode)
|
|
173
|
+
srcNodeEnsured.value = tempNode.value;
|
|
171
174
|
srcNodeEnsured.height = tempNode.height;
|
|
172
175
|
}
|
|
173
176
|
return destNodeEnsured;
|
|
@@ -404,8 +407,8 @@ export class AVLTree extends BST {
|
|
|
404
407
|
*
|
|
405
408
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
406
409
|
* to restore balance in an AVL tree after inserting a node.
|
|
407
|
-
* @param {
|
|
408
|
-
* `
|
|
410
|
+
* @param {BTNRep<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
|
|
411
|
+
* `BTNRep<K, V, NODE>`.
|
|
409
412
|
*/
|
|
410
413
|
_balancePath(node) {
|
|
411
414
|
node = this.ensureNode(node);
|