deque-typed 1.54.1 → 1.54.3
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/LICENSE +1 -1
- package/coverage/lcov-report/index.ts.html +2 -2
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
- package/dist/data-structures/binary-tree/avl-tree-counter.js +8 -7
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +12 -12
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +2 -2
- package/dist/data-structures/binary-tree/avl-tree.d.ts +25 -21
- package/dist/data-structures/binary-tree/avl-tree.js +12 -8
- package/dist/data-structures/binary-tree/binary-tree.d.ts +173 -225
- package/dist/data-structures/binary-tree/binary-tree.js +239 -144
- package/dist/data-structures/binary-tree/bst.d.ts +62 -56
- package/dist/data-structures/binary-tree/bst.js +78 -122
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +19 -25
- package/dist/data-structures/binary-tree/red-black-tree.js +7 -13
- package/dist/data-structures/binary-tree/tree-counter.d.ts +19 -19
- package/dist/data-structures/binary-tree/tree-counter.js +12 -12
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +14 -14
- package/dist/data-structures/binary-tree/tree-multi-map.js +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/index.js +1 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
- package/dist/utils/utils.d.ts +2 -2
- package/package.json +3 -3
- package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +25 -15
- package/src/data-structures/binary-tree/avl-tree.ts +35 -29
- package/src/data-structures/binary-tree/binary-tree.ts +469 -252
- package/src/data-structures/binary-tree/bst.ts +141 -143
- package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
- package/src/data-structures/binary-tree/tree-counter.ts +33 -27
- package/src/data-structures/binary-tree/tree-multi-map.ts +25 -17
- package/src/index.ts +2 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/binary-tree/index.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-counter.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
- package/src/utils/utils.ts +2 -2
- /package/dist/types/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +0 -0
- /package/dist/types/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +0 -0
- /package/src/types/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +0 -0
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode,
|
|
8
|
+
import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, EntryCallback, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
|
|
9
9
|
import { IBinaryTree } from '../../interfaces';
|
|
10
10
|
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
11
11
|
export declare class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<K, V> {
|
|
12
|
+
parent?: TreeCounterNode<K, V>;
|
|
12
13
|
/**
|
|
13
14
|
* The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
|
|
14
15
|
* @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
|
|
@@ -22,13 +23,12 @@ export declare class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<
|
|
|
22
23
|
* in a Red-Black Tree. It is optional and has a default value of `'BLACK'`.
|
|
23
24
|
*/
|
|
24
25
|
constructor(key: K, value?: V, count?: number, color?: RBTNColor);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
set right(v: OptNodeOrNull<TreeCounterNode<K, V>>);
|
|
26
|
+
_left?: TreeCounterNode<K, V> | null | undefined;
|
|
27
|
+
get left(): TreeCounterNode<K, V> | null | undefined;
|
|
28
|
+
set left(v: TreeCounterNode<K, V> | null | undefined);
|
|
29
|
+
_right?: TreeCounterNode<K, V> | null | undefined;
|
|
30
|
+
get right(): TreeCounterNode<K, V> | null | undefined;
|
|
31
|
+
set right(v: TreeCounterNode<K, V> | null | undefined);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
*
|
|
@@ -43,7 +43,7 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
|
|
|
43
43
|
* behavior of the `TreeCounter` constructor. It can include properties such as `compareKeys` and
|
|
44
44
|
* `compareValues`, which are functions used to compare keys and values respectively.
|
|
45
45
|
*/
|
|
46
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<
|
|
46
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: TreeCounterOptions<K, V, R>);
|
|
47
47
|
protected _count: number;
|
|
48
48
|
/**
|
|
49
49
|
* The function calculates the sum of the count property of all nodes in a tree structure.
|
|
@@ -84,19 +84,19 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
|
|
|
84
84
|
createTree(options?: TreeCounterOptions<K, V, R>): TreeCounter<K, V, R, MK, MV, MR>;
|
|
85
85
|
/**
|
|
86
86
|
* The function checks if the input is an instance of the TreeCounterNode class.
|
|
87
|
-
* @param {
|
|
88
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
87
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
88
|
+
* `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
89
89
|
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
90
90
|
* an instance of the `TreeCounterNode` class.
|
|
91
91
|
*/
|
|
92
|
-
isNode(keyNodeOrEntry:
|
|
92
|
+
isNode(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is TreeCounterNode<K, V>;
|
|
93
93
|
/**
|
|
94
94
|
* Time Complexity: O(log n)
|
|
95
95
|
* Space Complexity: O(1)
|
|
96
96
|
*
|
|
97
97
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
98
98
|
* the count and returning a boolean indicating success.
|
|
99
|
-
* @param {
|
|
99
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
|
|
100
100
|
* `keyNodeOrEntry` parameter can accept one of the following types:
|
|
101
101
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
102
102
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -106,14 +106,14 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
|
|
|
106
106
|
* @returns The method is returning a boolean value. It returns true if the addition of the new node
|
|
107
107
|
* was successful, and false otherwise.
|
|
108
108
|
*/
|
|
109
|
-
add(keyNodeOrEntry:
|
|
109
|
+
add(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
|
|
110
110
|
/**
|
|
111
111
|
* Time Complexity: O(log n)
|
|
112
112
|
* Space Complexity: O(1)
|
|
113
113
|
*
|
|
114
114
|
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
115
115
|
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
116
|
-
* @param {
|
|
116
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
|
|
117
117
|
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
118
118
|
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
119
119
|
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
@@ -122,7 +122,7 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
|
|
|
122
122
|
* `ignoreCount` is `false
|
|
123
123
|
* @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<TreeCounterNode<K, V>>` objects.
|
|
124
124
|
*/
|
|
125
|
-
delete(keyNodeOrEntry:
|
|
125
|
+
delete(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, ignoreCount?: boolean): BinaryTreeDeleteResult<TreeCounterNode<K, V>>[];
|
|
126
126
|
/**
|
|
127
127
|
* Time Complexity: O(1)
|
|
128
128
|
* Space Complexity: O(1)
|
|
@@ -172,8 +172,8 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
|
|
|
172
172
|
/**
|
|
173
173
|
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
174
174
|
* node based on the input.
|
|
175
|
-
* @param {
|
|
176
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
175
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
176
|
+
* `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
177
177
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
178
178
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
179
179
|
* an existing node.
|
|
@@ -181,7 +181,7 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
|
|
|
181
181
|
* times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
|
|
182
182
|
* @returns either a TreeCounterNode<K, V> object or undefined.
|
|
183
183
|
*/
|
|
184
|
-
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry:
|
|
184
|
+
protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): [TreeCounterNode<K, V> | undefined, V | undefined];
|
|
185
185
|
/**
|
|
186
186
|
* Time Complexity: O(1)
|
|
187
187
|
* Space Complexity: O(1)
|
|
@@ -79,7 +79,7 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
|
|
|
79
79
|
*/
|
|
80
80
|
getComputedCount() {
|
|
81
81
|
let sum = 0;
|
|
82
|
-
this.dfs(node => (sum += node.count));
|
|
82
|
+
this.dfs(node => (sum += node ? node.count : 0));
|
|
83
83
|
return sum;
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
@@ -111,8 +111,8 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
|
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
113
|
* The function checks if the input is an instance of the TreeCounterNode class.
|
|
114
|
-
* @param {
|
|
115
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
114
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
115
|
+
* `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
116
116
|
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
117
117
|
* an instance of the `TreeCounterNode` class.
|
|
118
118
|
*/
|
|
@@ -125,7 +125,7 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
|
|
|
125
125
|
*
|
|
126
126
|
* The function overrides the add method of a class and adds a new node to a data structure, updating
|
|
127
127
|
* the count and returning a boolean indicating success.
|
|
128
|
-
* @param {
|
|
128
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
|
|
129
129
|
* `keyNodeOrEntry` parameter can accept one of the following types:
|
|
130
130
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
131
131
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -153,7 +153,7 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
|
|
|
153
153
|
*
|
|
154
154
|
* The function `delete` in TypeScript overrides the deletion operation in a binary tree data
|
|
155
155
|
* structure, handling cases where nodes have children and maintaining balance in the tree.
|
|
156
|
-
* @param {
|
|
156
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
|
|
157
157
|
* parameter in the `delete` method is used to specify the condition or key based on which a node
|
|
158
158
|
* should be deleted from the binary tree. It can be a key, a node, or an entry.
|
|
159
159
|
* @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
|
|
@@ -294,9 +294,9 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
|
|
|
294
294
|
return;
|
|
295
295
|
const m = l + Math.floor((r - l) / 2);
|
|
296
296
|
const midNode = sorted[m];
|
|
297
|
-
if (this._isMapMode)
|
|
297
|
+
if (this._isMapMode && midNode !== null)
|
|
298
298
|
this.add(midNode.key, undefined, midNode.count);
|
|
299
|
-
else
|
|
299
|
+
else if (midNode !== null)
|
|
300
300
|
this.add(midNode.key, midNode.value, midNode.count);
|
|
301
301
|
buildBalanceBST(l, m - 1);
|
|
302
302
|
buildBalanceBST(m + 1, r);
|
|
@@ -313,9 +313,9 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
|
|
|
313
313
|
if (l <= r) {
|
|
314
314
|
const m = l + Math.floor((r - l) / 2);
|
|
315
315
|
const midNode = sorted[m];
|
|
316
|
-
if (this._isMapMode)
|
|
316
|
+
if (this._isMapMode && midNode !== null)
|
|
317
317
|
this.add(midNode.key, undefined, midNode.count);
|
|
318
|
-
else
|
|
318
|
+
else if (midNode !== null)
|
|
319
319
|
this.add(midNode.key, midNode.value, midNode.count);
|
|
320
320
|
stack.push([m + 1, r]);
|
|
321
321
|
stack.push([l, m - 1]);
|
|
@@ -334,7 +334,7 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
|
|
|
334
334
|
*/
|
|
335
335
|
clone() {
|
|
336
336
|
const cloned = this.createTree();
|
|
337
|
-
this.bfs(node => cloned.add(node.key, undefined, node.count));
|
|
337
|
+
this.bfs(node => cloned.add(node === null ? null : node.key, undefined, node === null ? 0 : node.count));
|
|
338
338
|
if (this._isMapMode)
|
|
339
339
|
cloned._store = this._store;
|
|
340
340
|
return cloned;
|
|
@@ -365,8 +365,8 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
|
|
|
365
365
|
/**
|
|
366
366
|
* The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
|
|
367
367
|
* node based on the input.
|
|
368
|
-
* @param {
|
|
369
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
368
|
+
* @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
369
|
+
* `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
370
370
|
* @param {V} [value] - The `value` parameter is an optional value that represents the value
|
|
371
371
|
* associated with the key in the node. It is used when creating a new node or updating the value of
|
|
372
372
|
* an existing node.
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { TreeMultiMapOptions } from '../../types';
|
|
9
9
|
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
10
10
|
import { IBinaryTree } from '../../interfaces';
|
|
11
11
|
export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode<K, V[]> {
|
|
12
|
+
parent?: TreeMultiMapNode<K, V>;
|
|
12
13
|
/**
|
|
13
14
|
* This TypeScript constructor initializes an object with a key of type K and an array of values of
|
|
14
15
|
* type V.
|
|
@@ -19,21 +20,20 @@ export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode
|
|
|
19
20
|
* type `V`.
|
|
20
21
|
*/
|
|
21
22
|
constructor(key: K, value: V[]);
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
set right(v: OptNodeOrNull<TreeMultiMapNode<K, V>>);
|
|
23
|
+
_left?: TreeMultiMapNode<K, V> | null | undefined;
|
|
24
|
+
get left(): TreeMultiMapNode<K, V> | null | undefined;
|
|
25
|
+
set left(v: TreeMultiMapNode<K, V> | null | undefined);
|
|
26
|
+
_right?: TreeMultiMapNode<K, V> | null | undefined;
|
|
27
|
+
get right(): TreeMultiMapNode<K, V> | null | undefined;
|
|
28
|
+
set right(v: TreeMultiMapNode<K, V> | null | undefined);
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* // Find elements in a range
|
|
34
34
|
* const tmm = new TreeMultiMap<number>([10, 5, 15, 3, 7, 12, 18]);
|
|
35
|
-
* console.log(tmm.search(new Range(5, 10))); // [5,
|
|
36
|
-
* console.log(tmm.search(new Range(4, 12))); // [5, 10, 12
|
|
35
|
+
* console.log(tmm.search(new Range(5, 10))); // [5, 7, 10]
|
|
36
|
+
* console.log(tmm.search(new Range(4, 12))); // [5, 7, 10, 12]
|
|
37
37
|
* console.log(tmm.search(new Range(15, 20))); // [15, 18]
|
|
38
38
|
*/
|
|
39
39
|
export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends RedBlackTree<K, V[], R, MK, MV[], MR> implements IBinaryTree<K, V[], R, MK, MV, MR> {
|
|
@@ -48,7 +48,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
|
|
|
48
48
|
* `TreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
|
|
49
49
|
* additional options for configuring the TreeMultiMap instance.
|
|
50
50
|
*/
|
|
51
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<
|
|
51
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | R>, options?: TreeMultiMapOptions<K, V[], R>);
|
|
52
52
|
/**
|
|
53
53
|
* Time Complexity: O(1)
|
|
54
54
|
* Space Complexity: O(1)
|
|
@@ -75,7 +75,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
|
|
|
75
75
|
* an empty array as its value.
|
|
76
76
|
*/
|
|
77
77
|
createNode(key: K): TreeMultiMapNode<K, V>;
|
|
78
|
-
add(node:
|
|
78
|
+
add(node: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
|
|
79
79
|
add(key: K, value: V): boolean;
|
|
80
80
|
/**
|
|
81
81
|
* Time Complexity: O(log n)
|
|
@@ -83,7 +83,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
|
|
|
83
83
|
*
|
|
84
84
|
* The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
|
|
85
85
|
* and deletes the entire node if no values are left for that key.
|
|
86
|
-
* @param {
|
|
86
|
+
* @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
87
87
|
* parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
|
|
88
88
|
* array of values, or just a key itself.
|
|
89
89
|
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
|
@@ -93,7 +93,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
|
|
|
93
93
|
* @returns The `deleteValue` function returns a boolean value - `true` if the specified `value` was
|
|
94
94
|
* successfully deleted from the values associated with the `keyNodeOrEntry`, and `false` otherwise.
|
|
95
95
|
*/
|
|
96
|
-
deleteValue(keyNodeOrEntry:
|
|
96
|
+
deleteValue(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined, value: V): boolean;
|
|
97
97
|
/**
|
|
98
98
|
* Time Complexity: O(n)
|
|
99
99
|
* Space Complexity: O(n)
|
|
@@ -43,8 +43,8 @@ exports.TreeMultiMapNode = TreeMultiMapNode;
|
|
|
43
43
|
* @example
|
|
44
44
|
* // Find elements in a range
|
|
45
45
|
* const tmm = new TreeMultiMap<number>([10, 5, 15, 3, 7, 12, 18]);
|
|
46
|
-
* console.log(tmm.search(new Range(5, 10))); // [5,
|
|
47
|
-
* console.log(tmm.search(new Range(4, 12))); // [5, 10, 12
|
|
46
|
+
* console.log(tmm.search(new Range(5, 10))); // [5, 7, 10]
|
|
47
|
+
* console.log(tmm.search(new Range(4, 12))); // [5, 7, 10, 12]
|
|
48
48
|
* console.log(tmm.search(new Range(15, 20))); // [15, 18]
|
|
49
49
|
*/
|
|
50
50
|
class TreeMultiMap extends red_black_tree_1.RedBlackTree {
|
|
@@ -101,7 +101,7 @@ class TreeMultiMap extends red_black_tree_1.RedBlackTree {
|
|
|
101
101
|
*
|
|
102
102
|
* The function `add` in TypeScript overrides the superclass method to add key-value pairs to a
|
|
103
103
|
* TreeMultiMapNode, handling different input types and scenarios.
|
|
104
|
-
* @param {
|
|
104
|
+
* @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
105
105
|
* parameter in the `override add` method can be either a `BTNRep` object containing a key, an array
|
|
106
106
|
* of values, and a `TreeMultiMapNode`, or just a key.
|
|
107
107
|
* @param {V} [value] - The `value` parameter in the `override add` method represents the value that
|
|
@@ -153,7 +153,7 @@ class TreeMultiMap extends red_black_tree_1.RedBlackTree {
|
|
|
153
153
|
*
|
|
154
154
|
* The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
|
|
155
155
|
* and deletes the entire node if no values are left for that key.
|
|
156
|
-
* @param {
|
|
156
|
+
* @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
157
157
|
* parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
|
|
158
158
|
* array of values, or just a key itself.
|
|
159
159
|
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
|
export * from './data-structures/queue/deque';
|
package/dist/index.js
CHANGED
|
@@ -17,11 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
/**
|
|
18
18
|
* data-structure-typed
|
|
19
19
|
*
|
|
20
|
-
* @author
|
|
21
|
-
* @copyright Copyright (c) 2022
|
|
20
|
+
* @author Pablo Zeng
|
|
21
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
22
22
|
* @license MIT License
|
|
23
23
|
*/
|
|
24
|
-
// export { Deque, ObjectDeque, ArrayDeque } from 'data-structure-typed';
|
|
25
24
|
__exportStar(require("./data-structures/queue/deque"), exports);
|
|
26
25
|
__exportStar(require("./types/data-structures/queue/deque"), exports);
|
|
27
26
|
__exportStar(require("./types/common"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BinaryTreeOptions } from './binary-tree';
|
|
2
2
|
import { Comparable } from '../../utils';
|
|
3
3
|
import { OptValue } from '../../common';
|
|
4
|
-
export type BSTOptions<K, V, R> = BinaryTreeOptions<K, V, R> & {
|
|
4
|
+
export type BSTOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'> & {
|
|
5
5
|
specifyComparable?: (key: K) => Comparable;
|
|
6
6
|
isReverse?: boolean;
|
|
7
7
|
};
|
|
@@ -3,7 +3,7 @@ export * from './bst';
|
|
|
3
3
|
export * from './avl-tree';
|
|
4
4
|
export * from './segment-tree';
|
|
5
5
|
export * from './avl-tree-multi-map';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './red-black-tree';
|
|
7
7
|
export * from './tree-multi-map';
|
|
8
8
|
export * from './tree-counter';
|
|
9
9
|
export * from './avl-tree-counter';
|
|
@@ -19,7 +19,7 @@ __exportStar(require("./bst"), exports);
|
|
|
19
19
|
__exportStar(require("./avl-tree"), exports);
|
|
20
20
|
__exportStar(require("./segment-tree"), exports);
|
|
21
21
|
__exportStar(require("./avl-tree-multi-map"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./red-black-tree"), exports);
|
|
23
23
|
__exportStar(require("./tree-multi-map"), exports);
|
|
24
24
|
__exportStar(require("./tree-counter"), exports);
|
|
25
25
|
__exportStar(require("./avl-tree-counter"), exports);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RedBlackTreeOptions } from './
|
|
1
|
+
import type { RedBlackTreeOptions } from './red-black-tree';
|
|
2
2
|
export type TreeCounterOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { RedBlackTreeOptions } from './
|
|
1
|
+
import type { RedBlackTreeOptions } from './red-black-tree';
|
|
2
2
|
export type TreeMultiMapOptions<K, V, R> = Omit<RedBlackTreeOptions<K, V, R>, 'isMapMode'> & {};
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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 type { Comparable, Thunk, ToThunkFn, TrlAsyncFn, TrlFn } from '../types';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deque-typed",
|
|
3
|
-
"version": "1.54.
|
|
3
|
+
"version": "1.54.3",
|
|
4
4
|
"description": "Deque. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"documentation",
|
|
96
96
|
"visualization"
|
|
97
97
|
],
|
|
98
|
-
"author": "
|
|
98
|
+
"author": "Pablo Zeng zrwusa@gmail.com",
|
|
99
99
|
"license": "MIT",
|
|
100
100
|
"bugs": {
|
|
101
101
|
"url": "https://github.com/zrwusa/data-structure-typed/issues"
|
|
@@ -119,6 +119,6 @@
|
|
|
119
119
|
"typescript": "^4.9.5"
|
|
120
120
|
},
|
|
121
121
|
"dependencies": {
|
|
122
|
-
"data-structure-typed": "^1.54.
|
|
122
|
+
"data-structure-typed": "^1.54.3"
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -9,15 +9,15 @@ import type {
|
|
|
9
9
|
AVLTreeCounterOptions,
|
|
10
10
|
BinaryTreeDeleteResult,
|
|
11
11
|
BSTNOptKeyOrNode,
|
|
12
|
-
BTNRep,
|
|
13
12
|
EntryCallback,
|
|
14
|
-
IterationType
|
|
15
|
-
OptNodeOrNull
|
|
13
|
+
IterationType
|
|
16
14
|
} from '../../types';
|
|
17
15
|
import { IBinaryTree } from '../../interfaces';
|
|
18
16
|
import { AVLTree, AVLTreeNode } from './avl-tree';
|
|
19
17
|
|
|
20
18
|
export class AVLTreeCounterNode<K = any, V = any> extends AVLTreeNode<K, V> {
|
|
19
|
+
override parent?: AVLTreeCounterNode<K, V> = undefined;
|
|
20
|
+
|
|
21
21
|
/**
|
|
22
22
|
* The constructor function initializes a BinaryTreeNode object with a key, value, and count.
|
|
23
23
|
* @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
|
|
@@ -33,28 +33,26 @@ export class AVLTreeCounterNode<K = any, V = any> extends AVLTreeNode<K, V> {
|
|
|
33
33
|
this.count = count;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
override
|
|
37
|
-
|
|
38
|
-
override _left?: OptNodeOrNull<AVLTreeCounterNode<K, V>> = undefined;
|
|
36
|
+
override _left?: AVLTreeCounterNode<K, V> | null | undefined = undefined;
|
|
39
37
|
|
|
40
|
-
override get left():
|
|
38
|
+
override get left(): AVLTreeCounterNode<K, V> | null | undefined {
|
|
41
39
|
return this._left;
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
override set left(v:
|
|
42
|
+
override set left(v: AVLTreeCounterNode<K, V> | null | undefined) {
|
|
45
43
|
if (v) {
|
|
46
44
|
v.parent = this;
|
|
47
45
|
}
|
|
48
46
|
this._left = v;
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
override _right?:
|
|
49
|
+
override _right?: AVLTreeCounterNode<K, V> | null | undefined = undefined;
|
|
52
50
|
|
|
53
|
-
override get right():
|
|
51
|
+
override get right(): AVLTreeCounterNode<K, V> | null | undefined {
|
|
54
52
|
return this._right;
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
override set right(v:
|
|
55
|
+
override set right(v: AVLTreeCounterNode<K, V> | null | undefined) {
|
|
58
56
|
if (v) {
|
|
59
57
|
v.parent = this;
|
|
60
58
|
}
|
|
@@ -78,7 +76,9 @@ export class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR
|
|
|
78
76
|
* `compareValues` functions to define custom comparison logic for keys and values, respectively.
|
|
79
77
|
*/
|
|
80
78
|
constructor(
|
|
81
|
-
keysNodesEntriesOrRaws: Iterable<
|
|
79
|
+
keysNodesEntriesOrRaws: Iterable<
|
|
80
|
+
K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
|
|
81
|
+
> = [],
|
|
82
82
|
options?: AVLTreeCounterOptions<K, V, R>
|
|
83
83
|
) {
|
|
84
84
|
super([], options);
|
|
@@ -145,12 +145,14 @@ export class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR
|
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
147
|
* The function checks if the input is an instance of AVLTreeCounterNode.
|
|
148
|
-
* @param {
|
|
149
|
-
* `keyNodeOrEntry` can be of type `R` or `
|
|
148
|
+
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
|
|
149
|
+
* `keyNodeOrEntry` can be of type `R` or `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
150
150
|
* @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
|
|
151
151
|
* an instance of the `AVLTreeCounterNode` class.
|
|
152
152
|
*/
|
|
153
|
-
override isNode(
|
|
153
|
+
override isNode(
|
|
154
|
+
keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
|
|
155
|
+
): keyNodeOrEntry is AVLTreeCounterNode<K, V> {
|
|
154
156
|
return keyNodeOrEntry instanceof AVLTreeCounterNode;
|
|
155
157
|
}
|
|
156
158
|
|
|
@@ -160,9 +162,9 @@ export class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR
|
|
|
160
162
|
*
|
|
161
163
|
* The function overrides the add method of a TypeScript class to add a new node to a data structure
|
|
162
164
|
* and update the count.
|
|
163
|
-
* @param {
|
|
165
|
+
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
|
|
164
166
|
* `keyNodeOrEntry` parameter can accept a value of type `R`, which can be any type. It
|
|
165
|
-
* can also accept a value of type `
|
|
167
|
+
* can also accept a value of type `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`, which represents a key, node,
|
|
166
168
|
* entry, or raw element
|
|
167
169
|
* @param {V} [value] - The `value` parameter represents the value associated with the key in the
|
|
168
170
|
* data structure. It is an optional parameter, so it can be omitted if not needed.
|
|
@@ -171,7 +173,11 @@ export class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR
|
|
|
171
173
|
* be added once. However, you can specify a different value for `count` if you want to add
|
|
172
174
|
* @returns a boolean value.
|
|
173
175
|
*/
|
|
174
|
-
override add(
|
|
176
|
+
override add(
|
|
177
|
+
keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
178
|
+
value?: V,
|
|
179
|
+
count = 1
|
|
180
|
+
): boolean {
|
|
175
181
|
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
176
182
|
if (newNode === undefined) return false;
|
|
177
183
|
|
|
@@ -189,7 +195,7 @@ export class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR
|
|
|
189
195
|
*
|
|
190
196
|
* The function overrides the delete method in a binary tree data structure, handling deletion of
|
|
191
197
|
* nodes and maintaining balance in the tree.
|
|
192
|
-
* @param {
|
|
198
|
+
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
|
|
193
199
|
* parameter in the `delete` method is used to specify the condition for deleting a node from the
|
|
194
200
|
* binary tree. It can be a key, node, or entry that determines which
|
|
195
201
|
* node(s) should be deleted.
|
|
@@ -203,7 +209,7 @@ export class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR
|
|
|
203
209
|
* deleted node and whether balancing is needed in the tree.
|
|
204
210
|
*/
|
|
205
211
|
override delete(
|
|
206
|
-
keyNodeOrEntry:
|
|
212
|
+
keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
207
213
|
ignoreCount = false
|
|
208
214
|
): BinaryTreeDeleteResult<AVLTreeCounterNode<K, V>>[] {
|
|
209
215
|
const deletedResult: BinaryTreeDeleteResult<AVLTreeCounterNode<K, V>>[] = [];
|
|
@@ -276,6 +282,7 @@ export class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR
|
|
|
276
282
|
/**
|
|
277
283
|
* Time Complexity: O(n log n)
|
|
278
284
|
* Space Complexity: O(log n)
|
|
285
|
+
*
|
|
279
286
|
* The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
|
|
280
287
|
* tree using either a recursive or iterative approach.
|
|
281
288
|
* @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
|
|
@@ -374,8 +381,8 @@ export class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR
|
|
|
374
381
|
/**
|
|
375
382
|
* The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
|
|
376
383
|
* a node object.
|
|
377
|
-
* @param {
|
|
378
|
-
* `keyNodeOrEntry` parameter can be of type `R` or `
|
|
384
|
+
* @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
|
|
385
|
+
* `keyNodeOrEntry` parameter can be of type `R` or `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
|
|
379
386
|
* @param {V} [value] - The `value` parameter is an optional value that can be passed to the
|
|
380
387
|
* `override` function. It represents the value associated with the key in the data structure. If no
|
|
381
388
|
* value is provided, it will default to `undefined`.
|
|
@@ -384,7 +391,7 @@ export class AVLTreeCounter<K = any, V = any, R = object, MK = any, MV = any, MR
|
|
|
384
391
|
* @returns either a AVLTreeCounterNode<K, V> object or undefined.
|
|
385
392
|
*/
|
|
386
393
|
protected override _keyValueNodeOrEntryToNodeAndValue(
|
|
387
|
-
keyNodeOrEntry:
|
|
394
|
+
keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
|
|
388
395
|
value?: V,
|
|
389
396
|
count = 1
|
|
390
397
|
): [AVLTreeCounterNode<K, V> | undefined, V | undefined] {
|