bst-typed 1.54.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/data-structures/base/iterable-element-base.d.ts +14 -40
- package/dist/data-structures/base/iterable-element-base.js +14 -11
- package/dist/data-structures/base/linear-base.d.ts +277 -0
- package/dist/data-structures/base/linear-base.js +552 -0
- 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 +23 -19
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +51 -38
- package/dist/data-structures/binary-tree/avl-tree.d.ts +89 -21
- package/dist/data-structures/binary-tree/avl-tree.js +76 -8
- package/dist/data-structures/binary-tree/binary-tree.d.ts +173 -225
- package/dist/data-structures/binary-tree/binary-tree.js +244 -149
- package/dist/data-structures/binary-tree/bst.d.ts +62 -56
- package/dist/data-structures/binary-tree/bst.js +89 -133
- 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 +186 -25
- package/dist/data-structures/binary-tree/tree-multi-map.js +211 -41
- package/dist/data-structures/graph/abstract-graph.js +2 -2
- package/dist/data-structures/heap/heap.d.ts +3 -11
- package/dist/data-structures/heap/heap.js +0 -10
- package/dist/data-structures/heap/max-heap.d.ts +2 -2
- package/dist/data-structures/heap/min-heap.d.ts +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
- package/dist/data-structures/linked-list/doubly-linked-list.js +131 -146
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +79 -75
- package/dist/data-structures/linked-list/singly-linked-list.js +217 -169
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -2
- package/dist/data-structures/queue/deque.d.ts +130 -91
- package/dist/data-structures/queue/deque.js +269 -169
- package/dist/data-structures/queue/queue.d.ts +84 -40
- package/dist/data-structures/queue/queue.js +134 -50
- package/dist/data-structures/stack/stack.d.ts +3 -11
- package/dist/data-structures/stack/stack.js +0 -10
- package/dist/data-structures/trie/trie.d.ts +4 -3
- package/dist/data-structures/trie/trie.js +3 -0
- package/dist/types/data-structures/base/base.d.ts +9 -4
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- 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/tree-multi-map.d.ts +1 -1
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/queue/deque.d.ts +2 -3
- package/dist/types/data-structures/queue/queue.d.ts +2 -2
- package/dist/utils/utils.d.ts +2 -2
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +29 -20
- package/src/data-structures/base/linear-base.ts +649 -0
- package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +74 -49
- package/src/data-structures/binary-tree/avl-tree.ts +99 -29
- package/src/data-structures/binary-tree/binary-tree.ts +474 -257
- package/src/data-structures/binary-tree/bst.ts +150 -152
- 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 +235 -53
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/heap/heap.ts +3 -14
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/heap/min-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
- package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +286 -183
- package/src/data-structures/queue/queue.ts +149 -63
- package/src/data-structures/stack/stack.ts +3 -18
- package/src/data-structures/trie/trie.ts +7 -3
- package/src/types/data-structures/base/base.ts +17 -8
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- 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/tree-multi-map.ts +1 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
- package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/types/data-structures/queue/deque.ts +2 -3
- package/src/types/data-structures/queue/queue.ts +2 -2
- package/src/utils/utils.ts +2 -2
|
@@ -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.
|
|
@@ -18,23 +19,180 @@ export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode
|
|
|
18
19
|
* @param {V[]} value - The `value` parameter in the constructor represents an array of values of
|
|
19
20
|
* type `V`.
|
|
20
21
|
*/
|
|
21
|
-
constructor(key: K, value
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
set right(v: OptNodeOrNull<TreeMultiMapNode<K, V>>);
|
|
22
|
+
constructor(key: K, value?: 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
|
-
* //
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
33
|
+
* // players ranked by score with their equipment
|
|
34
|
+
* type Equipment = {
|
|
35
|
+
* name: string; // Equipment name
|
|
36
|
+
* quality: 'legendary' | 'epic' | 'rare' | 'common';
|
|
37
|
+
* level: number;
|
|
38
|
+
* };
|
|
39
|
+
*
|
|
40
|
+
* type Player = {
|
|
41
|
+
* name: string;
|
|
42
|
+
* score: number;
|
|
43
|
+
* equipments: Equipment[];
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* // Mock player data with their scores and equipment
|
|
47
|
+
* const players: Player[] = [
|
|
48
|
+
* {
|
|
49
|
+
* name: 'DragonSlayer',
|
|
50
|
+
* score: 8750,
|
|
51
|
+
* equipments: [
|
|
52
|
+
* { name: 'AWM', quality: 'legendary', level: 85 },
|
|
53
|
+
* { name: 'Level 3 Helmet', quality: 'epic', level: 80 },
|
|
54
|
+
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 75 },
|
|
55
|
+
* { name: 'Compensator', quality: 'epic', level: 78 },
|
|
56
|
+
* { name: 'Vertical Grip', quality: 'rare', level: 72 }
|
|
57
|
+
* ]
|
|
58
|
+
* },
|
|
59
|
+
* {
|
|
60
|
+
* name: 'ShadowNinja',
|
|
61
|
+
* score: 7200,
|
|
62
|
+
* equipments: [
|
|
63
|
+
* { name: 'M416', quality: 'epic', level: 75 },
|
|
64
|
+
* { name: 'Ghillie Suit', quality: 'rare', level: 70 },
|
|
65
|
+
* { name: 'Red Dot Sight', quality: 'common', level: 65 },
|
|
66
|
+
* { name: 'Extended QuickDraw Mag', quality: 'rare', level: 68 }
|
|
67
|
+
* ]
|
|
68
|
+
* },
|
|
69
|
+
* {
|
|
70
|
+
* name: 'RuneMaster',
|
|
71
|
+
* score: 9100,
|
|
72
|
+
* equipments: [
|
|
73
|
+
* { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
74
|
+
* { name: 'Level 3 Vest', quality: 'legendary', level: 85 },
|
|
75
|
+
* { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
76
|
+
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
77
|
+
* { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
78
|
+
* ]
|
|
79
|
+
* },
|
|
80
|
+
* {
|
|
81
|
+
* name: 'BattleKing',
|
|
82
|
+
* score: 8500,
|
|
83
|
+
* equipments: [
|
|
84
|
+
* { name: 'AUG', quality: 'epic', level: 82 },
|
|
85
|
+
* { name: 'Red Dot Sight', quality: 'rare', level: 75 },
|
|
86
|
+
* { name: 'Extended Mag', quality: 'common', level: 70 },
|
|
87
|
+
* { name: 'Tactical Stock', quality: 'rare', level: 76 }
|
|
88
|
+
* ]
|
|
89
|
+
* },
|
|
90
|
+
* {
|
|
91
|
+
* name: 'SniperElite',
|
|
92
|
+
* score: 7800,
|
|
93
|
+
* equipments: [
|
|
94
|
+
* { name: 'M24', quality: 'legendary', level: 88 },
|
|
95
|
+
* { name: 'Compensator', quality: 'epic', level: 80 },
|
|
96
|
+
* { name: 'Scope 8x', quality: 'legendary', level: 85 },
|
|
97
|
+
* { name: 'Level 2 Helmet', quality: 'rare', level: 75 }
|
|
98
|
+
* ]
|
|
99
|
+
* },
|
|
100
|
+
* {
|
|
101
|
+
* name: 'RushMaster',
|
|
102
|
+
* score: 7500,
|
|
103
|
+
* equipments: [
|
|
104
|
+
* { name: 'Vector', quality: 'rare', level: 72 },
|
|
105
|
+
* { name: 'Level 2 Helmet', quality: 'common', level: 65 },
|
|
106
|
+
* { name: 'Quickdraw Mag', quality: 'common', level: 60 },
|
|
107
|
+
* { name: 'Laser Sight', quality: 'rare', level: 68 }
|
|
108
|
+
* ]
|
|
109
|
+
* },
|
|
110
|
+
* {
|
|
111
|
+
* name: 'GhostWarrior',
|
|
112
|
+
* score: 8200,
|
|
113
|
+
* equipments: [
|
|
114
|
+
* { name: 'SCAR-L', quality: 'epic', level: 78 },
|
|
115
|
+
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 70 },
|
|
116
|
+
* { name: 'Holographic Sight', quality: 'epic', level: 75 },
|
|
117
|
+
* { name: 'Suppressor', quality: 'rare', level: 72 },
|
|
118
|
+
* { name: 'Vertical Grip', quality: 'common', level: 65 }
|
|
119
|
+
* ]
|
|
120
|
+
* },
|
|
121
|
+
* {
|
|
122
|
+
* name: 'DeathDealer',
|
|
123
|
+
* score: 7300,
|
|
124
|
+
* equipments: [
|
|
125
|
+
* { name: 'SKS', quality: 'epic', level: 76 },
|
|
126
|
+
* { name: 'Holographic Sight', quality: 'rare', level: 68 },
|
|
127
|
+
* { name: 'Extended Mag', quality: 'common', level: 65 }
|
|
128
|
+
* ]
|
|
129
|
+
* },
|
|
130
|
+
* {
|
|
131
|
+
* name: 'StormRider',
|
|
132
|
+
* score: 8900,
|
|
133
|
+
* equipments: [
|
|
134
|
+
* { name: 'MK14', quality: 'legendary', level: 92 },
|
|
135
|
+
* { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
136
|
+
* { name: 'Scope 8x', quality: 'epic', level: 80 },
|
|
137
|
+
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
138
|
+
* { name: 'Tactical Stock', quality: 'rare', level: 75 }
|
|
139
|
+
* ]
|
|
140
|
+
* },
|
|
141
|
+
* {
|
|
142
|
+
* name: 'CombatLegend',
|
|
143
|
+
* score: 7600,
|
|
144
|
+
* equipments: [
|
|
145
|
+
* { name: 'UMP45', quality: 'rare', level: 74 },
|
|
146
|
+
* { name: 'Level 2 Vest', quality: 'common', level: 67 },
|
|
147
|
+
* { name: 'Red Dot Sight', quality: 'common', level: 62 },
|
|
148
|
+
* { name: 'Extended Mag', quality: 'rare', level: 70 }
|
|
149
|
+
* ]
|
|
150
|
+
* }
|
|
151
|
+
* ];
|
|
152
|
+
*
|
|
153
|
+
* // Create a TreeMultiMap for player rankings
|
|
154
|
+
* const playerRankings = new TreeMultiMap<number, Equipment, Player>(players, {
|
|
155
|
+
* toEntryFn: ({ score, equipments }) => [score, equipments],
|
|
156
|
+
* isMapMode: false
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* const topPlayersEquipments = playerRankings.rangeSearch([8900, 10000], node => playerRankings.get(node));
|
|
160
|
+
* console.log(topPlayersEquipments); // [
|
|
161
|
+
* // [
|
|
162
|
+
* // {
|
|
163
|
+
* // name: 'MK14',
|
|
164
|
+
* // quality: 'legendary',
|
|
165
|
+
* // level: 92
|
|
166
|
+
* // },
|
|
167
|
+
* // { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
168
|
+
* // {
|
|
169
|
+
* // name: 'Scope 8x',
|
|
170
|
+
* // quality: 'epic',
|
|
171
|
+
* // level: 80
|
|
172
|
+
* // },
|
|
173
|
+
* // { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
174
|
+
* // {
|
|
175
|
+
* // name: 'Tactical Stock',
|
|
176
|
+
* // quality: 'rare',
|
|
177
|
+
* // level: 75
|
|
178
|
+
* // }
|
|
179
|
+
* // ],
|
|
180
|
+
* // [
|
|
181
|
+
* // { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
182
|
+
* // {
|
|
183
|
+
* // name: 'Level 3 Vest',
|
|
184
|
+
* // quality: 'legendary',
|
|
185
|
+
* // level: 85
|
|
186
|
+
* // },
|
|
187
|
+
* // { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
188
|
+
* // {
|
|
189
|
+
* // name: 'Suppressor',
|
|
190
|
+
* // quality: 'legendary',
|
|
191
|
+
* // level: 88
|
|
192
|
+
* // },
|
|
193
|
+
* // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
194
|
+
* // ]
|
|
195
|
+
* // ]
|
|
38
196
|
*/
|
|
39
197
|
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> {
|
|
40
198
|
/**
|
|
@@ -48,7 +206,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
|
|
|
48
206
|
* `TreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
|
|
49
207
|
* additional options for configuring the TreeMultiMap instance.
|
|
50
208
|
*/
|
|
51
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<
|
|
209
|
+
constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | R>, options?: TreeMultiMapOptions<K, V[], R>);
|
|
52
210
|
/**
|
|
53
211
|
* Time Complexity: O(1)
|
|
54
212
|
* Space Complexity: O(1)
|
|
@@ -67,15 +225,18 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
|
|
|
67
225
|
* Time Complexity: O(1)
|
|
68
226
|
* Space Complexity: O(1)
|
|
69
227
|
*
|
|
70
|
-
* The function `createNode` overrides the
|
|
71
|
-
*
|
|
72
|
-
* @param {K} key - The `key` parameter
|
|
73
|
-
*
|
|
74
|
-
* @
|
|
75
|
-
*
|
|
228
|
+
* The function `createNode` overrides the creation of a new TreeMultiMapNode with a specified key
|
|
229
|
+
* and value array.
|
|
230
|
+
* @param {K} key - The `key` parameter represents the key of the node being created in the
|
|
231
|
+
* `TreeMultiMap`.
|
|
232
|
+
* @param {V[]} value - The `value` parameter in the `createNode` method represents an array of
|
|
233
|
+
* values associated with a specific key in the TreeMultiMap data structure.
|
|
234
|
+
* @returns A new instance of `TreeMultiMapNode<K, V>` is being returned with the specified key and
|
|
235
|
+
* value. If `_isMapMode` is true, an empty array is passed as the value, otherwise the provided
|
|
236
|
+
* value is used.
|
|
76
237
|
*/
|
|
77
|
-
createNode(key: K): TreeMultiMapNode<K, V>;
|
|
78
|
-
add(
|
|
238
|
+
createNode(key: K, value?: V[]): TreeMultiMapNode<K, V>;
|
|
239
|
+
add(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
|
|
79
240
|
add(key: K, value: V): boolean;
|
|
80
241
|
/**
|
|
81
242
|
* Time Complexity: O(log n)
|
|
@@ -83,7 +244,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
|
|
|
83
244
|
*
|
|
84
245
|
* The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
|
|
85
246
|
* and deletes the entire node if no values are left for that key.
|
|
86
|
-
* @param {
|
|
247
|
+
* @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
|
|
87
248
|
* parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
|
|
88
249
|
* array of values, or just a key itself.
|
|
89
250
|
* @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
|
|
@@ -93,7 +254,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
|
|
|
93
254
|
* @returns The `deleteValue` function returns a boolean value - `true` if the specified `value` was
|
|
94
255
|
* successfully deleted from the values associated with the `keyNodeOrEntry`, and `false` otherwise.
|
|
95
256
|
*/
|
|
96
|
-
deleteValue(keyNodeOrEntry:
|
|
257
|
+
deleteValue(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined, value: V): boolean;
|
|
97
258
|
/**
|
|
98
259
|
* Time Complexity: O(n)
|
|
99
260
|
* Space Complexity: O(n)
|