min-heap-typed 2.1.0 → 2.1.2
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/cjs/index.cjs +987 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +980 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/data-structures/base/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
- package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
- package/dist/types/data-structures/graph/index.d.ts +2 -1
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +503 -5
- package/dist/types/data-structures/heap/index.d.ts +2 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
- package/dist/types/data-structures/index.d.ts +7 -7
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
- package/dist/types/data-structures/matrix/index.d.ts +1 -1
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
- package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
- package/dist/types/data-structures/queue/deque.d.ts +431 -4
- package/dist/types/data-structures/queue/queue.d.ts +308 -4
- package/dist/types/data-structures/stack/stack.d.ts +306 -2
- package/dist/types/data-structures/tree/tree.d.ts +62 -1
- package/dist/types/data-structures/trie/trie.d.ts +350 -4
- package/dist/types/index.d.ts +13 -2
- package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +209 -22
- package/dist/umd/max-heap-typed.js +992 -0
- package/dist/umd/max-heap-typed.js.map +1 -0
- package/dist/umd/max-heap-typed.min.js +16 -0
- package/dist/umd/max-heap-typed.min.js.map +1 -0
- package/package.json +25 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
- package/src/data-structures/binary-tree/avl-tree.ts +6 -8
- package/src/data-structures/binary-tree/binary-tree.ts +13 -15
- package/src/data-structures/binary-tree/bst.ts +6 -11
- package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
- package/src/data-structures/binary-tree/tree-counter.ts +8 -13
- package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +3 -3
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +8 -34
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +37 -0
- package/dist/common/index.js +0 -28
- package/dist/constants/index.js +0 -8
- package/dist/data-structures/base/index.d.ts +0 -2
- package/dist/data-structures/base/index.js +0 -18
- package/dist/data-structures/base/iterable-element-base.js +0 -243
- package/dist/data-structures/base/iterable-entry-base.js +0 -183
- package/dist/data-structures/base/linear-base.js +0 -415
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
- package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
- package/dist/data-structures/binary-tree/avl-tree.js +0 -611
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
- package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
- package/dist/data-structures/binary-tree/bst.d.ts +0 -413
- package/dist/data-structures/binary-tree/bst.js +0 -903
- package/dist/data-structures/binary-tree/index.js +0 -26
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
- package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/data-structures/binary-tree/segment-tree.js +0 -297
- package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
- package/dist/data-structures/binary-tree/tree-counter.js +0 -413
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
- package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
- package/dist/data-structures/graph/abstract-graph.js +0 -896
- package/dist/data-structures/graph/directed-graph.d.ts +0 -207
- package/dist/data-structures/graph/directed-graph.js +0 -525
- package/dist/data-structures/graph/index.js +0 -20
- package/dist/data-structures/graph/map-graph.d.ts +0 -78
- package/dist/data-structures/graph/map-graph.js +0 -107
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
- package/dist/data-structures/graph/undirected-graph.js +0 -424
- package/dist/data-structures/hash/hash-map.d.ts +0 -345
- package/dist/data-structures/hash/hash-map.js +0 -692
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -17
- package/dist/data-structures/heap/heap.d.ts +0 -503
- package/dist/data-structures/heap/heap.js +0 -901
- package/dist/data-structures/heap/index.d.ts +0 -3
- package/dist/data-structures/heap/index.js +0 -19
- package/dist/data-structures/heap/max-heap.d.ts +0 -32
- package/dist/data-structures/heap/max-heap.js +0 -40
- package/dist/data-structures/heap/min-heap.d.ts +0 -33
- package/dist/data-structures/heap/min-heap.js +0 -31
- package/dist/data-structures/index.js +0 -28
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
- package/dist/data-structures/linked-list/index.js +0 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
- package/dist/data-structures/matrix/index.js +0 -18
- package/dist/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/data-structures/matrix/matrix.js +0 -448
- package/dist/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/data-structures/matrix/navigator.js +0 -111
- package/dist/data-structures/priority-queue/index.js +0 -19
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/priority-queue.js +0 -20
- package/dist/data-structures/queue/deque.d.ts +0 -431
- package/dist/data-structures/queue/deque.js +0 -879
- package/dist/data-structures/queue/index.js +0 -18
- package/dist/data-structures/queue/queue.d.ts +0 -308
- package/dist/data-structures/queue/queue.js +0 -473
- package/dist/data-structures/stack/index.js +0 -17
- package/dist/data-structures/stack/stack.d.ts +0 -306
- package/dist/data-structures/stack/stack.js +0 -401
- package/dist/data-structures/tree/index.js +0 -17
- package/dist/data-structures/tree/tree.d.ts +0 -62
- package/dist/data-structures/tree/tree.js +0 -107
- package/dist/data-structures/trie/index.js +0 -17
- package/dist/data-structures/trie/trie.d.ts +0 -350
- package/dist/data-structures/trie/trie.js +0 -610
- package/dist/index.d.ts +0 -14
- package/dist/index.js +0 -30
- package/dist/interfaces/binary-tree.js +0 -2
- package/dist/interfaces/doubly-linked-list.js +0 -2
- package/dist/interfaces/graph.js +0 -2
- package/dist/interfaces/heap.js +0 -2
- package/dist/interfaces/index.js +0 -24
- package/dist/interfaces/navigator.js +0 -2
- package/dist/interfaces/priority-queue.js +0 -2
- package/dist/interfaces/segment-tree.js +0 -2
- package/dist/interfaces/singly-linked-list.js +0 -2
- package/dist/types/common.js +0 -2
- package/dist/types/data-structures/base/base.js +0 -2
- package/dist/types/data-structures/base/index.js +0 -17
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/types/data-structures/binary-tree/index.js +0 -25
- package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/types/data-structures/graph/index.js +0 -19
- package/dist/types/data-structures/graph/map-graph.js +0 -2
- package/dist/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/types/data-structures/hash/hash-map.js +0 -2
- package/dist/types/data-structures/hash/index.js +0 -17
- package/dist/types/data-structures/heap/heap.js +0 -2
- package/dist/types/data-structures/heap/index.js +0 -17
- package/dist/types/data-structures/heap/max-heap.js +0 -2
- package/dist/types/data-structures/heap/min-heap.js +0 -2
- package/dist/types/data-structures/index.js +0 -28
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/index.js +0 -19
- package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/types/data-structures/matrix/index.js +0 -18
- package/dist/types/data-structures/matrix/matrix.js +0 -2
- package/dist/types/data-structures/matrix/navigator.js +0 -2
- package/dist/types/data-structures/priority-queue/index.js +0 -19
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/types/data-structures/queue/deque.js +0 -2
- package/dist/types/data-structures/queue/index.js +0 -18
- package/dist/types/data-structures/queue/queue.js +0 -2
- package/dist/types/data-structures/stack/index.js +0 -17
- package/dist/types/data-structures/stack/stack.js +0 -2
- package/dist/types/data-structures/tree/index.js +0 -17
- package/dist/types/data-structures/tree/tree.js +0 -2
- package/dist/types/data-structures/trie/index.js +0 -17
- package/dist/types/data-structures/trie/trie.js +0 -2
- package/dist/types/index.js +0 -19
- package/dist/types/utils/index.js +0 -18
- package/dist/types/utils/utils.js +0 -2
- package/dist/types/utils/validate-type.js +0 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/number.js +0 -24
- package/dist/utils/utils.d.ts +0 -209
- package/dist/utils/utils.js +0 -353
- package/dist/{common → types/common}/index.d.ts +0 -0
- package/dist/{constants → types/constants}/index.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
- package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
- package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
- package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
- /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
- /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/number.d.ts +0 -0
|
@@ -1,413 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* data-structure-typed
|
|
4
|
-
*
|
|
5
|
-
* @author Pablo Zeng
|
|
6
|
-
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
7
|
-
* @license MIT License
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.TreeCounter = exports.TreeCounterNode = void 0;
|
|
11
|
-
const red_black_tree_1 = require("./red-black-tree");
|
|
12
|
-
/**
|
|
13
|
-
* RB-tree node with an extra 'count' field; keeps parent/child links.
|
|
14
|
-
* @remarks Time O(1), Space O(1)
|
|
15
|
-
* @template K
|
|
16
|
-
* @template V
|
|
17
|
-
*/
|
|
18
|
-
class TreeCounterNode extends red_black_tree_1.RedBlackTreeNode {
|
|
19
|
-
/**
|
|
20
|
-
* Create a tree counter node.
|
|
21
|
-
* @remarks Time O(1), Space O(1)
|
|
22
|
-
* @param key - Key of the node.
|
|
23
|
-
* @param [value] - Value associated with the key (ignored in map mode).
|
|
24
|
-
* @param [count] - Initial count for this node (default 1).
|
|
25
|
-
* @param color - Initial color ('RED' or 'BLACK').
|
|
26
|
-
* @returns New TreeCounterNode instance.
|
|
27
|
-
*/
|
|
28
|
-
constructor(key, value, count = 1, color = 'BLACK') {
|
|
29
|
-
super(key, value, color);
|
|
30
|
-
this.parent = undefined;
|
|
31
|
-
this._left = undefined;
|
|
32
|
-
this._right = undefined;
|
|
33
|
-
this.count = count;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Get the left child pointer.
|
|
37
|
-
* @remarks Time O(1), Space O(1)
|
|
38
|
-
* @returns Left child node, or null/undefined.
|
|
39
|
-
*/
|
|
40
|
-
get left() {
|
|
41
|
-
return this._left;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Set the left child and update its parent pointer.
|
|
45
|
-
* @remarks Time O(1), Space O(1)
|
|
46
|
-
* @param v - New left child node, or null/undefined.
|
|
47
|
-
* @returns void
|
|
48
|
-
*/
|
|
49
|
-
set left(v) {
|
|
50
|
-
if (v) {
|
|
51
|
-
v.parent = this;
|
|
52
|
-
}
|
|
53
|
-
this._left = v;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Get the right child pointer.
|
|
57
|
-
* @remarks Time O(1), Space O(1)
|
|
58
|
-
* @returns Right child node, or null/undefined.
|
|
59
|
-
*/
|
|
60
|
-
get right() {
|
|
61
|
-
return this._right;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Set the right child and update its parent pointer.
|
|
65
|
-
* @remarks Time O(1), Space O(1)
|
|
66
|
-
* @param v - New right child node, or null/undefined.
|
|
67
|
-
* @returns void
|
|
68
|
-
*/
|
|
69
|
-
set right(v) {
|
|
70
|
-
if (v) {
|
|
71
|
-
v.parent = this;
|
|
72
|
-
}
|
|
73
|
-
this._right = v;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.TreeCounterNode = TreeCounterNode;
|
|
77
|
-
/**
|
|
78
|
-
* Red-Black Tree–based counter map (key → value with per-node count). Supports O(log N) updates and map-like mode.
|
|
79
|
-
* @remarks Time O(1), Space O(1)
|
|
80
|
-
* @template K
|
|
81
|
-
* @template V
|
|
82
|
-
* @template R
|
|
83
|
-
*/
|
|
84
|
-
class TreeCounter extends red_black_tree_1.RedBlackTree {
|
|
85
|
-
/**
|
|
86
|
-
* Create a TreeCounter and optionally bulk-insert items.
|
|
87
|
-
* @remarks Time O(N log N), Space O(N)
|
|
88
|
-
* @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
|
|
89
|
-
* @param [options] - Options for TreeCounter (comparator, reverse, map mode).
|
|
90
|
-
* @returns New TreeCounter instance.
|
|
91
|
-
*/
|
|
92
|
-
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
93
|
-
super([], options);
|
|
94
|
-
this._count = 0;
|
|
95
|
-
if (keysNodesEntriesOrRaws)
|
|
96
|
-
this.addMany(keysNodesEntriesOrRaws);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Get the total aggregate count across all nodes.
|
|
100
|
-
* @remarks Time O(1), Space O(1)
|
|
101
|
-
* @returns Total count.
|
|
102
|
-
*/
|
|
103
|
-
get count() {
|
|
104
|
-
return this._count;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Compute the total count by traversing the tree (sums node.count).
|
|
108
|
-
* @remarks Time O(N), Space O(H)
|
|
109
|
-
* @returns Total count recomputed from nodes.
|
|
110
|
-
*/
|
|
111
|
-
getComputedCount() {
|
|
112
|
-
let sum = 0;
|
|
113
|
-
this.dfs(node => (sum += node ? node.count : 0));
|
|
114
|
-
return sum;
|
|
115
|
-
}
|
|
116
|
-
_createNode(key, value, color = 'BLACK', count) {
|
|
117
|
-
return new TreeCounterNode(key, this._isMapMode ? undefined : value, count, color);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Type guard: check whether the input is a TreeCounterNode.
|
|
121
|
-
* @remarks Time O(1), Space O(1)
|
|
122
|
-
* @returns True if the value is a TreeCounterNode.
|
|
123
|
-
*/
|
|
124
|
-
isNode(keyNodeOrEntry) {
|
|
125
|
-
return keyNodeOrEntry instanceof TreeCounterNode;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Insert or increment a node and update aggregate count.
|
|
129
|
-
* @remarks Time O(log N), Space O(1)
|
|
130
|
-
* @param keyNodeOrEntry - Key, node, or [key, value] entry to insert.
|
|
131
|
-
* @param [value] - Value when a bare key is provided (ignored in map mode).
|
|
132
|
-
* @param [count] - How much to increase the node's count (default 1).
|
|
133
|
-
* @returns True if inserted/updated; false if ignored.
|
|
134
|
-
*/
|
|
135
|
-
add(keyNodeOrEntry, value, count = 1) {
|
|
136
|
-
const [newNode, newValue] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count);
|
|
137
|
-
const orgCount = (newNode === null || newNode === void 0 ? void 0 : newNode.count) || 0;
|
|
138
|
-
const isSuccessAdded = super.add(newNode, newValue);
|
|
139
|
-
if (isSuccessAdded) {
|
|
140
|
-
this._count += orgCount;
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Delete a node (or decrement its count) and rebalance if needed.
|
|
149
|
-
* @remarks Time O(log N), Space O(1)
|
|
150
|
-
* @param keyNodeOrEntry - Key, node, or [key, value] entry identifying the node.
|
|
151
|
-
* @param [ignoreCount] - If true, remove the node regardless of its count.
|
|
152
|
-
* @returns Array of deletion results including deleted node and a rebalance hint when present.
|
|
153
|
-
*/
|
|
154
|
-
delete(keyNodeOrEntry, ignoreCount = false) {
|
|
155
|
-
if (keyNodeOrEntry === null)
|
|
156
|
-
return [];
|
|
157
|
-
const results = [];
|
|
158
|
-
let nodeToDelete;
|
|
159
|
-
if (this._isPredicate(keyNodeOrEntry))
|
|
160
|
-
nodeToDelete = this.getNode(keyNodeOrEntry);
|
|
161
|
-
else
|
|
162
|
-
nodeToDelete = this.isRealNode(keyNodeOrEntry) ? keyNodeOrEntry : this.getNode(keyNodeOrEntry);
|
|
163
|
-
if (!nodeToDelete) {
|
|
164
|
-
return results;
|
|
165
|
-
}
|
|
166
|
-
let originalColor = nodeToDelete.color;
|
|
167
|
-
let replacementNode;
|
|
168
|
-
if (!this.isRealNode(nodeToDelete.left)) {
|
|
169
|
-
if (nodeToDelete.right !== null)
|
|
170
|
-
replacementNode = nodeToDelete.right;
|
|
171
|
-
if (ignoreCount || nodeToDelete.count <= 1) {
|
|
172
|
-
if (nodeToDelete.right !== null) {
|
|
173
|
-
this._transplant(nodeToDelete, nodeToDelete.right);
|
|
174
|
-
this._count -= nodeToDelete.count;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
nodeToDelete.count--;
|
|
179
|
-
this._count--;
|
|
180
|
-
results.push({ deleted: nodeToDelete, needBalanced: undefined });
|
|
181
|
-
return results;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
else if (!this.isRealNode(nodeToDelete.right)) {
|
|
185
|
-
replacementNode = nodeToDelete.left;
|
|
186
|
-
if (ignoreCount || nodeToDelete.count <= 1) {
|
|
187
|
-
this._transplant(nodeToDelete, nodeToDelete.left);
|
|
188
|
-
this._count -= nodeToDelete.count;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
nodeToDelete.count--;
|
|
192
|
-
this._count--;
|
|
193
|
-
results.push({ deleted: nodeToDelete, needBalanced: undefined });
|
|
194
|
-
return results;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
const successor = this.getLeftMost(node => node, nodeToDelete.right);
|
|
199
|
-
if (successor) {
|
|
200
|
-
originalColor = successor.color;
|
|
201
|
-
if (successor.right !== null)
|
|
202
|
-
replacementNode = successor.right;
|
|
203
|
-
if (successor.parent === nodeToDelete) {
|
|
204
|
-
if (this.isRealNode(replacementNode)) {
|
|
205
|
-
replacementNode.parent = successor;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
if (ignoreCount || nodeToDelete.count <= 1) {
|
|
210
|
-
if (successor.right !== null) {
|
|
211
|
-
this._transplant(successor, successor.right);
|
|
212
|
-
this._count -= nodeToDelete.count;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
nodeToDelete.count--;
|
|
217
|
-
this._count--;
|
|
218
|
-
results.push({ deleted: nodeToDelete, needBalanced: undefined });
|
|
219
|
-
return results;
|
|
220
|
-
}
|
|
221
|
-
successor.right = nodeToDelete.right;
|
|
222
|
-
if (this.isRealNode(successor.right)) {
|
|
223
|
-
successor.right.parent = successor;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (ignoreCount || nodeToDelete.count <= 1) {
|
|
227
|
-
this._transplant(nodeToDelete, successor);
|
|
228
|
-
this._count -= nodeToDelete.count;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
nodeToDelete.count--;
|
|
232
|
-
this._count--;
|
|
233
|
-
results.push({ deleted: nodeToDelete, needBalanced: undefined });
|
|
234
|
-
return results;
|
|
235
|
-
}
|
|
236
|
-
successor.left = nodeToDelete.left;
|
|
237
|
-
if (this.isRealNode(successor.left)) {
|
|
238
|
-
successor.left.parent = successor;
|
|
239
|
-
}
|
|
240
|
-
successor.color = nodeToDelete.color;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
this._size--;
|
|
244
|
-
if (originalColor === 'BLACK') {
|
|
245
|
-
this._deleteFixup(replacementNode);
|
|
246
|
-
}
|
|
247
|
-
results.push({ deleted: nodeToDelete, needBalanced: undefined });
|
|
248
|
-
return results;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Remove all nodes and reset aggregate counters.
|
|
252
|
-
* @remarks Time O(N), Space O(1)
|
|
253
|
-
* @returns void
|
|
254
|
-
*/
|
|
255
|
-
clear() {
|
|
256
|
-
super.clear();
|
|
257
|
-
this._count = 0;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Rebuild the tree into a perfectly balanced form using in-order nodes.
|
|
261
|
-
* @remarks Time O(N), Space O(N)
|
|
262
|
-
* @param [iterationType] - Traversal style to use when constructing the balanced tree.
|
|
263
|
-
* @returns True if rebalancing succeeded (tree not empty).
|
|
264
|
-
*/
|
|
265
|
-
perfectlyBalance(iterationType = this.iterationType) {
|
|
266
|
-
const nodes = this.dfs(node => node, 'IN', false, this._root, iterationType);
|
|
267
|
-
const n = nodes.length;
|
|
268
|
-
if (n < 1)
|
|
269
|
-
return false;
|
|
270
|
-
let total = 0;
|
|
271
|
-
for (const nd of nodes)
|
|
272
|
-
total += nd ? nd.count : 0;
|
|
273
|
-
this._clearNodes();
|
|
274
|
-
const build = (l, r, parent) => {
|
|
275
|
-
if (l > r)
|
|
276
|
-
return undefined;
|
|
277
|
-
const m = l + ((r - l) >> 1);
|
|
278
|
-
const root = nodes[m];
|
|
279
|
-
const leftChild = build(l, m - 1, root);
|
|
280
|
-
const rightChild = build(m + 1, r, root);
|
|
281
|
-
root.left = leftChild;
|
|
282
|
-
root.right = rightChild;
|
|
283
|
-
root.parent = parent;
|
|
284
|
-
return root;
|
|
285
|
-
};
|
|
286
|
-
const newRoot = build(0, n - 1, undefined);
|
|
287
|
-
this._setRoot(newRoot);
|
|
288
|
-
this._size = n;
|
|
289
|
-
this._count = total;
|
|
290
|
-
return true;
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Create a new TreeCounter by mapping each [key, value] entry.
|
|
294
|
-
* @remarks Time O(N log N), Space O(N)
|
|
295
|
-
* @template MK
|
|
296
|
-
* @template MV
|
|
297
|
-
* @template MR
|
|
298
|
-
* @param callback - Function mapping (key, value, index, tree) → [newKey, newValue].
|
|
299
|
-
* @param [options] - Options for the output tree.
|
|
300
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
301
|
-
* @returns A new TreeCounter with mapped entries.
|
|
302
|
-
*/
|
|
303
|
-
map(callback, options, thisArg) {
|
|
304
|
-
const out = this._createLike([], options);
|
|
305
|
-
let index = 0;
|
|
306
|
-
for (const [key, value] of this) {
|
|
307
|
-
out.add(callback.call(thisArg, key, value, index++, this));
|
|
308
|
-
}
|
|
309
|
-
return out;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Deep copy this tree, preserving map mode and aggregate counts.
|
|
313
|
-
* @remarks Time O(N), Space O(N)
|
|
314
|
-
* @returns A deep copy of this tree.
|
|
315
|
-
*/
|
|
316
|
-
clone() {
|
|
317
|
-
const out = this._createInstance();
|
|
318
|
-
this._clone(out);
|
|
319
|
-
out._count = this._count;
|
|
320
|
-
return out;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* (Protected) Create an empty instance of the same concrete class.
|
|
324
|
-
* @remarks Time O(1), Space O(1)
|
|
325
|
-
* @template TK
|
|
326
|
-
* @template TV
|
|
327
|
-
* @template TR
|
|
328
|
-
* @param [options] - Optional constructor options for the like-kind instance.
|
|
329
|
-
* @returns An empty like-kind instance.
|
|
330
|
-
*/
|
|
331
|
-
_createInstance(options) {
|
|
332
|
-
const Ctor = this.constructor;
|
|
333
|
-
return new Ctor([], Object.assign(Object.assign({}, this._snapshotOptions()), (options !== null && options !== void 0 ? options : {})));
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
337
|
-
* @remarks Time O(N log N), Space O(N)
|
|
338
|
-
* @template TK
|
|
339
|
-
* @template TV
|
|
340
|
-
* @template TR
|
|
341
|
-
* @param iter - Iterable used to seed the new tree.
|
|
342
|
-
* @param [options] - Options merged with the current snapshot.
|
|
343
|
-
* @returns A like-kind TreeCounter built from the iterable.
|
|
344
|
-
*/
|
|
345
|
-
_createLike(iter = [], options) {
|
|
346
|
-
const Ctor = this.constructor;
|
|
347
|
-
return new Ctor(iter, Object.assign(Object.assign({}, this._snapshotOptions()), (options !== null && options !== void 0 ? options : {})));
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* (Protected) Normalize input into a node plus its effective value and count.
|
|
351
|
-
* @remarks Time O(1), Space O(1)
|
|
352
|
-
* @param keyNodeOrEntry - Key, node, or [key, value] entry.
|
|
353
|
-
* @param [value] - Value used when a bare key is provided.
|
|
354
|
-
* @param [count] - Count increment to apply (default 1).
|
|
355
|
-
* @returns Tuple [node, value] where node may be undefined.
|
|
356
|
-
*/
|
|
357
|
-
_keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value, count = 1) {
|
|
358
|
-
if (keyNodeOrEntry === undefined || keyNodeOrEntry === null)
|
|
359
|
-
return [undefined, undefined];
|
|
360
|
-
if (this.isNode(keyNodeOrEntry))
|
|
361
|
-
return [keyNodeOrEntry, value];
|
|
362
|
-
if (this.isEntry(keyNodeOrEntry)) {
|
|
363
|
-
const [key, entryValue] = keyNodeOrEntry;
|
|
364
|
-
if (key === undefined || key === null)
|
|
365
|
-
return [undefined, undefined];
|
|
366
|
-
const finalValue = value !== null && value !== void 0 ? value : entryValue;
|
|
367
|
-
return [this._createNode(key, finalValue, 'BLACK', count), finalValue];
|
|
368
|
-
}
|
|
369
|
-
return [this._createNode(keyNodeOrEntry, value, 'BLACK', count), value];
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* (Protected) Swap keys/values/counters between the source and destination nodes.
|
|
373
|
-
* @remarks Time O(1), Space O(1)
|
|
374
|
-
* @param srcNode - Source node (or key) whose properties will be moved.
|
|
375
|
-
* @param destNode - Destination node (or key) to receive properties.
|
|
376
|
-
* @returns Destination node after swap, or undefined.
|
|
377
|
-
*/
|
|
378
|
-
_swapProperties(srcNode, destNode) {
|
|
379
|
-
srcNode = this.ensureNode(srcNode);
|
|
380
|
-
destNode = this.ensureNode(destNode);
|
|
381
|
-
if (srcNode && destNode) {
|
|
382
|
-
const { key, value, count, color } = destNode;
|
|
383
|
-
const tempNode = this._createNode(key, value, color, count);
|
|
384
|
-
if (tempNode) {
|
|
385
|
-
tempNode.color = color;
|
|
386
|
-
destNode.key = srcNode.key;
|
|
387
|
-
if (!this._isMapMode)
|
|
388
|
-
destNode.value = srcNode.value;
|
|
389
|
-
destNode.count = srcNode.count;
|
|
390
|
-
destNode.color = srcNode.color;
|
|
391
|
-
srcNode.key = tempNode.key;
|
|
392
|
-
if (!this._isMapMode)
|
|
393
|
-
srcNode.value = tempNode.value;
|
|
394
|
-
srcNode.count = tempNode.count;
|
|
395
|
-
srcNode.color = tempNode.color;
|
|
396
|
-
}
|
|
397
|
-
return destNode;
|
|
398
|
-
}
|
|
399
|
-
return undefined;
|
|
400
|
-
}
|
|
401
|
-
/**
|
|
402
|
-
* (Protected) Replace one node by another and adjust counters accordingly.
|
|
403
|
-
* @remarks Time O(1), Space O(1)
|
|
404
|
-
* @param oldNode - Node being replaced.
|
|
405
|
-
* @param newNode - Replacement node.
|
|
406
|
-
* @returns The new node after replacement.
|
|
407
|
-
*/
|
|
408
|
-
_replaceNode(oldNode, newNode) {
|
|
409
|
-
newNode.count = oldNode.count + newNode.count;
|
|
410
|
-
return super._replaceNode(oldNode, newNode);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
exports.TreeCounter = TreeCounter;
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* data-structure-typed
|
|
3
|
-
*
|
|
4
|
-
* @author Pablo Zeng
|
|
5
|
-
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
|
-
* @license MIT License
|
|
7
|
-
*/
|
|
8
|
-
import type { ElemOf, EntryCallback, RedBlackTreeOptions, TreeMultiMapOptions } from '../../types';
|
|
9
|
-
import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
|
|
10
|
-
import { IBinaryTree } from '../../interfaces';
|
|
11
|
-
/**
|
|
12
|
-
* Node used by TreeMultiMap; stores the key with a bucket of values (array).
|
|
13
|
-
* @remarks Time O(1), Space O(1)
|
|
14
|
-
* @template K
|
|
15
|
-
* @template V
|
|
16
|
-
*/
|
|
17
|
-
export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode<K, V[]> {
|
|
18
|
-
parent?: TreeMultiMapNode<K, V>;
|
|
19
|
-
/**
|
|
20
|
-
* Create a TreeMultiMap node with an optional value bucket.
|
|
21
|
-
* @remarks Time O(1), Space O(1)
|
|
22
|
-
* @param key - Key of the node.
|
|
23
|
-
* @param [value] - Initial array of values.
|
|
24
|
-
* @returns New TreeMultiMapNode instance.
|
|
25
|
-
*/
|
|
26
|
-
constructor(key: K, value?: V[]);
|
|
27
|
-
_left?: TreeMultiMapNode<K, V> | null | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Get the left child pointer.
|
|
30
|
-
* @remarks Time O(1), Space O(1)
|
|
31
|
-
* @returns Left child node, or null/undefined.
|
|
32
|
-
*/
|
|
33
|
-
get left(): TreeMultiMapNode<K, V> | null | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Set the left child and update its parent pointer.
|
|
36
|
-
* @remarks Time O(1), Space O(1)
|
|
37
|
-
* @param v - New left child node, or null/undefined.
|
|
38
|
-
* @returns void
|
|
39
|
-
*/
|
|
40
|
-
set left(v: TreeMultiMapNode<K, V> | null | undefined);
|
|
41
|
-
_right?: TreeMultiMapNode<K, V> | null | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Get the right child pointer.
|
|
44
|
-
* @remarks Time O(1), Space O(1)
|
|
45
|
-
* @returns Right child node, or null/undefined.
|
|
46
|
-
*/
|
|
47
|
-
get right(): TreeMultiMapNode<K, V> | null | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Set the right child and update its parent pointer.
|
|
50
|
-
* @remarks Time O(1), Space O(1)
|
|
51
|
-
* @param v - New right child node, or null/undefined.
|
|
52
|
-
* @returns void
|
|
53
|
-
*/
|
|
54
|
-
set right(v: TreeMultiMapNode<K, V> | null | undefined);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Red-Black Tree–based multimap (key → array of values). Preserves O(log N) updates and supports map-like mode.
|
|
58
|
-
* @remarks Time O(1), Space O(1)
|
|
59
|
-
* @template K
|
|
60
|
-
* @template V
|
|
61
|
-
* @template R
|
|
62
|
-
* @example
|
|
63
|
-
* // players ranked by score with their equipment
|
|
64
|
-
* type Equipment = {
|
|
65
|
-
* name: string; // Equipment name
|
|
66
|
-
* quality: 'legendary' | 'epic' | 'rare' | 'common';
|
|
67
|
-
* level: number;
|
|
68
|
-
* };
|
|
69
|
-
*
|
|
70
|
-
* type Player = {
|
|
71
|
-
* name: string;
|
|
72
|
-
* score: number;
|
|
73
|
-
* equipments: Equipment[];
|
|
74
|
-
* };
|
|
75
|
-
*
|
|
76
|
-
* // Mock player data with their scores and equipment
|
|
77
|
-
* const players: Player[] = [
|
|
78
|
-
* {
|
|
79
|
-
* name: 'DragonSlayer',
|
|
80
|
-
* score: 8750,
|
|
81
|
-
* equipments: [
|
|
82
|
-
* { name: 'AWM', quality: 'legendary', level: 85 },
|
|
83
|
-
* { name: 'Level 3 Helmet', quality: 'epic', level: 80 },
|
|
84
|
-
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 75 },
|
|
85
|
-
* { name: 'Compensator', quality: 'epic', level: 78 },
|
|
86
|
-
* { name: 'Vertical Grip', quality: 'rare', level: 72 }
|
|
87
|
-
* ]
|
|
88
|
-
* },
|
|
89
|
-
* {
|
|
90
|
-
* name: 'ShadowNinja',
|
|
91
|
-
* score: 7200,
|
|
92
|
-
* equipments: [
|
|
93
|
-
* { name: 'M416', quality: 'epic', level: 75 },
|
|
94
|
-
* { name: 'Ghillie Suit', quality: 'rare', level: 70 },
|
|
95
|
-
* { name: 'Red Dot Sight', quality: 'common', level: 65 },
|
|
96
|
-
* { name: 'Extended QuickDraw Mag', quality: 'rare', level: 68 }
|
|
97
|
-
* ]
|
|
98
|
-
* },
|
|
99
|
-
* {
|
|
100
|
-
* name: 'RuneMaster',
|
|
101
|
-
* score: 9100,
|
|
102
|
-
* equipments: [
|
|
103
|
-
* { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
104
|
-
* { name: 'Level 3 Vest', quality: 'legendary', level: 85 },
|
|
105
|
-
* { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
106
|
-
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
107
|
-
* { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
108
|
-
* ]
|
|
109
|
-
* },
|
|
110
|
-
* {
|
|
111
|
-
* name: 'BattleKing',
|
|
112
|
-
* score: 8500,
|
|
113
|
-
* equipments: [
|
|
114
|
-
* { name: 'AUG', quality: 'epic', level: 82 },
|
|
115
|
-
* { name: 'Red Dot Sight', quality: 'rare', level: 75 },
|
|
116
|
-
* { name: 'Extended Mag', quality: 'common', level: 70 },
|
|
117
|
-
* { name: 'Tactical Stock', quality: 'rare', level: 76 }
|
|
118
|
-
* ]
|
|
119
|
-
* },
|
|
120
|
-
* {
|
|
121
|
-
* name: 'SniperElite',
|
|
122
|
-
* score: 7800,
|
|
123
|
-
* equipments: [
|
|
124
|
-
* { name: 'M24', quality: 'legendary', level: 88 },
|
|
125
|
-
* { name: 'Compensator', quality: 'epic', level: 80 },
|
|
126
|
-
* { name: 'Scope 8x', quality: 'legendary', level: 85 },
|
|
127
|
-
* { name: 'Level 2 Helmet', quality: 'rare', level: 75 }
|
|
128
|
-
* ]
|
|
129
|
-
* },
|
|
130
|
-
* {
|
|
131
|
-
* name: 'RushMaster',
|
|
132
|
-
* score: 7500,
|
|
133
|
-
* equipments: [
|
|
134
|
-
* { name: 'Vector', quality: 'rare', level: 72 },
|
|
135
|
-
* { name: 'Level 2 Helmet', quality: 'common', level: 65 },
|
|
136
|
-
* { name: 'Quickdraw Mag', quality: 'common', level: 60 },
|
|
137
|
-
* { name: 'Laser Sight', quality: 'rare', level: 68 }
|
|
138
|
-
* ]
|
|
139
|
-
* },
|
|
140
|
-
* {
|
|
141
|
-
* name: 'GhostWarrior',
|
|
142
|
-
* score: 8200,
|
|
143
|
-
* equipments: [
|
|
144
|
-
* { name: 'SCAR-L', quality: 'epic', level: 78 },
|
|
145
|
-
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 70 },
|
|
146
|
-
* { name: 'Holographic Sight', quality: 'epic', level: 75 },
|
|
147
|
-
* { name: 'Suppressor', quality: 'rare', level: 72 },
|
|
148
|
-
* { name: 'Vertical Grip', quality: 'common', level: 65 }
|
|
149
|
-
* ]
|
|
150
|
-
* },
|
|
151
|
-
* {
|
|
152
|
-
* name: 'DeathDealer',
|
|
153
|
-
* score: 7300,
|
|
154
|
-
* equipments: [
|
|
155
|
-
* { name: 'SKS', quality: 'epic', level: 76 },
|
|
156
|
-
* { name: 'Holographic Sight', quality: 'rare', level: 68 },
|
|
157
|
-
* { name: 'Extended Mag', quality: 'common', level: 65 }
|
|
158
|
-
* ]
|
|
159
|
-
* },
|
|
160
|
-
* {
|
|
161
|
-
* name: 'StormRider',
|
|
162
|
-
* score: 8900,
|
|
163
|
-
* equipments: [
|
|
164
|
-
* { name: 'MK14', quality: 'legendary', level: 92 },
|
|
165
|
-
* { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
166
|
-
* { name: 'Scope 8x', quality: 'epic', level: 80 },
|
|
167
|
-
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
168
|
-
* { name: 'Tactical Stock', quality: 'rare', level: 75 }
|
|
169
|
-
* ]
|
|
170
|
-
* },
|
|
171
|
-
* {
|
|
172
|
-
* name: 'CombatLegend',
|
|
173
|
-
* score: 7600,
|
|
174
|
-
* equipments: [
|
|
175
|
-
* { name: 'UMP45', quality: 'rare', level: 74 },
|
|
176
|
-
* { name: 'Level 2 Vest', quality: 'common', level: 67 },
|
|
177
|
-
* { name: 'Red Dot Sight', quality: 'common', level: 62 },
|
|
178
|
-
* { name: 'Extended Mag', quality: 'rare', level: 70 }
|
|
179
|
-
* ]
|
|
180
|
-
* }
|
|
181
|
-
* ];
|
|
182
|
-
*
|
|
183
|
-
* // Create a TreeMultiMap for player rankings
|
|
184
|
-
* const playerRankings = new TreeMultiMap<number, Equipment, Player>(players, {
|
|
185
|
-
* toEntryFn: ({ score, equipments }) => [score, equipments],
|
|
186
|
-
* isMapMode: false
|
|
187
|
-
* });
|
|
188
|
-
*
|
|
189
|
-
* const topPlayersEquipments = playerRankings.rangeSearch([8900, 10000], node => playerRankings.get(node));
|
|
190
|
-
* console.log(topPlayersEquipments); // [
|
|
191
|
-
* // [
|
|
192
|
-
* // {
|
|
193
|
-
* // name: 'MK14',
|
|
194
|
-
* // quality: 'legendary',
|
|
195
|
-
* // level: 92
|
|
196
|
-
* // },
|
|
197
|
-
* // { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
198
|
-
* // {
|
|
199
|
-
* // name: 'Scope 8x',
|
|
200
|
-
* // quality: 'epic',
|
|
201
|
-
* // level: 80
|
|
202
|
-
* // },
|
|
203
|
-
* // { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
204
|
-
* // {
|
|
205
|
-
* // name: 'Tactical Stock',
|
|
206
|
-
* // quality: 'rare',
|
|
207
|
-
* // level: 75
|
|
208
|
-
* // }
|
|
209
|
-
* // ],
|
|
210
|
-
* // [
|
|
211
|
-
* // { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
212
|
-
* // {
|
|
213
|
-
* // name: 'Level 3 Vest',
|
|
214
|
-
* // quality: 'legendary',
|
|
215
|
-
* // level: 85
|
|
216
|
-
* // },
|
|
217
|
-
* // { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
218
|
-
* // {
|
|
219
|
-
* // name: 'Suppressor',
|
|
220
|
-
* // quality: 'legendary',
|
|
221
|
-
* // level: 88
|
|
222
|
-
* // },
|
|
223
|
-
* // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
224
|
-
* // ]
|
|
225
|
-
* // ]
|
|
226
|
-
*/
|
|
227
|
-
export declare class TreeMultiMap<K = any, V = any, R extends object = object> extends RedBlackTree<K, V[], R> implements IBinaryTree<K, V[], R> {
|
|
228
|
-
/**
|
|
229
|
-
* Create a TreeMultiMap and optionally bulk-insert items.
|
|
230
|
-
* @remarks Time O(N log N), Space O(N)
|
|
231
|
-
* @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
|
|
232
|
-
* @param [options] - Options for TreeMultiMap (comparator, reverse, map mode).
|
|
233
|
-
* @returns New TreeMultiMap instance.
|
|
234
|
-
*/
|
|
235
|
-
constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | R>, options?: TreeMultiMapOptions<K, V[], R>);
|
|
236
|
-
_createNode(key: K, value?: V[]): TreeMultiMapNode<K, V>;
|
|
237
|
-
add(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
|
|
238
|
-
add(key: K, value: V): boolean;
|
|
239
|
-
/**
|
|
240
|
-
* Delete a single value from the bucket at a given key. Removes the key if the bucket becomes empty.
|
|
241
|
-
* @remarks Time O(log N), Space O(1)
|
|
242
|
-
* @param keyNodeOrEntry - Key, node, or [key, values] entry to locate the bucket.
|
|
243
|
-
* @param value - Value to remove from the bucket.
|
|
244
|
-
* @returns True if the value was removed; false if not found.
|
|
245
|
-
*/
|
|
246
|
-
deleteValue(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined, value: V): boolean;
|
|
247
|
-
map<MK = K, MVArr extends unknown[] = V[], MR extends object = object>(callback: EntryCallback<K, V[] | undefined, [MK, MVArr]>, options?: Partial<RedBlackTreeOptions<MK, MVArr, MR>>, thisArg?: unknown): TreeMultiMap<MK, ElemOf<MVArr>, MR>;
|
|
248
|
-
map<MK = K, MV = V[], MR extends object = object>(callback: EntryCallback<K, V[] | undefined, [MK, MV]>, options?: Partial<RedBlackTreeOptions<MK, MV, MR>>, thisArg?: unknown): RedBlackTree<MK, MV, MR>;
|
|
249
|
-
/**
|
|
250
|
-
* (Protected) Create an empty instance of the same concrete class.
|
|
251
|
-
* @remarks Time O(1), Space O(1)
|
|
252
|
-
* @template TK
|
|
253
|
-
* @template TV
|
|
254
|
-
* @template TR
|
|
255
|
-
* @param [options] - Optional constructor options for the like-kind instance.
|
|
256
|
-
* @returns An empty like-kind instance.
|
|
257
|
-
*/
|
|
258
|
-
protected _createInstance<TK = K, TV = V, TR extends object = R>(options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): this;
|
|
259
|
-
/**
|
|
260
|
-
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
261
|
-
* @remarks Time O(N log N), Space O(N)
|
|
262
|
-
* @template TK
|
|
263
|
-
* @template TV
|
|
264
|
-
* @template TR
|
|
265
|
-
* @param iter - Iterable used to seed the new tree.
|
|
266
|
-
* @param [options] - Options merged with the current snapshot.
|
|
267
|
-
* @returns A like-kind RedBlackTree built from the iterable.
|
|
268
|
-
*/
|
|
269
|
-
protected _createLike<TK = K, TV = V, TR extends object = R>(iter?: Iterable<TK | RedBlackTreeNode<TK, TV> | [TK | null | undefined, TV | undefined] | null | undefined | TR>, options?: Partial<RedBlackTreeOptions<TK, TV, TR>>): RedBlackTree<TK, TV, TR>;
|
|
270
|
-
}
|