heap-typed 1.52.0 → 1.52.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/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +11 -11
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
- package/dist/data-structures/binary-tree/avl-tree.d.ts +11 -11
- package/dist/data-structures/binary-tree/avl-tree.js +6 -6
- package/dist/data-structures/binary-tree/binary-tree.d.ts +97 -97
- package/dist/data-structures/binary-tree/binary-tree.js +50 -50
- package/dist/data-structures/binary-tree/bst.d.ts +35 -35
- package/dist/data-structures/binary-tree/bst.js +15 -15
- package/dist/data-structures/binary-tree/rb-tree.d.ts +8 -8
- package/dist/data-structures/binary-tree/rb-tree.js +6 -6
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +10 -10
- package/dist/data-structures/binary-tree/tree-multi-map.js +5 -5
- package/dist/data-structures/graph/directed-graph.js +2 -1
- package/dist/data-structures/queue/deque.d.ts +7 -0
- package/dist/data-structures/queue/deque.js +16 -1
- package/dist/data-structures/queue/queue.d.ts +0 -1
- package/dist/data-structures/queue/queue.js +0 -1
- package/dist/index.js +0 -1
- package/dist/interfaces/binary-tree.d.ts +3 -3
- package/dist/types/common.d.ts +1 -22
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +18 -1
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -0
- package/dist/types/data-structures/queue/deque.d.ts +1 -0
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +12 -12
- package/src/data-structures/binary-tree/avl-tree.ts +11 -11
- package/src/data-structures/binary-tree/binary-tree.ts +151 -147
- package/src/data-structures/binary-tree/bst.ts +44 -41
- package/src/data-structures/binary-tree/rb-tree.ts +10 -10
- package/src/data-structures/binary-tree/tree-multi-map.ts +10 -10
- package/src/data-structures/graph/directed-graph.ts +2 -1
- package/src/data-structures/queue/deque.ts +15 -1
- package/src/data-structures/queue/queue.ts +0 -1
- package/src/index.ts +0 -1
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +2 -24
- package/src/types/data-structures/binary-tree/binary-tree.ts +21 -1
- package/src/types/data-structures/binary-tree/bst.ts +7 -0
- package/src/types/data-structures/queue/deque.ts +4 -1
|
@@ -13,7 +13,7 @@ import type {
|
|
|
13
13
|
BinaryTreeDeleteResult,
|
|
14
14
|
BSTNKeyOrNode,
|
|
15
15
|
BTNCallback,
|
|
16
|
-
|
|
16
|
+
BTNKeyOrNodeOrEntry
|
|
17
17
|
} from '../../types';
|
|
18
18
|
import { BTNEntry } from '../../types';
|
|
19
19
|
import { IBinaryTree } from '../../interfaces';
|
|
@@ -86,7 +86,7 @@ export class AVLTree<
|
|
|
86
86
|
* `nodeBuilder` (
|
|
87
87
|
*/
|
|
88
88
|
constructor(
|
|
89
|
-
keysOrNodesOrEntriesOrRawElements: Iterable<R |
|
|
89
|
+
keysOrNodesOrEntriesOrRawElements: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>> = [],
|
|
90
90
|
options?: AVLTreeOptions<K, V, R>
|
|
91
91
|
) {
|
|
92
92
|
super([], options);
|
|
@@ -123,13 +123,13 @@ export class AVLTree<
|
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
126
|
-
* @param {R |
|
|
127
|
-
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `
|
|
126
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
127
|
+
* `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
128
128
|
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
|
|
129
129
|
* an instance of the `AVLTreeNode` class.
|
|
130
130
|
*/
|
|
131
131
|
override isNode(
|
|
132
|
-
keyOrNodeOrEntryOrRawElement: R |
|
|
132
|
+
keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>
|
|
133
133
|
): keyOrNodeOrEntryOrRawElement is NODE {
|
|
134
134
|
return keyOrNodeOrEntryOrRawElement instanceof AVLTreeNode;
|
|
135
135
|
}
|
|
@@ -146,14 +146,14 @@ export class AVLTree<
|
|
|
146
146
|
*
|
|
147
147
|
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
148
148
|
* structure, then balances the path.
|
|
149
|
-
* @param {R |
|
|
150
|
-
* `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `
|
|
149
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
|
|
150
|
+
* `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
|
|
151
151
|
* `RawElement`.
|
|
152
152
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
153
153
|
* the key or node being added to the data structure.
|
|
154
154
|
* @returns The method is returning a boolean value.
|
|
155
155
|
*/
|
|
156
|
-
override add(keyOrNodeOrEntryOrRawElement: R |
|
|
156
|
+
override add(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean {
|
|
157
157
|
if (keyOrNodeOrEntryOrRawElement === null) return false;
|
|
158
158
|
const inserted = super.add(keyOrNodeOrEntryOrRawElement, value);
|
|
159
159
|
if (inserted) this._balancePath(keyOrNodeOrEntryOrRawElement);
|
|
@@ -488,10 +488,10 @@ export class AVLTree<
|
|
|
488
488
|
*
|
|
489
489
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
490
490
|
* to restore balance in an AVL tree after inserting a node.
|
|
491
|
-
* @param {R |
|
|
492
|
-
* `
|
|
491
|
+
* @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
|
|
492
|
+
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
493
493
|
*/
|
|
494
|
-
protected _balancePath(node: R |
|
|
494
|
+
protected _balancePath(node: R | BTNKeyOrNodeOrEntry<K, V, NODE>): void {
|
|
495
495
|
node = this.ensureNode(node);
|
|
496
496
|
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
|
|
497
497
|
for (let i = 0; i < path.length; i++) {
|