data-structure-typed 2.5.1 → 2.5.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/CHANGELOG.md +3 -1
- package/README.md +75 -17
- package/dist/cjs/binary-tree.cjs +2723 -139
- package/dist/cjs/graph.cjs +192 -6
- package/dist/cjs/hash.cjs +63 -15
- package/dist/cjs/heap.cjs +93 -31
- package/dist/cjs/index.cjs +3514 -379
- package/dist/cjs/linked-list.cjs +237 -31
- package/dist/cjs/matrix.cjs +47 -9
- package/dist/cjs/priority-queue.cjs +92 -30
- package/dist/cjs/queue.cjs +176 -2
- package/dist/cjs/stack.cjs +48 -2
- package/dist/cjs/trie.cjs +78 -28
- package/dist/cjs-legacy/binary-tree.cjs +2725 -136
- package/dist/cjs-legacy/graph.cjs +192 -6
- package/dist/cjs-legacy/hash.cjs +63 -15
- package/dist/cjs-legacy/heap.cjs +93 -31
- package/dist/cjs-legacy/index.cjs +3389 -249
- package/dist/cjs-legacy/linked-list.cjs +237 -31
- package/dist/cjs-legacy/matrix.cjs +47 -9
- package/dist/cjs-legacy/priority-queue.cjs +92 -30
- package/dist/cjs-legacy/queue.cjs +176 -2
- package/dist/cjs-legacy/stack.cjs +48 -2
- package/dist/cjs-legacy/trie.cjs +78 -28
- package/dist/esm/binary-tree.mjs +2723 -139
- package/dist/esm/graph.mjs +192 -6
- package/dist/esm/hash.mjs +63 -15
- package/dist/esm/heap.mjs +93 -31
- package/dist/esm/index.mjs +3514 -380
- package/dist/esm/linked-list.mjs +237 -31
- package/dist/esm/matrix.mjs +47 -9
- package/dist/esm/priority-queue.mjs +92 -30
- package/dist/esm/queue.mjs +176 -2
- package/dist/esm/stack.mjs +48 -2
- package/dist/esm/trie.mjs +78 -28
- package/dist/esm-legacy/binary-tree.mjs +2725 -136
- package/dist/esm-legacy/graph.mjs +192 -6
- package/dist/esm-legacy/hash.mjs +63 -15
- package/dist/esm-legacy/heap.mjs +93 -31
- package/dist/esm-legacy/index.mjs +3389 -250
- package/dist/esm-legacy/linked-list.mjs +237 -31
- package/dist/esm-legacy/matrix.mjs +47 -9
- package/dist/esm-legacy/priority-queue.mjs +92 -30
- package/dist/esm-legacy/queue.mjs +176 -2
- package/dist/esm-legacy/stack.mjs +48 -2
- package/dist/esm-legacy/trie.mjs +78 -28
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +48 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +102 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +195 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +76 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +528 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +531 -6
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +435 -6
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +505 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +44 -0
- package/dist/types/data-structures/heap/heap.d.ts +56 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +68 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +60 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
- package/dist/types/data-structures/queue/deque.d.ts +60 -0
- package/dist/types/data-structures/queue/queue.d.ts +48 -0
- package/dist/types/data-structures/stack/stack.d.ts +40 -0
- package/dist/types/data-structures/trie/trie.d.ts +48 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/umd/data-structure-typed.js +3404 -265
- package/dist/umd/data-structure-typed.min.js +5 -5
- package/docs-site-docusaurus/docs/api/classes/AVLTree.md +650 -136
- package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
- package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +71 -71
- package/docs-site-docusaurus/docs/api/classes/BST.md +591 -129
- package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
- package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +107 -107
- package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
- package/docs-site-docusaurus/docs/api/classes/Deque.md +82 -82
- package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +82 -82
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +74 -74
- package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
- package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
- package/docs-site-docusaurus/docs/api/classes/HashMap.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/Heap.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
- package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +33 -33
- package/docs-site-docusaurus/docs/api/classes/LinearBase.md +50 -50
- package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +55 -55
- package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +49 -49
- package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +78 -78
- package/docs-site-docusaurus/docs/api/classes/MapGraph.md +82 -82
- package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
- package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/MinHeap.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +45 -45
- package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
- package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +44 -44
- package/docs-site-docusaurus/docs/api/classes/Queue.md +60 -60
- package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +660 -146
- package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +78 -78
- package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
- package/docs-site-docusaurus/docs/api/classes/SkipList.md +44 -44
- package/docs-site-docusaurus/docs/api/classes/Stack.md +39 -39
- package/docs-site-docusaurus/docs/api/classes/TreeMap.md +165 -33
- package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +162 -46
- package/docs-site-docusaurus/docs/api/classes/TreeSet.md +161 -32
- package/docs-site-docusaurus/docs/api/classes/Trie.md +47 -47
- package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
- package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +81 -81
- package/docs-site-docusaurus/docs/guide/architecture.md +2 -0
- package/docs-site-docusaurus/docs/guide/concepts.md +32 -1
- package/docs-site-docusaurus/docs/guide/faq.md +180 -0
- package/docs-site-docusaurus/docs/guide/guides.md +40 -54
- package/docs-site-docusaurus/docs/guide/installation.md +2 -0
- package/docs-site-docusaurus/docs/guide/integrations.md +2 -0
- package/docs-site-docusaurus/docs/guide/overview.md +7 -0
- package/docs-site-docusaurus/docs/guide/performance.md +2 -0
- package/docs-site-docusaurus/docs/guide/quick-start.md +31 -0
- package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
- package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
- package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
- package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
- package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
- package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
- package/docs-site-docusaurus/docusaurus.config.ts +1 -1
- package/docs-site-docusaurus/src/pages/index.tsx +51 -2
- package/docs-site-docusaurus/static/llms.txt +37 -0
- package/llms.txt +37 -0
- package/package.json +64 -56
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/binary-tree/avl-tree.ts +47 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
- package/src/data-structures/binary-tree/binary-tree.ts +79 -4
- package/src/data-structures/binary-tree/bst.ts +441 -6
- package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
- package/src/data-structures/binary-tree/segment-tree.ts +18 -0
- package/src/data-structures/binary-tree/tree-map.ts +434 -9
- package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
- package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
- package/src/data-structures/binary-tree/tree-set.ts +410 -8
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/undirected-graph.ts +27 -0
- package/src/data-structures/hash/hash-map.ts +35 -4
- package/src/data-structures/heap/heap.ts +46 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
- package/src/data-structures/matrix/matrix.ts +33 -9
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +45 -0
- package/src/data-structures/queue/queue.ts +36 -0
- package/src/data-structures/stack/stack.ts +30 -0
- package/src/data-structures/trie/trie.ts +38 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
|
@@ -68,6 +68,55 @@ function makeTrampoline(fn) {
|
|
|
68
68
|
}
|
|
69
69
|
__name(makeTrampoline, "makeTrampoline");
|
|
70
70
|
|
|
71
|
+
// src/common/error.ts
|
|
72
|
+
function raise(ErrorClass, message) {
|
|
73
|
+
throw new ErrorClass(message);
|
|
74
|
+
}
|
|
75
|
+
__name(raise, "raise");
|
|
76
|
+
var ERR = {
|
|
77
|
+
// Range / index
|
|
78
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
79
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
80
|
+
// Type / argument
|
|
81
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
82
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
83
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
84
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
85
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
86
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
87
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
88
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
89
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
90
|
+
// State / operation
|
|
91
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
92
|
+
// Matrix
|
|
93
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
94
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
95
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
96
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
97
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
98
|
+
// Order statistic
|
|
99
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/common/index.ts
|
|
103
|
+
var _Range = class _Range {
|
|
104
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
105
|
+
this.low = low;
|
|
106
|
+
this.high = high;
|
|
107
|
+
this.includeLow = includeLow;
|
|
108
|
+
this.includeHigh = includeHigh;
|
|
109
|
+
}
|
|
110
|
+
// Determine whether a key is within the range
|
|
111
|
+
isInRange(key, comparator) {
|
|
112
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
113
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
114
|
+
return lowCheck && highCheck;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
__name(_Range, "Range");
|
|
118
|
+
var Range = _Range;
|
|
119
|
+
|
|
71
120
|
// src/data-structures/base/iterable-element-base.ts
|
|
72
121
|
var _IterableElementBase = class _IterableElementBase {
|
|
73
122
|
/**
|
|
@@ -90,7 +139,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
90
139
|
if (options) {
|
|
91
140
|
const { toElementFn } = options;
|
|
92
141
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
93
|
-
else if (toElementFn)
|
|
142
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
94
143
|
}
|
|
95
144
|
}
|
|
96
145
|
/**
|
|
@@ -246,7 +295,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
246
295
|
acc = initialValue;
|
|
247
296
|
} else {
|
|
248
297
|
const first = iter.next();
|
|
249
|
-
if (first.done)
|
|
298
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
250
299
|
acc = first.value;
|
|
251
300
|
index = 1;
|
|
252
301
|
}
|
|
@@ -482,49 +531,6 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
482
531
|
__name(_LinearBase, "LinearBase");
|
|
483
532
|
var LinearBase = _LinearBase;
|
|
484
533
|
|
|
485
|
-
// src/common/error.ts
|
|
486
|
-
var ERR = {
|
|
487
|
-
// Range / index
|
|
488
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
489
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
490
|
-
// Type / argument
|
|
491
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
492
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
493
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
494
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
495
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
496
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
497
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
498
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
499
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
500
|
-
// State / operation
|
|
501
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
502
|
-
// Matrix
|
|
503
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
504
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
505
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
506
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
507
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
// src/common/index.ts
|
|
511
|
-
var _Range = class _Range {
|
|
512
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
513
|
-
this.low = low;
|
|
514
|
-
this.high = high;
|
|
515
|
-
this.includeLow = includeLow;
|
|
516
|
-
this.includeHigh = includeHigh;
|
|
517
|
-
}
|
|
518
|
-
// Determine whether a key is within the range
|
|
519
|
-
isInRange(key, comparator) {
|
|
520
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
521
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
522
|
-
return lowCheck && highCheck;
|
|
523
|
-
}
|
|
524
|
-
};
|
|
525
|
-
__name(_Range, "Range");
|
|
526
|
-
var Range = _Range;
|
|
527
|
-
|
|
528
534
|
// src/data-structures/base/iterable-entry-base.ts
|
|
529
535
|
var _IterableEntryBase = class _IterableEntryBase {
|
|
530
536
|
/**
|
|
@@ -789,6 +795,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
789
795
|
|
|
790
796
|
|
|
791
797
|
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
792
802
|
|
|
793
803
|
|
|
794
804
|
|
|
@@ -835,6 +845,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
835
845
|
|
|
836
846
|
|
|
837
847
|
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
838
852
|
|
|
839
853
|
|
|
840
854
|
|
|
@@ -897,6 +911,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
897
911
|
|
|
898
912
|
|
|
899
913
|
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
900
918
|
|
|
901
919
|
|
|
902
920
|
|
|
@@ -955,6 +973,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
955
973
|
|
|
956
974
|
|
|
957
975
|
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
958
980
|
|
|
959
981
|
|
|
960
982
|
|
|
@@ -1020,6 +1042,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1020
1042
|
|
|
1021
1043
|
|
|
1022
1044
|
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
|
|
1023
1049
|
|
|
1024
1050
|
|
|
1025
1051
|
|
|
@@ -1075,6 +1101,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1075
1101
|
|
|
1076
1102
|
|
|
1077
1103
|
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
|
|
1078
1108
|
|
|
1079
1109
|
|
|
1080
1110
|
|
|
@@ -1123,6 +1153,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1123
1153
|
|
|
1124
1154
|
|
|
1125
1155
|
|
|
1156
|
+
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
|
|
1126
1160
|
|
|
1127
1161
|
|
|
1128
1162
|
|
|
@@ -1212,6 +1246,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1212
1246
|
|
|
1213
1247
|
|
|
1214
1248
|
|
|
1249
|
+
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
|
|
1215
1253
|
|
|
1216
1254
|
|
|
1217
1255
|
|
|
@@ -1254,6 +1292,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1254
1292
|
|
|
1255
1293
|
|
|
1256
1294
|
|
|
1295
|
+
|
|
1296
|
+
|
|
1297
|
+
|
|
1298
|
+
|
|
1257
1299
|
|
|
1258
1300
|
|
|
1259
1301
|
|
|
@@ -1319,6 +1361,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1319
1361
|
|
|
1320
1362
|
|
|
1321
1363
|
|
|
1364
|
+
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
|
|
1322
1368
|
|
|
1323
1369
|
|
|
1324
1370
|
|
|
@@ -1368,6 +1414,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1368
1414
|
|
|
1369
1415
|
|
|
1370
1416
|
|
|
1417
|
+
|
|
1418
|
+
|
|
1419
|
+
|
|
1420
|
+
|
|
1371
1421
|
|
|
1372
1422
|
|
|
1373
1423
|
|
|
@@ -1421,6 +1471,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1421
1471
|
|
|
1422
1472
|
|
|
1423
1473
|
|
|
1474
|
+
|
|
1475
|
+
|
|
1476
|
+
|
|
1477
|
+
|
|
1424
1478
|
|
|
1425
1479
|
|
|
1426
1480
|
|
|
@@ -1694,7 +1748,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1694
1748
|
if (isMapMode !== void 0) this._isMapMode = isMapMode;
|
|
1695
1749
|
if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
|
|
1696
1750
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1697
|
-
else if (toEntryFn)
|
|
1751
|
+
else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
|
|
1698
1752
|
}
|
|
1699
1753
|
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1700
1754
|
}
|
|
@@ -1925,6 +1979,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1925
1979
|
|
|
1926
1980
|
|
|
1927
1981
|
|
|
1982
|
+
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
|
|
1928
1986
|
|
|
1929
1987
|
|
|
1930
1988
|
|
|
@@ -1975,6 +2033,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1975
2033
|
|
|
1976
2034
|
|
|
1977
2035
|
|
|
2036
|
+
|
|
2037
|
+
|
|
2038
|
+
|
|
2039
|
+
|
|
1978
2040
|
|
|
1979
2041
|
|
|
1980
2042
|
|
|
@@ -2077,6 +2139,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2077
2139
|
|
|
2078
2140
|
|
|
2079
2141
|
|
|
2142
|
+
|
|
2143
|
+
|
|
2144
|
+
|
|
2145
|
+
|
|
2080
2146
|
|
|
2081
2147
|
|
|
2082
2148
|
|
|
@@ -2115,6 +2181,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2115
2181
|
|
|
2116
2182
|
|
|
2117
2183
|
|
|
2184
|
+
|
|
2185
|
+
|
|
2186
|
+
|
|
2187
|
+
|
|
2118
2188
|
|
|
2119
2189
|
|
|
2120
2190
|
|
|
@@ -2174,6 +2244,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2174
2244
|
|
|
2175
2245
|
|
|
2176
2246
|
|
|
2247
|
+
|
|
2248
|
+
|
|
2249
|
+
|
|
2250
|
+
|
|
2177
2251
|
|
|
2178
2252
|
|
|
2179
2253
|
|
|
@@ -2232,6 +2306,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2232
2306
|
|
|
2233
2307
|
|
|
2234
2308
|
|
|
2309
|
+
|
|
2310
|
+
|
|
2311
|
+
|
|
2312
|
+
|
|
2235
2313
|
|
|
2236
2314
|
|
|
2237
2315
|
|
|
@@ -2368,6 +2446,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2368
2446
|
|
|
2369
2447
|
|
|
2370
2448
|
|
|
2449
|
+
|
|
2450
|
+
|
|
2451
|
+
|
|
2452
|
+
|
|
2371
2453
|
|
|
2372
2454
|
|
|
2373
2455
|
|
|
@@ -2422,6 +2504,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2422
2504
|
|
|
2423
2505
|
|
|
2424
2506
|
|
|
2507
|
+
|
|
2508
|
+
|
|
2509
|
+
|
|
2510
|
+
|
|
2425
2511
|
|
|
2426
2512
|
|
|
2427
2513
|
|
|
@@ -2479,6 +2565,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2479
2565
|
|
|
2480
2566
|
|
|
2481
2567
|
|
|
2568
|
+
|
|
2569
|
+
|
|
2570
|
+
|
|
2571
|
+
|
|
2482
2572
|
|
|
2483
2573
|
|
|
2484
2574
|
|
|
@@ -2523,6 +2613,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2523
2613
|
|
|
2524
2614
|
|
|
2525
2615
|
|
|
2616
|
+
|
|
2617
|
+
|
|
2618
|
+
|
|
2619
|
+
|
|
2526
2620
|
|
|
2527
2621
|
|
|
2528
2622
|
|
|
@@ -2576,6 +2670,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2576
2670
|
|
|
2577
2671
|
|
|
2578
2672
|
|
|
2673
|
+
|
|
2674
|
+
|
|
2675
|
+
|
|
2676
|
+
|
|
2579
2677
|
|
|
2580
2678
|
|
|
2581
2679
|
|
|
@@ -2656,6 +2754,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2656
2754
|
|
|
2657
2755
|
|
|
2658
2756
|
|
|
2757
|
+
|
|
2758
|
+
|
|
2759
|
+
|
|
2760
|
+
|
|
2659
2761
|
|
|
2660
2762
|
|
|
2661
2763
|
|
|
@@ -2713,6 +2815,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2713
2815
|
|
|
2714
2816
|
|
|
2715
2817
|
|
|
2818
|
+
|
|
2819
|
+
|
|
2820
|
+
|
|
2821
|
+
|
|
2716
2822
|
|
|
2717
2823
|
|
|
2718
2824
|
|
|
@@ -3186,6 +3292,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3186
3292
|
|
|
3187
3293
|
|
|
3188
3294
|
|
|
3295
|
+
|
|
3296
|
+
|
|
3297
|
+
|
|
3298
|
+
|
|
3189
3299
|
|
|
3190
3300
|
|
|
3191
3301
|
|
|
@@ -3234,6 +3344,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3234
3344
|
|
|
3235
3345
|
|
|
3236
3346
|
|
|
3347
|
+
|
|
3348
|
+
|
|
3349
|
+
|
|
3350
|
+
|
|
3237
3351
|
|
|
3238
3352
|
|
|
3239
3353
|
|
|
@@ -3286,6 +3400,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3286
3400
|
|
|
3287
3401
|
|
|
3288
3402
|
|
|
3403
|
+
|
|
3404
|
+
|
|
3405
|
+
|
|
3406
|
+
|
|
3289
3407
|
|
|
3290
3408
|
|
|
3291
3409
|
|
|
@@ -3363,6 +3481,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3363
3481
|
|
|
3364
3482
|
|
|
3365
3483
|
|
|
3484
|
+
|
|
3485
|
+
|
|
3486
|
+
|
|
3487
|
+
|
|
3366
3488
|
|
|
3367
3489
|
|
|
3368
3490
|
|
|
@@ -3986,6 +4108,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3986
4108
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
3987
4109
|
super([], options);
|
|
3988
4110
|
__publicField(this, "_root");
|
|
4111
|
+
__publicField(this, "_enableOrderStatistic", false);
|
|
3989
4112
|
/**
|
|
3990
4113
|
* The comparator function used to determine the order of keys in the tree.
|
|
3991
4114
|
|
|
@@ -3998,6 +4121,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3998
4121
|
} else {
|
|
3999
4122
|
this._comparator = this._createDefaultComparator();
|
|
4000
4123
|
}
|
|
4124
|
+
if (options.enableOrderStatistic) {
|
|
4125
|
+
this._enableOrderStatistic = true;
|
|
4126
|
+
}
|
|
4001
4127
|
} else {
|
|
4002
4128
|
this._comparator = this._createDefaultComparator();
|
|
4003
4129
|
}
|
|
@@ -4163,6 +4289,14 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4163
4289
|
|
|
4164
4290
|
|
|
4165
4291
|
|
|
4292
|
+
|
|
4293
|
+
|
|
4294
|
+
|
|
4295
|
+
|
|
4296
|
+
|
|
4297
|
+
|
|
4298
|
+
|
|
4299
|
+
|
|
4166
4300
|
|
|
4167
4301
|
|
|
4168
4302
|
|
|
@@ -4327,6 +4461,85 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4327
4461
|
const searchRange = range instanceof Range ? range : new Range(range[0], range[1]);
|
|
4328
4462
|
return this.search(searchRange, false, callback, startNode, iterationType);
|
|
4329
4463
|
}
|
|
4464
|
+
getByRank(k, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4465
|
+
if (!this._enableOrderStatistic) {
|
|
4466
|
+
raise(Error, ERR.orderStatisticNotEnabled("getByRank"));
|
|
4467
|
+
}
|
|
4468
|
+
if (k < 0 || k >= this._size) return void 0;
|
|
4469
|
+
let actualCallback = void 0;
|
|
4470
|
+
let actualIterationType = this.iterationType;
|
|
4471
|
+
if (typeof callback === "string") {
|
|
4472
|
+
actualIterationType = callback;
|
|
4473
|
+
} else if (callback) {
|
|
4474
|
+
actualCallback = callback;
|
|
4475
|
+
if (iterationType) {
|
|
4476
|
+
actualIterationType = iterationType;
|
|
4477
|
+
}
|
|
4478
|
+
}
|
|
4479
|
+
const node = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, k) : this._getByRankIterative(this._root, k);
|
|
4480
|
+
if (!node) return void 0;
|
|
4481
|
+
return actualCallback ? actualCallback(node) : node.key;
|
|
4482
|
+
}
|
|
4483
|
+
getRank(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
|
|
4484
|
+
var _a;
|
|
4485
|
+
if (!this._enableOrderStatistic) {
|
|
4486
|
+
raise(Error, ERR.orderStatisticNotEnabled("getRank"));
|
|
4487
|
+
}
|
|
4488
|
+
if (!this._root || this._size === 0) return -1;
|
|
4489
|
+
let actualIterationType = this.iterationType;
|
|
4490
|
+
if (iterationType) actualIterationType = iterationType;
|
|
4491
|
+
let key;
|
|
4492
|
+
if (typeof keyNodeEntryOrPredicate === "function") {
|
|
4493
|
+
const results = this.search(keyNodeEntryOrPredicate, true);
|
|
4494
|
+
if (results.length === 0 || results[0] === void 0) return -1;
|
|
4495
|
+
key = results[0];
|
|
4496
|
+
} else if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0) {
|
|
4497
|
+
return -1;
|
|
4498
|
+
} else if (this.isNode(keyNodeEntryOrPredicate)) {
|
|
4499
|
+
key = keyNodeEntryOrPredicate.key;
|
|
4500
|
+
} else if (Array.isArray(keyNodeEntryOrPredicate)) {
|
|
4501
|
+
key = (_a = keyNodeEntryOrPredicate[0]) != null ? _a : void 0;
|
|
4502
|
+
if (key === void 0 || key === null) return -1;
|
|
4503
|
+
} else {
|
|
4504
|
+
key = keyNodeEntryOrPredicate;
|
|
4505
|
+
}
|
|
4506
|
+
if (key === void 0) return -1;
|
|
4507
|
+
return actualIterationType === "RECURSIVE" ? this._getRankRecursive(this._root, key) : this._getRankIterative(this._root, key);
|
|
4508
|
+
}
|
|
4509
|
+
rangeByRank(start, end, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4510
|
+
if (!this._enableOrderStatistic) {
|
|
4511
|
+
raise(Error, ERR.orderStatisticNotEnabled("rangeByRank"));
|
|
4512
|
+
}
|
|
4513
|
+
if (this._size === 0) return [];
|
|
4514
|
+
const lo = Math.max(0, start);
|
|
4515
|
+
const hi = Math.min(this._size - 1, end);
|
|
4516
|
+
if (lo > hi) return [];
|
|
4517
|
+
let actualCallback = void 0;
|
|
4518
|
+
let actualIterationType = this.iterationType;
|
|
4519
|
+
if (typeof callback === "string") {
|
|
4520
|
+
actualIterationType = callback;
|
|
4521
|
+
} else if (callback) {
|
|
4522
|
+
actualCallback = callback;
|
|
4523
|
+
if (iterationType) {
|
|
4524
|
+
actualIterationType = iterationType;
|
|
4525
|
+
}
|
|
4526
|
+
}
|
|
4527
|
+
const results = [];
|
|
4528
|
+
const count = hi - lo + 1;
|
|
4529
|
+
const startNode = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, lo) : this._getByRankIterative(this._root, lo);
|
|
4530
|
+
if (!startNode) return [];
|
|
4531
|
+
let collected = 0;
|
|
4532
|
+
const cb = actualCallback != null ? actualCallback : this._DEFAULT_NODE_CALLBACK;
|
|
4533
|
+
let current = startNode;
|
|
4534
|
+
while (current && collected < count) {
|
|
4535
|
+
results.push(cb(current));
|
|
4536
|
+
collected++;
|
|
4537
|
+
if (collected < count) {
|
|
4538
|
+
current = this._next(current);
|
|
4539
|
+
}
|
|
4540
|
+
}
|
|
4541
|
+
return results;
|
|
4542
|
+
}
|
|
4330
4543
|
/**
|
|
4331
4544
|
* Adds a new node to the BST based on key comparison.
|
|
4332
4545
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -4419,20 +4632,33 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4419
4632
|
|
|
4420
4633
|
|
|
4421
4634
|
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4635
|
+
|
|
4636
|
+
|
|
4637
|
+
|
|
4638
|
+
|
|
4639
|
+
|
|
4640
|
+
|
|
4641
|
+
|
|
4642
|
+
|
|
4643
|
+
|
|
4644
|
+
|
|
4645
|
+
|
|
4646
|
+
|
|
4647
|
+
* @example
|
|
4648
|
+
* // Set a key-value pair
|
|
4649
|
+
* const bst = new BST<number, string>();
|
|
4650
|
+
* bst.set(1, 'one');
|
|
4651
|
+
* bst.set(2, 'two');
|
|
4652
|
+
* console.log(bst.get(1)); // 'one';
|
|
4653
|
+
*/
|
|
4654
|
+
set(keyNodeOrEntry, value) {
|
|
4655
|
+
const [newNode] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
4656
|
+
if (newNode === void 0) return false;
|
|
4657
|
+
if (this._root === void 0) {
|
|
4433
4658
|
this._setRoot(newNode);
|
|
4434
4659
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4435
4660
|
this._size++;
|
|
4661
|
+
this._updateCount(newNode);
|
|
4436
4662
|
return true;
|
|
4437
4663
|
}
|
|
4438
4664
|
let current = this._root;
|
|
@@ -4446,6 +4672,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4446
4672
|
current.left = newNode;
|
|
4447
4673
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4448
4674
|
this._size++;
|
|
4675
|
+
this._updateCountAlongPath(newNode);
|
|
4449
4676
|
return true;
|
|
4450
4677
|
}
|
|
4451
4678
|
if (current.left !== null) current = current.left;
|
|
@@ -4454,6 +4681,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4454
4681
|
current.right = newNode;
|
|
4455
4682
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4456
4683
|
this._size++;
|
|
4684
|
+
this._updateCountAlongPath(newNode);
|
|
4457
4685
|
return true;
|
|
4458
4686
|
}
|
|
4459
4687
|
if (current.right !== null) current = current.right;
|
|
@@ -4514,6 +4742,14 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4514
4742
|
|
|
4515
4743
|
|
|
4516
4744
|
|
|
4745
|
+
|
|
4746
|
+
|
|
4747
|
+
|
|
4748
|
+
|
|
4749
|
+
|
|
4750
|
+
|
|
4751
|
+
|
|
4752
|
+
|
|
4517
4753
|
|
|
4518
4754
|
|
|
4519
4755
|
|
|
@@ -4801,6 +5037,10 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4801
5037
|
|
|
4802
5038
|
|
|
4803
5039
|
|
|
5040
|
+
|
|
5041
|
+
|
|
5042
|
+
|
|
5043
|
+
|
|
4804
5044
|
|
|
4805
5045
|
|
|
4806
5046
|
|
|
@@ -4866,6 +5106,10 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4866
5106
|
|
|
4867
5107
|
|
|
4868
5108
|
|
|
5109
|
+
|
|
5110
|
+
|
|
5111
|
+
|
|
5112
|
+
|
|
4869
5113
|
|
|
4870
5114
|
|
|
4871
5115
|
|
|
@@ -4976,6 +5220,14 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4976
5220
|
|
|
4977
5221
|
|
|
4978
5222
|
|
|
5223
|
+
|
|
5224
|
+
|
|
5225
|
+
|
|
5226
|
+
|
|
5227
|
+
|
|
5228
|
+
|
|
5229
|
+
|
|
5230
|
+
|
|
4979
5231
|
|
|
4980
5232
|
|
|
4981
5233
|
|
|
@@ -5059,13 +5311,11 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5059
5311
|
if (a instanceof Date && b instanceof Date) {
|
|
5060
5312
|
const ta = a.getTime();
|
|
5061
5313
|
const tb = b.getTime();
|
|
5062
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
5314
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate("BST"));
|
|
5063
5315
|
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
5064
5316
|
}
|
|
5065
5317
|
if (typeof a === "object" || typeof b === "object") {
|
|
5066
|
-
|
|
5067
|
-
ERR.comparatorRequired("BST")
|
|
5068
|
-
);
|
|
5318
|
+
raise(TypeError, ERR.comparatorRequired("BST"));
|
|
5069
5319
|
}
|
|
5070
5320
|
return 0;
|
|
5071
5321
|
};
|
|
@@ -5387,7 +5637,8 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5387
5637
|
_snapshotOptions() {
|
|
5388
5638
|
return {
|
|
5389
5639
|
...super._snapshotOptions(),
|
|
5390
|
-
comparator: this._comparator
|
|
5640
|
+
comparator: this._comparator,
|
|
5641
|
+
enableOrderStatistic: this._enableOrderStatistic
|
|
5391
5642
|
};
|
|
5392
5643
|
}
|
|
5393
5644
|
/**
|
|
@@ -5409,6 +5660,113 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5409
5660
|
*
|
|
5410
5661
|
* @param v - The node to set as root.
|
|
5411
5662
|
*/
|
|
5663
|
+
/**
|
|
5664
|
+
* (Protected) Recalculates the subtree count for a single node.
|
|
5665
|
+
* @remarks Time O(1). Only active when enableOrderStatistic is true.
|
|
5666
|
+
*/
|
|
5667
|
+
_updateCount(node) {
|
|
5668
|
+
if (!this._enableOrderStatistic) return;
|
|
5669
|
+
node._count = 1 + (this.isRealNode(node.left) ? node.left._count : 0) + (this.isRealNode(node.right) ? node.right._count : 0);
|
|
5670
|
+
}
|
|
5671
|
+
/**
|
|
5672
|
+
* (Protected) Updates subtree counts from a node up to the root.
|
|
5673
|
+
* @remarks Time O(log n). Only active when enableOrderStatistic is true.
|
|
5674
|
+
*/
|
|
5675
|
+
_updateCountAlongPath(node) {
|
|
5676
|
+
if (!this._enableOrderStatistic) return;
|
|
5677
|
+
let current = node;
|
|
5678
|
+
while (current) {
|
|
5679
|
+
this._updateCount(current);
|
|
5680
|
+
current = current.parent;
|
|
5681
|
+
}
|
|
5682
|
+
}
|
|
5683
|
+
/**
|
|
5684
|
+
* (Protected) Finds the node at position k in tree order (iterative).
|
|
5685
|
+
* @remarks Time O(log n), Space O(1)
|
|
5686
|
+
*/
|
|
5687
|
+
_getByRankIterative(node, k) {
|
|
5688
|
+
let current = node;
|
|
5689
|
+
let remaining = k;
|
|
5690
|
+
while (current) {
|
|
5691
|
+
const leftCount = this.isRealNode(current.left) ? current.left._count : 0;
|
|
5692
|
+
if (remaining < leftCount) {
|
|
5693
|
+
current = current.left;
|
|
5694
|
+
} else if (remaining === leftCount) {
|
|
5695
|
+
return current;
|
|
5696
|
+
} else {
|
|
5697
|
+
remaining = remaining - leftCount - 1;
|
|
5698
|
+
current = current.right;
|
|
5699
|
+
}
|
|
5700
|
+
}
|
|
5701
|
+
return void 0;
|
|
5702
|
+
}
|
|
5703
|
+
/**
|
|
5704
|
+
* (Protected) Finds the node at position k in tree order (recursive).
|
|
5705
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5706
|
+
*/
|
|
5707
|
+
_getByRankRecursive(node, k) {
|
|
5708
|
+
if (!node) return void 0;
|
|
5709
|
+
const leftCount = this.isRealNode(node.left) ? node.left._count : 0;
|
|
5710
|
+
if (k < leftCount) return this._getByRankRecursive(node.left, k);
|
|
5711
|
+
if (k === leftCount) return node;
|
|
5712
|
+
return this._getByRankRecursive(node.right, k - leftCount - 1);
|
|
5713
|
+
}
|
|
5714
|
+
/**
|
|
5715
|
+
* (Protected) Computes the rank of a key iteratively.
|
|
5716
|
+
* @remarks Time O(log n), Space O(1)
|
|
5717
|
+
*/
|
|
5718
|
+
_getRankIterative(node, key) {
|
|
5719
|
+
let rank = 0;
|
|
5720
|
+
let current = node;
|
|
5721
|
+
while (this.isRealNode(current)) {
|
|
5722
|
+
const cmp = this._compare(current.key, key);
|
|
5723
|
+
if (cmp > 0) {
|
|
5724
|
+
current = current.left;
|
|
5725
|
+
} else if (cmp < 0) {
|
|
5726
|
+
rank += (this.isRealNode(current.left) ? current.left._count : 0) + 1;
|
|
5727
|
+
current = current.right;
|
|
5728
|
+
} else {
|
|
5729
|
+
rank += this.isRealNode(current.left) ? current.left._count : 0;
|
|
5730
|
+
return rank;
|
|
5731
|
+
}
|
|
5732
|
+
}
|
|
5733
|
+
return rank;
|
|
5734
|
+
}
|
|
5735
|
+
/**
|
|
5736
|
+
* (Protected) Computes the rank of a key recursively.
|
|
5737
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5738
|
+
*/
|
|
5739
|
+
_getRankRecursive(node, key) {
|
|
5740
|
+
if (!node) return 0;
|
|
5741
|
+
const cmp = this._compare(node.key, key);
|
|
5742
|
+
if (cmp > 0) {
|
|
5743
|
+
return this._getRankRecursive(node.left, key);
|
|
5744
|
+
} else if (cmp < 0) {
|
|
5745
|
+
return (this.isRealNode(node.left) ? node.left._count : 0) + 1 + this._getRankRecursive(node.right, key);
|
|
5746
|
+
} else {
|
|
5747
|
+
return this.isRealNode(node.left) ? node.left._count : 0;
|
|
5748
|
+
}
|
|
5749
|
+
}
|
|
5750
|
+
/**
|
|
5751
|
+
* (Protected) Finds the in-order successor of a node.
|
|
5752
|
+
* @remarks Time O(log n), Space O(1)
|
|
5753
|
+
*/
|
|
5754
|
+
_next(node) {
|
|
5755
|
+
if (this.isRealNode(node.right)) {
|
|
5756
|
+
let current2 = node.right;
|
|
5757
|
+
while (this.isRealNode(current2.left)) {
|
|
5758
|
+
current2 = current2.left;
|
|
5759
|
+
}
|
|
5760
|
+
return current2;
|
|
5761
|
+
}
|
|
5762
|
+
let current = node;
|
|
5763
|
+
let parent = current.parent;
|
|
5764
|
+
while (parent && current === parent.right) {
|
|
5765
|
+
current = parent;
|
|
5766
|
+
parent = parent.parent;
|
|
5767
|
+
}
|
|
5768
|
+
return parent;
|
|
5769
|
+
}
|
|
5412
5770
|
_setRoot(v) {
|
|
5413
5771
|
if (v) v.parent = void 0;
|
|
5414
5772
|
this._root = v;
|
|
@@ -5455,21 +5813,28 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5455
5813
|
while (x.left !== void 0 && x.left !== null) x = x.left;
|
|
5456
5814
|
return x;
|
|
5457
5815
|
}, "minNode");
|
|
5816
|
+
let countUpdateStart;
|
|
5458
5817
|
if (node.left === void 0) {
|
|
5818
|
+
countUpdateStart = node.parent;
|
|
5459
5819
|
transplant(node, node.right);
|
|
5460
5820
|
} else if (node.right === void 0) {
|
|
5821
|
+
countUpdateStart = node.parent;
|
|
5461
5822
|
transplant(node, node.left);
|
|
5462
5823
|
} else {
|
|
5463
5824
|
const succ = minNode(node.right);
|
|
5464
5825
|
if (succ.parent !== node) {
|
|
5826
|
+
countUpdateStart = succ.parent;
|
|
5465
5827
|
transplant(succ, succ.right);
|
|
5466
5828
|
succ.right = node.right;
|
|
5467
5829
|
if (succ.right) succ.right.parent = succ;
|
|
5830
|
+
} else {
|
|
5831
|
+
countUpdateStart = succ;
|
|
5468
5832
|
}
|
|
5469
5833
|
transplant(node, succ);
|
|
5470
5834
|
succ.left = node.left;
|
|
5471
5835
|
if (succ.left) succ.left.parent = succ;
|
|
5472
5836
|
}
|
|
5837
|
+
this._updateCountAlongPath(countUpdateStart);
|
|
5473
5838
|
this._size = Math.max(0, this._size - 1);
|
|
5474
5839
|
return true;
|
|
5475
5840
|
}
|
|
@@ -5495,7 +5860,7 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5495
5860
|
}
|
|
5496
5861
|
} else {
|
|
5497
5862
|
if (!Number.isInteger(sizeOrElements) || sizeOrElements < 0) {
|
|
5498
|
-
|
|
5863
|
+
raise(RangeError, ERR.invalidArgument("size must be a non-negative integer", "BinaryIndexedTree"));
|
|
5499
5864
|
}
|
|
5500
5865
|
this._size = sizeOrElements;
|
|
5501
5866
|
this._tree = new Array(this._size + 1).fill(0);
|
|
@@ -5550,6 +5915,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5550
5915
|
|
|
5551
5916
|
|
|
5552
5917
|
|
|
5918
|
+
|
|
5919
|
+
|
|
5920
|
+
|
|
5921
|
+
|
|
5922
|
+
|
|
5923
|
+
|
|
5924
|
+
|
|
5925
|
+
|
|
5553
5926
|
|
|
5554
5927
|
|
|
5555
5928
|
|
|
@@ -5618,6 +5991,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5618
5991
|
|
|
5619
5992
|
|
|
5620
5993
|
|
|
5994
|
+
|
|
5995
|
+
|
|
5996
|
+
|
|
5997
|
+
|
|
5998
|
+
|
|
5999
|
+
|
|
6000
|
+
|
|
6001
|
+
|
|
5621
6002
|
|
|
5622
6003
|
|
|
5623
6004
|
|
|
@@ -5686,6 +6067,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5686
6067
|
|
|
5687
6068
|
|
|
5688
6069
|
|
|
6070
|
+
|
|
6071
|
+
|
|
6072
|
+
|
|
6073
|
+
|
|
6074
|
+
|
|
6075
|
+
|
|
6076
|
+
|
|
6077
|
+
|
|
5689
6078
|
|
|
5690
6079
|
|
|
5691
6080
|
|
|
@@ -5754,6 +6143,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5754
6143
|
|
|
5755
6144
|
|
|
5756
6145
|
|
|
6146
|
+
|
|
6147
|
+
|
|
6148
|
+
|
|
6149
|
+
|
|
6150
|
+
|
|
6151
|
+
|
|
6152
|
+
|
|
6153
|
+
|
|
5757
6154
|
|
|
5758
6155
|
|
|
5759
6156
|
|
|
@@ -5820,6 +6217,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5820
6217
|
|
|
5821
6218
|
|
|
5822
6219
|
|
|
6220
|
+
|
|
6221
|
+
|
|
6222
|
+
|
|
6223
|
+
|
|
6224
|
+
|
|
6225
|
+
|
|
6226
|
+
|
|
6227
|
+
|
|
5823
6228
|
|
|
5824
6229
|
|
|
5825
6230
|
|
|
@@ -5893,6 +6298,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5893
6298
|
|
|
5894
6299
|
|
|
5895
6300
|
|
|
6301
|
+
|
|
6302
|
+
|
|
6303
|
+
|
|
6304
|
+
|
|
6305
|
+
|
|
6306
|
+
|
|
6307
|
+
|
|
6308
|
+
|
|
5896
6309
|
|
|
5897
6310
|
|
|
5898
6311
|
|
|
@@ -5943,6 +6356,10 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5943
6356
|
|
|
5944
6357
|
|
|
5945
6358
|
|
|
6359
|
+
|
|
6360
|
+
|
|
6361
|
+
|
|
6362
|
+
|
|
5946
6363
|
|
|
5947
6364
|
|
|
5948
6365
|
|
|
@@ -6000,6 +6417,10 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
6000
6417
|
|
|
6001
6418
|
|
|
6002
6419
|
|
|
6420
|
+
|
|
6421
|
+
|
|
6422
|
+
|
|
6423
|
+
|
|
6003
6424
|
|
|
6004
6425
|
|
|
6005
6426
|
|
|
@@ -6074,10 +6495,10 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
6074
6495
|
}
|
|
6075
6496
|
_checkIndex(index) {
|
|
6076
6497
|
if (!Number.isInteger(index)) {
|
|
6077
|
-
|
|
6498
|
+
raise(TypeError, ERR.invalidIndex("BinaryIndexedTree"));
|
|
6078
6499
|
}
|
|
6079
6500
|
if (index < 0 || index >= this._size) {
|
|
6080
|
-
|
|
6501
|
+
raise(RangeError, ERR.indexOutOfRange(index, 0, this._size - 1, "BinaryIndexedTree"));
|
|
6081
6502
|
}
|
|
6082
6503
|
}
|
|
6083
6504
|
/** Returns highest power of 2 <= n. */
|
|
@@ -6159,6 +6580,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6159
6580
|
|
|
6160
6581
|
|
|
6161
6582
|
|
|
6583
|
+
|
|
6584
|
+
|
|
6585
|
+
|
|
6586
|
+
|
|
6162
6587
|
|
|
6163
6588
|
|
|
6164
6589
|
|
|
@@ -6227,6 +6652,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6227
6652
|
|
|
6228
6653
|
|
|
6229
6654
|
|
|
6655
|
+
|
|
6656
|
+
|
|
6657
|
+
|
|
6658
|
+
|
|
6230
6659
|
|
|
6231
6660
|
|
|
6232
6661
|
|
|
@@ -6289,6 +6718,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6289
6718
|
|
|
6290
6719
|
|
|
6291
6720
|
|
|
6721
|
+
|
|
6722
|
+
|
|
6723
|
+
|
|
6724
|
+
|
|
6292
6725
|
|
|
6293
6726
|
|
|
6294
6727
|
|
|
@@ -6358,6 +6791,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6358
6791
|
|
|
6359
6792
|
|
|
6360
6793
|
|
|
6794
|
+
|
|
6795
|
+
|
|
6796
|
+
|
|
6797
|
+
|
|
6361
6798
|
|
|
6362
6799
|
|
|
6363
6800
|
|
|
@@ -6405,6 +6842,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6405
6842
|
|
|
6406
6843
|
|
|
6407
6844
|
|
|
6845
|
+
|
|
6846
|
+
|
|
6847
|
+
|
|
6848
|
+
|
|
6408
6849
|
|
|
6409
6850
|
|
|
6410
6851
|
|
|
@@ -6478,6 +6919,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6478
6919
|
|
|
6479
6920
|
|
|
6480
6921
|
|
|
6922
|
+
|
|
6923
|
+
|
|
6924
|
+
|
|
6925
|
+
|
|
6481
6926
|
|
|
6482
6927
|
|
|
6483
6928
|
|
|
@@ -6845,6 +7290,22 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6845
7290
|
|
|
6846
7291
|
|
|
6847
7292
|
|
|
7293
|
+
|
|
7294
|
+
|
|
7295
|
+
|
|
7296
|
+
|
|
7297
|
+
|
|
7298
|
+
|
|
7299
|
+
|
|
7300
|
+
|
|
7301
|
+
|
|
7302
|
+
|
|
7303
|
+
|
|
7304
|
+
|
|
7305
|
+
|
|
7306
|
+
|
|
7307
|
+
|
|
7308
|
+
|
|
6848
7309
|
|
|
6849
7310
|
|
|
6850
7311
|
|
|
@@ -6961,6 +7422,18 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6961
7422
|
|
|
6962
7423
|
|
|
6963
7424
|
|
|
7425
|
+
|
|
7426
|
+
|
|
7427
|
+
|
|
7428
|
+
|
|
7429
|
+
|
|
7430
|
+
|
|
7431
|
+
|
|
7432
|
+
|
|
7433
|
+
|
|
7434
|
+
|
|
7435
|
+
|
|
7436
|
+
|
|
6964
7437
|
|
|
6965
7438
|
|
|
6966
7439
|
|
|
@@ -7040,6 +7513,14 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7040
7513
|
|
|
7041
7514
|
|
|
7042
7515
|
|
|
7516
|
+
|
|
7517
|
+
|
|
7518
|
+
|
|
7519
|
+
|
|
7520
|
+
|
|
7521
|
+
|
|
7522
|
+
|
|
7523
|
+
|
|
7043
7524
|
|
|
7044
7525
|
|
|
7045
7526
|
|
|
@@ -7160,6 +7641,18 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7160
7641
|
|
|
7161
7642
|
|
|
7162
7643
|
|
|
7644
|
+
|
|
7645
|
+
|
|
7646
|
+
|
|
7647
|
+
|
|
7648
|
+
|
|
7649
|
+
|
|
7650
|
+
|
|
7651
|
+
|
|
7652
|
+
|
|
7653
|
+
|
|
7654
|
+
|
|
7655
|
+
|
|
7163
7656
|
|
|
7164
7657
|
|
|
7165
7658
|
|
|
@@ -7291,6 +7784,8 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7291
7784
|
}
|
|
7292
7785
|
this._updateHeight(A);
|
|
7293
7786
|
if (B) this._updateHeight(B);
|
|
7787
|
+
this._updateCount(A);
|
|
7788
|
+
if (B) this._updateCount(B);
|
|
7294
7789
|
}
|
|
7295
7790
|
/**
|
|
7296
7791
|
* (Protected) Performs a Left-Right (LR) double rotation.
|
|
@@ -7336,6 +7831,9 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7336
7831
|
this._updateHeight(A);
|
|
7337
7832
|
if (B) this._updateHeight(B);
|
|
7338
7833
|
if (C) this._updateHeight(C);
|
|
7834
|
+
this._updateCount(A);
|
|
7835
|
+
if (B) this._updateCount(B);
|
|
7836
|
+
if (C) this._updateCount(C);
|
|
7339
7837
|
}
|
|
7340
7838
|
/**
|
|
7341
7839
|
* (Protected) Performs a Right-Right (RR) rotation (a single left rotation).
|
|
@@ -7370,6 +7868,8 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7370
7868
|
}
|
|
7371
7869
|
this._updateHeight(A);
|
|
7372
7870
|
if (B) this._updateHeight(B);
|
|
7871
|
+
this._updateCount(A);
|
|
7872
|
+
if (B) this._updateCount(B);
|
|
7373
7873
|
}
|
|
7374
7874
|
/**
|
|
7375
7875
|
* (Protected) Performs a Right-Left (RL) double rotation.
|
|
@@ -7413,6 +7913,9 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7413
7913
|
this._updateHeight(A);
|
|
7414
7914
|
if (B) this._updateHeight(B);
|
|
7415
7915
|
if (C) this._updateHeight(C);
|
|
7916
|
+
this._updateCount(A);
|
|
7917
|
+
if (B) this._updateCount(B);
|
|
7918
|
+
if (C) this._updateCount(C);
|
|
7416
7919
|
}
|
|
7417
7920
|
/**
|
|
7418
7921
|
* (Protected) Traverses up the tree from the specified node, updating heights and performing rotations as needed.
|
|
@@ -7427,6 +7930,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7427
7930
|
const A = path[i];
|
|
7428
7931
|
if (A) {
|
|
7429
7932
|
this._updateHeight(A);
|
|
7933
|
+
this._updateCount(A);
|
|
7430
7934
|
switch (this._balanceFactor(A)) {
|
|
7431
7935
|
case -2:
|
|
7432
7936
|
if (A && A.left) {
|
|
@@ -7754,6 +8258,22 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
7754
8258
|
|
|
7755
8259
|
|
|
7756
8260
|
|
|
8261
|
+
|
|
8262
|
+
|
|
8263
|
+
|
|
8264
|
+
|
|
8265
|
+
|
|
8266
|
+
|
|
8267
|
+
|
|
8268
|
+
|
|
8269
|
+
|
|
8270
|
+
|
|
8271
|
+
|
|
8272
|
+
|
|
8273
|
+
|
|
8274
|
+
|
|
8275
|
+
|
|
8276
|
+
|
|
7757
8277
|
|
|
7758
8278
|
|
|
7759
8279
|
|
|
@@ -7861,6 +8381,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
7861
8381
|
node.left = NIL;
|
|
7862
8382
|
node.right = NIL;
|
|
7863
8383
|
node.color = "RED";
|
|
8384
|
+
this._updateCountAlongPath(node);
|
|
7864
8385
|
this._insertFixup(node);
|
|
7865
8386
|
if (this.isRealNode(this._root)) this._root.color = "BLACK";
|
|
7866
8387
|
}
|
|
@@ -7971,6 +8492,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
7971
8492
|
newNode.left = NIL;
|
|
7972
8493
|
newNode.right = NIL;
|
|
7973
8494
|
newNode.color = "RED";
|
|
8495
|
+
this._updateCountAlongPath(newNode);
|
|
7974
8496
|
this._insertFixup(newNode);
|
|
7975
8497
|
if (this.isRealNode(this._root)) this._root.color = "BLACK";
|
|
7976
8498
|
else return void 0;
|
|
@@ -8214,6 +8736,22 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8214
8736
|
|
|
8215
8737
|
|
|
8216
8738
|
|
|
8739
|
+
|
|
8740
|
+
|
|
8741
|
+
|
|
8742
|
+
|
|
8743
|
+
|
|
8744
|
+
|
|
8745
|
+
|
|
8746
|
+
|
|
8747
|
+
|
|
8748
|
+
|
|
8749
|
+
|
|
8750
|
+
|
|
8751
|
+
|
|
8752
|
+
|
|
8753
|
+
|
|
8754
|
+
|
|
8217
8755
|
|
|
8218
8756
|
|
|
8219
8757
|
|
|
@@ -8414,16 +8952,32 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8414
8952
|
|
|
8415
8953
|
|
|
8416
8954
|
|
|
8417
|
-
|
|
8418
|
-
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
|
|
8955
|
+
|
|
8956
|
+
|
|
8957
|
+
|
|
8958
|
+
|
|
8959
|
+
|
|
8960
|
+
|
|
8961
|
+
|
|
8962
|
+
|
|
8963
|
+
|
|
8964
|
+
|
|
8965
|
+
|
|
8966
|
+
|
|
8967
|
+
|
|
8968
|
+
|
|
8969
|
+
|
|
8970
|
+
|
|
8971
|
+
* @example
|
|
8972
|
+
* // Remove and rebalance
|
|
8973
|
+
* const rbt = new RedBlackTree<number>([10, 5, 15, 3, 7]);
|
|
8974
|
+
* rbt.delete(5);
|
|
8975
|
+
* console.log(rbt.has(5)); // false;
|
|
8976
|
+
* console.log(rbt.size); // 4;
|
|
8977
|
+
*/
|
|
8978
|
+
delete(keyNodeEntryRawOrPredicate) {
|
|
8979
|
+
var _a, _b, _c;
|
|
8980
|
+
if (keyNodeEntryRawOrPredicate === null) return [];
|
|
8427
8981
|
const results = [];
|
|
8428
8982
|
let nodeToDelete;
|
|
8429
8983
|
if (this._isPredicate(keyNodeEntryRawOrPredicate)) nodeToDelete = this.getNode(keyNodeEntryRawOrPredicate);
|
|
@@ -8468,6 +9022,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8468
9022
|
}
|
|
8469
9023
|
if (this._isMapMode) this._store.delete(nodeToDelete.key);
|
|
8470
9024
|
this._size--;
|
|
9025
|
+
this._updateCountAlongPath((_c = replacementNode == null ? void 0 : replacementNode.parent) != null ? _c : replacementNode);
|
|
8471
9026
|
if (this._size <= 0) {
|
|
8472
9027
|
this._setMinCache(void 0);
|
|
8473
9028
|
this._setMaxCache(void 0);
|
|
@@ -8574,6 +9129,18 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8574
9129
|
|
|
8575
9130
|
|
|
8576
9131
|
|
|
9132
|
+
|
|
9133
|
+
|
|
9134
|
+
|
|
9135
|
+
|
|
9136
|
+
|
|
9137
|
+
|
|
9138
|
+
|
|
9139
|
+
|
|
9140
|
+
|
|
9141
|
+
|
|
9142
|
+
|
|
9143
|
+
|
|
8577
9144
|
|
|
8578
9145
|
|
|
8579
9146
|
|
|
@@ -8706,6 +9273,22 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8706
9273
|
|
|
8707
9274
|
|
|
8708
9275
|
|
|
9276
|
+
|
|
9277
|
+
|
|
9278
|
+
|
|
9279
|
+
|
|
9280
|
+
|
|
9281
|
+
|
|
9282
|
+
|
|
9283
|
+
|
|
9284
|
+
|
|
9285
|
+
|
|
9286
|
+
|
|
9287
|
+
|
|
9288
|
+
|
|
9289
|
+
|
|
9290
|
+
|
|
9291
|
+
|
|
8709
9292
|
|
|
8710
9293
|
|
|
8711
9294
|
|
|
@@ -8809,6 +9392,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8809
9392
|
node.left = NIL;
|
|
8810
9393
|
node.right = NIL;
|
|
8811
9394
|
node.color = "RED";
|
|
9395
|
+
this._updateCountAlongPath(node);
|
|
8812
9396
|
this._insertFixup(node);
|
|
8813
9397
|
return "CREATED";
|
|
8814
9398
|
}
|
|
@@ -8977,6 +9561,8 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8977
9561
|
}
|
|
8978
9562
|
y.left = x;
|
|
8979
9563
|
x.parent = y;
|
|
9564
|
+
this._updateCount(x);
|
|
9565
|
+
this._updateCount(y);
|
|
8980
9566
|
}
|
|
8981
9567
|
/**
|
|
8982
9568
|
* (Protected) Perform a right rotation around y.
|
|
@@ -9003,6 +9589,8 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
9003
9589
|
}
|
|
9004
9590
|
x.right = y;
|
|
9005
9591
|
y.parent = x;
|
|
9592
|
+
this._updateCount(y);
|
|
9593
|
+
this._updateCount(x);
|
|
9006
9594
|
}
|
|
9007
9595
|
};
|
|
9008
9596
|
__name(_RedBlackTree, "RedBlackTree");
|
|
@@ -9035,7 +9623,7 @@ var _TreeSet = class _TreeSet {
|
|
|
9035
9623
|
const toElementFn = options.toElementFn;
|
|
9036
9624
|
const comparator = (_a = options.comparator) != null ? _a : _TreeSet.createDefaultComparator();
|
|
9037
9625
|
__privateSet(this, _isDefaultComparator, options.comparator === void 0);
|
|
9038
|
-
__privateSet(this, _core, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
9626
|
+
__privateSet(this, _core, new RedBlackTree([], { comparator, isMapMode: options.isMapMode, enableOrderStatistic: options.enableOrderStatistic }));
|
|
9039
9627
|
for (const item of elements) {
|
|
9040
9628
|
const k = toElementFn ? toElementFn(item) : item;
|
|
9041
9629
|
this.add(k);
|
|
@@ -9054,7 +9642,7 @@ var _TreeSet = class _TreeSet {
|
|
|
9054
9642
|
static createDefaultComparator() {
|
|
9055
9643
|
return (a, b) => {
|
|
9056
9644
|
if (typeof a === "number" && typeof b === "number") {
|
|
9057
|
-
if (Number.isNaN(a) || Number.isNaN(b))
|
|
9645
|
+
if (Number.isNaN(a) || Number.isNaN(b)) raise(TypeError, ERR.invalidNaN("TreeSet"));
|
|
9058
9646
|
const aa = Object.is(a, -0) ? 0 : a;
|
|
9059
9647
|
const bb = Object.is(b, -0) ? 0 : b;
|
|
9060
9648
|
return aa > bb ? 1 : aa < bb ? -1 : 0;
|
|
@@ -9065,10 +9653,10 @@ var _TreeSet = class _TreeSet {
|
|
|
9065
9653
|
if (a instanceof Date && b instanceof Date) {
|
|
9066
9654
|
const ta = a.getTime();
|
|
9067
9655
|
const tb = b.getTime();
|
|
9068
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
9656
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate("TreeSet"));
|
|
9069
9657
|
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
9070
9658
|
}
|
|
9071
|
-
|
|
9659
|
+
raise(TypeError, ERR.comparatorRequired("TreeSet"));
|
|
9072
9660
|
};
|
|
9073
9661
|
}
|
|
9074
9662
|
/**
|
|
@@ -9196,6 +9784,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9196
9784
|
|
|
9197
9785
|
|
|
9198
9786
|
|
|
9787
|
+
|
|
9788
|
+
|
|
9789
|
+
|
|
9790
|
+
|
|
9791
|
+
|
|
9792
|
+
|
|
9793
|
+
|
|
9794
|
+
|
|
9795
|
+
|
|
9796
|
+
|
|
9797
|
+
|
|
9798
|
+
|
|
9799
|
+
|
|
9800
|
+
|
|
9801
|
+
|
|
9802
|
+
|
|
9803
|
+
|
|
9804
|
+
|
|
9805
|
+
|
|
9806
|
+
|
|
9199
9807
|
|
|
9200
9808
|
|
|
9201
9809
|
|
|
@@ -9227,15 +9835,15 @@ var _TreeSet = class _TreeSet {
|
|
|
9227
9835
|
_validateKey(key) {
|
|
9228
9836
|
if (!__privateGet(this, _isDefaultComparator)) return;
|
|
9229
9837
|
if (typeof key === "number") {
|
|
9230
|
-
if (Number.isNaN(key))
|
|
9838
|
+
if (Number.isNaN(key)) raise(TypeError, ERR.invalidNaN("TreeSet"));
|
|
9231
9839
|
return;
|
|
9232
9840
|
}
|
|
9233
9841
|
if (typeof key === "string") return;
|
|
9234
9842
|
if (key instanceof Date) {
|
|
9235
|
-
if (Number.isNaN(key.getTime()))
|
|
9843
|
+
if (Number.isNaN(key.getTime())) raise(TypeError, ERR.invalidDate("TreeSet"));
|
|
9236
9844
|
return;
|
|
9237
9845
|
}
|
|
9238
|
-
|
|
9846
|
+
raise(TypeError, ERR.comparatorRequired("TreeSet"));
|
|
9239
9847
|
}
|
|
9240
9848
|
/**
|
|
9241
9849
|
* Add a key to the set (no-op if already present).
|
|
@@ -9360,6 +9968,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9360
9968
|
|
|
9361
9969
|
|
|
9362
9970
|
|
|
9971
|
+
|
|
9972
|
+
|
|
9973
|
+
|
|
9974
|
+
|
|
9975
|
+
|
|
9976
|
+
|
|
9977
|
+
|
|
9978
|
+
|
|
9979
|
+
|
|
9980
|
+
|
|
9981
|
+
|
|
9982
|
+
|
|
9983
|
+
|
|
9984
|
+
|
|
9985
|
+
|
|
9986
|
+
|
|
9987
|
+
|
|
9988
|
+
|
|
9989
|
+
|
|
9990
|
+
|
|
9363
9991
|
|
|
9364
9992
|
|
|
9365
9993
|
|
|
@@ -9529,6 +10157,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9529
10157
|
|
|
9530
10158
|
|
|
9531
10159
|
|
|
10160
|
+
|
|
10161
|
+
|
|
10162
|
+
|
|
10163
|
+
|
|
10164
|
+
|
|
10165
|
+
|
|
10166
|
+
|
|
10167
|
+
|
|
10168
|
+
|
|
10169
|
+
|
|
10170
|
+
|
|
10171
|
+
|
|
10172
|
+
|
|
10173
|
+
|
|
10174
|
+
|
|
10175
|
+
|
|
10176
|
+
|
|
10177
|
+
|
|
10178
|
+
|
|
10179
|
+
|
|
9532
10180
|
|
|
9533
10181
|
|
|
9534
10182
|
|
|
@@ -9693,6 +10341,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9693
10341
|
|
|
9694
10342
|
|
|
9695
10343
|
|
|
10344
|
+
|
|
10345
|
+
|
|
10346
|
+
|
|
10347
|
+
|
|
10348
|
+
|
|
10349
|
+
|
|
10350
|
+
|
|
10351
|
+
|
|
10352
|
+
|
|
10353
|
+
|
|
10354
|
+
|
|
10355
|
+
|
|
10356
|
+
|
|
10357
|
+
|
|
10358
|
+
|
|
10359
|
+
|
|
10360
|
+
|
|
10361
|
+
|
|
10362
|
+
|
|
10363
|
+
|
|
9696
10364
|
|
|
9697
10365
|
|
|
9698
10366
|
|
|
@@ -9847,6 +10515,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9847
10515
|
|
|
9848
10516
|
|
|
9849
10517
|
|
|
10518
|
+
|
|
10519
|
+
|
|
10520
|
+
|
|
10521
|
+
|
|
10522
|
+
|
|
10523
|
+
|
|
10524
|
+
|
|
10525
|
+
|
|
10526
|
+
|
|
10527
|
+
|
|
10528
|
+
|
|
10529
|
+
|
|
10530
|
+
|
|
10531
|
+
|
|
10532
|
+
|
|
10533
|
+
|
|
10534
|
+
|
|
10535
|
+
|
|
10536
|
+
|
|
10537
|
+
|
|
9850
10538
|
|
|
9851
10539
|
|
|
9852
10540
|
|
|
@@ -9996,6 +10684,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9996
10684
|
|
|
9997
10685
|
|
|
9998
10686
|
|
|
10687
|
+
|
|
10688
|
+
|
|
10689
|
+
|
|
10690
|
+
|
|
10691
|
+
|
|
10692
|
+
|
|
10693
|
+
|
|
10694
|
+
|
|
10695
|
+
|
|
10696
|
+
|
|
10697
|
+
|
|
10698
|
+
|
|
10699
|
+
|
|
10700
|
+
|
|
10701
|
+
|
|
10702
|
+
|
|
10703
|
+
|
|
10704
|
+
|
|
10705
|
+
|
|
10706
|
+
|
|
9999
10707
|
|
|
10000
10708
|
|
|
10001
10709
|
|
|
@@ -10146,6 +10854,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10146
10854
|
|
|
10147
10855
|
|
|
10148
10856
|
|
|
10857
|
+
|
|
10858
|
+
|
|
10859
|
+
|
|
10860
|
+
|
|
10861
|
+
|
|
10862
|
+
|
|
10863
|
+
|
|
10864
|
+
|
|
10865
|
+
|
|
10866
|
+
|
|
10867
|
+
|
|
10868
|
+
|
|
10869
|
+
|
|
10870
|
+
|
|
10871
|
+
|
|
10872
|
+
|
|
10873
|
+
|
|
10874
|
+
|
|
10875
|
+
|
|
10876
|
+
|
|
10149
10877
|
|
|
10150
10878
|
|
|
10151
10879
|
|
|
@@ -10296,6 +11024,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10296
11024
|
|
|
10297
11025
|
|
|
10298
11026
|
|
|
11027
|
+
|
|
11028
|
+
|
|
11029
|
+
|
|
11030
|
+
|
|
11031
|
+
|
|
11032
|
+
|
|
11033
|
+
|
|
11034
|
+
|
|
11035
|
+
|
|
11036
|
+
|
|
11037
|
+
|
|
11038
|
+
|
|
11039
|
+
|
|
11040
|
+
|
|
11041
|
+
|
|
11042
|
+
|
|
11043
|
+
|
|
11044
|
+
|
|
11045
|
+
|
|
11046
|
+
|
|
10299
11047
|
|
|
10300
11048
|
|
|
10301
11049
|
|
|
@@ -10449,6 +11197,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10449
11197
|
|
|
10450
11198
|
|
|
10451
11199
|
|
|
11200
|
+
|
|
11201
|
+
|
|
11202
|
+
|
|
11203
|
+
|
|
11204
|
+
|
|
11205
|
+
|
|
11206
|
+
|
|
11207
|
+
|
|
11208
|
+
|
|
11209
|
+
|
|
11210
|
+
|
|
11211
|
+
|
|
11212
|
+
|
|
11213
|
+
|
|
11214
|
+
|
|
11215
|
+
|
|
11216
|
+
|
|
11217
|
+
|
|
11218
|
+
|
|
11219
|
+
|
|
10452
11220
|
|
|
10453
11221
|
|
|
10454
11222
|
|
|
@@ -10602,6 +11370,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10602
11370
|
|
|
10603
11371
|
|
|
10604
11372
|
|
|
11373
|
+
|
|
11374
|
+
|
|
11375
|
+
|
|
11376
|
+
|
|
11377
|
+
|
|
11378
|
+
|
|
11379
|
+
|
|
11380
|
+
|
|
11381
|
+
|
|
11382
|
+
|
|
11383
|
+
|
|
11384
|
+
|
|
11385
|
+
|
|
11386
|
+
|
|
11387
|
+
|
|
11388
|
+
|
|
11389
|
+
|
|
11390
|
+
|
|
11391
|
+
|
|
11392
|
+
|
|
10605
11393
|
|
|
10606
11394
|
|
|
10607
11395
|
|
|
@@ -10779,8 +11567,28 @@ var _TreeSet = class _TreeSet {
|
|
|
10779
11567
|
|
|
10780
11568
|
|
|
10781
11569
|
|
|
10782
|
-
|
|
10783
|
-
|
|
11570
|
+
|
|
11571
|
+
|
|
11572
|
+
|
|
11573
|
+
|
|
11574
|
+
|
|
11575
|
+
|
|
11576
|
+
|
|
11577
|
+
|
|
11578
|
+
|
|
11579
|
+
|
|
11580
|
+
|
|
11581
|
+
|
|
11582
|
+
|
|
11583
|
+
|
|
11584
|
+
|
|
11585
|
+
|
|
11586
|
+
|
|
11587
|
+
|
|
11588
|
+
|
|
11589
|
+
|
|
11590
|
+
* @example
|
|
11591
|
+
* // Filter
|
|
10784
11592
|
* const ts = new TreeSet<number>([1, 2, 3, 4, 5]);
|
|
10785
11593
|
* const evens = ts.filter(k => k % 2 === 0);
|
|
10786
11594
|
* console.log([...evens]); // [2, 4];
|
|
@@ -10914,6 +11722,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10914
11722
|
|
|
10915
11723
|
|
|
10916
11724
|
|
|
11725
|
+
|
|
11726
|
+
|
|
11727
|
+
|
|
11728
|
+
|
|
11729
|
+
|
|
11730
|
+
|
|
11731
|
+
|
|
11732
|
+
|
|
11733
|
+
|
|
11734
|
+
|
|
11735
|
+
|
|
11736
|
+
|
|
11737
|
+
|
|
11738
|
+
|
|
11739
|
+
|
|
11740
|
+
|
|
11741
|
+
|
|
11742
|
+
|
|
11743
|
+
|
|
11744
|
+
|
|
10917
11745
|
|
|
10918
11746
|
|
|
10919
11747
|
|
|
@@ -11065,6 +11893,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11065
11893
|
|
|
11066
11894
|
|
|
11067
11895
|
|
|
11896
|
+
|
|
11897
|
+
|
|
11898
|
+
|
|
11899
|
+
|
|
11900
|
+
|
|
11901
|
+
|
|
11902
|
+
|
|
11903
|
+
|
|
11904
|
+
|
|
11905
|
+
|
|
11906
|
+
|
|
11907
|
+
|
|
11908
|
+
|
|
11909
|
+
|
|
11910
|
+
|
|
11911
|
+
|
|
11912
|
+
|
|
11913
|
+
|
|
11914
|
+
|
|
11915
|
+
|
|
11068
11916
|
|
|
11069
11917
|
|
|
11070
11918
|
|
|
@@ -11217,6 +12065,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11217
12065
|
|
|
11218
12066
|
|
|
11219
12067
|
|
|
12068
|
+
|
|
12069
|
+
|
|
12070
|
+
|
|
12071
|
+
|
|
12072
|
+
|
|
12073
|
+
|
|
12074
|
+
|
|
12075
|
+
|
|
12076
|
+
|
|
12077
|
+
|
|
12078
|
+
|
|
12079
|
+
|
|
12080
|
+
|
|
12081
|
+
|
|
12082
|
+
|
|
12083
|
+
|
|
12084
|
+
|
|
12085
|
+
|
|
12086
|
+
|
|
12087
|
+
|
|
11220
12088
|
|
|
11221
12089
|
|
|
11222
12090
|
|
|
@@ -11369,6 +12237,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11369
12237
|
|
|
11370
12238
|
|
|
11371
12239
|
|
|
12240
|
+
|
|
12241
|
+
|
|
12242
|
+
|
|
12243
|
+
|
|
12244
|
+
|
|
12245
|
+
|
|
12246
|
+
|
|
12247
|
+
|
|
12248
|
+
|
|
12249
|
+
|
|
12250
|
+
|
|
12251
|
+
|
|
12252
|
+
|
|
12253
|
+
|
|
12254
|
+
|
|
12255
|
+
|
|
12256
|
+
|
|
12257
|
+
|
|
12258
|
+
|
|
12259
|
+
|
|
11372
12260
|
|
|
11373
12261
|
|
|
11374
12262
|
|
|
@@ -11524,6 +12412,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11524
12412
|
|
|
11525
12413
|
|
|
11526
12414
|
|
|
12415
|
+
|
|
12416
|
+
|
|
12417
|
+
|
|
12418
|
+
|
|
12419
|
+
|
|
12420
|
+
|
|
12421
|
+
|
|
12422
|
+
|
|
12423
|
+
|
|
12424
|
+
|
|
12425
|
+
|
|
12426
|
+
|
|
12427
|
+
|
|
12428
|
+
|
|
12429
|
+
|
|
12430
|
+
|
|
12431
|
+
|
|
12432
|
+
|
|
12433
|
+
|
|
12434
|
+
|
|
11527
12435
|
|
|
11528
12436
|
|
|
11529
12437
|
|
|
@@ -11673,6 +12581,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11673
12581
|
|
|
11674
12582
|
|
|
11675
12583
|
|
|
12584
|
+
|
|
12585
|
+
|
|
12586
|
+
|
|
12587
|
+
|
|
12588
|
+
|
|
12589
|
+
|
|
12590
|
+
|
|
12591
|
+
|
|
12592
|
+
|
|
12593
|
+
|
|
12594
|
+
|
|
12595
|
+
|
|
12596
|
+
|
|
12597
|
+
|
|
12598
|
+
|
|
12599
|
+
|
|
12600
|
+
|
|
12601
|
+
|
|
12602
|
+
|
|
12603
|
+
|
|
11676
12604
|
|
|
11677
12605
|
|
|
11678
12606
|
|
|
@@ -11731,6 +12659,10 @@ var _TreeSet = class _TreeSet {
|
|
|
11731
12659
|
|
|
11732
12660
|
|
|
11733
12661
|
|
|
12662
|
+
|
|
12663
|
+
|
|
12664
|
+
|
|
12665
|
+
|
|
11734
12666
|
|
|
11735
12667
|
|
|
11736
12668
|
|
|
@@ -11795,6 +12727,10 @@ var _TreeSet = class _TreeSet {
|
|
|
11795
12727
|
|
|
11796
12728
|
|
|
11797
12729
|
|
|
12730
|
+
|
|
12731
|
+
|
|
12732
|
+
|
|
12733
|
+
|
|
11798
12734
|
|
|
11799
12735
|
|
|
11800
12736
|
|
|
@@ -11837,6 +12773,10 @@ var _TreeSet = class _TreeSet {
|
|
|
11837
12773
|
|
|
11838
12774
|
|
|
11839
12775
|
|
|
12776
|
+
|
|
12777
|
+
|
|
12778
|
+
|
|
12779
|
+
|
|
11840
12780
|
|
|
11841
12781
|
|
|
11842
12782
|
|
|
@@ -11884,6 +12824,10 @@ var _TreeSet = class _TreeSet {
|
|
|
11884
12824
|
|
|
11885
12825
|
|
|
11886
12826
|
|
|
12827
|
+
|
|
12828
|
+
|
|
12829
|
+
|
|
12830
|
+
|
|
11887
12831
|
|
|
11888
12832
|
|
|
11889
12833
|
|
|
@@ -12005,6 +12949,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12005
12949
|
|
|
12006
12950
|
|
|
12007
12951
|
|
|
12952
|
+
|
|
12953
|
+
|
|
12954
|
+
|
|
12955
|
+
|
|
12956
|
+
|
|
12957
|
+
|
|
12958
|
+
|
|
12959
|
+
|
|
12960
|
+
|
|
12961
|
+
|
|
12962
|
+
|
|
12963
|
+
|
|
12964
|
+
|
|
12965
|
+
|
|
12966
|
+
|
|
12967
|
+
|
|
12008
12968
|
|
|
12009
12969
|
|
|
12010
12970
|
|
|
@@ -12146,6 +13106,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12146
13106
|
|
|
12147
13107
|
|
|
12148
13108
|
|
|
13109
|
+
|
|
13110
|
+
|
|
13111
|
+
|
|
13112
|
+
|
|
13113
|
+
|
|
13114
|
+
|
|
13115
|
+
|
|
13116
|
+
|
|
13117
|
+
|
|
13118
|
+
|
|
13119
|
+
|
|
13120
|
+
|
|
13121
|
+
|
|
13122
|
+
|
|
13123
|
+
|
|
13124
|
+
|
|
12149
13125
|
|
|
12150
13126
|
|
|
12151
13127
|
|
|
@@ -12279,6 +13255,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12279
13255
|
|
|
12280
13256
|
|
|
12281
13257
|
|
|
13258
|
+
|
|
13259
|
+
|
|
13260
|
+
|
|
13261
|
+
|
|
13262
|
+
|
|
13263
|
+
|
|
13264
|
+
|
|
13265
|
+
|
|
13266
|
+
|
|
13267
|
+
|
|
13268
|
+
|
|
13269
|
+
|
|
13270
|
+
|
|
13271
|
+
|
|
13272
|
+
|
|
13273
|
+
|
|
12282
13274
|
|
|
12283
13275
|
|
|
12284
13276
|
|
|
@@ -12410,6 +13402,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12410
13402
|
|
|
12411
13403
|
|
|
12412
13404
|
|
|
13405
|
+
|
|
13406
|
+
|
|
13407
|
+
|
|
13408
|
+
|
|
13409
|
+
|
|
13410
|
+
|
|
13411
|
+
|
|
13412
|
+
|
|
13413
|
+
|
|
13414
|
+
|
|
13415
|
+
|
|
13416
|
+
|
|
13417
|
+
|
|
13418
|
+
|
|
13419
|
+
|
|
13420
|
+
|
|
12413
13421
|
|
|
12414
13422
|
|
|
12415
13423
|
|
|
@@ -12544,6 +13552,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12544
13552
|
|
|
12545
13553
|
|
|
12546
13554
|
|
|
13555
|
+
|
|
13556
|
+
|
|
13557
|
+
|
|
13558
|
+
|
|
13559
|
+
|
|
13560
|
+
|
|
13561
|
+
|
|
13562
|
+
|
|
13563
|
+
|
|
13564
|
+
|
|
13565
|
+
|
|
13566
|
+
|
|
13567
|
+
|
|
13568
|
+
|
|
13569
|
+
|
|
13570
|
+
|
|
12547
13571
|
|
|
12548
13572
|
|
|
12549
13573
|
|
|
@@ -12595,6 +13619,62 @@ var _TreeSet = class _TreeSet {
|
|
|
12595
13619
|
}
|
|
12596
13620
|
return out;
|
|
12597
13621
|
}
|
|
13622
|
+
// ─── Order-Statistic Methods ───────────────────────────
|
|
13623
|
+
/**
|
|
13624
|
+
* Returns the element at the k-th position in tree order (0-indexed).
|
|
13625
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
13626
|
+
|
|
13627
|
+
|
|
13628
|
+
|
|
13629
|
+
* @example
|
|
13630
|
+
* // Find k-th element in a TreeSet
|
|
13631
|
+
* const set = new TreeSet<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
13632
|
+
* console.log(set.getByRank(0)); // 10;
|
|
13633
|
+
* console.log(set.getByRank(2)); // 30;
|
|
13634
|
+
* console.log(set.getRank(30)); // 2;
|
|
13635
|
+
*/
|
|
13636
|
+
getByRank(k) {
|
|
13637
|
+
return __privateGet(this, _core).getByRank(k);
|
|
13638
|
+
}
|
|
13639
|
+
/**
|
|
13640
|
+
* Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
13641
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
13642
|
+
* @example
|
|
13643
|
+
* // Get the rank of a key in sorted order
|
|
13644
|
+
* const tree = new TreeSet<number>(
|
|
13645
|
+
* [10, 20, 30, 40, 50],
|
|
13646
|
+
* { enableOrderStatistic: true }
|
|
13647
|
+
* );
|
|
13648
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
13649
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
13650
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
13651
|
+
* console.log(tree.getRank(25)); // 2;
|
|
13652
|
+
*/
|
|
13653
|
+
getRank(key) {
|
|
13654
|
+
return __privateGet(this, _core).getRank(key);
|
|
13655
|
+
}
|
|
13656
|
+
/**
|
|
13657
|
+
* Returns elements by rank range (0-indexed, inclusive on both ends).
|
|
13658
|
+
* @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
|
|
13659
|
+
|
|
13660
|
+
* @example
|
|
13661
|
+
* // Pagination with rangeByRank
|
|
13662
|
+
* const tree = new TreeSet<number>(
|
|
13663
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
13664
|
+
* { enableOrderStatistic: true }
|
|
13665
|
+
* );
|
|
13666
|
+
* const pageSize = 3;
|
|
13667
|
+
*
|
|
13668
|
+
* // Page 1
|
|
13669
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
13670
|
+
* // Page 2
|
|
13671
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
13672
|
+
* // Page 3
|
|
13673
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
13674
|
+
*/
|
|
13675
|
+
rangeByRank(start, end) {
|
|
13676
|
+
return __privateGet(this, _core).rangeByRank(start, end).filter((k) => k !== void 0);
|
|
13677
|
+
}
|
|
12598
13678
|
/**
|
|
12599
13679
|
* Creates a shallow clone of this set.
|
|
12600
13680
|
* @remarks Time O(n log n), Space O(n)
|
|
@@ -12737,7 +13817,27 @@ var _TreeSet = class _TreeSet {
|
|
|
12737
13817
|
|
|
12738
13818
|
|
|
12739
13819
|
|
|
12740
|
-
|
|
13820
|
+
|
|
13821
|
+
|
|
13822
|
+
|
|
13823
|
+
|
|
13824
|
+
|
|
13825
|
+
|
|
13826
|
+
|
|
13827
|
+
|
|
13828
|
+
|
|
13829
|
+
|
|
13830
|
+
|
|
13831
|
+
|
|
13832
|
+
|
|
13833
|
+
|
|
13834
|
+
|
|
13835
|
+
|
|
13836
|
+
|
|
13837
|
+
|
|
13838
|
+
|
|
13839
|
+
|
|
13840
|
+
* @example
|
|
12741
13841
|
* // Deep clone
|
|
12742
13842
|
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
12743
13843
|
* const copy = ts.clone();
|
|
@@ -12780,7 +13880,7 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
12780
13880
|
const comparator = (_a = options.comparator) != null ? _a : TreeSet.createDefaultComparator();
|
|
12781
13881
|
__privateSet(this, _isDefaultComparator2, options.comparator === void 0);
|
|
12782
13882
|
const toEntryFn = options.toEntryFn;
|
|
12783
|
-
__privateSet(this, _core2, new RedBlackTree([], { ...options, comparator, isMapMode: options.isMapMode }));
|
|
13883
|
+
__privateSet(this, _core2, new RedBlackTree([], { ...options, comparator, isMapMode: options.isMapMode, enableOrderStatistic: options.enableOrderStatistic }));
|
|
12784
13884
|
for (const x of keysNodesEntriesOrRaws) {
|
|
12785
13885
|
if (x === null || x === void 0) continue;
|
|
12786
13886
|
if (toEntryFn) {
|
|
@@ -12813,15 +13913,15 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
12813
13913
|
_validateKey(key) {
|
|
12814
13914
|
if (!__privateGet(this, _isDefaultComparator2)) return;
|
|
12815
13915
|
if (typeof key === "number") {
|
|
12816
|
-
if (Number.isNaN(key))
|
|
13916
|
+
if (Number.isNaN(key)) raise(TypeError, ERR.invalidNaN("TreeMultiMap"));
|
|
12817
13917
|
return;
|
|
12818
13918
|
}
|
|
12819
13919
|
if (typeof key === "string") return;
|
|
12820
13920
|
if (key instanceof Date) {
|
|
12821
|
-
if (Number.isNaN(key.getTime()))
|
|
13921
|
+
if (Number.isNaN(key.getTime())) raise(TypeError, ERR.invalidDate("TreeMultiMap"));
|
|
12822
13922
|
return;
|
|
12823
13923
|
}
|
|
12824
|
-
|
|
13924
|
+
raise(TypeError, ERR.comparatorRequired("TreeMultiMap"));
|
|
12825
13925
|
}
|
|
12826
13926
|
/**
|
|
12827
13927
|
* Number of distinct keys.
|
|
@@ -12950,6 +14050,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
12950
14050
|
|
|
12951
14051
|
|
|
12952
14052
|
|
|
14053
|
+
|
|
14054
|
+
|
|
14055
|
+
|
|
14056
|
+
|
|
14057
|
+
|
|
14058
|
+
|
|
14059
|
+
|
|
14060
|
+
|
|
14061
|
+
|
|
14062
|
+
|
|
14063
|
+
|
|
14064
|
+
|
|
14065
|
+
|
|
14066
|
+
|
|
14067
|
+
|
|
14068
|
+
|
|
14069
|
+
|
|
14070
|
+
|
|
14071
|
+
|
|
14072
|
+
|
|
12953
14073
|
|
|
12954
14074
|
|
|
12955
14075
|
|
|
@@ -13098,6 +14218,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13098
14218
|
|
|
13099
14219
|
|
|
13100
14220
|
|
|
14221
|
+
|
|
14222
|
+
|
|
14223
|
+
|
|
14224
|
+
|
|
14225
|
+
|
|
14226
|
+
|
|
14227
|
+
|
|
14228
|
+
|
|
14229
|
+
|
|
14230
|
+
|
|
14231
|
+
|
|
14232
|
+
|
|
14233
|
+
|
|
14234
|
+
|
|
14235
|
+
|
|
14236
|
+
|
|
14237
|
+
|
|
14238
|
+
|
|
14239
|
+
|
|
14240
|
+
|
|
13101
14241
|
|
|
13102
14242
|
|
|
13103
14243
|
|
|
@@ -13149,6 +14289,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13149
14289
|
|
|
13150
14290
|
|
|
13151
14291
|
|
|
14292
|
+
|
|
14293
|
+
|
|
14294
|
+
|
|
14295
|
+
|
|
13152
14296
|
|
|
13153
14297
|
|
|
13154
14298
|
|
|
@@ -13185,6 +14329,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13185
14329
|
|
|
13186
14330
|
|
|
13187
14331
|
|
|
14332
|
+
|
|
14333
|
+
|
|
14334
|
+
|
|
14335
|
+
|
|
13188
14336
|
|
|
13189
14337
|
|
|
13190
14338
|
|
|
@@ -13357,6 +14505,30 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13357
14505
|
|
|
13358
14506
|
|
|
13359
14507
|
|
|
14508
|
+
|
|
14509
|
+
|
|
14510
|
+
|
|
14511
|
+
|
|
14512
|
+
|
|
14513
|
+
|
|
14514
|
+
|
|
14515
|
+
|
|
14516
|
+
|
|
14517
|
+
|
|
14518
|
+
|
|
14519
|
+
|
|
14520
|
+
|
|
14521
|
+
|
|
14522
|
+
|
|
14523
|
+
|
|
14524
|
+
|
|
14525
|
+
|
|
14526
|
+
|
|
14527
|
+
|
|
14528
|
+
|
|
14529
|
+
|
|
14530
|
+
|
|
14531
|
+
|
|
13360
14532
|
|
|
13361
14533
|
|
|
13362
14534
|
|
|
@@ -13543,6 +14715,30 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13543
14715
|
|
|
13544
14716
|
|
|
13545
14717
|
|
|
14718
|
+
|
|
14719
|
+
|
|
14720
|
+
|
|
14721
|
+
|
|
14722
|
+
|
|
14723
|
+
|
|
14724
|
+
|
|
14725
|
+
|
|
14726
|
+
|
|
14727
|
+
|
|
14728
|
+
|
|
14729
|
+
|
|
14730
|
+
|
|
14731
|
+
|
|
14732
|
+
|
|
14733
|
+
|
|
14734
|
+
|
|
14735
|
+
|
|
14736
|
+
|
|
14737
|
+
|
|
14738
|
+
|
|
14739
|
+
|
|
14740
|
+
|
|
14741
|
+
|
|
13546
14742
|
|
|
13547
14743
|
|
|
13548
14744
|
|
|
@@ -13689,6 +14885,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13689
14885
|
|
|
13690
14886
|
|
|
13691
14887
|
|
|
14888
|
+
|
|
14889
|
+
|
|
14890
|
+
|
|
14891
|
+
|
|
14892
|
+
|
|
14893
|
+
|
|
14894
|
+
|
|
14895
|
+
|
|
14896
|
+
|
|
14897
|
+
|
|
14898
|
+
|
|
14899
|
+
|
|
14900
|
+
|
|
14901
|
+
|
|
14902
|
+
|
|
14903
|
+
|
|
14904
|
+
|
|
14905
|
+
|
|
14906
|
+
|
|
14907
|
+
|
|
13692
14908
|
|
|
13693
14909
|
|
|
13694
14910
|
|
|
@@ -13900,6 +15116,30 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13900
15116
|
|
|
13901
15117
|
|
|
13902
15118
|
|
|
15119
|
+
|
|
15120
|
+
|
|
15121
|
+
|
|
15122
|
+
|
|
15123
|
+
|
|
15124
|
+
|
|
15125
|
+
|
|
15126
|
+
|
|
15127
|
+
|
|
15128
|
+
|
|
15129
|
+
|
|
15130
|
+
|
|
15131
|
+
|
|
15132
|
+
|
|
15133
|
+
|
|
15134
|
+
|
|
15135
|
+
|
|
15136
|
+
|
|
15137
|
+
|
|
15138
|
+
|
|
15139
|
+
|
|
15140
|
+
|
|
15141
|
+
|
|
15142
|
+
|
|
13903
15143
|
|
|
13904
15144
|
|
|
13905
15145
|
|
|
@@ -13953,6 +15193,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13953
15193
|
|
|
13954
15194
|
|
|
13955
15195
|
|
|
15196
|
+
|
|
15197
|
+
|
|
15198
|
+
|
|
15199
|
+
|
|
13956
15200
|
|
|
13957
15201
|
|
|
13958
15202
|
|
|
@@ -13990,6 +15234,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13990
15234
|
|
|
13991
15235
|
|
|
13992
15236
|
|
|
15237
|
+
|
|
15238
|
+
|
|
15239
|
+
|
|
15240
|
+
|
|
13993
15241
|
|
|
13994
15242
|
|
|
13995
15243
|
|
|
@@ -14032,6 +15280,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14032
15280
|
|
|
14033
15281
|
|
|
14034
15282
|
|
|
15283
|
+
|
|
15284
|
+
|
|
15285
|
+
|
|
15286
|
+
|
|
14035
15287
|
|
|
14036
15288
|
|
|
14037
15289
|
|
|
@@ -14192,6 +15444,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14192
15444
|
|
|
14193
15445
|
|
|
14194
15446
|
|
|
15447
|
+
|
|
15448
|
+
|
|
15449
|
+
|
|
15450
|
+
|
|
15451
|
+
|
|
15452
|
+
|
|
15453
|
+
|
|
15454
|
+
|
|
15455
|
+
|
|
15456
|
+
|
|
15457
|
+
|
|
15458
|
+
|
|
15459
|
+
|
|
15460
|
+
|
|
15461
|
+
|
|
15462
|
+
|
|
15463
|
+
|
|
15464
|
+
|
|
15465
|
+
|
|
15466
|
+
|
|
14195
15467
|
|
|
14196
15468
|
|
|
14197
15469
|
|
|
@@ -14343,6 +15615,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14343
15615
|
|
|
14344
15616
|
|
|
14345
15617
|
|
|
15618
|
+
|
|
15619
|
+
|
|
15620
|
+
|
|
15621
|
+
|
|
15622
|
+
|
|
15623
|
+
|
|
15624
|
+
|
|
15625
|
+
|
|
15626
|
+
|
|
15627
|
+
|
|
15628
|
+
|
|
15629
|
+
|
|
15630
|
+
|
|
15631
|
+
|
|
15632
|
+
|
|
15633
|
+
|
|
15634
|
+
|
|
15635
|
+
|
|
15636
|
+
|
|
15637
|
+
|
|
14346
15638
|
|
|
14347
15639
|
|
|
14348
15640
|
|
|
@@ -14395,6 +15687,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14395
15687
|
|
|
14396
15688
|
|
|
14397
15689
|
|
|
15690
|
+
|
|
15691
|
+
|
|
15692
|
+
|
|
15693
|
+
|
|
14398
15694
|
|
|
14399
15695
|
|
|
14400
15696
|
|
|
@@ -14432,6 +15728,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14432
15728
|
|
|
14433
15729
|
|
|
14434
15730
|
|
|
15731
|
+
|
|
15732
|
+
|
|
15733
|
+
|
|
15734
|
+
|
|
14435
15735
|
|
|
14436
15736
|
|
|
14437
15737
|
|
|
@@ -14469,6 +15769,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14469
15769
|
|
|
14470
15770
|
|
|
14471
15771
|
|
|
15772
|
+
|
|
15773
|
+
|
|
15774
|
+
|
|
15775
|
+
|
|
14472
15776
|
|
|
14473
15777
|
|
|
14474
15778
|
|
|
@@ -14536,6 +15840,14 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14536
15840
|
|
|
14537
15841
|
|
|
14538
15842
|
|
|
15843
|
+
|
|
15844
|
+
|
|
15845
|
+
|
|
15846
|
+
|
|
15847
|
+
|
|
15848
|
+
|
|
15849
|
+
|
|
15850
|
+
|
|
14539
15851
|
|
|
14540
15852
|
|
|
14541
15853
|
|
|
@@ -14609,6 +15921,14 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14609
15921
|
|
|
14610
15922
|
|
|
14611
15923
|
|
|
15924
|
+
|
|
15925
|
+
|
|
15926
|
+
|
|
15927
|
+
|
|
15928
|
+
|
|
15929
|
+
|
|
15930
|
+
|
|
15931
|
+
|
|
14612
15932
|
|
|
14613
15933
|
|
|
14614
15934
|
|
|
@@ -14655,6 +15975,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14655
15975
|
|
|
14656
15976
|
|
|
14657
15977
|
|
|
15978
|
+
|
|
15979
|
+
|
|
15980
|
+
|
|
15981
|
+
|
|
14658
15982
|
|
|
14659
15983
|
|
|
14660
15984
|
|
|
@@ -14696,6 +16020,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14696
16020
|
|
|
14697
16021
|
|
|
14698
16022
|
|
|
16023
|
+
|
|
16024
|
+
|
|
16025
|
+
|
|
16026
|
+
|
|
14699
16027
|
|
|
14700
16028
|
|
|
14701
16029
|
|
|
@@ -14859,13 +16187,33 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14859
16187
|
|
|
14860
16188
|
|
|
14861
16189
|
|
|
14862
|
-
|
|
14863
|
-
|
|
14864
|
-
|
|
14865
|
-
|
|
14866
|
-
|
|
14867
|
-
|
|
14868
|
-
|
|
16190
|
+
|
|
16191
|
+
|
|
16192
|
+
|
|
16193
|
+
|
|
16194
|
+
|
|
16195
|
+
|
|
16196
|
+
|
|
16197
|
+
|
|
16198
|
+
|
|
16199
|
+
|
|
16200
|
+
|
|
16201
|
+
|
|
16202
|
+
|
|
16203
|
+
|
|
16204
|
+
|
|
16205
|
+
|
|
16206
|
+
|
|
16207
|
+
|
|
16208
|
+
|
|
16209
|
+
|
|
16210
|
+
* @example
|
|
16211
|
+
* // Least key ≥ target
|
|
16212
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
16213
|
+
* mm.add(10, 'a');
|
|
16214
|
+
* mm.add(20, 'b');
|
|
16215
|
+
* mm.add(30, 'c');
|
|
16216
|
+
* console.log(mm.ceiling(15)?.[0]); // 20;
|
|
14869
16217
|
*/
|
|
14870
16218
|
ceiling(key) {
|
|
14871
16219
|
this._validateKey(key);
|
|
@@ -15000,6 +16348,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15000
16348
|
|
|
15001
16349
|
|
|
15002
16350
|
|
|
16351
|
+
|
|
16352
|
+
|
|
16353
|
+
|
|
16354
|
+
|
|
16355
|
+
|
|
16356
|
+
|
|
16357
|
+
|
|
16358
|
+
|
|
16359
|
+
|
|
16360
|
+
|
|
16361
|
+
|
|
16362
|
+
|
|
16363
|
+
|
|
16364
|
+
|
|
16365
|
+
|
|
16366
|
+
|
|
16367
|
+
|
|
16368
|
+
|
|
16369
|
+
|
|
16370
|
+
|
|
15003
16371
|
|
|
15004
16372
|
|
|
15005
16373
|
|
|
@@ -15135,6 +16503,22 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15135
16503
|
|
|
15136
16504
|
|
|
15137
16505
|
|
|
16506
|
+
|
|
16507
|
+
|
|
16508
|
+
|
|
16509
|
+
|
|
16510
|
+
|
|
16511
|
+
|
|
16512
|
+
|
|
16513
|
+
|
|
16514
|
+
|
|
16515
|
+
|
|
16516
|
+
|
|
16517
|
+
|
|
16518
|
+
|
|
16519
|
+
|
|
16520
|
+
|
|
16521
|
+
|
|
15138
16522
|
|
|
15139
16523
|
|
|
15140
16524
|
|
|
@@ -15265,6 +16649,22 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15265
16649
|
|
|
15266
16650
|
|
|
15267
16651
|
|
|
16652
|
+
|
|
16653
|
+
|
|
16654
|
+
|
|
16655
|
+
|
|
16656
|
+
|
|
16657
|
+
|
|
16658
|
+
|
|
16659
|
+
|
|
16660
|
+
|
|
16661
|
+
|
|
16662
|
+
|
|
16663
|
+
|
|
16664
|
+
|
|
16665
|
+
|
|
16666
|
+
|
|
16667
|
+
|
|
15268
16668
|
|
|
15269
16669
|
|
|
15270
16670
|
|
|
@@ -15420,6 +16820,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15420
16820
|
|
|
15421
16821
|
|
|
15422
16822
|
|
|
16823
|
+
|
|
16824
|
+
|
|
16825
|
+
|
|
16826
|
+
|
|
16827
|
+
|
|
16828
|
+
|
|
16829
|
+
|
|
16830
|
+
|
|
16831
|
+
|
|
16832
|
+
|
|
16833
|
+
|
|
16834
|
+
|
|
16835
|
+
|
|
16836
|
+
|
|
16837
|
+
|
|
16838
|
+
|
|
16839
|
+
|
|
16840
|
+
|
|
16841
|
+
|
|
16842
|
+
|
|
15423
16843
|
|
|
15424
16844
|
|
|
15425
16845
|
|
|
@@ -15570,6 +16990,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15570
16990
|
|
|
15571
16991
|
|
|
15572
16992
|
|
|
16993
|
+
|
|
16994
|
+
|
|
16995
|
+
|
|
16996
|
+
|
|
16997
|
+
|
|
16998
|
+
|
|
16999
|
+
|
|
17000
|
+
|
|
17001
|
+
|
|
17002
|
+
|
|
17003
|
+
|
|
17004
|
+
|
|
17005
|
+
|
|
17006
|
+
|
|
17007
|
+
|
|
17008
|
+
|
|
17009
|
+
|
|
17010
|
+
|
|
17011
|
+
|
|
17012
|
+
|
|
15573
17013
|
|
|
15574
17014
|
|
|
15575
17015
|
|
|
@@ -15725,6 +17165,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15725
17165
|
|
|
15726
17166
|
|
|
15727
17167
|
|
|
17168
|
+
|
|
17169
|
+
|
|
17170
|
+
|
|
17171
|
+
|
|
17172
|
+
|
|
17173
|
+
|
|
17174
|
+
|
|
17175
|
+
|
|
17176
|
+
|
|
17177
|
+
|
|
17178
|
+
|
|
17179
|
+
|
|
17180
|
+
|
|
17181
|
+
|
|
17182
|
+
|
|
17183
|
+
|
|
17184
|
+
|
|
17185
|
+
|
|
17186
|
+
|
|
17187
|
+
|
|
15728
17188
|
|
|
15729
17189
|
|
|
15730
17190
|
|
|
@@ -15882,6 +17342,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15882
17342
|
|
|
15883
17343
|
|
|
15884
17344
|
|
|
17345
|
+
|
|
17346
|
+
|
|
17347
|
+
|
|
17348
|
+
|
|
17349
|
+
|
|
17350
|
+
|
|
17351
|
+
|
|
17352
|
+
|
|
17353
|
+
|
|
17354
|
+
|
|
17355
|
+
|
|
17356
|
+
|
|
17357
|
+
|
|
17358
|
+
|
|
17359
|
+
|
|
17360
|
+
|
|
17361
|
+
|
|
17362
|
+
|
|
17363
|
+
|
|
17364
|
+
|
|
15885
17365
|
|
|
15886
17366
|
|
|
15887
17367
|
|
|
@@ -16037,6 +17517,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
16037
17517
|
|
|
16038
17518
|
|
|
16039
17519
|
|
|
17520
|
+
|
|
17521
|
+
|
|
17522
|
+
|
|
17523
|
+
|
|
17524
|
+
|
|
17525
|
+
|
|
17526
|
+
|
|
17527
|
+
|
|
17528
|
+
|
|
17529
|
+
|
|
17530
|
+
|
|
17531
|
+
|
|
17532
|
+
|
|
17533
|
+
|
|
17534
|
+
|
|
17535
|
+
|
|
17536
|
+
|
|
17537
|
+
|
|
17538
|
+
|
|
17539
|
+
|
|
16040
17540
|
|
|
16041
17541
|
|
|
16042
17542
|
|
|
@@ -16185,6 +17685,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
16185
17685
|
|
|
16186
17686
|
|
|
16187
17687
|
|
|
17688
|
+
|
|
17689
|
+
|
|
17690
|
+
|
|
17691
|
+
|
|
17692
|
+
|
|
17693
|
+
|
|
17694
|
+
|
|
17695
|
+
|
|
17696
|
+
|
|
17697
|
+
|
|
17698
|
+
|
|
17699
|
+
|
|
17700
|
+
|
|
17701
|
+
|
|
17702
|
+
|
|
17703
|
+
|
|
17704
|
+
|
|
17705
|
+
|
|
17706
|
+
|
|
17707
|
+
|
|
16188
17708
|
|
|
16189
17709
|
|
|
16190
17710
|
|
|
@@ -16315,6 +17835,22 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
16315
17835
|
|
|
16316
17836
|
|
|
16317
17837
|
|
|
17838
|
+
|
|
17839
|
+
|
|
17840
|
+
|
|
17841
|
+
|
|
17842
|
+
|
|
17843
|
+
|
|
17844
|
+
|
|
17845
|
+
|
|
17846
|
+
|
|
17847
|
+
|
|
17848
|
+
|
|
17849
|
+
|
|
17850
|
+
|
|
17851
|
+
|
|
17852
|
+
|
|
17853
|
+
|
|
16318
17854
|
|
|
16319
17855
|
|
|
16320
17856
|
|
|
@@ -16482,6 +18018,85 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
16482
18018
|
|
|
16483
18019
|
|
|
16484
18020
|
|
|
18021
|
+
|
|
18022
|
+
|
|
18023
|
+
|
|
18024
|
+
|
|
18025
|
+
|
|
18026
|
+
|
|
18027
|
+
|
|
18028
|
+
|
|
18029
|
+
|
|
18030
|
+
|
|
18031
|
+
|
|
18032
|
+
|
|
18033
|
+
|
|
18034
|
+
|
|
18035
|
+
|
|
18036
|
+
|
|
18037
|
+
|
|
18038
|
+
|
|
18039
|
+
|
|
18040
|
+
|
|
18041
|
+
|
|
18042
|
+
* @example
|
|
18043
|
+
* // Order-statistic on BST
|
|
18044
|
+
* const tree = new TreeMultiMap<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
18045
|
+
* console.log(tree.getByRank(0)); // 10;
|
|
18046
|
+
* console.log(tree.getByRank(4)); // 50;
|
|
18047
|
+
* console.log(tree.getRank(30)); // 2;
|
|
18048
|
+
*/
|
|
18049
|
+
// ─── Order-Statistic Methods ───────────────────────────
|
|
18050
|
+
getByRank(k) {
|
|
18051
|
+
var _a;
|
|
18052
|
+
const key = __privateGet(this, _core2).getByRank(k);
|
|
18053
|
+
if (key === void 0) return void 0;
|
|
18054
|
+
return [key, (_a = __privateGet(this, _core2).get(key)) != null ? _a : []];
|
|
18055
|
+
}
|
|
18056
|
+
/**
|
|
18057
|
+
* Get the rank of a key in sorted order
|
|
18058
|
+
* @example
|
|
18059
|
+
* // Get the rank of a key in sorted order
|
|
18060
|
+
* const tree = new TreeMultiMap<number>(
|
|
18061
|
+
* [10, 20, 30, 40, 50],
|
|
18062
|
+
* { enableOrderStatistic: true }
|
|
18063
|
+
* );
|
|
18064
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
18065
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
18066
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
18067
|
+
* console.log(tree.getRank(25)); // 2;
|
|
18068
|
+
*/
|
|
18069
|
+
getRank(key) {
|
|
18070
|
+
return __privateGet(this, _core2).getRank(key);
|
|
18071
|
+
}
|
|
18072
|
+
/**
|
|
18073
|
+
* Get elements by rank range
|
|
18074
|
+
|
|
18075
|
+
* @example
|
|
18076
|
+
* // Pagination with rangeByRank
|
|
18077
|
+
* const tree = new TreeMultiMap<number>(
|
|
18078
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
18079
|
+
* { enableOrderStatistic: true }
|
|
18080
|
+
* );
|
|
18081
|
+
* const pageSize = 3;
|
|
18082
|
+
*
|
|
18083
|
+
* // Page 1
|
|
18084
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
18085
|
+
* // Page 2
|
|
18086
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
18087
|
+
* // Page 3
|
|
18088
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
18089
|
+
*/
|
|
18090
|
+
rangeByRank(start, end) {
|
|
18091
|
+
const keys = __privateGet(this, _core2).rangeByRank(start, end);
|
|
18092
|
+
return keys.filter((k) => k !== void 0).map((k) => {
|
|
18093
|
+
var _a;
|
|
18094
|
+
return [k, (_a = __privateGet(this, _core2).get(k)) != null ? _a : []];
|
|
18095
|
+
});
|
|
18096
|
+
}
|
|
18097
|
+
/**
|
|
18098
|
+
* Deep copy
|
|
18099
|
+
|
|
16485
18100
|
|
|
16486
18101
|
|
|
16487
18102
|
|
|
@@ -16536,7 +18151,7 @@ var _TreeMap = class _TreeMap {
|
|
|
16536
18151
|
const toEntryFn = options.toEntryFn;
|
|
16537
18152
|
const comparator = (_a = options.comparator) != null ? _a : _TreeMap.createDefaultComparator();
|
|
16538
18153
|
__privateSet(this, _isDefaultComparator3, options.comparator === void 0);
|
|
16539
|
-
__privateSet(this, _core3, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
18154
|
+
__privateSet(this, _core3, new RedBlackTree([], { comparator, isMapMode: options.isMapMode, enableOrderStatistic: options.enableOrderStatistic }));
|
|
16540
18155
|
for (const item of entries) {
|
|
16541
18156
|
let k;
|
|
16542
18157
|
let v;
|
|
@@ -16544,7 +18159,7 @@ var _TreeMap = class _TreeMap {
|
|
|
16544
18159
|
[k, v] = toEntryFn(item);
|
|
16545
18160
|
} else {
|
|
16546
18161
|
if (!Array.isArray(item) || item.length < 2) {
|
|
16547
|
-
|
|
18162
|
+
raise(TypeError, ERR.invalidEntry("TreeMap"));
|
|
16548
18163
|
}
|
|
16549
18164
|
k = item[0];
|
|
16550
18165
|
v = item[1];
|
|
@@ -16565,7 +18180,7 @@ var _TreeMap = class _TreeMap {
|
|
|
16565
18180
|
static createDefaultComparator() {
|
|
16566
18181
|
return (a, b) => {
|
|
16567
18182
|
if (typeof a === "number" && typeof b === "number") {
|
|
16568
|
-
if (Number.isNaN(a) || Number.isNaN(b))
|
|
18183
|
+
if (Number.isNaN(a) || Number.isNaN(b)) raise(TypeError, ERR.invalidNaN("TreeMap"));
|
|
16569
18184
|
const aa = Object.is(a, -0) ? 0 : a;
|
|
16570
18185
|
const bb = Object.is(b, -0) ? 0 : b;
|
|
16571
18186
|
return aa > bb ? 1 : aa < bb ? -1 : 0;
|
|
@@ -16576,24 +18191,24 @@ var _TreeMap = class _TreeMap {
|
|
|
16576
18191
|
if (a instanceof Date && b instanceof Date) {
|
|
16577
18192
|
const ta = a.getTime();
|
|
16578
18193
|
const tb = b.getTime();
|
|
16579
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
18194
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate("TreeMap"));
|
|
16580
18195
|
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
16581
18196
|
}
|
|
16582
|
-
|
|
18197
|
+
raise(TypeError, ERR.comparatorRequired("TreeMap"));
|
|
16583
18198
|
};
|
|
16584
18199
|
}
|
|
16585
18200
|
_validateKey(key) {
|
|
16586
18201
|
if (!__privateGet(this, _isDefaultComparator3)) return;
|
|
16587
18202
|
if (typeof key === "number") {
|
|
16588
|
-
if (Number.isNaN(key))
|
|
18203
|
+
if (Number.isNaN(key)) raise(TypeError, ERR.invalidNaN("TreeMap"));
|
|
16589
18204
|
return;
|
|
16590
18205
|
}
|
|
16591
18206
|
if (typeof key === "string") return;
|
|
16592
18207
|
if (key instanceof Date) {
|
|
16593
|
-
if (Number.isNaN(key.getTime()))
|
|
18208
|
+
if (Number.isNaN(key.getTime())) raise(TypeError, ERR.invalidDate("TreeMap"));
|
|
16594
18209
|
return;
|
|
16595
18210
|
}
|
|
16596
|
-
|
|
18211
|
+
raise(TypeError, ERR.comparatorRequired("TreeMap"));
|
|
16597
18212
|
}
|
|
16598
18213
|
/**
|
|
16599
18214
|
* Number of entries in the map.
|
|
@@ -16741,11 +18356,31 @@ var _TreeMap = class _TreeMap {
|
|
|
16741
18356
|
|
|
16742
18357
|
|
|
16743
18358
|
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
|
|
16748
|
-
|
|
18359
|
+
|
|
18360
|
+
|
|
18361
|
+
|
|
18362
|
+
|
|
18363
|
+
|
|
18364
|
+
|
|
18365
|
+
|
|
18366
|
+
|
|
18367
|
+
|
|
18368
|
+
|
|
18369
|
+
|
|
18370
|
+
|
|
18371
|
+
|
|
18372
|
+
|
|
18373
|
+
|
|
18374
|
+
|
|
18375
|
+
|
|
18376
|
+
|
|
18377
|
+
|
|
18378
|
+
|
|
18379
|
+
* @example
|
|
18380
|
+
* // Check empty
|
|
18381
|
+
* console.log(new TreeMap().isEmpty()); // true;
|
|
18382
|
+
*/
|
|
18383
|
+
isEmpty() {
|
|
16749
18384
|
return this.size === 0;
|
|
16750
18385
|
}
|
|
16751
18386
|
/**
|
|
@@ -16877,6 +18512,26 @@ var _TreeMap = class _TreeMap {
|
|
|
16877
18512
|
|
|
16878
18513
|
|
|
16879
18514
|
|
|
18515
|
+
|
|
18516
|
+
|
|
18517
|
+
|
|
18518
|
+
|
|
18519
|
+
|
|
18520
|
+
|
|
18521
|
+
|
|
18522
|
+
|
|
18523
|
+
|
|
18524
|
+
|
|
18525
|
+
|
|
18526
|
+
|
|
18527
|
+
|
|
18528
|
+
|
|
18529
|
+
|
|
18530
|
+
|
|
18531
|
+
|
|
18532
|
+
|
|
18533
|
+
|
|
18534
|
+
|
|
16880
18535
|
|
|
16881
18536
|
|
|
16882
18537
|
|
|
@@ -17055,6 +18710,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17055
18710
|
|
|
17056
18711
|
|
|
17057
18712
|
|
|
18713
|
+
|
|
18714
|
+
|
|
18715
|
+
|
|
18716
|
+
|
|
18717
|
+
|
|
18718
|
+
|
|
18719
|
+
|
|
18720
|
+
|
|
18721
|
+
|
|
18722
|
+
|
|
18723
|
+
|
|
18724
|
+
|
|
18725
|
+
|
|
18726
|
+
|
|
18727
|
+
|
|
18728
|
+
|
|
18729
|
+
|
|
18730
|
+
|
|
18731
|
+
|
|
18732
|
+
|
|
17058
18733
|
|
|
17059
18734
|
|
|
17060
18735
|
|
|
@@ -17223,6 +18898,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17223
18898
|
|
|
17224
18899
|
|
|
17225
18900
|
|
|
18901
|
+
|
|
18902
|
+
|
|
18903
|
+
|
|
18904
|
+
|
|
18905
|
+
|
|
18906
|
+
|
|
18907
|
+
|
|
18908
|
+
|
|
18909
|
+
|
|
18910
|
+
|
|
18911
|
+
|
|
18912
|
+
|
|
18913
|
+
|
|
18914
|
+
|
|
18915
|
+
|
|
18916
|
+
|
|
18917
|
+
|
|
18918
|
+
|
|
18919
|
+
|
|
18920
|
+
|
|
17226
18921
|
|
|
17227
18922
|
|
|
17228
18923
|
|
|
@@ -17391,6 +19086,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17391
19086
|
|
|
17392
19087
|
|
|
17393
19088
|
|
|
19089
|
+
|
|
19090
|
+
|
|
19091
|
+
|
|
19092
|
+
|
|
19093
|
+
|
|
19094
|
+
|
|
19095
|
+
|
|
19096
|
+
|
|
19097
|
+
|
|
19098
|
+
|
|
19099
|
+
|
|
19100
|
+
|
|
19101
|
+
|
|
19102
|
+
|
|
19103
|
+
|
|
19104
|
+
|
|
19105
|
+
|
|
19106
|
+
|
|
19107
|
+
|
|
19108
|
+
|
|
17394
19109
|
|
|
17395
19110
|
|
|
17396
19111
|
|
|
@@ -17550,6 +19265,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17550
19265
|
|
|
17551
19266
|
|
|
17552
19267
|
|
|
19268
|
+
|
|
19269
|
+
|
|
19270
|
+
|
|
19271
|
+
|
|
19272
|
+
|
|
19273
|
+
|
|
19274
|
+
|
|
19275
|
+
|
|
19276
|
+
|
|
19277
|
+
|
|
19278
|
+
|
|
19279
|
+
|
|
19280
|
+
|
|
19281
|
+
|
|
19282
|
+
|
|
19283
|
+
|
|
19284
|
+
|
|
19285
|
+
|
|
19286
|
+
|
|
19287
|
+
|
|
17553
19288
|
|
|
17554
19289
|
|
|
17555
19290
|
|
|
@@ -17699,6 +19434,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17699
19434
|
|
|
17700
19435
|
|
|
17701
19436
|
|
|
19437
|
+
|
|
19438
|
+
|
|
19439
|
+
|
|
19440
|
+
|
|
19441
|
+
|
|
19442
|
+
|
|
19443
|
+
|
|
19444
|
+
|
|
19445
|
+
|
|
19446
|
+
|
|
19447
|
+
|
|
19448
|
+
|
|
19449
|
+
|
|
19450
|
+
|
|
19451
|
+
|
|
19452
|
+
|
|
19453
|
+
|
|
19454
|
+
|
|
19455
|
+
|
|
19456
|
+
|
|
17702
19457
|
|
|
17703
19458
|
|
|
17704
19459
|
|
|
@@ -17852,6 +19607,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17852
19607
|
|
|
17853
19608
|
|
|
17854
19609
|
|
|
19610
|
+
|
|
19611
|
+
|
|
19612
|
+
|
|
19613
|
+
|
|
19614
|
+
|
|
19615
|
+
|
|
19616
|
+
|
|
19617
|
+
|
|
19618
|
+
|
|
19619
|
+
|
|
19620
|
+
|
|
19621
|
+
|
|
19622
|
+
|
|
19623
|
+
|
|
19624
|
+
|
|
19625
|
+
|
|
19626
|
+
|
|
19627
|
+
|
|
19628
|
+
|
|
19629
|
+
|
|
17855
19630
|
|
|
17856
19631
|
|
|
17857
19632
|
|
|
@@ -18002,6 +19777,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18002
19777
|
|
|
18003
19778
|
|
|
18004
19779
|
|
|
19780
|
+
|
|
19781
|
+
|
|
19782
|
+
|
|
19783
|
+
|
|
19784
|
+
|
|
19785
|
+
|
|
19786
|
+
|
|
19787
|
+
|
|
19788
|
+
|
|
19789
|
+
|
|
19790
|
+
|
|
19791
|
+
|
|
19792
|
+
|
|
19793
|
+
|
|
19794
|
+
|
|
19795
|
+
|
|
19796
|
+
|
|
19797
|
+
|
|
19798
|
+
|
|
19799
|
+
|
|
18005
19800
|
|
|
18006
19801
|
|
|
18007
19802
|
|
|
@@ -18155,6 +19950,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18155
19950
|
|
|
18156
19951
|
|
|
18157
19952
|
|
|
19953
|
+
|
|
19954
|
+
|
|
19955
|
+
|
|
19956
|
+
|
|
19957
|
+
|
|
19958
|
+
|
|
19959
|
+
|
|
19960
|
+
|
|
19961
|
+
|
|
19962
|
+
|
|
19963
|
+
|
|
19964
|
+
|
|
19965
|
+
|
|
19966
|
+
|
|
19967
|
+
|
|
19968
|
+
|
|
19969
|
+
|
|
19970
|
+
|
|
19971
|
+
|
|
19972
|
+
|
|
18158
19973
|
|
|
18159
19974
|
|
|
18160
19975
|
|
|
@@ -18308,6 +20123,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18308
20123
|
|
|
18309
20124
|
|
|
18310
20125
|
|
|
20126
|
+
|
|
20127
|
+
|
|
20128
|
+
|
|
20129
|
+
|
|
20130
|
+
|
|
20131
|
+
|
|
20132
|
+
|
|
20133
|
+
|
|
20134
|
+
|
|
20135
|
+
|
|
20136
|
+
|
|
20137
|
+
|
|
20138
|
+
|
|
20139
|
+
|
|
20140
|
+
|
|
20141
|
+
|
|
20142
|
+
|
|
20143
|
+
|
|
20144
|
+
|
|
20145
|
+
|
|
18311
20146
|
|
|
18312
20147
|
|
|
18313
20148
|
|
|
@@ -18464,6 +20299,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18464
20299
|
|
|
18465
20300
|
|
|
18466
20301
|
|
|
20302
|
+
|
|
20303
|
+
|
|
20304
|
+
|
|
20305
|
+
|
|
20306
|
+
|
|
20307
|
+
|
|
20308
|
+
|
|
20309
|
+
|
|
20310
|
+
|
|
20311
|
+
|
|
20312
|
+
|
|
20313
|
+
|
|
20314
|
+
|
|
20315
|
+
|
|
20316
|
+
|
|
20317
|
+
|
|
20318
|
+
|
|
20319
|
+
|
|
20320
|
+
|
|
20321
|
+
|
|
18467
20322
|
|
|
18468
20323
|
|
|
18469
20324
|
|
|
@@ -18641,17 +20496,37 @@ var _TreeMap = class _TreeMap {
|
|
|
18641
20496
|
|
|
18642
20497
|
|
|
18643
20498
|
|
|
18644
|
-
|
|
18645
|
-
|
|
18646
|
-
|
|
18647
|
-
|
|
18648
|
-
|
|
18649
|
-
|
|
18650
|
-
|
|
18651
|
-
|
|
18652
|
-
|
|
18653
|
-
|
|
18654
|
-
|
|
20499
|
+
|
|
20500
|
+
|
|
20501
|
+
|
|
20502
|
+
|
|
20503
|
+
|
|
20504
|
+
|
|
20505
|
+
|
|
20506
|
+
|
|
20507
|
+
|
|
20508
|
+
|
|
20509
|
+
|
|
20510
|
+
|
|
20511
|
+
|
|
20512
|
+
|
|
20513
|
+
|
|
20514
|
+
|
|
20515
|
+
|
|
20516
|
+
|
|
20517
|
+
|
|
20518
|
+
|
|
20519
|
+
* @example
|
|
20520
|
+
* // Aggregate values
|
|
20521
|
+
* const tm = new TreeMap<number, number>([[1, 10], [2, 20]]);
|
|
20522
|
+
* console.log(tm.reduce((acc, v) => acc + (v ?? 0), 0)); // 30;
|
|
20523
|
+
*/
|
|
20524
|
+
reduce(callbackfn, initialValue) {
|
|
20525
|
+
let acc = initialValue;
|
|
20526
|
+
let index = 0;
|
|
20527
|
+
for (const [k, v] of this) acc = callbackfn(acc, v, k, index++, this);
|
|
20528
|
+
return acc;
|
|
20529
|
+
}
|
|
18655
20530
|
/**
|
|
18656
20531
|
* Test whether all entries satisfy a predicate.
|
|
18657
20532
|
* @remarks Time O(n), Space O(1)
|
|
@@ -18770,6 +20645,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18770
20645
|
|
|
18771
20646
|
|
|
18772
20647
|
|
|
20648
|
+
|
|
20649
|
+
|
|
20650
|
+
|
|
20651
|
+
|
|
20652
|
+
|
|
20653
|
+
|
|
20654
|
+
|
|
20655
|
+
|
|
20656
|
+
|
|
20657
|
+
|
|
20658
|
+
|
|
20659
|
+
|
|
20660
|
+
|
|
20661
|
+
|
|
20662
|
+
|
|
20663
|
+
|
|
20664
|
+
|
|
20665
|
+
|
|
20666
|
+
|
|
20667
|
+
|
|
18773
20668
|
|
|
18774
20669
|
|
|
18775
20670
|
|
|
@@ -18922,6 +20817,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18922
20817
|
|
|
18923
20818
|
|
|
18924
20819
|
|
|
20820
|
+
|
|
20821
|
+
|
|
20822
|
+
|
|
20823
|
+
|
|
20824
|
+
|
|
20825
|
+
|
|
20826
|
+
|
|
20827
|
+
|
|
20828
|
+
|
|
20829
|
+
|
|
20830
|
+
|
|
20831
|
+
|
|
20832
|
+
|
|
20833
|
+
|
|
20834
|
+
|
|
20835
|
+
|
|
20836
|
+
|
|
20837
|
+
|
|
20838
|
+
|
|
20839
|
+
|
|
18925
20840
|
|
|
18926
20841
|
|
|
18927
20842
|
|
|
@@ -19075,6 +20990,26 @@ var _TreeMap = class _TreeMap {
|
|
|
19075
20990
|
|
|
19076
20991
|
|
|
19077
20992
|
|
|
20993
|
+
|
|
20994
|
+
|
|
20995
|
+
|
|
20996
|
+
|
|
20997
|
+
|
|
20998
|
+
|
|
20999
|
+
|
|
21000
|
+
|
|
21001
|
+
|
|
21002
|
+
|
|
21003
|
+
|
|
21004
|
+
|
|
21005
|
+
|
|
21006
|
+
|
|
21007
|
+
|
|
21008
|
+
|
|
21009
|
+
|
|
21010
|
+
|
|
21011
|
+
|
|
21012
|
+
|
|
19078
21013
|
|
|
19079
21014
|
|
|
19080
21015
|
|
|
@@ -19229,6 +21164,26 @@ var _TreeMap = class _TreeMap {
|
|
|
19229
21164
|
|
|
19230
21165
|
|
|
19231
21166
|
|
|
21167
|
+
|
|
21168
|
+
|
|
21169
|
+
|
|
21170
|
+
|
|
21171
|
+
|
|
21172
|
+
|
|
21173
|
+
|
|
21174
|
+
|
|
21175
|
+
|
|
21176
|
+
|
|
21177
|
+
|
|
21178
|
+
|
|
21179
|
+
|
|
21180
|
+
|
|
21181
|
+
|
|
21182
|
+
|
|
21183
|
+
|
|
21184
|
+
|
|
21185
|
+
|
|
21186
|
+
|
|
19232
21187
|
|
|
19233
21188
|
|
|
19234
21189
|
|
|
@@ -19378,6 +21333,26 @@ var _TreeMap = class _TreeMap {
|
|
|
19378
21333
|
|
|
19379
21334
|
|
|
19380
21335
|
|
|
21336
|
+
|
|
21337
|
+
|
|
21338
|
+
|
|
21339
|
+
|
|
21340
|
+
|
|
21341
|
+
|
|
21342
|
+
|
|
21343
|
+
|
|
21344
|
+
|
|
21345
|
+
|
|
21346
|
+
|
|
21347
|
+
|
|
21348
|
+
|
|
21349
|
+
|
|
21350
|
+
|
|
21351
|
+
|
|
21352
|
+
|
|
21353
|
+
|
|
21354
|
+
|
|
21355
|
+
|
|
19381
21356
|
|
|
19382
21357
|
|
|
19383
21358
|
|
|
@@ -19437,6 +21412,10 @@ var _TreeMap = class _TreeMap {
|
|
|
19437
21412
|
|
|
19438
21413
|
|
|
19439
21414
|
|
|
21415
|
+
|
|
21416
|
+
|
|
21417
|
+
|
|
21418
|
+
|
|
19440
21419
|
|
|
19441
21420
|
|
|
19442
21421
|
|
|
@@ -19501,6 +21480,10 @@ var _TreeMap = class _TreeMap {
|
|
|
19501
21480
|
|
|
19502
21481
|
|
|
19503
21482
|
|
|
21483
|
+
|
|
21484
|
+
|
|
21485
|
+
|
|
21486
|
+
|
|
19504
21487
|
|
|
19505
21488
|
|
|
19506
21489
|
|
|
@@ -19549,6 +21532,10 @@ var _TreeMap = class _TreeMap {
|
|
|
19549
21532
|
|
|
19550
21533
|
|
|
19551
21534
|
|
|
21535
|
+
|
|
21536
|
+
|
|
21537
|
+
|
|
21538
|
+
|
|
19552
21539
|
|
|
19553
21540
|
|
|
19554
21541
|
|
|
@@ -19601,6 +21588,10 @@ var _TreeMap = class _TreeMap {
|
|
|
19601
21588
|
|
|
19602
21589
|
|
|
19603
21590
|
|
|
21591
|
+
|
|
21592
|
+
|
|
21593
|
+
|
|
21594
|
+
|
|
19604
21595
|
|
|
19605
21596
|
|
|
19606
21597
|
|
|
@@ -19728,6 +21719,22 @@ var _TreeMap = class _TreeMap {
|
|
|
19728
21719
|
|
|
19729
21720
|
|
|
19730
21721
|
|
|
21722
|
+
|
|
21723
|
+
|
|
21724
|
+
|
|
21725
|
+
|
|
21726
|
+
|
|
21727
|
+
|
|
21728
|
+
|
|
21729
|
+
|
|
21730
|
+
|
|
21731
|
+
|
|
21732
|
+
|
|
21733
|
+
|
|
21734
|
+
|
|
21735
|
+
|
|
21736
|
+
|
|
21737
|
+
|
|
19731
21738
|
|
|
19732
21739
|
|
|
19733
21740
|
|
|
@@ -19885,6 +21892,22 @@ var _TreeMap = class _TreeMap {
|
|
|
19885
21892
|
|
|
19886
21893
|
|
|
19887
21894
|
|
|
21895
|
+
|
|
21896
|
+
|
|
21897
|
+
|
|
21898
|
+
|
|
21899
|
+
|
|
21900
|
+
|
|
21901
|
+
|
|
21902
|
+
|
|
21903
|
+
|
|
21904
|
+
|
|
21905
|
+
|
|
21906
|
+
|
|
21907
|
+
|
|
21908
|
+
|
|
21909
|
+
|
|
21910
|
+
|
|
19888
21911
|
|
|
19889
21912
|
|
|
19890
21913
|
|
|
@@ -20026,6 +22049,22 @@ var _TreeMap = class _TreeMap {
|
|
|
20026
22049
|
|
|
20027
22050
|
|
|
20028
22051
|
|
|
22052
|
+
|
|
22053
|
+
|
|
22054
|
+
|
|
22055
|
+
|
|
22056
|
+
|
|
22057
|
+
|
|
22058
|
+
|
|
22059
|
+
|
|
22060
|
+
|
|
22061
|
+
|
|
22062
|
+
|
|
22063
|
+
|
|
22064
|
+
|
|
22065
|
+
|
|
22066
|
+
|
|
22067
|
+
|
|
20029
22068
|
|
|
20030
22069
|
|
|
20031
22070
|
|
|
@@ -20167,6 +22206,22 @@ var _TreeMap = class _TreeMap {
|
|
|
20167
22206
|
|
|
20168
22207
|
|
|
20169
22208
|
|
|
22209
|
+
|
|
22210
|
+
|
|
22211
|
+
|
|
22212
|
+
|
|
22213
|
+
|
|
22214
|
+
|
|
22215
|
+
|
|
22216
|
+
|
|
22217
|
+
|
|
22218
|
+
|
|
22219
|
+
|
|
22220
|
+
|
|
22221
|
+
|
|
22222
|
+
|
|
22223
|
+
|
|
22224
|
+
|
|
20170
22225
|
|
|
20171
22226
|
|
|
20172
22227
|
|
|
@@ -20309,6 +22364,22 @@ var _TreeMap = class _TreeMap {
|
|
|
20309
22364
|
|
|
20310
22365
|
|
|
20311
22366
|
|
|
22367
|
+
|
|
22368
|
+
|
|
22369
|
+
|
|
22370
|
+
|
|
22371
|
+
|
|
22372
|
+
|
|
22373
|
+
|
|
22374
|
+
|
|
22375
|
+
|
|
22376
|
+
|
|
22377
|
+
|
|
22378
|
+
|
|
22379
|
+
|
|
22380
|
+
|
|
22381
|
+
|
|
22382
|
+
|
|
20312
22383
|
|
|
20313
22384
|
|
|
20314
22385
|
|
|
@@ -20373,6 +22444,68 @@ var _TreeMap = class _TreeMap {
|
|
|
20373
22444
|
}
|
|
20374
22445
|
return out;
|
|
20375
22446
|
}
|
|
22447
|
+
// ─── Order-Statistic Methods ───────────────────────────
|
|
22448
|
+
/**
|
|
22449
|
+
* Returns the entry at the k-th position in tree order (0-indexed).
|
|
22450
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
22451
|
+
|
|
22452
|
+
|
|
22453
|
+
|
|
22454
|
+
* @example
|
|
22455
|
+
* // Find k-th entry in a TreeMap
|
|
22456
|
+
* const map = new TreeMap<string, number>(
|
|
22457
|
+
* [['alice', 95], ['bob', 87], ['charlie', 92]],
|
|
22458
|
+
* { enableOrderStatistic: true }
|
|
22459
|
+
* );
|
|
22460
|
+
* console.log(map.getByRank(0)); // 'alice';
|
|
22461
|
+
* console.log(map.getByRank(1)); // 'bob';
|
|
22462
|
+
* console.log(map.getByRank(2)); // 'charlie';
|
|
22463
|
+
*/
|
|
22464
|
+
getByRank(k) {
|
|
22465
|
+
const key = __privateGet(this, _core3).getByRank(k);
|
|
22466
|
+
if (key === void 0) return void 0;
|
|
22467
|
+
return [key, __privateGet(this, _core3).get(key)];
|
|
22468
|
+
}
|
|
22469
|
+
/**
|
|
22470
|
+
* Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
22471
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
22472
|
+
* @example
|
|
22473
|
+
* // Get the rank of a key in sorted order
|
|
22474
|
+
* const tree = new TreeMap<number>(
|
|
22475
|
+
* [10, 20, 30, 40, 50],
|
|
22476
|
+
* { enableOrderStatistic: true }
|
|
22477
|
+
* );
|
|
22478
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
22479
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
22480
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
22481
|
+
* console.log(tree.getRank(25)); // 2;
|
|
22482
|
+
*/
|
|
22483
|
+
getRank(key) {
|
|
22484
|
+
return __privateGet(this, _core3).getRank(key);
|
|
22485
|
+
}
|
|
22486
|
+
/**
|
|
22487
|
+
* Returns keys by rank range (0-indexed, inclusive on both ends).
|
|
22488
|
+
* @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
|
|
22489
|
+
|
|
22490
|
+
* @example
|
|
22491
|
+
* // Pagination with rangeByRank
|
|
22492
|
+
* const tree = new TreeMap<number>(
|
|
22493
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
22494
|
+
* { enableOrderStatistic: true }
|
|
22495
|
+
* );
|
|
22496
|
+
* const pageSize = 3;
|
|
22497
|
+
*
|
|
22498
|
+
* // Page 1
|
|
22499
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
22500
|
+
* // Page 2
|
|
22501
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
22502
|
+
* // Page 3
|
|
22503
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
22504
|
+
*/
|
|
22505
|
+
rangeByRank(start, end) {
|
|
22506
|
+
const keys = __privateGet(this, _core3).rangeByRank(start, end);
|
|
22507
|
+
return keys.filter((k) => k !== void 0).map((k) => [k, __privateGet(this, _core3).get(k)]);
|
|
22508
|
+
}
|
|
20376
22509
|
/**
|
|
20377
22510
|
* Creates a shallow clone of this map.
|
|
20378
22511
|
* @remarks Time O(n log n), Space O(n)
|
|
@@ -20515,17 +22648,37 @@ var _TreeMap = class _TreeMap {
|
|
|
20515
22648
|
|
|
20516
22649
|
|
|
20517
22650
|
|
|
20518
|
-
|
|
20519
|
-
|
|
20520
|
-
|
|
20521
|
-
|
|
20522
|
-
|
|
20523
|
-
|
|
20524
|
-
|
|
20525
|
-
|
|
20526
|
-
|
|
20527
|
-
|
|
20528
|
-
|
|
22651
|
+
|
|
22652
|
+
|
|
22653
|
+
|
|
22654
|
+
|
|
22655
|
+
|
|
22656
|
+
|
|
22657
|
+
|
|
22658
|
+
|
|
22659
|
+
|
|
22660
|
+
|
|
22661
|
+
|
|
22662
|
+
|
|
22663
|
+
|
|
22664
|
+
|
|
22665
|
+
|
|
22666
|
+
|
|
22667
|
+
|
|
22668
|
+
|
|
22669
|
+
|
|
22670
|
+
|
|
22671
|
+
* @example
|
|
22672
|
+
* // Deep clone
|
|
22673
|
+
* const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
|
|
22674
|
+
* const copy = tm.clone();
|
|
22675
|
+
* copy.delete(1);
|
|
22676
|
+
* console.log(tm.has(1)); // true;
|
|
22677
|
+
*/
|
|
22678
|
+
clone() {
|
|
22679
|
+
return new _TreeMap(this, {
|
|
22680
|
+
comparator: __privateGet(this, _isDefaultComparator3) ? void 0 : __privateGet(this, _userComparator2),
|
|
22681
|
+
isMapMode: __privateGet(this, _core3).isMapMode
|
|
20529
22682
|
});
|
|
20530
22683
|
}
|
|
20531
22684
|
};
|
|
@@ -20560,7 +22713,7 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20560
22713
|
const toElementFn = options.toElementFn;
|
|
20561
22714
|
const comparator = (_a = options.comparator) != null ? _a : TreeSet.createDefaultComparator();
|
|
20562
22715
|
__privateSet(this, _isDefaultComparator4, options.comparator === void 0);
|
|
20563
|
-
__privateSet(this, _core4, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
22716
|
+
__privateSet(this, _core4, new RedBlackTree([], { comparator, isMapMode: options.isMapMode, enableOrderStatistic: options.enableOrderStatistic }));
|
|
20564
22717
|
for (const item of elements) {
|
|
20565
22718
|
const k = toElementFn ? toElementFn(item) : item;
|
|
20566
22719
|
this.add(k);
|
|
@@ -20573,22 +22726,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20573
22726
|
_validateKey(key) {
|
|
20574
22727
|
if (!__privateGet(this, _isDefaultComparator4)) return;
|
|
20575
22728
|
if (typeof key === "number") {
|
|
20576
|
-
if (Number.isNaN(key))
|
|
22729
|
+
if (Number.isNaN(key)) raise(TypeError, ERR.invalidNaN("TreeMultiSet"));
|
|
20577
22730
|
return;
|
|
20578
22731
|
}
|
|
20579
22732
|
if (typeof key === "string") return;
|
|
20580
22733
|
if (key instanceof Date) {
|
|
20581
|
-
if (Number.isNaN(key.getTime()))
|
|
22734
|
+
if (Number.isNaN(key.getTime())) raise(TypeError, ERR.invalidDate("TreeMultiSet"));
|
|
20582
22735
|
return;
|
|
20583
22736
|
}
|
|
20584
|
-
|
|
22737
|
+
raise(TypeError, ERR.comparatorRequired("TreeMultiSet"));
|
|
20585
22738
|
}
|
|
20586
22739
|
/**
|
|
20587
22740
|
* Validates that count is a non-negative safe integer.
|
|
20588
22741
|
* @remarks Time O(1), Space O(1)
|
|
20589
22742
|
*/
|
|
20590
22743
|
_validateCount(n) {
|
|
20591
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
22744
|
+
if (!Number.isSafeInteger(n) || n < 0) raise(RangeError, ERR.invalidArgument("count must be a safe integer >= 0.", "TreeMultiSet"));
|
|
20592
22745
|
}
|
|
20593
22746
|
/**
|
|
20594
22747
|
* Total occurrences (sumCounts).
|
|
@@ -20617,6 +22770,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20617
22770
|
|
|
20618
22771
|
|
|
20619
22772
|
|
|
22773
|
+
|
|
22774
|
+
|
|
22775
|
+
|
|
22776
|
+
|
|
20620
22777
|
|
|
20621
22778
|
|
|
20622
22779
|
|
|
@@ -20752,6 +22909,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20752
22909
|
|
|
20753
22910
|
|
|
20754
22911
|
|
|
22912
|
+
|
|
22913
|
+
|
|
22914
|
+
|
|
22915
|
+
|
|
22916
|
+
|
|
22917
|
+
|
|
22918
|
+
|
|
22919
|
+
|
|
22920
|
+
|
|
22921
|
+
|
|
22922
|
+
|
|
22923
|
+
|
|
22924
|
+
|
|
22925
|
+
|
|
22926
|
+
|
|
22927
|
+
|
|
22928
|
+
|
|
22929
|
+
|
|
22930
|
+
|
|
22931
|
+
|
|
20755
22932
|
|
|
20756
22933
|
|
|
20757
22934
|
|
|
@@ -20903,6 +23080,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20903
23080
|
|
|
20904
23081
|
|
|
20905
23082
|
|
|
23083
|
+
|
|
23084
|
+
|
|
23085
|
+
|
|
23086
|
+
|
|
23087
|
+
|
|
23088
|
+
|
|
23089
|
+
|
|
23090
|
+
|
|
23091
|
+
|
|
23092
|
+
|
|
23093
|
+
|
|
23094
|
+
|
|
23095
|
+
|
|
23096
|
+
|
|
23097
|
+
|
|
23098
|
+
|
|
23099
|
+
|
|
23100
|
+
|
|
23101
|
+
|
|
23102
|
+
|
|
20906
23103
|
|
|
20907
23104
|
|
|
20908
23105
|
|
|
@@ -20955,6 +23152,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20955
23152
|
|
|
20956
23153
|
|
|
20957
23154
|
|
|
23155
|
+
|
|
23156
|
+
|
|
23157
|
+
|
|
23158
|
+
|
|
20958
23159
|
|
|
20959
23160
|
|
|
20960
23161
|
|
|
@@ -21086,6 +23287,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21086
23287
|
|
|
21087
23288
|
|
|
21088
23289
|
|
|
23290
|
+
|
|
23291
|
+
|
|
23292
|
+
|
|
23293
|
+
|
|
23294
|
+
|
|
23295
|
+
|
|
23296
|
+
|
|
23297
|
+
|
|
23298
|
+
|
|
23299
|
+
|
|
23300
|
+
|
|
23301
|
+
|
|
23302
|
+
|
|
23303
|
+
|
|
23304
|
+
|
|
23305
|
+
|
|
23306
|
+
|
|
23307
|
+
|
|
23308
|
+
|
|
23309
|
+
|
|
21089
23310
|
|
|
21090
23311
|
|
|
21091
23312
|
|
|
@@ -21148,6 +23369,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21148
23369
|
|
|
21149
23370
|
|
|
21150
23371
|
|
|
23372
|
+
|
|
23373
|
+
|
|
23374
|
+
|
|
23375
|
+
|
|
21151
23376
|
|
|
21152
23377
|
|
|
21153
23378
|
|
|
@@ -21297,6 +23522,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21297
23522
|
|
|
21298
23523
|
|
|
21299
23524
|
|
|
23525
|
+
|
|
23526
|
+
|
|
23527
|
+
|
|
23528
|
+
|
|
23529
|
+
|
|
23530
|
+
|
|
23531
|
+
|
|
23532
|
+
|
|
23533
|
+
|
|
23534
|
+
|
|
23535
|
+
|
|
23536
|
+
|
|
23537
|
+
|
|
23538
|
+
|
|
23539
|
+
|
|
23540
|
+
|
|
23541
|
+
|
|
23542
|
+
|
|
23543
|
+
|
|
23544
|
+
|
|
21300
23545
|
|
|
21301
23546
|
|
|
21302
23547
|
|
|
@@ -21360,6 +23605,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21360
23605
|
|
|
21361
23606
|
|
|
21362
23607
|
|
|
23608
|
+
|
|
23609
|
+
|
|
23610
|
+
|
|
23611
|
+
|
|
21363
23612
|
|
|
21364
23613
|
|
|
21365
23614
|
|
|
@@ -21401,6 +23650,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21401
23650
|
|
|
21402
23651
|
|
|
21403
23652
|
|
|
23653
|
+
|
|
23654
|
+
|
|
23655
|
+
|
|
23656
|
+
|
|
21404
23657
|
|
|
21405
23658
|
|
|
21406
23659
|
|
|
@@ -21536,6 +23789,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21536
23789
|
|
|
21537
23790
|
|
|
21538
23791
|
|
|
23792
|
+
|
|
23793
|
+
|
|
23794
|
+
|
|
23795
|
+
|
|
23796
|
+
|
|
23797
|
+
|
|
23798
|
+
|
|
23799
|
+
|
|
23800
|
+
|
|
23801
|
+
|
|
23802
|
+
|
|
23803
|
+
|
|
23804
|
+
|
|
23805
|
+
|
|
23806
|
+
|
|
23807
|
+
|
|
23808
|
+
|
|
23809
|
+
|
|
23810
|
+
|
|
23811
|
+
|
|
21539
23812
|
|
|
21540
23813
|
|
|
21541
23814
|
|
|
@@ -21697,6 +23970,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21697
23970
|
|
|
21698
23971
|
|
|
21699
23972
|
|
|
23973
|
+
|
|
23974
|
+
|
|
23975
|
+
|
|
23976
|
+
|
|
23977
|
+
|
|
23978
|
+
|
|
23979
|
+
|
|
23980
|
+
|
|
23981
|
+
|
|
23982
|
+
|
|
23983
|
+
|
|
23984
|
+
|
|
23985
|
+
|
|
23986
|
+
|
|
23987
|
+
|
|
23988
|
+
|
|
23989
|
+
|
|
23990
|
+
|
|
23991
|
+
|
|
23992
|
+
|
|
21700
23993
|
|
|
21701
23994
|
|
|
21702
23995
|
|
|
@@ -21748,6 +24041,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21748
24041
|
|
|
21749
24042
|
|
|
21750
24043
|
|
|
24044
|
+
|
|
24045
|
+
|
|
24046
|
+
|
|
24047
|
+
|
|
21751
24048
|
|
|
21752
24049
|
|
|
21753
24050
|
|
|
@@ -21783,6 +24080,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21783
24080
|
|
|
21784
24081
|
|
|
21785
24082
|
|
|
24083
|
+
|
|
24084
|
+
|
|
24085
|
+
|
|
24086
|
+
|
|
21786
24087
|
|
|
21787
24088
|
|
|
21788
24089
|
|
|
@@ -21927,6 +24228,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21927
24228
|
|
|
21928
24229
|
|
|
21929
24230
|
|
|
24231
|
+
|
|
24232
|
+
|
|
24233
|
+
|
|
24234
|
+
|
|
24235
|
+
|
|
24236
|
+
|
|
24237
|
+
|
|
24238
|
+
|
|
24239
|
+
|
|
24240
|
+
|
|
24241
|
+
|
|
24242
|
+
|
|
24243
|
+
|
|
24244
|
+
|
|
24245
|
+
|
|
24246
|
+
|
|
24247
|
+
|
|
24248
|
+
|
|
24249
|
+
|
|
24250
|
+
|
|
21930
24251
|
|
|
21931
24252
|
|
|
21932
24253
|
|
|
@@ -21981,6 +24302,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21981
24302
|
|
|
21982
24303
|
|
|
21983
24304
|
|
|
24305
|
+
|
|
24306
|
+
|
|
24307
|
+
|
|
24308
|
+
|
|
21984
24309
|
|
|
21985
24310
|
|
|
21986
24311
|
|
|
@@ -22017,6 +24342,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22017
24342
|
|
|
22018
24343
|
|
|
22019
24344
|
|
|
24345
|
+
|
|
24346
|
+
|
|
24347
|
+
|
|
24348
|
+
|
|
22020
24349
|
|
|
22021
24350
|
|
|
22022
24351
|
|
|
@@ -22053,6 +24382,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22053
24382
|
|
|
22054
24383
|
|
|
22055
24384
|
|
|
24385
|
+
|
|
24386
|
+
|
|
24387
|
+
|
|
24388
|
+
|
|
22056
24389
|
|
|
22057
24390
|
|
|
22058
24391
|
|
|
@@ -22093,6 +24426,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22093
24426
|
|
|
22094
24427
|
|
|
22095
24428
|
|
|
24429
|
+
|
|
24430
|
+
|
|
24431
|
+
|
|
24432
|
+
|
|
22096
24433
|
|
|
22097
24434
|
|
|
22098
24435
|
|
|
@@ -22207,6 +24544,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22207
24544
|
|
|
22208
24545
|
|
|
22209
24546
|
|
|
24547
|
+
|
|
24548
|
+
|
|
24549
|
+
|
|
24550
|
+
|
|
24551
|
+
|
|
24552
|
+
|
|
24553
|
+
|
|
24554
|
+
|
|
24555
|
+
|
|
24556
|
+
|
|
24557
|
+
|
|
24558
|
+
|
|
24559
|
+
|
|
24560
|
+
|
|
24561
|
+
|
|
24562
|
+
|
|
22210
24563
|
|
|
22211
24564
|
|
|
22212
24565
|
|
|
@@ -22332,6 +24685,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22332
24685
|
|
|
22333
24686
|
|
|
22334
24687
|
|
|
24688
|
+
|
|
24689
|
+
|
|
24690
|
+
|
|
24691
|
+
|
|
24692
|
+
|
|
24693
|
+
|
|
24694
|
+
|
|
24695
|
+
|
|
24696
|
+
|
|
24697
|
+
|
|
24698
|
+
|
|
24699
|
+
|
|
24700
|
+
|
|
24701
|
+
|
|
24702
|
+
|
|
24703
|
+
|
|
22335
24704
|
|
|
22336
24705
|
|
|
22337
24706
|
|
|
@@ -22457,6 +24826,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22457
24826
|
|
|
22458
24827
|
|
|
22459
24828
|
|
|
24829
|
+
|
|
24830
|
+
|
|
24831
|
+
|
|
24832
|
+
|
|
24833
|
+
|
|
24834
|
+
|
|
24835
|
+
|
|
24836
|
+
|
|
24837
|
+
|
|
24838
|
+
|
|
24839
|
+
|
|
24840
|
+
|
|
24841
|
+
|
|
24842
|
+
|
|
24843
|
+
|
|
24844
|
+
|
|
22460
24845
|
|
|
22461
24846
|
|
|
22462
24847
|
|
|
@@ -22581,6 +24966,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22581
24966
|
|
|
22582
24967
|
|
|
22583
24968
|
|
|
24969
|
+
|
|
24970
|
+
|
|
24971
|
+
|
|
24972
|
+
|
|
24973
|
+
|
|
24974
|
+
|
|
24975
|
+
|
|
24976
|
+
|
|
24977
|
+
|
|
24978
|
+
|
|
24979
|
+
|
|
24980
|
+
|
|
24981
|
+
|
|
24982
|
+
|
|
24983
|
+
|
|
24984
|
+
|
|
22584
24985
|
|
|
22585
24986
|
|
|
22586
24987
|
|
|
@@ -22731,6 +25132,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22731
25132
|
|
|
22732
25133
|
|
|
22733
25134
|
|
|
25135
|
+
|
|
25136
|
+
|
|
25137
|
+
|
|
25138
|
+
|
|
25139
|
+
|
|
25140
|
+
|
|
25141
|
+
|
|
25142
|
+
|
|
25143
|
+
|
|
25144
|
+
|
|
25145
|
+
|
|
25146
|
+
|
|
25147
|
+
|
|
25148
|
+
|
|
25149
|
+
|
|
25150
|
+
|
|
25151
|
+
|
|
25152
|
+
|
|
25153
|
+
|
|
25154
|
+
|
|
22734
25155
|
|
|
22735
25156
|
|
|
22736
25157
|
|
|
@@ -22887,6 +25308,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22887
25308
|
|
|
22888
25309
|
|
|
22889
25310
|
|
|
25311
|
+
|
|
25312
|
+
|
|
25313
|
+
|
|
25314
|
+
|
|
25315
|
+
|
|
25316
|
+
|
|
25317
|
+
|
|
25318
|
+
|
|
25319
|
+
|
|
25320
|
+
|
|
25321
|
+
|
|
25322
|
+
|
|
25323
|
+
|
|
25324
|
+
|
|
25325
|
+
|
|
25326
|
+
|
|
25327
|
+
|
|
25328
|
+
|
|
25329
|
+
|
|
25330
|
+
|
|
22890
25331
|
|
|
22891
25332
|
|
|
22892
25333
|
|
|
@@ -23050,6 +25491,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23050
25491
|
|
|
23051
25492
|
|
|
23052
25493
|
|
|
25494
|
+
|
|
25495
|
+
|
|
25496
|
+
|
|
25497
|
+
|
|
25498
|
+
|
|
25499
|
+
|
|
25500
|
+
|
|
25501
|
+
|
|
25502
|
+
|
|
25503
|
+
|
|
25504
|
+
|
|
25505
|
+
|
|
25506
|
+
|
|
25507
|
+
|
|
25508
|
+
|
|
25509
|
+
|
|
25510
|
+
|
|
25511
|
+
|
|
25512
|
+
|
|
25513
|
+
|
|
23053
25514
|
|
|
23054
25515
|
|
|
23055
25516
|
|
|
@@ -23208,6 +25669,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23208
25669
|
|
|
23209
25670
|
|
|
23210
25671
|
|
|
25672
|
+
|
|
25673
|
+
|
|
25674
|
+
|
|
25675
|
+
|
|
25676
|
+
|
|
25677
|
+
|
|
25678
|
+
|
|
25679
|
+
|
|
25680
|
+
|
|
25681
|
+
|
|
25682
|
+
|
|
25683
|
+
|
|
25684
|
+
|
|
25685
|
+
|
|
25686
|
+
|
|
25687
|
+
|
|
25688
|
+
|
|
25689
|
+
|
|
25690
|
+
|
|
25691
|
+
|
|
23211
25692
|
|
|
23212
25693
|
|
|
23213
25694
|
|
|
@@ -23387,6 +25868,78 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23387
25868
|
|
|
23388
25869
|
|
|
23389
25870
|
|
|
25871
|
+
|
|
25872
|
+
|
|
25873
|
+
|
|
25874
|
+
|
|
25875
|
+
|
|
25876
|
+
|
|
25877
|
+
|
|
25878
|
+
|
|
25879
|
+
|
|
25880
|
+
|
|
25881
|
+
|
|
25882
|
+
|
|
25883
|
+
|
|
25884
|
+
|
|
25885
|
+
|
|
25886
|
+
|
|
25887
|
+
|
|
25888
|
+
|
|
25889
|
+
|
|
25890
|
+
|
|
25891
|
+
|
|
25892
|
+
* @example
|
|
25893
|
+
* // Order-statistic on BST
|
|
25894
|
+
* const tree = new TreeMultiSet<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
25895
|
+
* console.log(tree.getByRank(0)); // 10;
|
|
25896
|
+
* console.log(tree.getByRank(4)); // 50;
|
|
25897
|
+
* console.log(tree.getRank(30)); // 2;
|
|
25898
|
+
*/
|
|
25899
|
+
// ─── Order-Statistic Methods ───────────────────────────
|
|
25900
|
+
getByRank(k) {
|
|
25901
|
+
return __privateGet(this, _core4).getByRank(k);
|
|
25902
|
+
}
|
|
25903
|
+
/**
|
|
25904
|
+
* Get the rank of a key in sorted order
|
|
25905
|
+
* @example
|
|
25906
|
+
* // Get the rank of a key in sorted order
|
|
25907
|
+
* const tree = new TreeMultiSet<number>(
|
|
25908
|
+
* [10, 20, 30, 40, 50],
|
|
25909
|
+
* { enableOrderStatistic: true }
|
|
25910
|
+
* );
|
|
25911
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
25912
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
25913
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
25914
|
+
* console.log(tree.getRank(25)); // 2;
|
|
25915
|
+
*/
|
|
25916
|
+
getRank(key) {
|
|
25917
|
+
return __privateGet(this, _core4).getRank(key);
|
|
25918
|
+
}
|
|
25919
|
+
/**
|
|
25920
|
+
* Get elements by rank range
|
|
25921
|
+
|
|
25922
|
+
* @example
|
|
25923
|
+
* // Pagination with rangeByRank
|
|
25924
|
+
* const tree = new TreeMultiSet<number>(
|
|
25925
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
25926
|
+
* { enableOrderStatistic: true }
|
|
25927
|
+
* );
|
|
25928
|
+
* const pageSize = 3;
|
|
25929
|
+
*
|
|
25930
|
+
* // Page 1
|
|
25931
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
25932
|
+
* // Page 2
|
|
25933
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
25934
|
+
* // Page 3
|
|
25935
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
25936
|
+
*/
|
|
25937
|
+
rangeByRank(start, end) {
|
|
25938
|
+
return __privateGet(this, _core4).rangeByRank(start, end).filter((k) => k !== void 0);
|
|
25939
|
+
}
|
|
25940
|
+
/**
|
|
25941
|
+
* Deep copy
|
|
25942
|
+
|
|
23390
25943
|
|
|
23391
25944
|
|
|
23392
25945
|
|
|
@@ -23505,6 +26058,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23505
26058
|
|
|
23506
26059
|
|
|
23507
26060
|
|
|
26061
|
+
|
|
26062
|
+
|
|
26063
|
+
|
|
26064
|
+
|
|
26065
|
+
|
|
26066
|
+
|
|
26067
|
+
|
|
26068
|
+
|
|
26069
|
+
|
|
26070
|
+
|
|
26071
|
+
|
|
26072
|
+
|
|
26073
|
+
|
|
26074
|
+
|
|
26075
|
+
|
|
26076
|
+
|
|
23508
26077
|
|
|
23509
26078
|
|
|
23510
26079
|
|
|
@@ -23656,6 +26225,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23656
26225
|
|
|
23657
26226
|
|
|
23658
26227
|
|
|
26228
|
+
|
|
26229
|
+
|
|
26230
|
+
|
|
26231
|
+
|
|
26232
|
+
|
|
26233
|
+
|
|
26234
|
+
|
|
26235
|
+
|
|
26236
|
+
|
|
26237
|
+
|
|
26238
|
+
|
|
26239
|
+
|
|
26240
|
+
|
|
26241
|
+
|
|
26242
|
+
|
|
26243
|
+
|
|
26244
|
+
|
|
26245
|
+
|
|
26246
|
+
|
|
26247
|
+
|
|
23659
26248
|
|
|
23660
26249
|
|
|
23661
26250
|
|