directed-graph-typed 2.1.1 → 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 +2798 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +2789 -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 +1 -1
- 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/directed-graph-typed.js +2791 -0
- package/dist/umd/directed-graph-typed.js.map +1 -0
- package/dist/umd/directed-graph-typed.min.js +9 -0
- package/dist/umd/directed-graph-typed.min.js.map +1 -0
- package/package.json +25 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +4 -4
- package/src/data-structures/binary-tree/bst.ts +1 -1
- package/src/data-structures/binary-tree/red-black-tree.ts +2 -2
- package/src/data-structures/binary-tree/tree-counter.ts +4 -4
- package/src/data-structures/binary-tree/tree-multi-map.ts +1 -1
- 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 +1 -1
- 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,384 +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.TreeMultiMap = exports.TreeMultiMapNode = void 0;
|
|
11
|
-
const red_black_tree_1 = require("./red-black-tree");
|
|
12
|
-
/**
|
|
13
|
-
* Node used by TreeMultiMap; stores the key with a bucket of values (array).
|
|
14
|
-
* @remarks Time O(1), Space O(1)
|
|
15
|
-
* @template K
|
|
16
|
-
* @template V
|
|
17
|
-
*/
|
|
18
|
-
class TreeMultiMapNode extends red_black_tree_1.RedBlackTreeNode {
|
|
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, value) {
|
|
27
|
-
super(key, value);
|
|
28
|
-
this.parent = undefined;
|
|
29
|
-
this._left = undefined;
|
|
30
|
-
this._right = undefined;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Get the left child pointer.
|
|
34
|
-
* @remarks Time O(1), Space O(1)
|
|
35
|
-
* @returns Left child node, or null/undefined.
|
|
36
|
-
*/
|
|
37
|
-
get left() {
|
|
38
|
-
return this._left;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Set the left child and update its parent pointer.
|
|
42
|
-
* @remarks Time O(1), Space O(1)
|
|
43
|
-
* @param v - New left child node, or null/undefined.
|
|
44
|
-
* @returns void
|
|
45
|
-
*/
|
|
46
|
-
set left(v) {
|
|
47
|
-
if (v) {
|
|
48
|
-
v.parent = this;
|
|
49
|
-
}
|
|
50
|
-
this._left = v;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Get the right child pointer.
|
|
54
|
-
* @remarks Time O(1), Space O(1)
|
|
55
|
-
* @returns Right child node, or null/undefined.
|
|
56
|
-
*/
|
|
57
|
-
get right() {
|
|
58
|
-
return this._right;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Set the right child and update its parent pointer.
|
|
62
|
-
* @remarks Time O(1), Space O(1)
|
|
63
|
-
* @param v - New right child node, or null/undefined.
|
|
64
|
-
* @returns void
|
|
65
|
-
*/
|
|
66
|
-
set right(v) {
|
|
67
|
-
if (v) {
|
|
68
|
-
v.parent = this;
|
|
69
|
-
}
|
|
70
|
-
this._right = v;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.TreeMultiMapNode = TreeMultiMapNode;
|
|
74
|
-
/**
|
|
75
|
-
* Red-Black Tree–based multimap (key → array of values). Preserves O(log N) updates and supports map-like mode.
|
|
76
|
-
* @remarks Time O(1), Space O(1)
|
|
77
|
-
* @template K
|
|
78
|
-
* @template V
|
|
79
|
-
* @template R
|
|
80
|
-
* @example
|
|
81
|
-
* // players ranked by score with their equipment
|
|
82
|
-
* type Equipment = {
|
|
83
|
-
* name: string; // Equipment name
|
|
84
|
-
* quality: 'legendary' | 'epic' | 'rare' | 'common';
|
|
85
|
-
* level: number;
|
|
86
|
-
* };
|
|
87
|
-
*
|
|
88
|
-
* type Player = {
|
|
89
|
-
* name: string;
|
|
90
|
-
* score: number;
|
|
91
|
-
* equipments: Equipment[];
|
|
92
|
-
* };
|
|
93
|
-
*
|
|
94
|
-
* // Mock player data with their scores and equipment
|
|
95
|
-
* const players: Player[] = [
|
|
96
|
-
* {
|
|
97
|
-
* name: 'DragonSlayer',
|
|
98
|
-
* score: 8750,
|
|
99
|
-
* equipments: [
|
|
100
|
-
* { name: 'AWM', quality: 'legendary', level: 85 },
|
|
101
|
-
* { name: 'Level 3 Helmet', quality: 'epic', level: 80 },
|
|
102
|
-
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 75 },
|
|
103
|
-
* { name: 'Compensator', quality: 'epic', level: 78 },
|
|
104
|
-
* { name: 'Vertical Grip', quality: 'rare', level: 72 }
|
|
105
|
-
* ]
|
|
106
|
-
* },
|
|
107
|
-
* {
|
|
108
|
-
* name: 'ShadowNinja',
|
|
109
|
-
* score: 7200,
|
|
110
|
-
* equipments: [
|
|
111
|
-
* { name: 'M416', quality: 'epic', level: 75 },
|
|
112
|
-
* { name: 'Ghillie Suit', quality: 'rare', level: 70 },
|
|
113
|
-
* { name: 'Red Dot Sight', quality: 'common', level: 65 },
|
|
114
|
-
* { name: 'Extended QuickDraw Mag', quality: 'rare', level: 68 }
|
|
115
|
-
* ]
|
|
116
|
-
* },
|
|
117
|
-
* {
|
|
118
|
-
* name: 'RuneMaster',
|
|
119
|
-
* score: 9100,
|
|
120
|
-
* equipments: [
|
|
121
|
-
* { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
122
|
-
* { name: 'Level 3 Vest', quality: 'legendary', level: 85 },
|
|
123
|
-
* { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
124
|
-
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
125
|
-
* { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
126
|
-
* ]
|
|
127
|
-
* },
|
|
128
|
-
* {
|
|
129
|
-
* name: 'BattleKing',
|
|
130
|
-
* score: 8500,
|
|
131
|
-
* equipments: [
|
|
132
|
-
* { name: 'AUG', quality: 'epic', level: 82 },
|
|
133
|
-
* { name: 'Red Dot Sight', quality: 'rare', level: 75 },
|
|
134
|
-
* { name: 'Extended Mag', quality: 'common', level: 70 },
|
|
135
|
-
* { name: 'Tactical Stock', quality: 'rare', level: 76 }
|
|
136
|
-
* ]
|
|
137
|
-
* },
|
|
138
|
-
* {
|
|
139
|
-
* name: 'SniperElite',
|
|
140
|
-
* score: 7800,
|
|
141
|
-
* equipments: [
|
|
142
|
-
* { name: 'M24', quality: 'legendary', level: 88 },
|
|
143
|
-
* { name: 'Compensator', quality: 'epic', level: 80 },
|
|
144
|
-
* { name: 'Scope 8x', quality: 'legendary', level: 85 },
|
|
145
|
-
* { name: 'Level 2 Helmet', quality: 'rare', level: 75 }
|
|
146
|
-
* ]
|
|
147
|
-
* },
|
|
148
|
-
* {
|
|
149
|
-
* name: 'RushMaster',
|
|
150
|
-
* score: 7500,
|
|
151
|
-
* equipments: [
|
|
152
|
-
* { name: 'Vector', quality: 'rare', level: 72 },
|
|
153
|
-
* { name: 'Level 2 Helmet', quality: 'common', level: 65 },
|
|
154
|
-
* { name: 'Quickdraw Mag', quality: 'common', level: 60 },
|
|
155
|
-
* { name: 'Laser Sight', quality: 'rare', level: 68 }
|
|
156
|
-
* ]
|
|
157
|
-
* },
|
|
158
|
-
* {
|
|
159
|
-
* name: 'GhostWarrior',
|
|
160
|
-
* score: 8200,
|
|
161
|
-
* equipments: [
|
|
162
|
-
* { name: 'SCAR-L', quality: 'epic', level: 78 },
|
|
163
|
-
* { name: 'Extended Quickdraw Mag', quality: 'rare', level: 70 },
|
|
164
|
-
* { name: 'Holographic Sight', quality: 'epic', level: 75 },
|
|
165
|
-
* { name: 'Suppressor', quality: 'rare', level: 72 },
|
|
166
|
-
* { name: 'Vertical Grip', quality: 'common', level: 65 }
|
|
167
|
-
* ]
|
|
168
|
-
* },
|
|
169
|
-
* {
|
|
170
|
-
* name: 'DeathDealer',
|
|
171
|
-
* score: 7300,
|
|
172
|
-
* equipments: [
|
|
173
|
-
* { name: 'SKS', quality: 'epic', level: 76 },
|
|
174
|
-
* { name: 'Holographic Sight', quality: 'rare', level: 68 },
|
|
175
|
-
* { name: 'Extended Mag', quality: 'common', level: 65 }
|
|
176
|
-
* ]
|
|
177
|
-
* },
|
|
178
|
-
* {
|
|
179
|
-
* name: 'StormRider',
|
|
180
|
-
* score: 8900,
|
|
181
|
-
* equipments: [
|
|
182
|
-
* { name: 'MK14', quality: 'legendary', level: 92 },
|
|
183
|
-
* { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
184
|
-
* { name: 'Scope 8x', quality: 'epic', level: 80 },
|
|
185
|
-
* { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
186
|
-
* { name: 'Tactical Stock', quality: 'rare', level: 75 }
|
|
187
|
-
* ]
|
|
188
|
-
* },
|
|
189
|
-
* {
|
|
190
|
-
* name: 'CombatLegend',
|
|
191
|
-
* score: 7600,
|
|
192
|
-
* equipments: [
|
|
193
|
-
* { name: 'UMP45', quality: 'rare', level: 74 },
|
|
194
|
-
* { name: 'Level 2 Vest', quality: 'common', level: 67 },
|
|
195
|
-
* { name: 'Red Dot Sight', quality: 'common', level: 62 },
|
|
196
|
-
* { name: 'Extended Mag', quality: 'rare', level: 70 }
|
|
197
|
-
* ]
|
|
198
|
-
* }
|
|
199
|
-
* ];
|
|
200
|
-
*
|
|
201
|
-
* // Create a TreeMultiMap for player rankings
|
|
202
|
-
* const playerRankings = new TreeMultiMap<number, Equipment, Player>(players, {
|
|
203
|
-
* toEntryFn: ({ score, equipments }) => [score, equipments],
|
|
204
|
-
* isMapMode: false
|
|
205
|
-
* });
|
|
206
|
-
*
|
|
207
|
-
* const topPlayersEquipments = playerRankings.rangeSearch([8900, 10000], node => playerRankings.get(node));
|
|
208
|
-
* console.log(topPlayersEquipments); // [
|
|
209
|
-
* // [
|
|
210
|
-
* // {
|
|
211
|
-
* // name: 'MK14',
|
|
212
|
-
* // quality: 'legendary',
|
|
213
|
-
* // level: 92
|
|
214
|
-
* // },
|
|
215
|
-
* // { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
|
|
216
|
-
* // {
|
|
217
|
-
* // name: 'Scope 8x',
|
|
218
|
-
* // quality: 'epic',
|
|
219
|
-
* // level: 80
|
|
220
|
-
* // },
|
|
221
|
-
* // { name: 'Suppressor', quality: 'legendary', level: 88 },
|
|
222
|
-
* // {
|
|
223
|
-
* // name: 'Tactical Stock',
|
|
224
|
-
* // quality: 'rare',
|
|
225
|
-
* // level: 75
|
|
226
|
-
* // }
|
|
227
|
-
* // ],
|
|
228
|
-
* // [
|
|
229
|
-
* // { name: 'KAR98K', quality: 'legendary', level: 90 },
|
|
230
|
-
* // {
|
|
231
|
-
* // name: 'Level 3 Vest',
|
|
232
|
-
* // quality: 'legendary',
|
|
233
|
-
* // level: 85
|
|
234
|
-
* // },
|
|
235
|
-
* // { name: 'Holographic Sight', quality: 'epic', level: 82 },
|
|
236
|
-
* // {
|
|
237
|
-
* // name: 'Suppressor',
|
|
238
|
-
* // quality: 'legendary',
|
|
239
|
-
* // level: 88
|
|
240
|
-
* // },
|
|
241
|
-
* // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
|
|
242
|
-
* // ]
|
|
243
|
-
* // ]
|
|
244
|
-
*/
|
|
245
|
-
class TreeMultiMap extends red_black_tree_1.RedBlackTree {
|
|
246
|
-
/**
|
|
247
|
-
* Create a TreeMultiMap and optionally bulk-insert items.
|
|
248
|
-
* @remarks Time O(N log N), Space O(N)
|
|
249
|
-
* @param [keysNodesEntriesOrRaws] - Iterable of keys/nodes/entries/raw items to insert.
|
|
250
|
-
* @param [options] - Options for TreeMultiMap (comparator, reverse, map mode).
|
|
251
|
-
* @returns New TreeMultiMap instance.
|
|
252
|
-
*/
|
|
253
|
-
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
254
|
-
super([], Object.assign({}, options));
|
|
255
|
-
if (keysNodesEntriesOrRaws) {
|
|
256
|
-
this.addMany(keysNodesEntriesOrRaws);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
_createNode(key, value = []) {
|
|
260
|
-
return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Insert a value or a list of values into the multimap. If the key exists, values are appended.
|
|
264
|
-
* @remarks Time O(log N + M), Space O(1)
|
|
265
|
-
* @param keyNodeOrEntry - Key, node, or [key, values] entry.
|
|
266
|
-
* @param [value] - Single value to add when a bare key is provided.
|
|
267
|
-
* @returns True if inserted or appended; false if ignored.
|
|
268
|
-
*/
|
|
269
|
-
add(keyNodeOrEntry, value) {
|
|
270
|
-
if (this.isRealNode(keyNodeOrEntry))
|
|
271
|
-
return super.add(keyNodeOrEntry);
|
|
272
|
-
const _commonAdd = (key, values) => {
|
|
273
|
-
if (key === undefined || key === null)
|
|
274
|
-
return false;
|
|
275
|
-
const _addToValues = () => {
|
|
276
|
-
const existingValues = this.get(key);
|
|
277
|
-
if (existingValues !== undefined && values !== undefined) {
|
|
278
|
-
for (const value of values)
|
|
279
|
-
existingValues.push(value);
|
|
280
|
-
return true;
|
|
281
|
-
}
|
|
282
|
-
return false;
|
|
283
|
-
};
|
|
284
|
-
const _addByNode = () => {
|
|
285
|
-
const existingNode = this.getNode(key);
|
|
286
|
-
if (this.isRealNode(existingNode)) {
|
|
287
|
-
const existingValues = this.get(existingNode);
|
|
288
|
-
if (existingValues === undefined) {
|
|
289
|
-
super.add(key, values);
|
|
290
|
-
return true;
|
|
291
|
-
}
|
|
292
|
-
if (values !== undefined) {
|
|
293
|
-
for (const value of values)
|
|
294
|
-
existingValues.push(value);
|
|
295
|
-
return true;
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
return false;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
return super.add(key, values);
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
if (this._isMapMode) {
|
|
306
|
-
return _addByNode() || _addToValues();
|
|
307
|
-
}
|
|
308
|
-
return _addToValues() || _addByNode();
|
|
309
|
-
};
|
|
310
|
-
if (this.isEntry(keyNodeOrEntry)) {
|
|
311
|
-
const [key, values] = keyNodeOrEntry;
|
|
312
|
-
return _commonAdd(key, value !== undefined ? [value] : values);
|
|
313
|
-
}
|
|
314
|
-
return _commonAdd(keyNodeOrEntry, value !== undefined ? [value] : undefined);
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Delete a single value from the bucket at a given key. Removes the key if the bucket becomes empty.
|
|
318
|
-
* @remarks Time O(log N), Space O(1)
|
|
319
|
-
* @param keyNodeOrEntry - Key, node, or [key, values] entry to locate the bucket.
|
|
320
|
-
* @param value - Value to remove from the bucket.
|
|
321
|
-
* @returns True if the value was removed; false if not found.
|
|
322
|
-
*/
|
|
323
|
-
deleteValue(keyNodeOrEntry, value) {
|
|
324
|
-
const values = this.get(keyNodeOrEntry);
|
|
325
|
-
if (Array.isArray(values)) {
|
|
326
|
-
const index = values.indexOf(value);
|
|
327
|
-
if (index === -1)
|
|
328
|
-
return false;
|
|
329
|
-
values.splice(index, 1);
|
|
330
|
-
if (values.length === 0)
|
|
331
|
-
this.delete(keyNodeOrEntry);
|
|
332
|
-
return true;
|
|
333
|
-
}
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
/**
|
|
337
|
-
* Create a new tree by mapping each [key, values] bucket.
|
|
338
|
-
* @remarks Time O(N log N), Space O(N)
|
|
339
|
-
* @template MK
|
|
340
|
-
* @template MV
|
|
341
|
-
* @template MR
|
|
342
|
-
* @param callback - Function mapping (key, values, index, tree) → [newKey, newValue].
|
|
343
|
-
* @param [options] - Options for the output tree.
|
|
344
|
-
* @param [thisArg] - Value for `this` inside the callback.
|
|
345
|
-
* @returns A new RedBlackTree (or TreeMultiMap when mapping to array values; see overloads).
|
|
346
|
-
*/
|
|
347
|
-
map(callback, options, thisArg) {
|
|
348
|
-
const out = this._createLike([], options);
|
|
349
|
-
let i = 0;
|
|
350
|
-
for (const [k, v] of this)
|
|
351
|
-
out.add(callback.call(thisArg, k, v, i++, this));
|
|
352
|
-
return out;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* (Protected) Create an empty instance of the same concrete class.
|
|
356
|
-
* @remarks Time O(1), Space O(1)
|
|
357
|
-
* @template TK
|
|
358
|
-
* @template TV
|
|
359
|
-
* @template TR
|
|
360
|
-
* @param [options] - Optional constructor options for the like-kind instance.
|
|
361
|
-
* @returns An empty like-kind instance.
|
|
362
|
-
*/
|
|
363
|
-
_createInstance(options) {
|
|
364
|
-
var _a, _b;
|
|
365
|
-
const Ctor = this.constructor;
|
|
366
|
-
return new Ctor([], Object.assign(Object.assign({}, ((_b = (_a = this._snapshotOptions) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : {})), (options !== null && options !== void 0 ? options : {})));
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* (Protected) Create a like-kind instance and seed it from an iterable.
|
|
370
|
-
* @remarks Time O(N log N), Space O(N)
|
|
371
|
-
* @template TK
|
|
372
|
-
* @template TV
|
|
373
|
-
* @template TR
|
|
374
|
-
* @param iter - Iterable used to seed the new tree.
|
|
375
|
-
* @param [options] - Options merged with the current snapshot.
|
|
376
|
-
* @returns A like-kind RedBlackTree built from the iterable.
|
|
377
|
-
*/
|
|
378
|
-
_createLike(iter = [], options) {
|
|
379
|
-
var _a, _b;
|
|
380
|
-
const Ctor = this.constructor;
|
|
381
|
-
return new Ctor(iter, Object.assign(Object.assign({}, ((_b = (_a = this._snapshotOptions) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : {})), (options !== null && options !== void 0 ? options : {})));
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
exports.TreeMultiMap = TreeMultiMap;
|