doubly-linked-list-typed 1.52.6 → 1.52.8
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/constants/index.d.ts +4 -0
- package/dist/constants/index.js +8 -0
- package/dist/data-structures/base/iterable-element-base.d.ts +8 -1
- package/dist/data-structures/base/iterable-element-base.js +10 -1
- package/dist/data-structures/base/iterable-entry-base.d.ts +8 -1
- package/dist/data-structures/base/iterable-entry-base.js +10 -10
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +31 -32
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +43 -44
- package/dist/data-structures/binary-tree/avl-tree.d.ts +23 -24
- package/dist/data-structures/binary-tree/avl-tree.js +71 -64
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +2 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +534 -402
- package/dist/data-structures/binary-tree/binary-tree.js +668 -597
- package/dist/data-structures/binary-tree/bst.d.ts +72 -65
- package/dist/data-structures/binary-tree/bst.js +115 -113
- package/dist/data-structures/binary-tree/rb-tree.d.ts +21 -24
- package/dist/data-structures/binary-tree/rb-tree.js +40 -39
- package/dist/data-structures/binary-tree/segment-tree.d.ts +2 -2
- package/dist/data-structures/binary-tree/segment-tree.js +2 -2
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +28 -31
- package/dist/data-structures/binary-tree/tree-multi-map.js +44 -43
- package/dist/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/data-structures/graph/abstract-graph.js +7 -4
- package/dist/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/data-structures/graph/directed-graph.js +4 -2
- package/dist/data-structures/graph/undirected-graph.d.ts +2 -2
- package/dist/data-structures/hash/hash-map.d.ts +2 -2
- package/dist/data-structures/hash/hash-map.js +1 -1
- package/dist/data-structures/heap/heap.js +3 -3
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.js +7 -7
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/data-structures/linked-list/singly-linked-list.js +6 -6
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/data-structures/matrix/matrix.d.ts +2 -2
- package/dist/data-structures/matrix/navigator.d.ts +2 -2
- package/dist/data-structures/matrix/navigator.js +4 -2
- package/dist/data-structures/queue/deque.d.ts +3 -3
- package/dist/data-structures/queue/deque.js +29 -29
- package/dist/data-structures/queue/queue.d.ts +1 -1
- package/dist/data-structures/stack/stack.d.ts +2 -2
- package/dist/data-structures/trie/trie.d.ts +2 -2
- package/dist/data-structures/trie/trie.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interfaces/binary-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -4
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -6
- package/package.json +2 -2
- 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 +697 -725
- 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 +2 -1
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +3 -5
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
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 || (exports.DFSOperation = {}));
|
|
@@ -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;
|
|
@@ -182,8 +182,17 @@ class IterableElementBase {
|
|
|
182
182
|
*
|
|
183
183
|
* The print function logs the elements of an array to the console.
|
|
184
184
|
*/
|
|
185
|
-
|
|
185
|
+
toVisual() {
|
|
186
186
|
return [...this];
|
|
187
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Time Complexity: O(n)
|
|
190
|
+
* Space Complexity: O(n)
|
|
191
|
+
*
|
|
192
|
+
* The print function logs the elements of an array to the console.
|
|
193
|
+
*/
|
|
194
|
+
print() {
|
|
195
|
+
console.log(this.toVisual());
|
|
196
|
+
}
|
|
188
197
|
}
|
|
189
198
|
exports.IterableElementBase = IterableElementBase;
|
|
@@ -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;
|
|
@@ -2,15 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.IterableEntryBase = void 0;
|
|
4
4
|
class IterableEntryBase {
|
|
5
|
-
// protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
|
|
6
|
-
//
|
|
7
|
-
// /**
|
|
8
|
-
// * The function returns the value of the _toEntryFn property.
|
|
9
|
-
// * @returns The function being returned is `this._toEntryFn`.
|
|
10
|
-
// */
|
|
11
|
-
// get toEntryFn() {
|
|
12
|
-
// return this._toEntryFn;
|
|
13
|
-
// }
|
|
14
5
|
/**
|
|
15
6
|
* Time Complexity: O(n)
|
|
16
7
|
* Space Complexity: O(1)
|
|
@@ -233,8 +224,17 @@ class IterableEntryBase {
|
|
|
233
224
|
*
|
|
234
225
|
* The print function logs the elements of an array to the console.
|
|
235
226
|
*/
|
|
236
|
-
|
|
227
|
+
toVisual() {
|
|
237
228
|
return [...this];
|
|
238
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Time Complexity: O(n)
|
|
232
|
+
* Space Complexity: O(n)
|
|
233
|
+
*
|
|
234
|
+
* The print function logs the elements of an array to the console.
|
|
235
|
+
*/
|
|
236
|
+
print() {
|
|
237
|
+
console.log(this.toVisual());
|
|
238
|
+
}
|
|
239
239
|
}
|
|
240
240
|
exports.IterableEntryBase = IterableEntryBase;
|
|
@@ -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)
|
|
@@ -41,17 +41,17 @@ exports.AVLTreeMultiMapNode = AVLTreeMultiMapNode;
|
|
|
41
41
|
class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
42
42
|
/**
|
|
43
43
|
* The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
|
|
44
|
-
* @param
|
|
44
|
+
* @param keysOrNodesOrEntriesOrRaws - The `keysOrNodesOrEntriesOrRaws` parameter is an
|
|
45
45
|
* iterable object that can contain either keys, nodes, entries, or raw elements.
|
|
46
46
|
* @param [options] - The `options` parameter is an optional object that can be used to customize the
|
|
47
47
|
* behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
|
|
48
48
|
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
49
49
|
*/
|
|
50
|
-
constructor(
|
|
50
|
+
constructor(keysOrNodesOrEntriesOrRaws = [], options) {
|
|
51
51
|
super([], options);
|
|
52
52
|
this._count = 0;
|
|
53
|
-
if (
|
|
54
|
-
this.addMany(
|
|
53
|
+
if (keysOrNodesOrEntriesOrRaws)
|
|
54
|
+
this.addMany(keysOrNodesOrEntriesOrRaws);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* The function calculates the sum of the count property of all nodes in a tree using depth-first
|
|
@@ -96,23 +96,23 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
96
96
|
* object.
|
|
97
97
|
*/
|
|
98
98
|
createTree(options) {
|
|
99
|
-
return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, comparator: this.
|
|
99
|
+
return new AVLTreeMultiMap([], Object.assign({ iterationType: this.iterationType, comparator: this._comparator, toEntryFn: this._toEntryFn }, options));
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
102
102
|
* The function checks if the input is an instance of AVLTreeMultiMapNode.
|
|
103
|
-
* @param {
|
|
104
|
-
* `
|
|
105
|
-
* @returns a boolean value indicating whether the input parameter `
|
|
103
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The parameter
|
|
104
|
+
* `keyOrNodeOrEntryOrRaw` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
105
|
+
* @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRaw` is
|
|
106
106
|
* an instance of the `AVLTreeMultiMapNode` class.
|
|
107
107
|
*/
|
|
108
|
-
isNode(
|
|
109
|
-
return
|
|
108
|
+
isNode(keyOrNodeOrEntryOrRaw) {
|
|
109
|
+
return keyOrNodeOrEntryOrRaw instanceof AVLTreeMultiMapNode;
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
|
|
113
113
|
* a node object.
|
|
114
|
-
* @param {
|
|
115
|
-
* `
|
|
114
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
115
|
+
* `keyOrNodeOrEntryOrRaw` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
|
|
116
116
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
117
117
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
118
118
|
* value is provided, it will default to `undefined`.
|
|
@@ -120,25 +120,25 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
120
120
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
121
121
|
* @returns either a NODE object or undefined.
|
|
122
122
|
*/
|
|
123
|
-
keyValueOrEntryOrRawElementToNode(
|
|
124
|
-
if (
|
|
123
|
+
keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count = 1) {
|
|
124
|
+
if (keyOrNodeOrEntryOrRaw === undefined || keyOrNodeOrEntryOrRaw === null)
|
|
125
125
|
return;
|
|
126
|
-
if (this.isNode(
|
|
127
|
-
return
|
|
128
|
-
if (this.isEntry(
|
|
129
|
-
const [key, entryValue] =
|
|
126
|
+
if (this.isNode(keyOrNodeOrEntryOrRaw))
|
|
127
|
+
return keyOrNodeOrEntryOrRaw;
|
|
128
|
+
if (this.isEntry(keyOrNodeOrEntryOrRaw)) {
|
|
129
|
+
const [key, entryValue] = keyOrNodeOrEntryOrRaw;
|
|
130
130
|
if (key === undefined || key === null)
|
|
131
131
|
return;
|
|
132
132
|
if (this.isKey(key))
|
|
133
133
|
return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, count);
|
|
134
134
|
}
|
|
135
|
-
if (this.
|
|
136
|
-
const [key, entryValue] = this.
|
|
135
|
+
if (this._toEntryFn) {
|
|
136
|
+
const [key, entryValue] = this._toEntryFn(keyOrNodeOrEntryOrRaw);
|
|
137
137
|
if (this.isKey(key))
|
|
138
138
|
return this.createNode(key, value !== null && value !== void 0 ? value : entryValue, count);
|
|
139
139
|
}
|
|
140
|
-
if (this.isKey(
|
|
141
|
-
return this.createNode(
|
|
140
|
+
if (this.isKey(keyOrNodeOrEntryOrRaw))
|
|
141
|
+
return this.createNode(keyOrNodeOrEntryOrRaw, value, count);
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
@@ -147,8 +147,8 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
147
147
|
*
|
|
148
148
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
149
149
|
* and update the count.
|
|
150
|
-
* @param {
|
|
151
|
-
* `
|
|
150
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R} keyOrNodeOrEntryOrRaw - The
|
|
151
|
+
* `keyOrNodeOrEntryOrRaw` parameter can accept a value of type `R`, which can be any type. It
|
|
152
152
|
* can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
|
|
153
153
|
* entry, or raw element
|
|
154
154
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
@@ -158,8 +158,8 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
158
158
|
* be added once. However, you can specify a different value for `count` if you want to add
|
|
159
159
|
* @returns a boolean value.
|
|
160
160
|
*/
|
|
161
|
-
add(
|
|
162
|
-
const newNode = this.keyValueOrEntryOrRawElementToNode(
|
|
161
|
+
add(keyOrNodeOrEntryOrRaw, value, count = 1) {
|
|
162
|
+
const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRaw, value, count);
|
|
163
163
|
if (newNode === undefined)
|
|
164
164
|
return false;
|
|
165
165
|
const orgNodeCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
|
|
@@ -173,28 +173,27 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
173
173
|
* Time Complexity: O(log n)
|
|
174
174
|
* Space Complexity: O(1)
|
|
175
175
|
*
|
|
176
|
-
* The
|
|
177
|
-
*
|
|
178
|
-
* @param
|
|
179
|
-
*
|
|
180
|
-
* function
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
176
|
+
* The function overrides the delete method in a binary tree data structure, handling deletion of
|
|
177
|
+
* nodes and maintaining balance in the tree.
|
|
178
|
+
* @param {BTNKeyOrNodeOrEntry<K, V, NODE> | R | BTNPredicate<NODE>} predicate - The `predicate`
|
|
179
|
+
* parameter in the `delete` method is used to specify the condition for deleting a node from the
|
|
180
|
+
* binary tree. It can be a key, node, entry, or a custom predicate function that determines which
|
|
181
|
+
* node(s) should be deleted.
|
|
182
|
+
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
183
|
+
* boolean flag that determines whether to ignore the count of the node being deleted. If
|
|
184
|
+
* `ignoreCount` is set to `true`, the method will delete the node regardless of its count. If
|
|
185
|
+
* `ignoreCount` is set to
|
|
186
|
+
* @returns The `delete` method overrides the default delete behavior in a binary tree data
|
|
187
|
+
* structure. It takes a predicate or node to be deleted and an optional flag to ignore count. The
|
|
188
|
+
* method returns an array of `BinaryTreeDeleteResult` objects, each containing information about the
|
|
189
|
+
* deleted node and whether balancing is needed in the tree.
|
|
190
190
|
*/
|
|
191
|
-
delete(
|
|
191
|
+
delete(predicate, ignoreCount = false) {
|
|
192
192
|
var _a;
|
|
193
193
|
const deletedResult = [];
|
|
194
194
|
if (!this.root)
|
|
195
195
|
return deletedResult;
|
|
196
|
-
|
|
197
|
-
const curr = (_a = this.getNode(identifier, callback)) !== null && _a !== void 0 ? _a : undefined;
|
|
196
|
+
const curr = (_a = this.getNode(predicate)) !== null && _a !== void 0 ? _a : undefined;
|
|
198
197
|
if (!curr)
|
|
199
198
|
return deletedResult;
|
|
200
199
|
const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : undefined;
|
|
@@ -236,7 +235,7 @@ class AVLTreeMultiMap extends avl_tree_1.AVLTree {
|
|
|
236
235
|
}
|
|
237
236
|
}
|
|
238
237
|
}
|
|
239
|
-
this._size = this.
|
|
238
|
+
this._size = this._size - 1;
|
|
240
239
|
// TODO How to handle when the count of target node is lesser than current node's count
|
|
241
240
|
if (orgCurrent)
|
|
242
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)
|