data-structure-typed 1.52.5 → 1.52.7
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 +33 -30
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +156 -156
- package/dist/cjs/constants/index.d.ts +4 -0
- package/dist/cjs/constants/index.js +9 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/cjs/data-structures/base/iterable-element-base.js +10 -1
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
- 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 +23 -24
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +71 -64
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +669 -598
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/cjs/data-structures/binary-tree/bst.js +115 -113
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +40 -39
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +44 -43
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/abstract-graph.js +7 -4
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js +4 -2
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +3 -3
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +7 -7
- 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 +2 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/cjs/data-structures/matrix/navigator.js +4 -2
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +3 -3
- package/dist/cjs/data-structures/queue/deque.js +29 -29
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +2 -2
- package/dist/cjs/data-structures/tree/tree.js +2 -0
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/cjs/data-structures/trie/trie.js +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -6
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/mjs/constants/index.d.ts +4 -0
- package/dist/mjs/constants/index.js +5 -0
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/mjs/data-structures/base/iterable-element-base.js +10 -1
- package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/mjs/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +44 -44
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +23 -24
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +72 -64
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +668 -592
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/mjs/data-structures/binary-tree/bst.js +116 -112
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +41 -38
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +45 -42
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/abstract-graph.js +7 -4
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/directed-graph.js +4 -2
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.js +1 -1
- package/dist/mjs/data-structures/heap/heap.js +3 -3
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +7 -7
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/mjs/data-structures/matrix/navigator.js +4 -2
- package/dist/mjs/data-structures/queue/deque.d.ts +3 -3
- package/dist/mjs/data-structures/queue/deque.js +29 -29
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/stack/stack.d.ts +2 -2
- package/dist/mjs/data-structures/tree/tree.js +2 -0
- package/dist/mjs/data-structures/trie/trie.d.ts +2 -2
- package/dist/mjs/data-structures/trie/trie.js +1 -1
- package/dist/mjs/index.d.ts +1 -0
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +1 -5
- package/dist/umd/data-structure-typed.js +1344 -1614
- package/dist/umd/data-structure-typed.min.js +10 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/eslint.config.mjs +69 -0
- package/package.json +30 -28
- package/src/constants/index.ts +4 -0
- package/src/data-structures/base/iterable-element-base.ts +11 -1
- package/src/data-structures/base/iterable-entry-base.ts +11 -19
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +47 -50
- package/src/data-structures/binary-tree/avl-tree.ts +69 -71
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +698 -726
- package/src/data-structures/binary-tree/bst.ts +123 -129
- package/src/data-structures/binary-tree/rb-tree.ts +44 -46
- package/src/data-structures/binary-tree/segment-tree.ts +2 -2
- package/src/data-structures/binary-tree/tree-multi-map.ts +48 -49
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +4 -4
- package/src/data-structures/graph/undirected-graph.ts +2 -2
- package/src/data-structures/hash/hash-map.ts +3 -3
- package/src/data-structures/heap/heap.ts +3 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +9 -9
- package/src/data-structures/linked-list/singly-linked-list.ts +8 -8
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/navigator.ts +4 -4
- package/src/data-structures/queue/deque.ts +31 -31
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/data-structures/stack/stack.ts +2 -2
- package/src/data-structures/trie/trie.ts +3 -3
- package/src/index.ts +1 -0
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
- package/test/config.ts +1 -7
- package/test/integration/all-in-one.test.ts +2 -2
- package/test/integration/avl-tree.test.ts +3 -3
- package/test/integration/bst.test.ts +19 -18
- package/test/integration/heap.test.js +6 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +39 -39
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +140 -112
- package/test/unit/data-structures/binary-tree/bst.test.ts +41 -13
- package/test/unit/data-structures/binary-tree/overall.test.ts +0 -6
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +88 -34
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +42 -42
- package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/undirected-graph.test.ts +14 -2
- package/test/unit/data-structures/hash/hash-map.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +4 -4
- package/test/unit/data-structures/stack/stack.test.ts +6 -0
- package/test/unit/unrestricted-interconversion.test.ts +24 -24
- package/test/utils/big-o.ts +5 -4
- package/.eslintrc.js +0 -64
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../data-structures';
|
|
2
|
-
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions,
|
|
2
|
+
import type { BinaryTreeDeleteResult, BinaryTreeNested, BinaryTreeNodeNested, BinaryTreeOptions, BTNKeyOrNodeOrEntry, BTNPredicate } from '../types';
|
|
3
3
|
export interface IBinaryTree<K = any, V = any, R = [K, V], 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
6
|
add(keyOrNodeOrEntryOrRawElement: BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V, count?: number): boolean;
|
|
7
7
|
addMany(nodes: Iterable<BTNKeyOrNodeOrEntry<K, V, NODE>>, values?: Iterable<V | undefined>): boolean[];
|
|
8
|
-
delete
|
|
8
|
+
delete(predicate: R | BTNKeyOrNodeOrEntry<K, V, NODE> | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
|
|
9
9
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BinaryTree, BinaryTreeNode } from '../../../data-structures';
|
|
2
2
|
import { IterationType, OptValue } from '../../common';
|
|
3
|
+
import { DFSOperation } from "bst-typed";
|
|
3
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
4
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>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>;
|
|
5
6
|
export type BinaryTreeOptions<K, V, R> = {
|
|
@@ -23,10 +24,7 @@ export type BinaryTreeDeleteResult<NODE> = {
|
|
|
23
24
|
needBalanced: OptBTNOrNull<NODE>;
|
|
24
25
|
};
|
|
25
26
|
export type BTNCallback<NODE, D = any> = (node: NODE) => D;
|
|
26
|
-
export
|
|
27
|
-
VISIT = 0,
|
|
28
|
-
PROCESS = 1
|
|
29
|
-
}
|
|
27
|
+
export type BTNPredicate<NODE> = (node: NODE) => boolean;
|
|
30
28
|
export type DFSStackItem<NODE> = {
|
|
31
29
|
opt: DFSOperation;
|
|
32
30
|
node: OptBTNOrNull<NODE>;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DFSOperation = void 0;
|
|
4
|
-
var DFSOperation;
|
|
5
|
-
(function (DFSOperation) {
|
|
6
|
-
DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
|
|
7
|
-
DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS";
|
|
8
|
-
})(DFSOperation || (exports.DFSOperation = DFSOperation = {}));
|
|
9
3
|
//# sourceMappingURL=binary-tree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binary-tree.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/binary-tree.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"binary-tree.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/binary-tree.ts"],"names":[],"mappings":""}
|
|
@@ -125,7 +125,14 @@ export declare abstract class IterableElementBase<E, R, C> {
|
|
|
125
125
|
*
|
|
126
126
|
* The print function logs the elements of an array to the console.
|
|
127
127
|
*/
|
|
128
|
-
|
|
128
|
+
toVisual(): E[];
|
|
129
|
+
/**
|
|
130
|
+
* Time Complexity: O(n)
|
|
131
|
+
* Space Complexity: O(n)
|
|
132
|
+
*
|
|
133
|
+
* The print function logs the elements of an array to the console.
|
|
134
|
+
*/
|
|
135
|
+
print(): void;
|
|
129
136
|
abstract isEmpty(): boolean;
|
|
130
137
|
abstract clear(): void;
|
|
131
138
|
abstract clone(): C;
|
|
@@ -180,7 +180,16 @@ export class IterableElementBase {
|
|
|
180
180
|
*
|
|
181
181
|
* The print function logs the elements of an array to the console.
|
|
182
182
|
*/
|
|
183
|
-
|
|
183
|
+
toVisual() {
|
|
184
184
|
return [...this];
|
|
185
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Time Complexity: O(n)
|
|
188
|
+
* Space Complexity: O(n)
|
|
189
|
+
*
|
|
190
|
+
* The print function logs the elements of an array to the console.
|
|
191
|
+
*/
|
|
192
|
+
print() {
|
|
193
|
+
console.log(this.toVisual());
|
|
194
|
+
}
|
|
186
195
|
}
|
|
@@ -151,7 +151,14 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
|
|
|
151
151
|
*
|
|
152
152
|
* The print function logs the elements of an array to the console.
|
|
153
153
|
*/
|
|
154
|
-
|
|
154
|
+
toVisual(): [K, V][] | string;
|
|
155
|
+
/**
|
|
156
|
+
* Time Complexity: O(n)
|
|
157
|
+
* Space Complexity: O(n)
|
|
158
|
+
*
|
|
159
|
+
* The print function logs the elements of an array to the console.
|
|
160
|
+
*/
|
|
161
|
+
print(): void;
|
|
155
162
|
abstract isEmpty(): boolean;
|
|
156
163
|
abstract clear(): void;
|
|
157
164
|
abstract clone(): any;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
export class IterableEntryBase {
|
|
2
|
-
// protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
3
|
-
//
|
|
4
|
-
// /**
|
|
5
|
-
// * The function returns the value of the _toEntryFn property.
|
|
6
|
-
// * @returns The function being returned is `this._toEntryFn`.
|
|
7
|
-
// */
|
|
8
|
-
// get toEntryFn() {
|
|
9
|
-
// return this._toEntryFn;
|
|
10
|
-
// }
|
|
11
2
|
/**
|
|
12
3
|
* Time Complexity: O(n)
|
|
13
4
|
* Space Complexity: O(1)
|
|
@@ -230,7 +221,16 @@ export class IterableEntryBase {
|
|
|
230
221
|
*
|
|
231
222
|
* The print function logs the elements of an array to the console.
|
|
232
223
|
*/
|
|
233
|
-
|
|
224
|
+
toVisual() {
|
|
234
225
|
return [...this];
|
|
235
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Time Complexity: O(n)
|
|
229
|
+
* Space Complexity: O(n)
|
|
230
|
+
*
|
|
231
|
+
* The print function logs the elements of an array to the console.
|
|
232
|
+
*/
|
|
233
|
+
print() {
|
|
234
|
+
console.log(this.toVisual());
|
|
235
|
+
}
|
|
236
236
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode,
|
|
9
|
-
import { BTNEntry } from '../../types';
|
|
8
|
+
import type { AVLTreeMultiMapNested, AVLTreeMultiMapNodeNested, AVLTreeMultiMapOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, IterationType, BTNEntry } from '../../types';
|
|
10
9
|
import { IBinaryTree } from '../../interfaces';
|
|
11
10
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
12
11
|
export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeMultiMapNode<K, V, NODE> = AVLTreeMultiMapNodeNested<K, V>> extends AVLTreeNode<K, V, NODE> {
|
|
@@ -40,13 +39,13 @@ export declare class AVLTreeMultiMapNode<K = any, V = any, NODE extends AVLTreeM
|
|
|
40
39
|
export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, 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> {
|
|
41
40
|
/**
|
|
42
41
|
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
43
|
-
* @param
|
|
42
|
+
* @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
|
|
44
43
|
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
45
44
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
46
45
|
* behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
|
|
47
46
|
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
48
47
|
*/
|
|
49
|
-
constructor(
|
|
48
|
+
constructor(keysOrNodesOrEntriesOrRaws?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeMultiMapOptions<K, V, R>);
|
|
50
49
|
protected _count: number;
|
|
51
50
|
/**
|
|
52
51
|
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
@@ -85,17 +84,17 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
|
|
|
85
84
|
createTree(options?: AVLTreeMultiMapOptions<K, V, R>): TREE;
|
|
86
85
|
/**
|
|
87
86
|
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
88
|
-
* @param {
|
|
89
|
-
* `
|
|
90
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
87
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
88
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
89
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
91
90
|
* an instance of the `AVLTreeMultiMapNode` class.
|
|
92
91
|
*/
|
|
93
|
-
isNode(
|
|
92
|
+
isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
|
|
94
93
|
/**
|
|
95
94
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
96
95
|
* a node object.
|
|
97
|
-
* @param {
|
|
98
|
-
* `
|
|
96
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
97
|
+
* `keyOrNodeOrEntryOrRaw` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
99
98
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
100
99
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
101
100
|
* value is provided, it will default to `undefined`.
|
|
@@ -103,15 +102,15 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
|
|
|
103
102
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
104
103
|
* @returns either a NODE object or undefined.
|
|
105
104
|
*/
|
|
106
|
-
keyValueOrEntryOrRawElementToNode(
|
|
105
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): NODE | undefined;
|
|
107
106
|
/**
|
|
108
107
|
* Time Complexity: O(log n)
|
|
109
108
|
* Space Complexity: O(1)
|
|
110
109
|
*
|
|
111
110
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
112
111
|
* and update the count.
|
|
113
|
-
* @param {
|
|
114
|
-
* `
|
|
112
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
113
|
+
* `keyOrNodeOrEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
|
|
115
114
|
* can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
116
115
|
* entry, or raw element
|
|
117
116
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
@@ -121,27 +120,27 @@ export declare class AVLTreeMultiMap<K = any, V = any, R = BTNEntry<K, V>, NODE
|
|
|
121
120
|
* be added once. However, you can specify a different value for `count` if you want to add
|
|
122
121
|
* @returns a boolean value.
|
|
123
122
|
*/
|
|
124
|
-
add(
|
|
123
|
+
add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V, count?: number): boolean;
|
|
125
124
|
/**
|
|
126
125
|
* Time Complexity: O(log n)
|
|
127
126
|
* Space Complexity: O(1)
|
|
128
127
|
*
|
|
129
|
-
* The
|
|
130
|
-
*
|
|
131
|
-
* @param
|
|
132
|
-
*
|
|
133
|
-
* function
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*/
|
|
144
|
-
delete<
|
|
128
|
+
* The function overrides the delete method in a binary tree data structure, handling deletion of
|
|
129
|
+
* nodes and maintaining balance in the tree.
|
|
130
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
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, entry, or a custom predicate function that determines which
|
|
133
|
+
* node(s) should be deleted.
|
|
134
|
+
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
135
|
+
* boolean flag that determines whether to ignore the count of the node being deleted. If
|
|
136
|
+
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
137
|
+
* `ignoreCount` is set to
|
|
138
|
+
* @returns The `delete` method overrides the default delete behavior in a binary tree data
|
|
139
|
+
* structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
|
|
140
|
+
* method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
|
|
141
|
+
* deleted node and whether balancing is needed in the tree.
|
|
142
|
+
*/
|
|
143
|
+
delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>, ignoreCount?: boolean): BinaryTreeDeleteResult<NODE>[];
|
|
145
144
|
/**
|
|
146
145
|
* Time Complexity: O(1)
|
|
147
146
|
* Space Complexity: O(1)
|
|
@@ -37,16 +37,16 @@ export class AVLTreeMultiMapNode extends AVLTreeNode {
|
|
|
37
37
|
export class AVLTreeMultiMap extends AVLTree {
|
|
38
38
|
/**
|
|
39
39
|
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
40
|
-
* @param
|
|
40
|
+
* @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
|
|
41
41
|
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
42
42
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
43
43
|
* behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
|
|
44
44
|
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
45
45
|
*/
|
|
46
|
-
constructor(
|
|
46
|
+
constructor(keysOrNodesOrEntriesOrRaws = [], options) {
|
|
47
47
|
super([], options);
|
|
48
|
-
if (
|
|
49
|
-
this.addMany(
|
|
48
|
+
if (keysOrNodesOrEntriesOrRaws)
|
|
49
|
+
this.addMany(keysOrNodesOrEntriesOrRaws);
|
|
50
50
|
}
|
|
51
51
|
_count = 0;
|
|
52
52
|
/**
|
|
@@ -94,25 +94,26 @@ export class AVLTreeMultiMap extends AVLTree {
|
|
|
94
94
|
createTree(options) {
|
|
95
95
|
return new AVLTreeMultiMap([], {
|
|
96
96
|
iterationType: this.iterationType,
|
|
97
|
-
comparator: this.
|
|
97
|
+
comparator: this._comparator,
|
|
98
|
+
toEntryFn: this._toEntryFn,
|
|
98
99
|
...options
|
|
99
100
|
});
|
|
100
101
|
}
|
|
101
102
|
/**
|
|
102
103
|
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
103
|
-
* @param {
|
|
104
|
-
* `
|
|
105
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
104
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
105
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
106
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
106
107
|
* an instance of the `AVLTreeMultiMapNode` class.
|
|
107
108
|
*/
|
|
108
|
-
isNode(
|
|
109
|
-
return
|
|
109
|
+
isNode(keyOrNodeOrEntryOrRaw) {
|
|
110
|
+
return keyOrNodeOrEntryOrRaw instanceof AVLTreeMultiMapNode;
|
|
110
111
|
}
|
|
111
112
|
/**
|
|
112
113
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
113
114
|
* a node object.
|
|
114
|
-
* @param {
|
|
115
|
-
* `
|
|
115
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
116
|
+
* `keyOrNodeOrEntryOrRaw` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
116
117
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
117
118
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
118
119
|
* value is provided, it will default to `undefined`.
|
|
@@ -120,25 +121,25 @@ export class AVLTreeMultiMap extends AVLTree {
|
|
|
120
121
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
121
122
|
* @returns either a NODE object or undefined.
|
|
122
123
|
*/
|
|
123
|
-
keyValueOrEntryOrRawElementToNode(
|
|
124
|
-
if (
|
|
124
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count = 1) {
|
|
125
|
+
if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null)
|
|
125
126
|
return;
|
|
126
|
-
if (this.isNode(
|
|
127
|
-
return
|
|
128
|
-
if (this.isEntry(
|
|
129
|
-
const [key, entryValue] =
|
|
127
|
+
if (this.isNode(keyOrNodeOrEntryOrRaw))
|
|
128
|
+
return keyOrNodeOrEntryOrRaw;
|
|
129
|
+
if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
|
|
130
|
+
const [key, entryValue] = keyOrNodeOrEntryOrRaw;
|
|
130
131
|
if (key === undefined || key === null)
|
|
131
132
|
return;
|
|
132
133
|
if (this.isKey(key))
|
|
133
134
|
return this.createNode(key, value ?? entryValue, count);
|
|
134
135
|
}
|
|
135
|
-
if (this.
|
|
136
|
-
const [key, entryValue] = this.
|
|
136
|
+
if (this._toEntryFn) {
|
|
137
|
+
const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
|
|
137
138
|
if (this.isKey(key))
|
|
138
139
|
return this.createNode(key, value ?? entryValue, count);
|
|
139
140
|
}
|
|
140
|
-
if (this.isKey(
|
|
141
|
-
return this.createNode(
|
|
141
|
+
if (this.isKey(keyOrNodeOrEntryOrRaw))
|
|
142
|
+
return this.createNode(keyOrNodeOrEntryOrRaw, value, count);
|
|
142
143
|
return;
|
|
143
144
|
}
|
|
144
145
|
/**
|
|
@@ -147,8 +148,8 @@ export class AVLTreeMultiMap extends AVLTree {
|
|
|
147
148
|
*
|
|
148
149
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
149
150
|
* and update the count.
|
|
150
|
-
* @param {
|
|
151
|
-
* `
|
|
151
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
152
|
+
* `keyOrNodeOrEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
|
|
152
153
|
* can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
153
154
|
* entry, or raw element
|
|
154
155
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
@@ -158,8 +159,8 @@ export class AVLTreeMultiMap extends AVLTree {
|
|
|
158
159
|
* be added once. However, you can specify a different value for `count` if you want to add
|
|
159
160
|
* @returns a boolean value.
|
|
160
161
|
*/
|
|
161
|
-
add(
|
|
162
|
-
const newNode = this.keyValueOrEntryOrRawElementToNode(
|
|
162
|
+
add(keyOrNodeOrEntryOrRaw, value, count = 1) {
|
|
163
|
+
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
|
|
163
164
|
if (newNode === undefined)
|
|
164
165
|
return false;
|
|
165
166
|
const orgNodeCount = newNode?.count || 0;
|
|
@@ -173,27 +174,26 @@ export class AVLTreeMultiMap extends AVLTree {
|
|
|
173
174
|
* Time Complexity: O(log n)
|
|
174
175
|
* Space Complexity: O(1)
|
|
175
176
|
*
|
|
176
|
-
* The
|
|
177
|
-
*
|
|
178
|
-
* @param
|
|
179
|
-
*
|
|
180
|
-
* function
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
177
|
+
* The function overrides the delete method in a binary tree data structure, handling deletion of
|
|
178
|
+
* nodes and maintaining balance in the tree.
|
|
179
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
180
|
+
* parameter in the `delete` method is used to specify the condition for deleting a node from the
|
|
181
|
+
* binary tree. It can be a key, node, entry, or a custom predicate function that determines which
|
|
182
|
+
* node(s) should be deleted.
|
|
183
|
+
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
184
|
+
* boolean flag that determines whether to ignore the count of the node being deleted. If
|
|
185
|
+
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
186
|
+
* `ignoreCount` is set to
|
|
187
|
+
* @returns The `delete` method overrides the default delete behavior in a binary tree data
|
|
188
|
+
* structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
|
|
189
|
+
* method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
|
|
190
|
+
* deleted node and whether balancing is needed in the tree.
|
|
190
191
|
*/
|
|
191
|
-
delete(
|
|
192
|
+
delete(predicate, ignoreCount = false) {
|
|
192
193
|
const deletedResult = [];
|
|
193
194
|
if (!this.root)
|
|
194
195
|
return deletedResult;
|
|
195
|
-
|
|
196
|
-
const curr = this.getNode(identifier, callback) ?? undefined;
|
|
196
|
+
const curr = this.getNode(predicate) ?? undefined;
|
|
197
197
|
if (!curr)
|
|
198
198
|
return deletedResult;
|
|
199
199
|
const parent = curr?.parent ? curr.parent : undefined;
|
|
@@ -235,7 +235,7 @@ export class AVLTreeMultiMap extends AVLTree {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
-
this._size = this.
|
|
238
|
+
this._size = this._size - 1;
|
|
239
239
|
// TODO How to handle when the count of target node is lesser than current node's count
|
|
240
240
|
if (orgCurrent)
|
|
241
241
|
this._count -= orgCurrent.count;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* data-structure-typed
|
|
3
3
|
*
|
|
4
|
-
* @author
|
|
5
|
-
* @copyright Copyright (c) 2022
|
|
4
|
+
* @author Pablo Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode,
|
|
10
|
-
import { BTNEntry } from '../../types';
|
|
9
|
+
import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNKeyOrNodeOrEntry, BTNPredicate, BTNEntry } from '../../types';
|
|
11
10
|
import { IBinaryTree } from '../../interfaces';
|
|
12
11
|
export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
|
|
13
12
|
/**
|
|
@@ -45,7 +44,7 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
|
|
|
45
44
|
/**
|
|
46
45
|
* This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
|
|
47
46
|
* entries, or raw elements.
|
|
48
|
-
* @param
|
|
47
|
+
* @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
|
|
49
48
|
* iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
|
|
50
49
|
* be used to initialize the AVLTree.
|
|
51
50
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
@@ -53,7 +52,7 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
|
|
|
53
52
|
* keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
|
|
54
53
|
* `nodeBuilder` (
|
|
55
54
|
*/
|
|
56
|
-
constructor(
|
|
55
|
+
constructor(keysOrNodesOrEntriesOrRaws?: Iterable<R | BTNKeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeOptions<K, V, R>);
|
|
57
56
|
/**
|
|
58
57
|
* The function creates a new AVL tree node with the given key and value.
|
|
59
58
|
* @param {K} key - The key parameter is of type K, which represents the key of the node being
|
|
@@ -74,40 +73,40 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
|
|
|
74
73
|
createTree(options?: AVLTreeOptions<K, V, R>): TREE;
|
|
75
74
|
/**
|
|
76
75
|
* The function checks if the input is an instance of AVLTreeNode.
|
|
77
|
-
* @param {
|
|
78
|
-
* `
|
|
79
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
76
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
77
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
78
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
80
79
|
* an instance of the `AVLTreeNode` class.
|
|
81
80
|
*/
|
|
82
|
-
isNode(
|
|
81
|
+
isNode(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R): keyOrNodeOrEntryOrRaw is NODE;
|
|
83
82
|
/**
|
|
84
83
|
* Time Complexity: O(log n)
|
|
85
84
|
* Space Complexity: O(1)
|
|
86
85
|
*
|
|
87
86
|
* The function overrides the add method of a class and inserts a key-value pair into a data
|
|
88
87
|
* structure, then balances the path.
|
|
89
|
-
* @param {
|
|
90
|
-
* `
|
|
88
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
89
|
+
* `keyOrNodeOrEntryOrRaw` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
|
|
91
90
|
* `RawElement`.
|
|
92
91
|
* @param {V} [value] - The `value` parameter is an optional value that you want to associate with
|
|
93
92
|
* the key or node being added to the data structure.
|
|
94
93
|
* @returns The method is returning a boolean value.
|
|
95
94
|
*/
|
|
96
|
-
add(
|
|
95
|
+
add(keyOrNodeOrEntryOrRaw: BTNKeyOrNodeOrEntry<K, V, NODE> | R, value?: V): boolean;
|
|
97
96
|
/**
|
|
98
97
|
* Time Complexity: O(log n)
|
|
99
98
|
* Space Complexity: O(1)
|
|
100
99
|
*
|
|
101
|
-
* The function overrides the delete method
|
|
102
|
-
*
|
|
103
|
-
* @param
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
100
|
+
* The function overrides the delete method in a TypeScript class, performs deletion, and then
|
|
101
|
+
* balances the tree if necessary.
|
|
102
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
103
|
+
* parameter in the `override delete` method can be one of the following types:
|
|
104
|
+
* @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
|
|
105
|
+
* method from the superclass (presumably a parent class) with the provided `predicate`, which could
|
|
106
|
+
* be a key, node, entry, or a custom predicate. The result of this deletion operation is stored in
|
|
107
|
+
* `deletedResults`, which is an array of `BinaryTreeDeleteResult` objects.
|
|
109
108
|
*/
|
|
110
|
-
delete<
|
|
109
|
+
delete(predicate: BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>): BinaryTreeDeleteResult<NODE>[];
|
|
111
110
|
/**
|
|
112
111
|
* Time Complexity: O(1)
|
|
113
112
|
* Space Complexity: O(1)
|
|
@@ -180,10 +179,10 @@ export declare class AVLTree<K = any, V = any, R = BTNEntry<K, V>, NODE extends
|
|
|
180
179
|
*
|
|
181
180
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
182
181
|
* to restore balance in an AVL tree after inserting a node.
|
|
183
|
-
* @param {
|
|
182
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} node - The `node` parameter can be of type `R` or
|
|
184
183
|
* `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
185
184
|
*/
|
|
186
|
-
protected _balancePath(node:
|
|
185
|
+
protected _balancePath(node: BTNKeyOrNodeOrEntry<K, V, NODE> | R): void;
|
|
187
186
|
/**
|
|
188
187
|
* Time Complexity: O(1)
|
|
189
188
|
* Space Complexity: O(1)
|