data-structure-typed 1.51.8 → 1.52.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 +152 -152
- package/dist/cjs/data-structures/base/index.d.ts +2 -1
- package/dist/cjs/data-structures/base/index.js +2 -1
- package/dist/cjs/data-structures/base/index.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/cjs/data-structures/base/iterable-element-base.js +226 -0
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -0
- package/dist/cjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/cjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +13 -190
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
- 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 +82 -62
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +78 -59
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +318 -226
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +475 -363
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +192 -202
- package/dist/cjs/data-structures/binary-tree/bst.js +207 -249
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +107 -98
- 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 +92 -75
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/cjs/data-structures/graph/abstract-graph.js +10 -15
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +33 -40
- package/dist/cjs/data-structures/hash/hash-map.js +40 -55
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +43 -114
- package/dist/cjs/data-structures/heap/heap.js +59 -127
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/cjs/data-structures/heap/max-heap.js +76 -10
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/cjs/data-structures/heap/min-heap.js +68 -11
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +21 -20
- package/dist/cjs/data-structures/queue/deque.js +29 -23
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +8 -28
- package/dist/cjs/data-structures/queue/queue.js +15 -31
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
- package/dist/cjs/data-structures/stack/stack.js +25 -24
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +19 -14
- package/dist/cjs/data-structures/trie/trie.js +27 -16
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +7 -7
- package/dist/cjs/types/common.d.ts +1 -2
- package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
- package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +4 -5
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
- package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/cjs/utils/utils.js +3 -5
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/index.d.ts +2 -1
- package/dist/mjs/data-structures/base/index.js +2 -1
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
- package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
- package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
- package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +82 -62
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +78 -59
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +318 -226
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +476 -364
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +192 -202
- package/dist/mjs/data-structures/binary-tree/bst.js +211 -255
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +107 -98
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +105 -93
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +10 -15
- package/dist/mjs/data-structures/graph/abstract-graph.js +10 -15
- package/dist/mjs/data-structures/hash/hash-map.d.ts +33 -40
- package/dist/mjs/data-structures/hash/hash-map.js +41 -55
- package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
- package/dist/mjs/data-structures/heap/heap.js +60 -128
- package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
- package/dist/mjs/data-structures/heap/max-heap.js +79 -10
- package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
- package/dist/mjs/data-structures/heap/min-heap.js +68 -11
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
- package/dist/mjs/data-structures/queue/deque.d.ts +21 -20
- package/dist/mjs/data-structures/queue/deque.js +29 -23
- package/dist/mjs/data-structures/queue/queue.d.ts +8 -28
- package/dist/mjs/data-structures/queue/queue.js +15 -31
- package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
- package/dist/mjs/data-structures/stack/stack.js +25 -24
- package/dist/mjs/data-structures/trie/trie.d.ts +19 -14
- package/dist/mjs/data-structures/trie/trie.js +27 -16
- package/dist/mjs/interfaces/binary-tree.d.ts +7 -7
- package/dist/mjs/types/common.d.ts +1 -2
- package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
- package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +4 -5
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
- package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
- package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
- package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
- package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -2
- package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
- package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
- package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
- package/dist/mjs/utils/utils.js +3 -5
- package/dist/umd/data-structure-typed.js +1949 -1481
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/base/index.ts +2 -1
- package/src/data-structures/base/iterable-element-base.ts +250 -0
- package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
- package/src/data-structures/binary-tree/avl-tree.ts +96 -69
- package/src/data-structures/binary-tree/binary-tree.ts +535 -403
- package/src/data-structures/binary-tree/bst.ts +247 -277
- package/src/data-structures/binary-tree/rb-tree.ts +123 -103
- package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
- package/src/data-structures/graph/abstract-graph.ts +10 -10
- package/src/data-structures/hash/hash-map.ts +46 -53
- package/src/data-structures/heap/heap.ts +71 -152
- package/src/data-structures/heap/max-heap.ts +88 -13
- package/src/data-structures/heap/min-heap.ts +78 -15
- package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
- package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
- package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
- package/src/data-structures/priority-queue/priority-queue.ts +81 -4
- package/src/data-structures/queue/deque.ts +37 -26
- package/src/data-structures/queue/queue.ts +23 -36
- package/src/data-structures/stack/stack.ts +31 -26
- package/src/data-structures/trie/trie.ts +35 -20
- package/src/interfaces/binary-tree.ts +9 -9
- package/src/types/common.ts +1 -2
- package/src/types/data-structures/base/base.ts +14 -6
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
- package/src/types/data-structures/binary-tree/bst.ts +4 -5
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
- package/src/types/data-structures/heap/heap.ts +4 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
- package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/types/data-structures/queue/deque.ts +3 -1
- package/src/types/data-structures/queue/queue.ts +3 -1
- package/src/types/data-structures/stack/stack.ts +3 -1
- package/src/types/data-structures/trie/trie.ts +3 -1
- package/src/utils/utils.ts +3 -3
- package/test/integration/avl-tree.test.ts +2 -2
- package/test/integration/bst.test.ts +3 -3
- package/test/integration/index.html +25 -11
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +68 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +56 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +80 -0
- package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
- package/test/unit/data-structures/queue/deque.test.ts +30 -0
- package/test/unit/data-structures/queue/queue.test.ts +56 -0
- package/test/utils/big-o.ts +12 -6
- package/tsconfig-base.json +1 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
|
@@ -47,27 +47,29 @@ export class AVLTreeNode extends BSTNode {
|
|
|
47
47
|
*/
|
|
48
48
|
export class AVLTree extends BST {
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
50
|
+
* This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
|
|
51
|
+
* entries, or raw elements.
|
|
52
|
+
* @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
|
|
53
|
+
* iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
|
|
54
|
+
* be used to initialize the AVLTree.
|
|
55
|
+
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
56
|
+
* behavior of the AVLTree. It can include properties such as `compareFn` (a function used to compare
|
|
57
|
+
* keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
|
|
58
|
+
* `nodeBuilder` (
|
|
57
59
|
*/
|
|
58
|
-
constructor(
|
|
60
|
+
constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
|
|
59
61
|
super([], options);
|
|
60
|
-
if (
|
|
61
|
-
super.addMany(
|
|
62
|
+
if (keysOrNodesOrEntriesOrRawElements)
|
|
63
|
+
super.addMany(keysOrNodesOrEntriesOrRawElements);
|
|
62
64
|
}
|
|
63
65
|
/**
|
|
64
|
-
* The function creates a new AVL tree node with the
|
|
65
|
-
* @param {K} key - The key parameter is the key
|
|
66
|
-
*
|
|
67
|
-
* @param [value] - The parameter
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
66
|
+
* The function creates a new AVL tree node with the given key and value.
|
|
67
|
+
* @param {K} key - The key parameter is of type K, which represents the key of the node being
|
|
68
|
+
* created.
|
|
69
|
+
* @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
|
|
70
|
+
* value associated with the key in the node being created.
|
|
71
|
+
* @returns The method is returning a new instance of the AVLTreeNode class, casted as the generic
|
|
72
|
+
* type NODE.
|
|
71
73
|
*/
|
|
72
74
|
createNode(key, value) {
|
|
73
75
|
return new AVLTreeNode(key, value);
|
|
@@ -87,12 +89,14 @@ export class AVLTree extends BST {
|
|
|
87
89
|
});
|
|
88
90
|
}
|
|
89
91
|
/**
|
|
90
|
-
* The function checks if
|
|
91
|
-
* @param
|
|
92
|
-
*
|
|
92
|
+
* The function checks if the input is an instance of AVLTreeNode.
|
|
93
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
94
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
95
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
96
|
+
* an instance of the `AVLTreeNode` class.
|
|
93
97
|
*/
|
|
94
|
-
isNode(
|
|
95
|
-
return
|
|
98
|
+
isNode(keyOrNodeOrEntryOrRawElement) {
|
|
99
|
+
return keyOrNodeOrEntryOrRawElement instanceof AVLTreeNode;
|
|
96
100
|
}
|
|
97
101
|
/**
|
|
98
102
|
* Time Complexity: O(log n)
|
|
@@ -103,20 +107,21 @@ export class AVLTree extends BST {
|
|
|
103
107
|
* Time Complexity: O(log n)
|
|
104
108
|
* Space Complexity: O(1)
|
|
105
109
|
*
|
|
106
|
-
* The function overrides the add method of a
|
|
107
|
-
*
|
|
108
|
-
* @param
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
110
|
+
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
111
|
+
* structure, then balances the path.
|
|
112
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
113
|
+
* `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `KeyOrNodeOrEntry<K, V, NODE>`, or
|
|
114
|
+
* `RawElement`.
|
|
115
|
+
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
116
|
+
* the key or node being added to the data structure.
|
|
117
|
+
* @returns The method is returning a boolean value.
|
|
113
118
|
*/
|
|
114
|
-
add(
|
|
115
|
-
if (
|
|
119
|
+
add(keyOrNodeOrEntryOrRawElement, value) {
|
|
120
|
+
if (keyOrNodeOrEntryOrRawElement === null)
|
|
116
121
|
return false;
|
|
117
|
-
const inserted = super.add(
|
|
122
|
+
const inserted = super.add(keyOrNodeOrEntryOrRawElement, value);
|
|
118
123
|
if (inserted)
|
|
119
|
-
this._balancePath(
|
|
124
|
+
this._balancePath(keyOrNodeOrEntryOrRawElement);
|
|
120
125
|
return inserted;
|
|
121
126
|
}
|
|
122
127
|
/**
|
|
@@ -127,16 +132,14 @@ export class AVLTree extends BST {
|
|
|
127
132
|
* Time Complexity: O(log n)
|
|
128
133
|
* Space Complexity: O(1)
|
|
129
134
|
*
|
|
130
|
-
* The function overrides the delete method of a binary tree
|
|
131
|
-
*
|
|
135
|
+
* The function overrides the delete method of a binary tree class and performs additional operations
|
|
136
|
+
* to balance the tree after deletion.
|
|
132
137
|
* @param identifier - The `identifier` parameter is the value or condition used to identify the
|
|
133
|
-
* node(s) to be deleted from the binary tree. It can be of any type
|
|
134
|
-
*
|
|
135
|
-
* @param {C} callback - The `callback` parameter is a function that will be
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* parameter of type `NODE
|
|
139
|
-
* @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
|
|
138
|
+
* node(s) to be deleted from the binary tree. It can be of any type that is compatible with the
|
|
139
|
+
* binary tree's node type.
|
|
140
|
+
* @param {C} callback - The `callback` parameter is a function that will be used to determine if a
|
|
141
|
+
* node should be deleted or not. It is optional and has a default value of `this._DEFAULT_CALLBACK`.
|
|
142
|
+
* @returns The method is returning an array of BinaryTreeDeleteResult<NODE> objects.
|
|
140
143
|
*/
|
|
141
144
|
delete(identifier, callback = this._DEFAULT_CALLBACK) {
|
|
142
145
|
const deletedResults = super.delete(identifier, callback);
|
|
@@ -148,14 +151,21 @@ export class AVLTree extends BST {
|
|
|
148
151
|
return deletedResults;
|
|
149
152
|
}
|
|
150
153
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
154
|
+
* Time Complexity: O(1)
|
|
155
|
+
* Space Complexity: O(1)
|
|
156
|
+
*/
|
|
157
|
+
/**
|
|
158
|
+
* Time Complexity: O(1)
|
|
159
|
+
* Space Complexity: O(1)
|
|
160
|
+
*
|
|
161
|
+
* The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
|
|
162
|
+
* binary search tree.
|
|
163
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
|
|
164
|
+
* object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
|
|
165
|
+
* @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
|
|
166
|
+
* `R` or an instance of `BSTNKeyOrNode<K, NODE>`.
|
|
167
|
+
* @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
|
|
168
|
+
* `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
|
|
159
169
|
*/
|
|
160
170
|
_swapProperties(srcNode, destNode) {
|
|
161
171
|
const srcNodeEnsured = this.ensureNode(srcNode);
|
|
@@ -185,7 +195,8 @@ export class AVLTree extends BST {
|
|
|
185
195
|
* Space Complexity: O(1)
|
|
186
196
|
*
|
|
187
197
|
* The function calculates the balance factor of a node in a binary tree.
|
|
188
|
-
* @param {NODE} node - The parameter "node" represents a node in a
|
|
198
|
+
* @param {NODE} node - The parameter "node" is of type "NODE", which likely represents a node in a
|
|
199
|
+
* binary tree data structure.
|
|
189
200
|
* @returns the balance factor of a given node. The balance factor is calculated by subtracting the
|
|
190
201
|
* height of the left subtree from the height of the right subtree.
|
|
191
202
|
*/
|
|
@@ -231,7 +242,7 @@ export class AVLTree extends BST {
|
|
|
231
242
|
* Time Complexity: O(1)
|
|
232
243
|
* Space Complexity: O(1)
|
|
233
244
|
*
|
|
234
|
-
* The
|
|
245
|
+
* The `_balanceLL` function performs a left-left rotation to balance a binary search tree.
|
|
235
246
|
* @param {NODE} A - A is a node in a binary tree.
|
|
236
247
|
*/
|
|
237
248
|
_balanceLL(A) {
|
|
@@ -429,8 +440,8 @@ export class AVLTree extends BST {
|
|
|
429
440
|
*
|
|
430
441
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
431
442
|
* to restore balance in an AVL tree after inserting a node.
|
|
432
|
-
* @param {NODE} node - The `node` parameter
|
|
433
|
-
*
|
|
443
|
+
* @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
|
|
444
|
+
* `KeyOrNodeOrEntry<K, V, NODE>`.
|
|
434
445
|
*/
|
|
435
446
|
_balancePath(node) {
|
|
436
447
|
node = this.ensureNode(node);
|
|
@@ -473,13 +484,21 @@ export class AVLTree extends BST {
|
|
|
473
484
|
}
|
|
474
485
|
}
|
|
475
486
|
/**
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
|
|
487
|
+
* Time Complexity: O(1)
|
|
488
|
+
* Space Complexity: O(1)
|
|
489
|
+
*/
|
|
490
|
+
/**
|
|
491
|
+
* Time Complexity: O(1)
|
|
492
|
+
* Space Complexity: O(1)
|
|
493
|
+
*
|
|
494
|
+
* The function replaces an old node with a new node and sets the height of the new node to be the
|
|
495
|
+
* same as the old node.
|
|
496
|
+
* @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
|
|
497
|
+
* the data structure.
|
|
479
498
|
* @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
|
|
480
499
|
* the data structure.
|
|
481
|
-
* @returns the result of calling the `_replaceNode` method
|
|
482
|
-
* `oldNode` and `newNode` as arguments.
|
|
500
|
+
* @returns The method is returning the result of calling the `_replaceNode` method from the
|
|
501
|
+
* superclass, with the `oldNode` and `newNode` as arguments.
|
|
483
502
|
*/
|
|
484
503
|
_replaceNode(oldNode, newNode) {
|
|
485
504
|
newNode.height = oldNode.height;
|