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
|
@@ -66,6 +66,55 @@ function makeTrampoline(fn) {
|
|
|
66
66
|
}
|
|
67
67
|
__name(makeTrampoline, "makeTrampoline");
|
|
68
68
|
|
|
69
|
+
// src/common/error.ts
|
|
70
|
+
function raise(ErrorClass, message) {
|
|
71
|
+
throw new ErrorClass(message);
|
|
72
|
+
}
|
|
73
|
+
__name(raise, "raise");
|
|
74
|
+
var ERR = {
|
|
75
|
+
// Range / index
|
|
76
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
77
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
78
|
+
// Type / argument
|
|
79
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
80
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
81
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
82
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
83
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
84
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
85
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
86
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
87
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
88
|
+
// State / operation
|
|
89
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
90
|
+
// Matrix
|
|
91
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
92
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
93
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
94
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
95
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
96
|
+
// Order statistic
|
|
97
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
// src/common/index.ts
|
|
101
|
+
var _Range = class _Range {
|
|
102
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
103
|
+
this.low = low;
|
|
104
|
+
this.high = high;
|
|
105
|
+
this.includeLow = includeLow;
|
|
106
|
+
this.includeHigh = includeHigh;
|
|
107
|
+
}
|
|
108
|
+
// Determine whether a key is within the range
|
|
109
|
+
isInRange(key, comparator) {
|
|
110
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
111
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
112
|
+
return lowCheck && highCheck;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
__name(_Range, "Range");
|
|
116
|
+
var Range = _Range;
|
|
117
|
+
|
|
69
118
|
// src/data-structures/base/iterable-element-base.ts
|
|
70
119
|
var _IterableElementBase = class _IterableElementBase {
|
|
71
120
|
/**
|
|
@@ -88,7 +137,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
88
137
|
if (options) {
|
|
89
138
|
const { toElementFn } = options;
|
|
90
139
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
91
|
-
else if (toElementFn)
|
|
140
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
92
141
|
}
|
|
93
142
|
}
|
|
94
143
|
/**
|
|
@@ -244,7 +293,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
244
293
|
acc = initialValue;
|
|
245
294
|
} else {
|
|
246
295
|
const first = iter.next();
|
|
247
|
-
if (first.done)
|
|
296
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
248
297
|
acc = first.value;
|
|
249
298
|
index = 1;
|
|
250
299
|
}
|
|
@@ -480,49 +529,6 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
|
|
|
480
529
|
__name(_LinearBase, "LinearBase");
|
|
481
530
|
var LinearBase = _LinearBase;
|
|
482
531
|
|
|
483
|
-
// src/common/error.ts
|
|
484
|
-
var ERR = {
|
|
485
|
-
// Range / index
|
|
486
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
487
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
488
|
-
// Type / argument
|
|
489
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
490
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
491
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
492
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
493
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
494
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
495
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
496
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
497
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
498
|
-
// State / operation
|
|
499
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
500
|
-
// Matrix
|
|
501
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
502
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
503
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
504
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
505
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
// src/common/index.ts
|
|
509
|
-
var _Range = class _Range {
|
|
510
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
511
|
-
this.low = low;
|
|
512
|
-
this.high = high;
|
|
513
|
-
this.includeLow = includeLow;
|
|
514
|
-
this.includeHigh = includeHigh;
|
|
515
|
-
}
|
|
516
|
-
// Determine whether a key is within the range
|
|
517
|
-
isInRange(key, comparator) {
|
|
518
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
519
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
520
|
-
return lowCheck && highCheck;
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
__name(_Range, "Range");
|
|
524
|
-
var Range = _Range;
|
|
525
|
-
|
|
526
532
|
// src/data-structures/base/iterable-entry-base.ts
|
|
527
533
|
var _IterableEntryBase = class _IterableEntryBase {
|
|
528
534
|
/**
|
|
@@ -787,6 +793,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
787
793
|
|
|
788
794
|
|
|
789
795
|
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
790
800
|
|
|
791
801
|
|
|
792
802
|
|
|
@@ -833,6 +843,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
833
843
|
|
|
834
844
|
|
|
835
845
|
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
836
850
|
|
|
837
851
|
|
|
838
852
|
|
|
@@ -895,6 +909,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
895
909
|
|
|
896
910
|
|
|
897
911
|
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
898
916
|
|
|
899
917
|
|
|
900
918
|
|
|
@@ -953,6 +971,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
953
971
|
|
|
954
972
|
|
|
955
973
|
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
956
978
|
|
|
957
979
|
|
|
958
980
|
|
|
@@ -1018,6 +1040,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1018
1040
|
|
|
1019
1041
|
|
|
1020
1042
|
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
1046
|
+
|
|
1021
1047
|
|
|
1022
1048
|
|
|
1023
1049
|
|
|
@@ -1073,6 +1099,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1073
1099
|
|
|
1074
1100
|
|
|
1075
1101
|
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
|
|
1076
1106
|
|
|
1077
1107
|
|
|
1078
1108
|
|
|
@@ -1121,6 +1151,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1121
1151
|
|
|
1122
1152
|
|
|
1123
1153
|
|
|
1154
|
+
|
|
1155
|
+
|
|
1156
|
+
|
|
1157
|
+
|
|
1124
1158
|
|
|
1125
1159
|
|
|
1126
1160
|
|
|
@@ -1210,6 +1244,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1210
1244
|
|
|
1211
1245
|
|
|
1212
1246
|
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
|
|
1250
|
+
|
|
1213
1251
|
|
|
1214
1252
|
|
|
1215
1253
|
|
|
@@ -1252,6 +1290,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1252
1290
|
|
|
1253
1291
|
|
|
1254
1292
|
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
|
|
1296
|
+
|
|
1255
1297
|
|
|
1256
1298
|
|
|
1257
1299
|
|
|
@@ -1317,6 +1359,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1317
1359
|
|
|
1318
1360
|
|
|
1319
1361
|
|
|
1362
|
+
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
|
|
1320
1366
|
|
|
1321
1367
|
|
|
1322
1368
|
|
|
@@ -1366,6 +1412,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1366
1412
|
|
|
1367
1413
|
|
|
1368
1414
|
|
|
1415
|
+
|
|
1416
|
+
|
|
1417
|
+
|
|
1418
|
+
|
|
1369
1419
|
|
|
1370
1420
|
|
|
1371
1421
|
|
|
@@ -1419,6 +1469,10 @@ var _Queue = class _Queue extends LinearBase {
|
|
|
1419
1469
|
|
|
1420
1470
|
|
|
1421
1471
|
|
|
1472
|
+
|
|
1473
|
+
|
|
1474
|
+
|
|
1475
|
+
|
|
1422
1476
|
|
|
1423
1477
|
|
|
1424
1478
|
|
|
@@ -1692,7 +1746,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1692
1746
|
if (isMapMode !== void 0) this._isMapMode = isMapMode;
|
|
1693
1747
|
if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
|
|
1694
1748
|
if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
|
|
1695
|
-
else if (toEntryFn)
|
|
1749
|
+
else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
|
|
1696
1750
|
}
|
|
1697
1751
|
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
1698
1752
|
}
|
|
@@ -1923,6 +1977,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1923
1977
|
|
|
1924
1978
|
|
|
1925
1979
|
|
|
1980
|
+
|
|
1981
|
+
|
|
1982
|
+
|
|
1983
|
+
|
|
1926
1984
|
|
|
1927
1985
|
|
|
1928
1986
|
|
|
@@ -1973,6 +2031,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
1973
2031
|
|
|
1974
2032
|
|
|
1975
2033
|
|
|
2034
|
+
|
|
2035
|
+
|
|
2036
|
+
|
|
2037
|
+
|
|
1976
2038
|
|
|
1977
2039
|
|
|
1978
2040
|
|
|
@@ -2075,6 +2137,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2075
2137
|
|
|
2076
2138
|
|
|
2077
2139
|
|
|
2140
|
+
|
|
2141
|
+
|
|
2142
|
+
|
|
2143
|
+
|
|
2078
2144
|
|
|
2079
2145
|
|
|
2080
2146
|
|
|
@@ -2113,6 +2179,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2113
2179
|
|
|
2114
2180
|
|
|
2115
2181
|
|
|
2182
|
+
|
|
2183
|
+
|
|
2184
|
+
|
|
2185
|
+
|
|
2116
2186
|
|
|
2117
2187
|
|
|
2118
2188
|
|
|
@@ -2172,6 +2242,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2172
2242
|
|
|
2173
2243
|
|
|
2174
2244
|
|
|
2245
|
+
|
|
2246
|
+
|
|
2247
|
+
|
|
2248
|
+
|
|
2175
2249
|
|
|
2176
2250
|
|
|
2177
2251
|
|
|
@@ -2230,6 +2304,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2230
2304
|
|
|
2231
2305
|
|
|
2232
2306
|
|
|
2307
|
+
|
|
2308
|
+
|
|
2309
|
+
|
|
2310
|
+
|
|
2233
2311
|
|
|
2234
2312
|
|
|
2235
2313
|
|
|
@@ -2366,6 +2444,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2366
2444
|
|
|
2367
2445
|
|
|
2368
2446
|
|
|
2447
|
+
|
|
2448
|
+
|
|
2449
|
+
|
|
2450
|
+
|
|
2369
2451
|
|
|
2370
2452
|
|
|
2371
2453
|
|
|
@@ -2420,6 +2502,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2420
2502
|
|
|
2421
2503
|
|
|
2422
2504
|
|
|
2505
|
+
|
|
2506
|
+
|
|
2507
|
+
|
|
2508
|
+
|
|
2423
2509
|
|
|
2424
2510
|
|
|
2425
2511
|
|
|
@@ -2477,6 +2563,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2477
2563
|
|
|
2478
2564
|
|
|
2479
2565
|
|
|
2566
|
+
|
|
2567
|
+
|
|
2568
|
+
|
|
2569
|
+
|
|
2480
2570
|
|
|
2481
2571
|
|
|
2482
2572
|
|
|
@@ -2521,6 +2611,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2521
2611
|
|
|
2522
2612
|
|
|
2523
2613
|
|
|
2614
|
+
|
|
2615
|
+
|
|
2616
|
+
|
|
2617
|
+
|
|
2524
2618
|
|
|
2525
2619
|
|
|
2526
2620
|
|
|
@@ -2574,6 +2668,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2574
2668
|
|
|
2575
2669
|
|
|
2576
2670
|
|
|
2671
|
+
|
|
2672
|
+
|
|
2673
|
+
|
|
2674
|
+
|
|
2577
2675
|
|
|
2578
2676
|
|
|
2579
2677
|
|
|
@@ -2654,6 +2752,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2654
2752
|
|
|
2655
2753
|
|
|
2656
2754
|
|
|
2755
|
+
|
|
2756
|
+
|
|
2757
|
+
|
|
2758
|
+
|
|
2657
2759
|
|
|
2658
2760
|
|
|
2659
2761
|
|
|
@@ -2711,6 +2813,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
2711
2813
|
|
|
2712
2814
|
|
|
2713
2815
|
|
|
2816
|
+
|
|
2817
|
+
|
|
2818
|
+
|
|
2819
|
+
|
|
2714
2820
|
|
|
2715
2821
|
|
|
2716
2822
|
|
|
@@ -3184,6 +3290,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3184
3290
|
|
|
3185
3291
|
|
|
3186
3292
|
|
|
3293
|
+
|
|
3294
|
+
|
|
3295
|
+
|
|
3296
|
+
|
|
3187
3297
|
|
|
3188
3298
|
|
|
3189
3299
|
|
|
@@ -3232,6 +3342,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3232
3342
|
|
|
3233
3343
|
|
|
3234
3344
|
|
|
3345
|
+
|
|
3346
|
+
|
|
3347
|
+
|
|
3348
|
+
|
|
3235
3349
|
|
|
3236
3350
|
|
|
3237
3351
|
|
|
@@ -3284,6 +3398,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3284
3398
|
|
|
3285
3399
|
|
|
3286
3400
|
|
|
3401
|
+
|
|
3402
|
+
|
|
3403
|
+
|
|
3404
|
+
|
|
3287
3405
|
|
|
3288
3406
|
|
|
3289
3407
|
|
|
@@ -3361,6 +3479,10 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
|
|
|
3361
3479
|
|
|
3362
3480
|
|
|
3363
3481
|
|
|
3482
|
+
|
|
3483
|
+
|
|
3484
|
+
|
|
3485
|
+
|
|
3364
3486
|
|
|
3365
3487
|
|
|
3366
3488
|
|
|
@@ -3984,6 +4106,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3984
4106
|
constructor(keysNodesEntriesOrRaws = [], options) {
|
|
3985
4107
|
super([], options);
|
|
3986
4108
|
__publicField(this, "_root");
|
|
4109
|
+
__publicField(this, "_enableOrderStatistic", false);
|
|
3987
4110
|
/**
|
|
3988
4111
|
* The comparator function used to determine the order of keys in the tree.
|
|
3989
4112
|
|
|
@@ -3996,6 +4119,9 @@ var _BST = class _BST extends BinaryTree {
|
|
|
3996
4119
|
} else {
|
|
3997
4120
|
this._comparator = this._createDefaultComparator();
|
|
3998
4121
|
}
|
|
4122
|
+
if (options.enableOrderStatistic) {
|
|
4123
|
+
this._enableOrderStatistic = true;
|
|
4124
|
+
}
|
|
3999
4125
|
} else {
|
|
4000
4126
|
this._comparator = this._createDefaultComparator();
|
|
4001
4127
|
}
|
|
@@ -4161,6 +4287,14 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4161
4287
|
|
|
4162
4288
|
|
|
4163
4289
|
|
|
4290
|
+
|
|
4291
|
+
|
|
4292
|
+
|
|
4293
|
+
|
|
4294
|
+
|
|
4295
|
+
|
|
4296
|
+
|
|
4297
|
+
|
|
4164
4298
|
|
|
4165
4299
|
|
|
4166
4300
|
|
|
@@ -4325,6 +4459,85 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4325
4459
|
const searchRange = range instanceof Range ? range : new Range(range[0], range[1]);
|
|
4326
4460
|
return this.search(searchRange, false, callback, startNode, iterationType);
|
|
4327
4461
|
}
|
|
4462
|
+
getByRank(k, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4463
|
+
if (!this._enableOrderStatistic) {
|
|
4464
|
+
raise(Error, ERR.orderStatisticNotEnabled("getByRank"));
|
|
4465
|
+
}
|
|
4466
|
+
if (k < 0 || k >= this._size) return void 0;
|
|
4467
|
+
let actualCallback = void 0;
|
|
4468
|
+
let actualIterationType = this.iterationType;
|
|
4469
|
+
if (typeof callback === "string") {
|
|
4470
|
+
actualIterationType = callback;
|
|
4471
|
+
} else if (callback) {
|
|
4472
|
+
actualCallback = callback;
|
|
4473
|
+
if (iterationType) {
|
|
4474
|
+
actualIterationType = iterationType;
|
|
4475
|
+
}
|
|
4476
|
+
}
|
|
4477
|
+
const node = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, k) : this._getByRankIterative(this._root, k);
|
|
4478
|
+
if (!node) return void 0;
|
|
4479
|
+
return actualCallback ? actualCallback(node) : node.key;
|
|
4480
|
+
}
|
|
4481
|
+
getRank(keyNodeEntryOrPredicate, iterationType = this.iterationType) {
|
|
4482
|
+
var _a;
|
|
4483
|
+
if (!this._enableOrderStatistic) {
|
|
4484
|
+
raise(Error, ERR.orderStatisticNotEnabled("getRank"));
|
|
4485
|
+
}
|
|
4486
|
+
if (!this._root || this._size === 0) return -1;
|
|
4487
|
+
let actualIterationType = this.iterationType;
|
|
4488
|
+
if (iterationType) actualIterationType = iterationType;
|
|
4489
|
+
let key;
|
|
4490
|
+
if (typeof keyNodeEntryOrPredicate === "function") {
|
|
4491
|
+
const results = this.search(keyNodeEntryOrPredicate, true);
|
|
4492
|
+
if (results.length === 0 || results[0] === void 0) return -1;
|
|
4493
|
+
key = results[0];
|
|
4494
|
+
} else if (keyNodeEntryOrPredicate === null || keyNodeEntryOrPredicate === void 0) {
|
|
4495
|
+
return -1;
|
|
4496
|
+
} else if (this.isNode(keyNodeEntryOrPredicate)) {
|
|
4497
|
+
key = keyNodeEntryOrPredicate.key;
|
|
4498
|
+
} else if (Array.isArray(keyNodeEntryOrPredicate)) {
|
|
4499
|
+
key = (_a = keyNodeEntryOrPredicate[0]) != null ? _a : void 0;
|
|
4500
|
+
if (key === void 0 || key === null) return -1;
|
|
4501
|
+
} else {
|
|
4502
|
+
key = keyNodeEntryOrPredicate;
|
|
4503
|
+
}
|
|
4504
|
+
if (key === void 0) return -1;
|
|
4505
|
+
return actualIterationType === "RECURSIVE" ? this._getRankRecursive(this._root, key) : this._getRankIterative(this._root, key);
|
|
4506
|
+
}
|
|
4507
|
+
rangeByRank(start, end, callback = this._DEFAULT_NODE_CALLBACK, iterationType = this.iterationType) {
|
|
4508
|
+
if (!this._enableOrderStatistic) {
|
|
4509
|
+
raise(Error, ERR.orderStatisticNotEnabled("rangeByRank"));
|
|
4510
|
+
}
|
|
4511
|
+
if (this._size === 0) return [];
|
|
4512
|
+
const lo = Math.max(0, start);
|
|
4513
|
+
const hi = Math.min(this._size - 1, end);
|
|
4514
|
+
if (lo > hi) return [];
|
|
4515
|
+
let actualCallback = void 0;
|
|
4516
|
+
let actualIterationType = this.iterationType;
|
|
4517
|
+
if (typeof callback === "string") {
|
|
4518
|
+
actualIterationType = callback;
|
|
4519
|
+
} else if (callback) {
|
|
4520
|
+
actualCallback = callback;
|
|
4521
|
+
if (iterationType) {
|
|
4522
|
+
actualIterationType = iterationType;
|
|
4523
|
+
}
|
|
4524
|
+
}
|
|
4525
|
+
const results = [];
|
|
4526
|
+
const count = hi - lo + 1;
|
|
4527
|
+
const startNode = actualIterationType === "RECURSIVE" ? this._getByRankRecursive(this._root, lo) : this._getByRankIterative(this._root, lo);
|
|
4528
|
+
if (!startNode) return [];
|
|
4529
|
+
let collected = 0;
|
|
4530
|
+
const cb = actualCallback != null ? actualCallback : this._DEFAULT_NODE_CALLBACK;
|
|
4531
|
+
let current = startNode;
|
|
4532
|
+
while (current && collected < count) {
|
|
4533
|
+
results.push(cb(current));
|
|
4534
|
+
collected++;
|
|
4535
|
+
if (collected < count) {
|
|
4536
|
+
current = this._next(current);
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4539
|
+
return results;
|
|
4540
|
+
}
|
|
4328
4541
|
/**
|
|
4329
4542
|
* Adds a new node to the BST based on key comparison.
|
|
4330
4543
|
* @remarks Time O(log N), where H is tree height. O(N) worst-case (unbalanced tree), O(log N) average. Space O(1).
|
|
@@ -4417,20 +4630,33 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4417
4630
|
|
|
4418
4631
|
|
|
4419
4632
|
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4633
|
+
|
|
4634
|
+
|
|
4635
|
+
|
|
4636
|
+
|
|
4637
|
+
|
|
4638
|
+
|
|
4639
|
+
|
|
4640
|
+
|
|
4641
|
+
|
|
4642
|
+
|
|
4643
|
+
|
|
4644
|
+
|
|
4645
|
+
* @example
|
|
4646
|
+
* // Set a key-value pair
|
|
4647
|
+
* const bst = new BST<number, string>();
|
|
4648
|
+
* bst.set(1, 'one');
|
|
4649
|
+
* bst.set(2, 'two');
|
|
4650
|
+
* console.log(bst.get(1)); // 'one';
|
|
4651
|
+
*/
|
|
4652
|
+
set(keyNodeOrEntry, value) {
|
|
4653
|
+
const [newNode] = this._keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry, value);
|
|
4654
|
+
if (newNode === void 0) return false;
|
|
4655
|
+
if (this._root === void 0) {
|
|
4431
4656
|
this._setRoot(newNode);
|
|
4432
4657
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4433
4658
|
this._size++;
|
|
4659
|
+
this._updateCount(newNode);
|
|
4434
4660
|
return true;
|
|
4435
4661
|
}
|
|
4436
4662
|
let current = this._root;
|
|
@@ -4444,6 +4670,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4444
4670
|
current.left = newNode;
|
|
4445
4671
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4446
4672
|
this._size++;
|
|
4673
|
+
this._updateCountAlongPath(newNode);
|
|
4447
4674
|
return true;
|
|
4448
4675
|
}
|
|
4449
4676
|
if (current.left !== null) current = current.left;
|
|
@@ -4452,6 +4679,7 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4452
4679
|
current.right = newNode;
|
|
4453
4680
|
if (this._isMapMode && this.isRealNode(newNode)) this._store.set(newNode.key, newNode);
|
|
4454
4681
|
this._size++;
|
|
4682
|
+
this._updateCountAlongPath(newNode);
|
|
4455
4683
|
return true;
|
|
4456
4684
|
}
|
|
4457
4685
|
if (current.right !== null) current = current.right;
|
|
@@ -4512,6 +4740,14 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4512
4740
|
|
|
4513
4741
|
|
|
4514
4742
|
|
|
4743
|
+
|
|
4744
|
+
|
|
4745
|
+
|
|
4746
|
+
|
|
4747
|
+
|
|
4748
|
+
|
|
4749
|
+
|
|
4750
|
+
|
|
4515
4751
|
|
|
4516
4752
|
|
|
4517
4753
|
|
|
@@ -4799,6 +5035,10 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4799
5035
|
|
|
4800
5036
|
|
|
4801
5037
|
|
|
5038
|
+
|
|
5039
|
+
|
|
5040
|
+
|
|
5041
|
+
|
|
4802
5042
|
|
|
4803
5043
|
|
|
4804
5044
|
|
|
@@ -4864,6 +5104,10 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4864
5104
|
|
|
4865
5105
|
|
|
4866
5106
|
|
|
5107
|
+
|
|
5108
|
+
|
|
5109
|
+
|
|
5110
|
+
|
|
4867
5111
|
|
|
4868
5112
|
|
|
4869
5113
|
|
|
@@ -4974,6 +5218,14 @@ var _BST = class _BST extends BinaryTree {
|
|
|
4974
5218
|
|
|
4975
5219
|
|
|
4976
5220
|
|
|
5221
|
+
|
|
5222
|
+
|
|
5223
|
+
|
|
5224
|
+
|
|
5225
|
+
|
|
5226
|
+
|
|
5227
|
+
|
|
5228
|
+
|
|
4977
5229
|
|
|
4978
5230
|
|
|
4979
5231
|
|
|
@@ -5057,13 +5309,11 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5057
5309
|
if (a instanceof Date && b instanceof Date) {
|
|
5058
5310
|
const ta = a.getTime();
|
|
5059
5311
|
const tb = b.getTime();
|
|
5060
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
5312
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate("BST"));
|
|
5061
5313
|
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
5062
5314
|
}
|
|
5063
5315
|
if (typeof a === "object" || typeof b === "object") {
|
|
5064
|
-
|
|
5065
|
-
ERR.comparatorRequired("BST")
|
|
5066
|
-
);
|
|
5316
|
+
raise(TypeError, ERR.comparatorRequired("BST"));
|
|
5067
5317
|
}
|
|
5068
5318
|
return 0;
|
|
5069
5319
|
};
|
|
@@ -5385,7 +5635,8 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5385
5635
|
_snapshotOptions() {
|
|
5386
5636
|
return {
|
|
5387
5637
|
...super._snapshotOptions(),
|
|
5388
|
-
comparator: this._comparator
|
|
5638
|
+
comparator: this._comparator,
|
|
5639
|
+
enableOrderStatistic: this._enableOrderStatistic
|
|
5389
5640
|
};
|
|
5390
5641
|
}
|
|
5391
5642
|
/**
|
|
@@ -5407,6 +5658,113 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5407
5658
|
*
|
|
5408
5659
|
* @param v - The node to set as root.
|
|
5409
5660
|
*/
|
|
5661
|
+
/**
|
|
5662
|
+
* (Protected) Recalculates the subtree count for a single node.
|
|
5663
|
+
* @remarks Time O(1). Only active when enableOrderStatistic is true.
|
|
5664
|
+
*/
|
|
5665
|
+
_updateCount(node) {
|
|
5666
|
+
if (!this._enableOrderStatistic) return;
|
|
5667
|
+
node._count = 1 + (this.isRealNode(node.left) ? node.left._count : 0) + (this.isRealNode(node.right) ? node.right._count : 0);
|
|
5668
|
+
}
|
|
5669
|
+
/**
|
|
5670
|
+
* (Protected) Updates subtree counts from a node up to the root.
|
|
5671
|
+
* @remarks Time O(log n). Only active when enableOrderStatistic is true.
|
|
5672
|
+
*/
|
|
5673
|
+
_updateCountAlongPath(node) {
|
|
5674
|
+
if (!this._enableOrderStatistic) return;
|
|
5675
|
+
let current = node;
|
|
5676
|
+
while (current) {
|
|
5677
|
+
this._updateCount(current);
|
|
5678
|
+
current = current.parent;
|
|
5679
|
+
}
|
|
5680
|
+
}
|
|
5681
|
+
/**
|
|
5682
|
+
* (Protected) Finds the node at position k in tree order (iterative).
|
|
5683
|
+
* @remarks Time O(log n), Space O(1)
|
|
5684
|
+
*/
|
|
5685
|
+
_getByRankIterative(node, k) {
|
|
5686
|
+
let current = node;
|
|
5687
|
+
let remaining = k;
|
|
5688
|
+
while (current) {
|
|
5689
|
+
const leftCount = this.isRealNode(current.left) ? current.left._count : 0;
|
|
5690
|
+
if (remaining < leftCount) {
|
|
5691
|
+
current = current.left;
|
|
5692
|
+
} else if (remaining === leftCount) {
|
|
5693
|
+
return current;
|
|
5694
|
+
} else {
|
|
5695
|
+
remaining = remaining - leftCount - 1;
|
|
5696
|
+
current = current.right;
|
|
5697
|
+
}
|
|
5698
|
+
}
|
|
5699
|
+
return void 0;
|
|
5700
|
+
}
|
|
5701
|
+
/**
|
|
5702
|
+
* (Protected) Finds the node at position k in tree order (recursive).
|
|
5703
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5704
|
+
*/
|
|
5705
|
+
_getByRankRecursive(node, k) {
|
|
5706
|
+
if (!node) return void 0;
|
|
5707
|
+
const leftCount = this.isRealNode(node.left) ? node.left._count : 0;
|
|
5708
|
+
if (k < leftCount) return this._getByRankRecursive(node.left, k);
|
|
5709
|
+
if (k === leftCount) return node;
|
|
5710
|
+
return this._getByRankRecursive(node.right, k - leftCount - 1);
|
|
5711
|
+
}
|
|
5712
|
+
/**
|
|
5713
|
+
* (Protected) Computes the rank of a key iteratively.
|
|
5714
|
+
* @remarks Time O(log n), Space O(1)
|
|
5715
|
+
*/
|
|
5716
|
+
_getRankIterative(node, key) {
|
|
5717
|
+
let rank = 0;
|
|
5718
|
+
let current = node;
|
|
5719
|
+
while (this.isRealNode(current)) {
|
|
5720
|
+
const cmp = this._compare(current.key, key);
|
|
5721
|
+
if (cmp > 0) {
|
|
5722
|
+
current = current.left;
|
|
5723
|
+
} else if (cmp < 0) {
|
|
5724
|
+
rank += (this.isRealNode(current.left) ? current.left._count : 0) + 1;
|
|
5725
|
+
current = current.right;
|
|
5726
|
+
} else {
|
|
5727
|
+
rank += this.isRealNode(current.left) ? current.left._count : 0;
|
|
5728
|
+
return rank;
|
|
5729
|
+
}
|
|
5730
|
+
}
|
|
5731
|
+
return rank;
|
|
5732
|
+
}
|
|
5733
|
+
/**
|
|
5734
|
+
* (Protected) Computes the rank of a key recursively.
|
|
5735
|
+
* @remarks Time O(log n), Space O(log n) call stack
|
|
5736
|
+
*/
|
|
5737
|
+
_getRankRecursive(node, key) {
|
|
5738
|
+
if (!node) return 0;
|
|
5739
|
+
const cmp = this._compare(node.key, key);
|
|
5740
|
+
if (cmp > 0) {
|
|
5741
|
+
return this._getRankRecursive(node.left, key);
|
|
5742
|
+
} else if (cmp < 0) {
|
|
5743
|
+
return (this.isRealNode(node.left) ? node.left._count : 0) + 1 + this._getRankRecursive(node.right, key);
|
|
5744
|
+
} else {
|
|
5745
|
+
return this.isRealNode(node.left) ? node.left._count : 0;
|
|
5746
|
+
}
|
|
5747
|
+
}
|
|
5748
|
+
/**
|
|
5749
|
+
* (Protected) Finds the in-order successor of a node.
|
|
5750
|
+
* @remarks Time O(log n), Space O(1)
|
|
5751
|
+
*/
|
|
5752
|
+
_next(node) {
|
|
5753
|
+
if (this.isRealNode(node.right)) {
|
|
5754
|
+
let current2 = node.right;
|
|
5755
|
+
while (this.isRealNode(current2.left)) {
|
|
5756
|
+
current2 = current2.left;
|
|
5757
|
+
}
|
|
5758
|
+
return current2;
|
|
5759
|
+
}
|
|
5760
|
+
let current = node;
|
|
5761
|
+
let parent = current.parent;
|
|
5762
|
+
while (parent && current === parent.right) {
|
|
5763
|
+
current = parent;
|
|
5764
|
+
parent = parent.parent;
|
|
5765
|
+
}
|
|
5766
|
+
return parent;
|
|
5767
|
+
}
|
|
5410
5768
|
_setRoot(v) {
|
|
5411
5769
|
if (v) v.parent = void 0;
|
|
5412
5770
|
this._root = v;
|
|
@@ -5453,21 +5811,28 @@ var _BST = class _BST extends BinaryTree {
|
|
|
5453
5811
|
while (x.left !== void 0 && x.left !== null) x = x.left;
|
|
5454
5812
|
return x;
|
|
5455
5813
|
}, "minNode");
|
|
5814
|
+
let countUpdateStart;
|
|
5456
5815
|
if (node.left === void 0) {
|
|
5816
|
+
countUpdateStart = node.parent;
|
|
5457
5817
|
transplant(node, node.right);
|
|
5458
5818
|
} else if (node.right === void 0) {
|
|
5819
|
+
countUpdateStart = node.parent;
|
|
5459
5820
|
transplant(node, node.left);
|
|
5460
5821
|
} else {
|
|
5461
5822
|
const succ = minNode(node.right);
|
|
5462
5823
|
if (succ.parent !== node) {
|
|
5824
|
+
countUpdateStart = succ.parent;
|
|
5463
5825
|
transplant(succ, succ.right);
|
|
5464
5826
|
succ.right = node.right;
|
|
5465
5827
|
if (succ.right) succ.right.parent = succ;
|
|
5828
|
+
} else {
|
|
5829
|
+
countUpdateStart = succ;
|
|
5466
5830
|
}
|
|
5467
5831
|
transplant(node, succ);
|
|
5468
5832
|
succ.left = node.left;
|
|
5469
5833
|
if (succ.left) succ.left.parent = succ;
|
|
5470
5834
|
}
|
|
5835
|
+
this._updateCountAlongPath(countUpdateStart);
|
|
5471
5836
|
this._size = Math.max(0, this._size - 1);
|
|
5472
5837
|
return true;
|
|
5473
5838
|
}
|
|
@@ -5493,7 +5858,7 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5493
5858
|
}
|
|
5494
5859
|
} else {
|
|
5495
5860
|
if (!Number.isInteger(sizeOrElements) || sizeOrElements < 0) {
|
|
5496
|
-
|
|
5861
|
+
raise(RangeError, ERR.invalidArgument("size must be a non-negative integer", "BinaryIndexedTree"));
|
|
5497
5862
|
}
|
|
5498
5863
|
this._size = sizeOrElements;
|
|
5499
5864
|
this._tree = new Array(this._size + 1).fill(0);
|
|
@@ -5548,6 +5913,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5548
5913
|
|
|
5549
5914
|
|
|
5550
5915
|
|
|
5916
|
+
|
|
5917
|
+
|
|
5918
|
+
|
|
5919
|
+
|
|
5920
|
+
|
|
5921
|
+
|
|
5922
|
+
|
|
5923
|
+
|
|
5551
5924
|
|
|
5552
5925
|
|
|
5553
5926
|
|
|
@@ -5616,6 +5989,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5616
5989
|
|
|
5617
5990
|
|
|
5618
5991
|
|
|
5992
|
+
|
|
5993
|
+
|
|
5994
|
+
|
|
5995
|
+
|
|
5996
|
+
|
|
5997
|
+
|
|
5998
|
+
|
|
5999
|
+
|
|
5619
6000
|
|
|
5620
6001
|
|
|
5621
6002
|
|
|
@@ -5684,6 +6065,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5684
6065
|
|
|
5685
6066
|
|
|
5686
6067
|
|
|
6068
|
+
|
|
6069
|
+
|
|
6070
|
+
|
|
6071
|
+
|
|
6072
|
+
|
|
6073
|
+
|
|
6074
|
+
|
|
6075
|
+
|
|
5687
6076
|
|
|
5688
6077
|
|
|
5689
6078
|
|
|
@@ -5752,6 +6141,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5752
6141
|
|
|
5753
6142
|
|
|
5754
6143
|
|
|
6144
|
+
|
|
6145
|
+
|
|
6146
|
+
|
|
6147
|
+
|
|
6148
|
+
|
|
6149
|
+
|
|
6150
|
+
|
|
6151
|
+
|
|
5755
6152
|
|
|
5756
6153
|
|
|
5757
6154
|
|
|
@@ -5818,6 +6215,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5818
6215
|
|
|
5819
6216
|
|
|
5820
6217
|
|
|
6218
|
+
|
|
6219
|
+
|
|
6220
|
+
|
|
6221
|
+
|
|
6222
|
+
|
|
6223
|
+
|
|
6224
|
+
|
|
6225
|
+
|
|
5821
6226
|
|
|
5822
6227
|
|
|
5823
6228
|
|
|
@@ -5891,6 +6296,14 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5891
6296
|
|
|
5892
6297
|
|
|
5893
6298
|
|
|
6299
|
+
|
|
6300
|
+
|
|
6301
|
+
|
|
6302
|
+
|
|
6303
|
+
|
|
6304
|
+
|
|
6305
|
+
|
|
6306
|
+
|
|
5894
6307
|
|
|
5895
6308
|
|
|
5896
6309
|
|
|
@@ -5941,6 +6354,10 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5941
6354
|
|
|
5942
6355
|
|
|
5943
6356
|
|
|
6357
|
+
|
|
6358
|
+
|
|
6359
|
+
|
|
6360
|
+
|
|
5944
6361
|
|
|
5945
6362
|
|
|
5946
6363
|
|
|
@@ -5998,6 +6415,10 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
5998
6415
|
|
|
5999
6416
|
|
|
6000
6417
|
|
|
6418
|
+
|
|
6419
|
+
|
|
6420
|
+
|
|
6421
|
+
|
|
6001
6422
|
|
|
6002
6423
|
|
|
6003
6424
|
|
|
@@ -6072,10 +6493,10 @@ var _BinaryIndexedTree = class _BinaryIndexedTree {
|
|
|
6072
6493
|
}
|
|
6073
6494
|
_checkIndex(index) {
|
|
6074
6495
|
if (!Number.isInteger(index)) {
|
|
6075
|
-
|
|
6496
|
+
raise(TypeError, ERR.invalidIndex("BinaryIndexedTree"));
|
|
6076
6497
|
}
|
|
6077
6498
|
if (index < 0 || index >= this._size) {
|
|
6078
|
-
|
|
6499
|
+
raise(RangeError, ERR.indexOutOfRange(index, 0, this._size - 1, "BinaryIndexedTree"));
|
|
6079
6500
|
}
|
|
6080
6501
|
}
|
|
6081
6502
|
/** Returns highest power of 2 <= n. */
|
|
@@ -6157,6 +6578,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6157
6578
|
|
|
6158
6579
|
|
|
6159
6580
|
|
|
6581
|
+
|
|
6582
|
+
|
|
6583
|
+
|
|
6584
|
+
|
|
6160
6585
|
|
|
6161
6586
|
|
|
6162
6587
|
|
|
@@ -6225,6 +6650,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6225
6650
|
|
|
6226
6651
|
|
|
6227
6652
|
|
|
6653
|
+
|
|
6654
|
+
|
|
6655
|
+
|
|
6656
|
+
|
|
6228
6657
|
|
|
6229
6658
|
|
|
6230
6659
|
|
|
@@ -6287,6 +6716,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6287
6716
|
|
|
6288
6717
|
|
|
6289
6718
|
|
|
6719
|
+
|
|
6720
|
+
|
|
6721
|
+
|
|
6722
|
+
|
|
6290
6723
|
|
|
6291
6724
|
|
|
6292
6725
|
|
|
@@ -6356,6 +6789,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6356
6789
|
|
|
6357
6790
|
|
|
6358
6791
|
|
|
6792
|
+
|
|
6793
|
+
|
|
6794
|
+
|
|
6795
|
+
|
|
6359
6796
|
|
|
6360
6797
|
|
|
6361
6798
|
|
|
@@ -6403,6 +6840,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6403
6840
|
|
|
6404
6841
|
|
|
6405
6842
|
|
|
6843
|
+
|
|
6844
|
+
|
|
6845
|
+
|
|
6846
|
+
|
|
6406
6847
|
|
|
6407
6848
|
|
|
6408
6849
|
|
|
@@ -6476,6 +6917,10 @@ var _SegmentTree = class _SegmentTree {
|
|
|
6476
6917
|
|
|
6477
6918
|
|
|
6478
6919
|
|
|
6920
|
+
|
|
6921
|
+
|
|
6922
|
+
|
|
6923
|
+
|
|
6479
6924
|
|
|
6480
6925
|
|
|
6481
6926
|
|
|
@@ -6843,6 +7288,22 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6843
7288
|
|
|
6844
7289
|
|
|
6845
7290
|
|
|
7291
|
+
|
|
7292
|
+
|
|
7293
|
+
|
|
7294
|
+
|
|
7295
|
+
|
|
7296
|
+
|
|
7297
|
+
|
|
7298
|
+
|
|
7299
|
+
|
|
7300
|
+
|
|
7301
|
+
|
|
7302
|
+
|
|
7303
|
+
|
|
7304
|
+
|
|
7305
|
+
|
|
7306
|
+
|
|
6846
7307
|
|
|
6847
7308
|
|
|
6848
7309
|
|
|
@@ -6959,6 +7420,18 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
6959
7420
|
|
|
6960
7421
|
|
|
6961
7422
|
|
|
7423
|
+
|
|
7424
|
+
|
|
7425
|
+
|
|
7426
|
+
|
|
7427
|
+
|
|
7428
|
+
|
|
7429
|
+
|
|
7430
|
+
|
|
7431
|
+
|
|
7432
|
+
|
|
7433
|
+
|
|
7434
|
+
|
|
6962
7435
|
|
|
6963
7436
|
|
|
6964
7437
|
|
|
@@ -7038,6 +7511,14 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7038
7511
|
|
|
7039
7512
|
|
|
7040
7513
|
|
|
7514
|
+
|
|
7515
|
+
|
|
7516
|
+
|
|
7517
|
+
|
|
7518
|
+
|
|
7519
|
+
|
|
7520
|
+
|
|
7521
|
+
|
|
7041
7522
|
|
|
7042
7523
|
|
|
7043
7524
|
|
|
@@ -7158,6 +7639,18 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7158
7639
|
|
|
7159
7640
|
|
|
7160
7641
|
|
|
7642
|
+
|
|
7643
|
+
|
|
7644
|
+
|
|
7645
|
+
|
|
7646
|
+
|
|
7647
|
+
|
|
7648
|
+
|
|
7649
|
+
|
|
7650
|
+
|
|
7651
|
+
|
|
7652
|
+
|
|
7653
|
+
|
|
7161
7654
|
|
|
7162
7655
|
|
|
7163
7656
|
|
|
@@ -7289,6 +7782,8 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7289
7782
|
}
|
|
7290
7783
|
this._updateHeight(A);
|
|
7291
7784
|
if (B) this._updateHeight(B);
|
|
7785
|
+
this._updateCount(A);
|
|
7786
|
+
if (B) this._updateCount(B);
|
|
7292
7787
|
}
|
|
7293
7788
|
/**
|
|
7294
7789
|
* (Protected) Performs a Left-Right (LR) double rotation.
|
|
@@ -7334,6 +7829,9 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7334
7829
|
this._updateHeight(A);
|
|
7335
7830
|
if (B) this._updateHeight(B);
|
|
7336
7831
|
if (C) this._updateHeight(C);
|
|
7832
|
+
this._updateCount(A);
|
|
7833
|
+
if (B) this._updateCount(B);
|
|
7834
|
+
if (C) this._updateCount(C);
|
|
7337
7835
|
}
|
|
7338
7836
|
/**
|
|
7339
7837
|
* (Protected) Performs a Right-Right (RR) rotation (a single left rotation).
|
|
@@ -7368,6 +7866,8 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7368
7866
|
}
|
|
7369
7867
|
this._updateHeight(A);
|
|
7370
7868
|
if (B) this._updateHeight(B);
|
|
7869
|
+
this._updateCount(A);
|
|
7870
|
+
if (B) this._updateCount(B);
|
|
7371
7871
|
}
|
|
7372
7872
|
/**
|
|
7373
7873
|
* (Protected) Performs a Right-Left (RL) double rotation.
|
|
@@ -7411,6 +7911,9 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7411
7911
|
this._updateHeight(A);
|
|
7412
7912
|
if (B) this._updateHeight(B);
|
|
7413
7913
|
if (C) this._updateHeight(C);
|
|
7914
|
+
this._updateCount(A);
|
|
7915
|
+
if (B) this._updateCount(B);
|
|
7916
|
+
if (C) this._updateCount(C);
|
|
7414
7917
|
}
|
|
7415
7918
|
/**
|
|
7416
7919
|
* (Protected) Traverses up the tree from the specified node, updating heights and performing rotations as needed.
|
|
@@ -7425,6 +7928,7 @@ var _AVLTree = class _AVLTree extends BST {
|
|
|
7425
7928
|
const A = path[i];
|
|
7426
7929
|
if (A) {
|
|
7427
7930
|
this._updateHeight(A);
|
|
7931
|
+
this._updateCount(A);
|
|
7428
7932
|
switch (this._balanceFactor(A)) {
|
|
7429
7933
|
case -2:
|
|
7430
7934
|
if (A && A.left) {
|
|
@@ -7752,6 +8256,22 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
7752
8256
|
|
|
7753
8257
|
|
|
7754
8258
|
|
|
8259
|
+
|
|
8260
|
+
|
|
8261
|
+
|
|
8262
|
+
|
|
8263
|
+
|
|
8264
|
+
|
|
8265
|
+
|
|
8266
|
+
|
|
8267
|
+
|
|
8268
|
+
|
|
8269
|
+
|
|
8270
|
+
|
|
8271
|
+
|
|
8272
|
+
|
|
8273
|
+
|
|
8274
|
+
|
|
7755
8275
|
|
|
7756
8276
|
|
|
7757
8277
|
|
|
@@ -7859,6 +8379,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
7859
8379
|
node.left = NIL;
|
|
7860
8380
|
node.right = NIL;
|
|
7861
8381
|
node.color = "RED";
|
|
8382
|
+
this._updateCountAlongPath(node);
|
|
7862
8383
|
this._insertFixup(node);
|
|
7863
8384
|
if (this.isRealNode(this._root)) this._root.color = "BLACK";
|
|
7864
8385
|
}
|
|
@@ -7969,6 +8490,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
7969
8490
|
newNode.left = NIL;
|
|
7970
8491
|
newNode.right = NIL;
|
|
7971
8492
|
newNode.color = "RED";
|
|
8493
|
+
this._updateCountAlongPath(newNode);
|
|
7972
8494
|
this._insertFixup(newNode);
|
|
7973
8495
|
if (this.isRealNode(this._root)) this._root.color = "BLACK";
|
|
7974
8496
|
else return void 0;
|
|
@@ -8212,6 +8734,22 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8212
8734
|
|
|
8213
8735
|
|
|
8214
8736
|
|
|
8737
|
+
|
|
8738
|
+
|
|
8739
|
+
|
|
8740
|
+
|
|
8741
|
+
|
|
8742
|
+
|
|
8743
|
+
|
|
8744
|
+
|
|
8745
|
+
|
|
8746
|
+
|
|
8747
|
+
|
|
8748
|
+
|
|
8749
|
+
|
|
8750
|
+
|
|
8751
|
+
|
|
8752
|
+
|
|
8215
8753
|
|
|
8216
8754
|
|
|
8217
8755
|
|
|
@@ -8412,16 +8950,32 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8412
8950
|
|
|
8413
8951
|
|
|
8414
8952
|
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8953
|
+
|
|
8954
|
+
|
|
8955
|
+
|
|
8956
|
+
|
|
8957
|
+
|
|
8958
|
+
|
|
8959
|
+
|
|
8960
|
+
|
|
8961
|
+
|
|
8962
|
+
|
|
8963
|
+
|
|
8964
|
+
|
|
8965
|
+
|
|
8966
|
+
|
|
8967
|
+
|
|
8968
|
+
|
|
8969
|
+
* @example
|
|
8970
|
+
* // Remove and rebalance
|
|
8971
|
+
* const rbt = new RedBlackTree<number>([10, 5, 15, 3, 7]);
|
|
8972
|
+
* rbt.delete(5);
|
|
8973
|
+
* console.log(rbt.has(5)); // false;
|
|
8974
|
+
* console.log(rbt.size); // 4;
|
|
8975
|
+
*/
|
|
8976
|
+
delete(keyNodeEntryRawOrPredicate) {
|
|
8977
|
+
var _a, _b, _c;
|
|
8978
|
+
if (keyNodeEntryRawOrPredicate === null) return [];
|
|
8425
8979
|
const results = [];
|
|
8426
8980
|
let nodeToDelete;
|
|
8427
8981
|
if (this._isPredicate(keyNodeEntryRawOrPredicate)) nodeToDelete = this.getNode(keyNodeEntryRawOrPredicate);
|
|
@@ -8466,6 +9020,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8466
9020
|
}
|
|
8467
9021
|
if (this._isMapMode) this._store.delete(nodeToDelete.key);
|
|
8468
9022
|
this._size--;
|
|
9023
|
+
this._updateCountAlongPath((_c = replacementNode == null ? void 0 : replacementNode.parent) != null ? _c : replacementNode);
|
|
8469
9024
|
if (this._size <= 0) {
|
|
8470
9025
|
this._setMinCache(void 0);
|
|
8471
9026
|
this._setMaxCache(void 0);
|
|
@@ -8572,6 +9127,18 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8572
9127
|
|
|
8573
9128
|
|
|
8574
9129
|
|
|
9130
|
+
|
|
9131
|
+
|
|
9132
|
+
|
|
9133
|
+
|
|
9134
|
+
|
|
9135
|
+
|
|
9136
|
+
|
|
9137
|
+
|
|
9138
|
+
|
|
9139
|
+
|
|
9140
|
+
|
|
9141
|
+
|
|
8575
9142
|
|
|
8576
9143
|
|
|
8577
9144
|
|
|
@@ -8704,6 +9271,22 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8704
9271
|
|
|
8705
9272
|
|
|
8706
9273
|
|
|
9274
|
+
|
|
9275
|
+
|
|
9276
|
+
|
|
9277
|
+
|
|
9278
|
+
|
|
9279
|
+
|
|
9280
|
+
|
|
9281
|
+
|
|
9282
|
+
|
|
9283
|
+
|
|
9284
|
+
|
|
9285
|
+
|
|
9286
|
+
|
|
9287
|
+
|
|
9288
|
+
|
|
9289
|
+
|
|
8707
9290
|
|
|
8708
9291
|
|
|
8709
9292
|
|
|
@@ -8807,6 +9390,7 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8807
9390
|
node.left = NIL;
|
|
8808
9391
|
node.right = NIL;
|
|
8809
9392
|
node.color = "RED";
|
|
9393
|
+
this._updateCountAlongPath(node);
|
|
8810
9394
|
this._insertFixup(node);
|
|
8811
9395
|
return "CREATED";
|
|
8812
9396
|
}
|
|
@@ -8975,6 +9559,8 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
8975
9559
|
}
|
|
8976
9560
|
y.left = x;
|
|
8977
9561
|
x.parent = y;
|
|
9562
|
+
this._updateCount(x);
|
|
9563
|
+
this._updateCount(y);
|
|
8978
9564
|
}
|
|
8979
9565
|
/**
|
|
8980
9566
|
* (Protected) Perform a right rotation around y.
|
|
@@ -9001,6 +9587,8 @@ var _RedBlackTree = class _RedBlackTree extends BST {
|
|
|
9001
9587
|
}
|
|
9002
9588
|
x.right = y;
|
|
9003
9589
|
y.parent = x;
|
|
9590
|
+
this._updateCount(y);
|
|
9591
|
+
this._updateCount(x);
|
|
9004
9592
|
}
|
|
9005
9593
|
};
|
|
9006
9594
|
__name(_RedBlackTree, "RedBlackTree");
|
|
@@ -9033,7 +9621,7 @@ var _TreeSet = class _TreeSet {
|
|
|
9033
9621
|
const toElementFn = options.toElementFn;
|
|
9034
9622
|
const comparator = (_a = options.comparator) != null ? _a : _TreeSet.createDefaultComparator();
|
|
9035
9623
|
__privateSet(this, _isDefaultComparator, options.comparator === void 0);
|
|
9036
|
-
__privateSet(this, _core, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
9624
|
+
__privateSet(this, _core, new RedBlackTree([], { comparator, isMapMode: options.isMapMode, enableOrderStatistic: options.enableOrderStatistic }));
|
|
9037
9625
|
for (const item of elements) {
|
|
9038
9626
|
const k = toElementFn ? toElementFn(item) : item;
|
|
9039
9627
|
this.add(k);
|
|
@@ -9052,7 +9640,7 @@ var _TreeSet = class _TreeSet {
|
|
|
9052
9640
|
static createDefaultComparator() {
|
|
9053
9641
|
return (a, b) => {
|
|
9054
9642
|
if (typeof a === "number" && typeof b === "number") {
|
|
9055
|
-
if (Number.isNaN(a) || Number.isNaN(b))
|
|
9643
|
+
if (Number.isNaN(a) || Number.isNaN(b)) raise(TypeError, ERR.invalidNaN("TreeSet"));
|
|
9056
9644
|
const aa = Object.is(a, -0) ? 0 : a;
|
|
9057
9645
|
const bb = Object.is(b, -0) ? 0 : b;
|
|
9058
9646
|
return aa > bb ? 1 : aa < bb ? -1 : 0;
|
|
@@ -9063,10 +9651,10 @@ var _TreeSet = class _TreeSet {
|
|
|
9063
9651
|
if (a instanceof Date && b instanceof Date) {
|
|
9064
9652
|
const ta = a.getTime();
|
|
9065
9653
|
const tb = b.getTime();
|
|
9066
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
9654
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate("TreeSet"));
|
|
9067
9655
|
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
9068
9656
|
}
|
|
9069
|
-
|
|
9657
|
+
raise(TypeError, ERR.comparatorRequired("TreeSet"));
|
|
9070
9658
|
};
|
|
9071
9659
|
}
|
|
9072
9660
|
/**
|
|
@@ -9194,6 +9782,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9194
9782
|
|
|
9195
9783
|
|
|
9196
9784
|
|
|
9785
|
+
|
|
9786
|
+
|
|
9787
|
+
|
|
9788
|
+
|
|
9789
|
+
|
|
9790
|
+
|
|
9791
|
+
|
|
9792
|
+
|
|
9793
|
+
|
|
9794
|
+
|
|
9795
|
+
|
|
9796
|
+
|
|
9797
|
+
|
|
9798
|
+
|
|
9799
|
+
|
|
9800
|
+
|
|
9801
|
+
|
|
9802
|
+
|
|
9803
|
+
|
|
9804
|
+
|
|
9197
9805
|
|
|
9198
9806
|
|
|
9199
9807
|
|
|
@@ -9225,15 +9833,15 @@ var _TreeSet = class _TreeSet {
|
|
|
9225
9833
|
_validateKey(key) {
|
|
9226
9834
|
if (!__privateGet(this, _isDefaultComparator)) return;
|
|
9227
9835
|
if (typeof key === "number") {
|
|
9228
|
-
if (Number.isNaN(key))
|
|
9836
|
+
if (Number.isNaN(key)) raise(TypeError, ERR.invalidNaN("TreeSet"));
|
|
9229
9837
|
return;
|
|
9230
9838
|
}
|
|
9231
9839
|
if (typeof key === "string") return;
|
|
9232
9840
|
if (key instanceof Date) {
|
|
9233
|
-
if (Number.isNaN(key.getTime()))
|
|
9841
|
+
if (Number.isNaN(key.getTime())) raise(TypeError, ERR.invalidDate("TreeSet"));
|
|
9234
9842
|
return;
|
|
9235
9843
|
}
|
|
9236
|
-
|
|
9844
|
+
raise(TypeError, ERR.comparatorRequired("TreeSet"));
|
|
9237
9845
|
}
|
|
9238
9846
|
/**
|
|
9239
9847
|
* Add a key to the set (no-op if already present).
|
|
@@ -9358,6 +9966,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9358
9966
|
|
|
9359
9967
|
|
|
9360
9968
|
|
|
9969
|
+
|
|
9970
|
+
|
|
9971
|
+
|
|
9972
|
+
|
|
9973
|
+
|
|
9974
|
+
|
|
9975
|
+
|
|
9976
|
+
|
|
9977
|
+
|
|
9978
|
+
|
|
9979
|
+
|
|
9980
|
+
|
|
9981
|
+
|
|
9982
|
+
|
|
9983
|
+
|
|
9984
|
+
|
|
9985
|
+
|
|
9986
|
+
|
|
9987
|
+
|
|
9988
|
+
|
|
9361
9989
|
|
|
9362
9990
|
|
|
9363
9991
|
|
|
@@ -9527,6 +10155,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9527
10155
|
|
|
9528
10156
|
|
|
9529
10157
|
|
|
10158
|
+
|
|
10159
|
+
|
|
10160
|
+
|
|
10161
|
+
|
|
10162
|
+
|
|
10163
|
+
|
|
10164
|
+
|
|
10165
|
+
|
|
10166
|
+
|
|
10167
|
+
|
|
10168
|
+
|
|
10169
|
+
|
|
10170
|
+
|
|
10171
|
+
|
|
10172
|
+
|
|
10173
|
+
|
|
10174
|
+
|
|
10175
|
+
|
|
10176
|
+
|
|
10177
|
+
|
|
9530
10178
|
|
|
9531
10179
|
|
|
9532
10180
|
|
|
@@ -9691,6 +10339,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9691
10339
|
|
|
9692
10340
|
|
|
9693
10341
|
|
|
10342
|
+
|
|
10343
|
+
|
|
10344
|
+
|
|
10345
|
+
|
|
10346
|
+
|
|
10347
|
+
|
|
10348
|
+
|
|
10349
|
+
|
|
10350
|
+
|
|
10351
|
+
|
|
10352
|
+
|
|
10353
|
+
|
|
10354
|
+
|
|
10355
|
+
|
|
10356
|
+
|
|
10357
|
+
|
|
10358
|
+
|
|
10359
|
+
|
|
10360
|
+
|
|
10361
|
+
|
|
9694
10362
|
|
|
9695
10363
|
|
|
9696
10364
|
|
|
@@ -9845,6 +10513,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9845
10513
|
|
|
9846
10514
|
|
|
9847
10515
|
|
|
10516
|
+
|
|
10517
|
+
|
|
10518
|
+
|
|
10519
|
+
|
|
10520
|
+
|
|
10521
|
+
|
|
10522
|
+
|
|
10523
|
+
|
|
10524
|
+
|
|
10525
|
+
|
|
10526
|
+
|
|
10527
|
+
|
|
10528
|
+
|
|
10529
|
+
|
|
10530
|
+
|
|
10531
|
+
|
|
10532
|
+
|
|
10533
|
+
|
|
10534
|
+
|
|
10535
|
+
|
|
9848
10536
|
|
|
9849
10537
|
|
|
9850
10538
|
|
|
@@ -9994,6 +10682,26 @@ var _TreeSet = class _TreeSet {
|
|
|
9994
10682
|
|
|
9995
10683
|
|
|
9996
10684
|
|
|
10685
|
+
|
|
10686
|
+
|
|
10687
|
+
|
|
10688
|
+
|
|
10689
|
+
|
|
10690
|
+
|
|
10691
|
+
|
|
10692
|
+
|
|
10693
|
+
|
|
10694
|
+
|
|
10695
|
+
|
|
10696
|
+
|
|
10697
|
+
|
|
10698
|
+
|
|
10699
|
+
|
|
10700
|
+
|
|
10701
|
+
|
|
10702
|
+
|
|
10703
|
+
|
|
10704
|
+
|
|
9997
10705
|
|
|
9998
10706
|
|
|
9999
10707
|
|
|
@@ -10144,6 +10852,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10144
10852
|
|
|
10145
10853
|
|
|
10146
10854
|
|
|
10855
|
+
|
|
10856
|
+
|
|
10857
|
+
|
|
10858
|
+
|
|
10859
|
+
|
|
10860
|
+
|
|
10861
|
+
|
|
10862
|
+
|
|
10863
|
+
|
|
10864
|
+
|
|
10865
|
+
|
|
10866
|
+
|
|
10867
|
+
|
|
10868
|
+
|
|
10869
|
+
|
|
10870
|
+
|
|
10871
|
+
|
|
10872
|
+
|
|
10873
|
+
|
|
10874
|
+
|
|
10147
10875
|
|
|
10148
10876
|
|
|
10149
10877
|
|
|
@@ -10294,6 +11022,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10294
11022
|
|
|
10295
11023
|
|
|
10296
11024
|
|
|
11025
|
+
|
|
11026
|
+
|
|
11027
|
+
|
|
11028
|
+
|
|
11029
|
+
|
|
11030
|
+
|
|
11031
|
+
|
|
11032
|
+
|
|
11033
|
+
|
|
11034
|
+
|
|
11035
|
+
|
|
11036
|
+
|
|
11037
|
+
|
|
11038
|
+
|
|
11039
|
+
|
|
11040
|
+
|
|
11041
|
+
|
|
11042
|
+
|
|
11043
|
+
|
|
11044
|
+
|
|
10297
11045
|
|
|
10298
11046
|
|
|
10299
11047
|
|
|
@@ -10447,6 +11195,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10447
11195
|
|
|
10448
11196
|
|
|
10449
11197
|
|
|
11198
|
+
|
|
11199
|
+
|
|
11200
|
+
|
|
11201
|
+
|
|
11202
|
+
|
|
11203
|
+
|
|
11204
|
+
|
|
11205
|
+
|
|
11206
|
+
|
|
11207
|
+
|
|
11208
|
+
|
|
11209
|
+
|
|
11210
|
+
|
|
11211
|
+
|
|
11212
|
+
|
|
11213
|
+
|
|
11214
|
+
|
|
11215
|
+
|
|
11216
|
+
|
|
11217
|
+
|
|
10450
11218
|
|
|
10451
11219
|
|
|
10452
11220
|
|
|
@@ -10600,6 +11368,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10600
11368
|
|
|
10601
11369
|
|
|
10602
11370
|
|
|
11371
|
+
|
|
11372
|
+
|
|
11373
|
+
|
|
11374
|
+
|
|
11375
|
+
|
|
11376
|
+
|
|
11377
|
+
|
|
11378
|
+
|
|
11379
|
+
|
|
11380
|
+
|
|
11381
|
+
|
|
11382
|
+
|
|
11383
|
+
|
|
11384
|
+
|
|
11385
|
+
|
|
11386
|
+
|
|
11387
|
+
|
|
11388
|
+
|
|
11389
|
+
|
|
11390
|
+
|
|
10603
11391
|
|
|
10604
11392
|
|
|
10605
11393
|
|
|
@@ -10777,8 +11565,28 @@ var _TreeSet = class _TreeSet {
|
|
|
10777
11565
|
|
|
10778
11566
|
|
|
10779
11567
|
|
|
10780
|
-
|
|
10781
|
-
|
|
11568
|
+
|
|
11569
|
+
|
|
11570
|
+
|
|
11571
|
+
|
|
11572
|
+
|
|
11573
|
+
|
|
11574
|
+
|
|
11575
|
+
|
|
11576
|
+
|
|
11577
|
+
|
|
11578
|
+
|
|
11579
|
+
|
|
11580
|
+
|
|
11581
|
+
|
|
11582
|
+
|
|
11583
|
+
|
|
11584
|
+
|
|
11585
|
+
|
|
11586
|
+
|
|
11587
|
+
|
|
11588
|
+
* @example
|
|
11589
|
+
* // Filter
|
|
10782
11590
|
* const ts = new TreeSet<number>([1, 2, 3, 4, 5]);
|
|
10783
11591
|
* const evens = ts.filter(k => k % 2 === 0);
|
|
10784
11592
|
* console.log([...evens]); // [2, 4];
|
|
@@ -10912,6 +11720,26 @@ var _TreeSet = class _TreeSet {
|
|
|
10912
11720
|
|
|
10913
11721
|
|
|
10914
11722
|
|
|
11723
|
+
|
|
11724
|
+
|
|
11725
|
+
|
|
11726
|
+
|
|
11727
|
+
|
|
11728
|
+
|
|
11729
|
+
|
|
11730
|
+
|
|
11731
|
+
|
|
11732
|
+
|
|
11733
|
+
|
|
11734
|
+
|
|
11735
|
+
|
|
11736
|
+
|
|
11737
|
+
|
|
11738
|
+
|
|
11739
|
+
|
|
11740
|
+
|
|
11741
|
+
|
|
11742
|
+
|
|
10915
11743
|
|
|
10916
11744
|
|
|
10917
11745
|
|
|
@@ -11063,6 +11891,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11063
11891
|
|
|
11064
11892
|
|
|
11065
11893
|
|
|
11894
|
+
|
|
11895
|
+
|
|
11896
|
+
|
|
11897
|
+
|
|
11898
|
+
|
|
11899
|
+
|
|
11900
|
+
|
|
11901
|
+
|
|
11902
|
+
|
|
11903
|
+
|
|
11904
|
+
|
|
11905
|
+
|
|
11906
|
+
|
|
11907
|
+
|
|
11908
|
+
|
|
11909
|
+
|
|
11910
|
+
|
|
11911
|
+
|
|
11912
|
+
|
|
11913
|
+
|
|
11066
11914
|
|
|
11067
11915
|
|
|
11068
11916
|
|
|
@@ -11215,6 +12063,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11215
12063
|
|
|
11216
12064
|
|
|
11217
12065
|
|
|
12066
|
+
|
|
12067
|
+
|
|
12068
|
+
|
|
12069
|
+
|
|
12070
|
+
|
|
12071
|
+
|
|
12072
|
+
|
|
12073
|
+
|
|
12074
|
+
|
|
12075
|
+
|
|
12076
|
+
|
|
12077
|
+
|
|
12078
|
+
|
|
12079
|
+
|
|
12080
|
+
|
|
12081
|
+
|
|
12082
|
+
|
|
12083
|
+
|
|
12084
|
+
|
|
12085
|
+
|
|
11218
12086
|
|
|
11219
12087
|
|
|
11220
12088
|
|
|
@@ -11367,6 +12235,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11367
12235
|
|
|
11368
12236
|
|
|
11369
12237
|
|
|
12238
|
+
|
|
12239
|
+
|
|
12240
|
+
|
|
12241
|
+
|
|
12242
|
+
|
|
12243
|
+
|
|
12244
|
+
|
|
12245
|
+
|
|
12246
|
+
|
|
12247
|
+
|
|
12248
|
+
|
|
12249
|
+
|
|
12250
|
+
|
|
12251
|
+
|
|
12252
|
+
|
|
12253
|
+
|
|
12254
|
+
|
|
12255
|
+
|
|
12256
|
+
|
|
12257
|
+
|
|
11370
12258
|
|
|
11371
12259
|
|
|
11372
12260
|
|
|
@@ -11522,6 +12410,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11522
12410
|
|
|
11523
12411
|
|
|
11524
12412
|
|
|
12413
|
+
|
|
12414
|
+
|
|
12415
|
+
|
|
12416
|
+
|
|
12417
|
+
|
|
12418
|
+
|
|
12419
|
+
|
|
12420
|
+
|
|
12421
|
+
|
|
12422
|
+
|
|
12423
|
+
|
|
12424
|
+
|
|
12425
|
+
|
|
12426
|
+
|
|
12427
|
+
|
|
12428
|
+
|
|
12429
|
+
|
|
12430
|
+
|
|
12431
|
+
|
|
12432
|
+
|
|
11525
12433
|
|
|
11526
12434
|
|
|
11527
12435
|
|
|
@@ -11671,6 +12579,26 @@ var _TreeSet = class _TreeSet {
|
|
|
11671
12579
|
|
|
11672
12580
|
|
|
11673
12581
|
|
|
12582
|
+
|
|
12583
|
+
|
|
12584
|
+
|
|
12585
|
+
|
|
12586
|
+
|
|
12587
|
+
|
|
12588
|
+
|
|
12589
|
+
|
|
12590
|
+
|
|
12591
|
+
|
|
12592
|
+
|
|
12593
|
+
|
|
12594
|
+
|
|
12595
|
+
|
|
12596
|
+
|
|
12597
|
+
|
|
12598
|
+
|
|
12599
|
+
|
|
12600
|
+
|
|
12601
|
+
|
|
11674
12602
|
|
|
11675
12603
|
|
|
11676
12604
|
|
|
@@ -11729,6 +12657,10 @@ var _TreeSet = class _TreeSet {
|
|
|
11729
12657
|
|
|
11730
12658
|
|
|
11731
12659
|
|
|
12660
|
+
|
|
12661
|
+
|
|
12662
|
+
|
|
12663
|
+
|
|
11732
12664
|
|
|
11733
12665
|
|
|
11734
12666
|
|
|
@@ -11793,6 +12725,10 @@ var _TreeSet = class _TreeSet {
|
|
|
11793
12725
|
|
|
11794
12726
|
|
|
11795
12727
|
|
|
12728
|
+
|
|
12729
|
+
|
|
12730
|
+
|
|
12731
|
+
|
|
11796
12732
|
|
|
11797
12733
|
|
|
11798
12734
|
|
|
@@ -11835,6 +12771,10 @@ var _TreeSet = class _TreeSet {
|
|
|
11835
12771
|
|
|
11836
12772
|
|
|
11837
12773
|
|
|
12774
|
+
|
|
12775
|
+
|
|
12776
|
+
|
|
12777
|
+
|
|
11838
12778
|
|
|
11839
12779
|
|
|
11840
12780
|
|
|
@@ -11882,6 +12822,10 @@ var _TreeSet = class _TreeSet {
|
|
|
11882
12822
|
|
|
11883
12823
|
|
|
11884
12824
|
|
|
12825
|
+
|
|
12826
|
+
|
|
12827
|
+
|
|
12828
|
+
|
|
11885
12829
|
|
|
11886
12830
|
|
|
11887
12831
|
|
|
@@ -12003,6 +12947,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12003
12947
|
|
|
12004
12948
|
|
|
12005
12949
|
|
|
12950
|
+
|
|
12951
|
+
|
|
12952
|
+
|
|
12953
|
+
|
|
12954
|
+
|
|
12955
|
+
|
|
12956
|
+
|
|
12957
|
+
|
|
12958
|
+
|
|
12959
|
+
|
|
12960
|
+
|
|
12961
|
+
|
|
12962
|
+
|
|
12963
|
+
|
|
12964
|
+
|
|
12965
|
+
|
|
12006
12966
|
|
|
12007
12967
|
|
|
12008
12968
|
|
|
@@ -12144,6 +13104,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12144
13104
|
|
|
12145
13105
|
|
|
12146
13106
|
|
|
13107
|
+
|
|
13108
|
+
|
|
13109
|
+
|
|
13110
|
+
|
|
13111
|
+
|
|
13112
|
+
|
|
13113
|
+
|
|
13114
|
+
|
|
13115
|
+
|
|
13116
|
+
|
|
13117
|
+
|
|
13118
|
+
|
|
13119
|
+
|
|
13120
|
+
|
|
13121
|
+
|
|
13122
|
+
|
|
12147
13123
|
|
|
12148
13124
|
|
|
12149
13125
|
|
|
@@ -12277,6 +13253,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12277
13253
|
|
|
12278
13254
|
|
|
12279
13255
|
|
|
13256
|
+
|
|
13257
|
+
|
|
13258
|
+
|
|
13259
|
+
|
|
13260
|
+
|
|
13261
|
+
|
|
13262
|
+
|
|
13263
|
+
|
|
13264
|
+
|
|
13265
|
+
|
|
13266
|
+
|
|
13267
|
+
|
|
13268
|
+
|
|
13269
|
+
|
|
13270
|
+
|
|
13271
|
+
|
|
12280
13272
|
|
|
12281
13273
|
|
|
12282
13274
|
|
|
@@ -12408,6 +13400,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12408
13400
|
|
|
12409
13401
|
|
|
12410
13402
|
|
|
13403
|
+
|
|
13404
|
+
|
|
13405
|
+
|
|
13406
|
+
|
|
13407
|
+
|
|
13408
|
+
|
|
13409
|
+
|
|
13410
|
+
|
|
13411
|
+
|
|
13412
|
+
|
|
13413
|
+
|
|
13414
|
+
|
|
13415
|
+
|
|
13416
|
+
|
|
13417
|
+
|
|
13418
|
+
|
|
12411
13419
|
|
|
12412
13420
|
|
|
12413
13421
|
|
|
@@ -12542,6 +13550,22 @@ var _TreeSet = class _TreeSet {
|
|
|
12542
13550
|
|
|
12543
13551
|
|
|
12544
13552
|
|
|
13553
|
+
|
|
13554
|
+
|
|
13555
|
+
|
|
13556
|
+
|
|
13557
|
+
|
|
13558
|
+
|
|
13559
|
+
|
|
13560
|
+
|
|
13561
|
+
|
|
13562
|
+
|
|
13563
|
+
|
|
13564
|
+
|
|
13565
|
+
|
|
13566
|
+
|
|
13567
|
+
|
|
13568
|
+
|
|
12545
13569
|
|
|
12546
13570
|
|
|
12547
13571
|
|
|
@@ -12593,6 +13617,62 @@ var _TreeSet = class _TreeSet {
|
|
|
12593
13617
|
}
|
|
12594
13618
|
return out;
|
|
12595
13619
|
}
|
|
13620
|
+
// ─── Order-Statistic Methods ───────────────────────────
|
|
13621
|
+
/**
|
|
13622
|
+
* Returns the element at the k-th position in tree order (0-indexed).
|
|
13623
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
13624
|
+
|
|
13625
|
+
|
|
13626
|
+
|
|
13627
|
+
* @example
|
|
13628
|
+
* // Find k-th element in a TreeSet
|
|
13629
|
+
* const set = new TreeSet<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
13630
|
+
* console.log(set.getByRank(0)); // 10;
|
|
13631
|
+
* console.log(set.getByRank(2)); // 30;
|
|
13632
|
+
* console.log(set.getRank(30)); // 2;
|
|
13633
|
+
*/
|
|
13634
|
+
getByRank(k) {
|
|
13635
|
+
return __privateGet(this, _core).getByRank(k);
|
|
13636
|
+
}
|
|
13637
|
+
/**
|
|
13638
|
+
* Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
13639
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
13640
|
+
* @example
|
|
13641
|
+
* // Get the rank of a key in sorted order
|
|
13642
|
+
* const tree = new TreeSet<number>(
|
|
13643
|
+
* [10, 20, 30, 40, 50],
|
|
13644
|
+
* { enableOrderStatistic: true }
|
|
13645
|
+
* );
|
|
13646
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
13647
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
13648
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
13649
|
+
* console.log(tree.getRank(25)); // 2;
|
|
13650
|
+
*/
|
|
13651
|
+
getRank(key) {
|
|
13652
|
+
return __privateGet(this, _core).getRank(key);
|
|
13653
|
+
}
|
|
13654
|
+
/**
|
|
13655
|
+
* Returns elements by rank range (0-indexed, inclusive on both ends).
|
|
13656
|
+
* @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
|
|
13657
|
+
|
|
13658
|
+
* @example
|
|
13659
|
+
* // Pagination with rangeByRank
|
|
13660
|
+
* const tree = new TreeSet<number>(
|
|
13661
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
13662
|
+
* { enableOrderStatistic: true }
|
|
13663
|
+
* );
|
|
13664
|
+
* const pageSize = 3;
|
|
13665
|
+
*
|
|
13666
|
+
* // Page 1
|
|
13667
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
13668
|
+
* // Page 2
|
|
13669
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
13670
|
+
* // Page 3
|
|
13671
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
13672
|
+
*/
|
|
13673
|
+
rangeByRank(start, end) {
|
|
13674
|
+
return __privateGet(this, _core).rangeByRank(start, end).filter((k) => k !== void 0);
|
|
13675
|
+
}
|
|
12596
13676
|
/**
|
|
12597
13677
|
* Creates a shallow clone of this set.
|
|
12598
13678
|
* @remarks Time O(n log n), Space O(n)
|
|
@@ -12735,7 +13815,27 @@ var _TreeSet = class _TreeSet {
|
|
|
12735
13815
|
|
|
12736
13816
|
|
|
12737
13817
|
|
|
12738
|
-
|
|
13818
|
+
|
|
13819
|
+
|
|
13820
|
+
|
|
13821
|
+
|
|
13822
|
+
|
|
13823
|
+
|
|
13824
|
+
|
|
13825
|
+
|
|
13826
|
+
|
|
13827
|
+
|
|
13828
|
+
|
|
13829
|
+
|
|
13830
|
+
|
|
13831
|
+
|
|
13832
|
+
|
|
13833
|
+
|
|
13834
|
+
|
|
13835
|
+
|
|
13836
|
+
|
|
13837
|
+
|
|
13838
|
+
* @example
|
|
12739
13839
|
* // Deep clone
|
|
12740
13840
|
* const ts = new TreeSet<number>([1, 2, 3]);
|
|
12741
13841
|
* const copy = ts.clone();
|
|
@@ -12778,7 +13878,7 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
12778
13878
|
const comparator = (_a = options.comparator) != null ? _a : TreeSet.createDefaultComparator();
|
|
12779
13879
|
__privateSet(this, _isDefaultComparator2, options.comparator === void 0);
|
|
12780
13880
|
const toEntryFn = options.toEntryFn;
|
|
12781
|
-
__privateSet(this, _core2, new RedBlackTree([], { ...options, comparator, isMapMode: options.isMapMode }));
|
|
13881
|
+
__privateSet(this, _core2, new RedBlackTree([], { ...options, comparator, isMapMode: options.isMapMode, enableOrderStatistic: options.enableOrderStatistic }));
|
|
12782
13882
|
for (const x of keysNodesEntriesOrRaws) {
|
|
12783
13883
|
if (x === null || x === void 0) continue;
|
|
12784
13884
|
if (toEntryFn) {
|
|
@@ -12811,15 +13911,15 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
12811
13911
|
_validateKey(key) {
|
|
12812
13912
|
if (!__privateGet(this, _isDefaultComparator2)) return;
|
|
12813
13913
|
if (typeof key === "number") {
|
|
12814
|
-
if (Number.isNaN(key))
|
|
13914
|
+
if (Number.isNaN(key)) raise(TypeError, ERR.invalidNaN("TreeMultiMap"));
|
|
12815
13915
|
return;
|
|
12816
13916
|
}
|
|
12817
13917
|
if (typeof key === "string") return;
|
|
12818
13918
|
if (key instanceof Date) {
|
|
12819
|
-
if (Number.isNaN(key.getTime()))
|
|
13919
|
+
if (Number.isNaN(key.getTime())) raise(TypeError, ERR.invalidDate("TreeMultiMap"));
|
|
12820
13920
|
return;
|
|
12821
13921
|
}
|
|
12822
|
-
|
|
13922
|
+
raise(TypeError, ERR.comparatorRequired("TreeMultiMap"));
|
|
12823
13923
|
}
|
|
12824
13924
|
/**
|
|
12825
13925
|
* Number of distinct keys.
|
|
@@ -12948,6 +14048,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
12948
14048
|
|
|
12949
14049
|
|
|
12950
14050
|
|
|
14051
|
+
|
|
14052
|
+
|
|
14053
|
+
|
|
14054
|
+
|
|
14055
|
+
|
|
14056
|
+
|
|
14057
|
+
|
|
14058
|
+
|
|
14059
|
+
|
|
14060
|
+
|
|
14061
|
+
|
|
14062
|
+
|
|
14063
|
+
|
|
14064
|
+
|
|
14065
|
+
|
|
14066
|
+
|
|
14067
|
+
|
|
14068
|
+
|
|
14069
|
+
|
|
14070
|
+
|
|
12951
14071
|
|
|
12952
14072
|
|
|
12953
14073
|
|
|
@@ -13096,6 +14216,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13096
14216
|
|
|
13097
14217
|
|
|
13098
14218
|
|
|
14219
|
+
|
|
14220
|
+
|
|
14221
|
+
|
|
14222
|
+
|
|
14223
|
+
|
|
14224
|
+
|
|
14225
|
+
|
|
14226
|
+
|
|
14227
|
+
|
|
14228
|
+
|
|
14229
|
+
|
|
14230
|
+
|
|
14231
|
+
|
|
14232
|
+
|
|
14233
|
+
|
|
14234
|
+
|
|
14235
|
+
|
|
14236
|
+
|
|
14237
|
+
|
|
14238
|
+
|
|
13099
14239
|
|
|
13100
14240
|
|
|
13101
14241
|
|
|
@@ -13147,6 +14287,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13147
14287
|
|
|
13148
14288
|
|
|
13149
14289
|
|
|
14290
|
+
|
|
14291
|
+
|
|
14292
|
+
|
|
14293
|
+
|
|
13150
14294
|
|
|
13151
14295
|
|
|
13152
14296
|
|
|
@@ -13183,6 +14327,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13183
14327
|
|
|
13184
14328
|
|
|
13185
14329
|
|
|
14330
|
+
|
|
14331
|
+
|
|
14332
|
+
|
|
14333
|
+
|
|
13186
14334
|
|
|
13187
14335
|
|
|
13188
14336
|
|
|
@@ -13355,6 +14503,30 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13355
14503
|
|
|
13356
14504
|
|
|
13357
14505
|
|
|
14506
|
+
|
|
14507
|
+
|
|
14508
|
+
|
|
14509
|
+
|
|
14510
|
+
|
|
14511
|
+
|
|
14512
|
+
|
|
14513
|
+
|
|
14514
|
+
|
|
14515
|
+
|
|
14516
|
+
|
|
14517
|
+
|
|
14518
|
+
|
|
14519
|
+
|
|
14520
|
+
|
|
14521
|
+
|
|
14522
|
+
|
|
14523
|
+
|
|
14524
|
+
|
|
14525
|
+
|
|
14526
|
+
|
|
14527
|
+
|
|
14528
|
+
|
|
14529
|
+
|
|
13358
14530
|
|
|
13359
14531
|
|
|
13360
14532
|
|
|
@@ -13541,6 +14713,30 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13541
14713
|
|
|
13542
14714
|
|
|
13543
14715
|
|
|
14716
|
+
|
|
14717
|
+
|
|
14718
|
+
|
|
14719
|
+
|
|
14720
|
+
|
|
14721
|
+
|
|
14722
|
+
|
|
14723
|
+
|
|
14724
|
+
|
|
14725
|
+
|
|
14726
|
+
|
|
14727
|
+
|
|
14728
|
+
|
|
14729
|
+
|
|
14730
|
+
|
|
14731
|
+
|
|
14732
|
+
|
|
14733
|
+
|
|
14734
|
+
|
|
14735
|
+
|
|
14736
|
+
|
|
14737
|
+
|
|
14738
|
+
|
|
14739
|
+
|
|
13544
14740
|
|
|
13545
14741
|
|
|
13546
14742
|
|
|
@@ -13687,6 +14883,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13687
14883
|
|
|
13688
14884
|
|
|
13689
14885
|
|
|
14886
|
+
|
|
14887
|
+
|
|
14888
|
+
|
|
14889
|
+
|
|
14890
|
+
|
|
14891
|
+
|
|
14892
|
+
|
|
14893
|
+
|
|
14894
|
+
|
|
14895
|
+
|
|
14896
|
+
|
|
14897
|
+
|
|
14898
|
+
|
|
14899
|
+
|
|
14900
|
+
|
|
14901
|
+
|
|
14902
|
+
|
|
14903
|
+
|
|
14904
|
+
|
|
14905
|
+
|
|
13690
14906
|
|
|
13691
14907
|
|
|
13692
14908
|
|
|
@@ -13898,6 +15114,30 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13898
15114
|
|
|
13899
15115
|
|
|
13900
15116
|
|
|
15117
|
+
|
|
15118
|
+
|
|
15119
|
+
|
|
15120
|
+
|
|
15121
|
+
|
|
15122
|
+
|
|
15123
|
+
|
|
15124
|
+
|
|
15125
|
+
|
|
15126
|
+
|
|
15127
|
+
|
|
15128
|
+
|
|
15129
|
+
|
|
15130
|
+
|
|
15131
|
+
|
|
15132
|
+
|
|
15133
|
+
|
|
15134
|
+
|
|
15135
|
+
|
|
15136
|
+
|
|
15137
|
+
|
|
15138
|
+
|
|
15139
|
+
|
|
15140
|
+
|
|
13901
15141
|
|
|
13902
15142
|
|
|
13903
15143
|
|
|
@@ -13951,6 +15191,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13951
15191
|
|
|
13952
15192
|
|
|
13953
15193
|
|
|
15194
|
+
|
|
15195
|
+
|
|
15196
|
+
|
|
15197
|
+
|
|
13954
15198
|
|
|
13955
15199
|
|
|
13956
15200
|
|
|
@@ -13988,6 +15232,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
13988
15232
|
|
|
13989
15233
|
|
|
13990
15234
|
|
|
15235
|
+
|
|
15236
|
+
|
|
15237
|
+
|
|
15238
|
+
|
|
13991
15239
|
|
|
13992
15240
|
|
|
13993
15241
|
|
|
@@ -14030,6 +15278,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14030
15278
|
|
|
14031
15279
|
|
|
14032
15280
|
|
|
15281
|
+
|
|
15282
|
+
|
|
15283
|
+
|
|
15284
|
+
|
|
14033
15285
|
|
|
14034
15286
|
|
|
14035
15287
|
|
|
@@ -14190,6 +15442,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14190
15442
|
|
|
14191
15443
|
|
|
14192
15444
|
|
|
15445
|
+
|
|
15446
|
+
|
|
15447
|
+
|
|
15448
|
+
|
|
15449
|
+
|
|
15450
|
+
|
|
15451
|
+
|
|
15452
|
+
|
|
15453
|
+
|
|
15454
|
+
|
|
15455
|
+
|
|
15456
|
+
|
|
15457
|
+
|
|
15458
|
+
|
|
15459
|
+
|
|
15460
|
+
|
|
15461
|
+
|
|
15462
|
+
|
|
15463
|
+
|
|
15464
|
+
|
|
14193
15465
|
|
|
14194
15466
|
|
|
14195
15467
|
|
|
@@ -14341,6 +15613,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14341
15613
|
|
|
14342
15614
|
|
|
14343
15615
|
|
|
15616
|
+
|
|
15617
|
+
|
|
15618
|
+
|
|
15619
|
+
|
|
15620
|
+
|
|
15621
|
+
|
|
15622
|
+
|
|
15623
|
+
|
|
15624
|
+
|
|
15625
|
+
|
|
15626
|
+
|
|
15627
|
+
|
|
15628
|
+
|
|
15629
|
+
|
|
15630
|
+
|
|
15631
|
+
|
|
15632
|
+
|
|
15633
|
+
|
|
15634
|
+
|
|
15635
|
+
|
|
14344
15636
|
|
|
14345
15637
|
|
|
14346
15638
|
|
|
@@ -14393,6 +15685,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14393
15685
|
|
|
14394
15686
|
|
|
14395
15687
|
|
|
15688
|
+
|
|
15689
|
+
|
|
15690
|
+
|
|
15691
|
+
|
|
14396
15692
|
|
|
14397
15693
|
|
|
14398
15694
|
|
|
@@ -14430,6 +15726,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14430
15726
|
|
|
14431
15727
|
|
|
14432
15728
|
|
|
15729
|
+
|
|
15730
|
+
|
|
15731
|
+
|
|
15732
|
+
|
|
14433
15733
|
|
|
14434
15734
|
|
|
14435
15735
|
|
|
@@ -14467,6 +15767,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14467
15767
|
|
|
14468
15768
|
|
|
14469
15769
|
|
|
15770
|
+
|
|
15771
|
+
|
|
15772
|
+
|
|
15773
|
+
|
|
14470
15774
|
|
|
14471
15775
|
|
|
14472
15776
|
|
|
@@ -14534,6 +15838,14 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14534
15838
|
|
|
14535
15839
|
|
|
14536
15840
|
|
|
15841
|
+
|
|
15842
|
+
|
|
15843
|
+
|
|
15844
|
+
|
|
15845
|
+
|
|
15846
|
+
|
|
15847
|
+
|
|
15848
|
+
|
|
14537
15849
|
|
|
14538
15850
|
|
|
14539
15851
|
|
|
@@ -14607,6 +15919,14 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14607
15919
|
|
|
14608
15920
|
|
|
14609
15921
|
|
|
15922
|
+
|
|
15923
|
+
|
|
15924
|
+
|
|
15925
|
+
|
|
15926
|
+
|
|
15927
|
+
|
|
15928
|
+
|
|
15929
|
+
|
|
14610
15930
|
|
|
14611
15931
|
|
|
14612
15932
|
|
|
@@ -14653,6 +15973,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14653
15973
|
|
|
14654
15974
|
|
|
14655
15975
|
|
|
15976
|
+
|
|
15977
|
+
|
|
15978
|
+
|
|
15979
|
+
|
|
14656
15980
|
|
|
14657
15981
|
|
|
14658
15982
|
|
|
@@ -14694,6 +16018,10 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14694
16018
|
|
|
14695
16019
|
|
|
14696
16020
|
|
|
16021
|
+
|
|
16022
|
+
|
|
16023
|
+
|
|
16024
|
+
|
|
14697
16025
|
|
|
14698
16026
|
|
|
14699
16027
|
|
|
@@ -14857,13 +16185,33 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14857
16185
|
|
|
14858
16186
|
|
|
14859
16187
|
|
|
14860
|
-
|
|
14861
|
-
|
|
14862
|
-
|
|
14863
|
-
|
|
14864
|
-
|
|
14865
|
-
|
|
14866
|
-
|
|
16188
|
+
|
|
16189
|
+
|
|
16190
|
+
|
|
16191
|
+
|
|
16192
|
+
|
|
16193
|
+
|
|
16194
|
+
|
|
16195
|
+
|
|
16196
|
+
|
|
16197
|
+
|
|
16198
|
+
|
|
16199
|
+
|
|
16200
|
+
|
|
16201
|
+
|
|
16202
|
+
|
|
16203
|
+
|
|
16204
|
+
|
|
16205
|
+
|
|
16206
|
+
|
|
16207
|
+
|
|
16208
|
+
* @example
|
|
16209
|
+
* // Least key ≥ target
|
|
16210
|
+
* const mm = new TreeMultiMap<number, string>();
|
|
16211
|
+
* mm.add(10, 'a');
|
|
16212
|
+
* mm.add(20, 'b');
|
|
16213
|
+
* mm.add(30, 'c');
|
|
16214
|
+
* console.log(mm.ceiling(15)?.[0]); // 20;
|
|
14867
16215
|
*/
|
|
14868
16216
|
ceiling(key) {
|
|
14869
16217
|
this._validateKey(key);
|
|
@@ -14998,6 +16346,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
14998
16346
|
|
|
14999
16347
|
|
|
15000
16348
|
|
|
16349
|
+
|
|
16350
|
+
|
|
16351
|
+
|
|
16352
|
+
|
|
16353
|
+
|
|
16354
|
+
|
|
16355
|
+
|
|
16356
|
+
|
|
16357
|
+
|
|
16358
|
+
|
|
16359
|
+
|
|
16360
|
+
|
|
16361
|
+
|
|
16362
|
+
|
|
16363
|
+
|
|
16364
|
+
|
|
16365
|
+
|
|
16366
|
+
|
|
16367
|
+
|
|
16368
|
+
|
|
15001
16369
|
|
|
15002
16370
|
|
|
15003
16371
|
|
|
@@ -15133,6 +16501,22 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15133
16501
|
|
|
15134
16502
|
|
|
15135
16503
|
|
|
16504
|
+
|
|
16505
|
+
|
|
16506
|
+
|
|
16507
|
+
|
|
16508
|
+
|
|
16509
|
+
|
|
16510
|
+
|
|
16511
|
+
|
|
16512
|
+
|
|
16513
|
+
|
|
16514
|
+
|
|
16515
|
+
|
|
16516
|
+
|
|
16517
|
+
|
|
16518
|
+
|
|
16519
|
+
|
|
15136
16520
|
|
|
15137
16521
|
|
|
15138
16522
|
|
|
@@ -15263,6 +16647,22 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15263
16647
|
|
|
15264
16648
|
|
|
15265
16649
|
|
|
16650
|
+
|
|
16651
|
+
|
|
16652
|
+
|
|
16653
|
+
|
|
16654
|
+
|
|
16655
|
+
|
|
16656
|
+
|
|
16657
|
+
|
|
16658
|
+
|
|
16659
|
+
|
|
16660
|
+
|
|
16661
|
+
|
|
16662
|
+
|
|
16663
|
+
|
|
16664
|
+
|
|
16665
|
+
|
|
15266
16666
|
|
|
15267
16667
|
|
|
15268
16668
|
|
|
@@ -15418,6 +16818,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15418
16818
|
|
|
15419
16819
|
|
|
15420
16820
|
|
|
16821
|
+
|
|
16822
|
+
|
|
16823
|
+
|
|
16824
|
+
|
|
16825
|
+
|
|
16826
|
+
|
|
16827
|
+
|
|
16828
|
+
|
|
16829
|
+
|
|
16830
|
+
|
|
16831
|
+
|
|
16832
|
+
|
|
16833
|
+
|
|
16834
|
+
|
|
16835
|
+
|
|
16836
|
+
|
|
16837
|
+
|
|
16838
|
+
|
|
16839
|
+
|
|
16840
|
+
|
|
15421
16841
|
|
|
15422
16842
|
|
|
15423
16843
|
|
|
@@ -15568,6 +16988,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15568
16988
|
|
|
15569
16989
|
|
|
15570
16990
|
|
|
16991
|
+
|
|
16992
|
+
|
|
16993
|
+
|
|
16994
|
+
|
|
16995
|
+
|
|
16996
|
+
|
|
16997
|
+
|
|
16998
|
+
|
|
16999
|
+
|
|
17000
|
+
|
|
17001
|
+
|
|
17002
|
+
|
|
17003
|
+
|
|
17004
|
+
|
|
17005
|
+
|
|
17006
|
+
|
|
17007
|
+
|
|
17008
|
+
|
|
17009
|
+
|
|
17010
|
+
|
|
15571
17011
|
|
|
15572
17012
|
|
|
15573
17013
|
|
|
@@ -15723,6 +17163,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15723
17163
|
|
|
15724
17164
|
|
|
15725
17165
|
|
|
17166
|
+
|
|
17167
|
+
|
|
17168
|
+
|
|
17169
|
+
|
|
17170
|
+
|
|
17171
|
+
|
|
17172
|
+
|
|
17173
|
+
|
|
17174
|
+
|
|
17175
|
+
|
|
17176
|
+
|
|
17177
|
+
|
|
17178
|
+
|
|
17179
|
+
|
|
17180
|
+
|
|
17181
|
+
|
|
17182
|
+
|
|
17183
|
+
|
|
17184
|
+
|
|
17185
|
+
|
|
15726
17186
|
|
|
15727
17187
|
|
|
15728
17188
|
|
|
@@ -15880,6 +17340,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
15880
17340
|
|
|
15881
17341
|
|
|
15882
17342
|
|
|
17343
|
+
|
|
17344
|
+
|
|
17345
|
+
|
|
17346
|
+
|
|
17347
|
+
|
|
17348
|
+
|
|
17349
|
+
|
|
17350
|
+
|
|
17351
|
+
|
|
17352
|
+
|
|
17353
|
+
|
|
17354
|
+
|
|
17355
|
+
|
|
17356
|
+
|
|
17357
|
+
|
|
17358
|
+
|
|
17359
|
+
|
|
17360
|
+
|
|
17361
|
+
|
|
17362
|
+
|
|
15883
17363
|
|
|
15884
17364
|
|
|
15885
17365
|
|
|
@@ -16035,6 +17515,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
16035
17515
|
|
|
16036
17516
|
|
|
16037
17517
|
|
|
17518
|
+
|
|
17519
|
+
|
|
17520
|
+
|
|
17521
|
+
|
|
17522
|
+
|
|
17523
|
+
|
|
17524
|
+
|
|
17525
|
+
|
|
17526
|
+
|
|
17527
|
+
|
|
17528
|
+
|
|
17529
|
+
|
|
17530
|
+
|
|
17531
|
+
|
|
17532
|
+
|
|
17533
|
+
|
|
17534
|
+
|
|
17535
|
+
|
|
17536
|
+
|
|
17537
|
+
|
|
16038
17538
|
|
|
16039
17539
|
|
|
16040
17540
|
|
|
@@ -16183,6 +17683,26 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
16183
17683
|
|
|
16184
17684
|
|
|
16185
17685
|
|
|
17686
|
+
|
|
17687
|
+
|
|
17688
|
+
|
|
17689
|
+
|
|
17690
|
+
|
|
17691
|
+
|
|
17692
|
+
|
|
17693
|
+
|
|
17694
|
+
|
|
17695
|
+
|
|
17696
|
+
|
|
17697
|
+
|
|
17698
|
+
|
|
17699
|
+
|
|
17700
|
+
|
|
17701
|
+
|
|
17702
|
+
|
|
17703
|
+
|
|
17704
|
+
|
|
17705
|
+
|
|
16186
17706
|
|
|
16187
17707
|
|
|
16188
17708
|
|
|
@@ -16313,6 +17833,22 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
16313
17833
|
|
|
16314
17834
|
|
|
16315
17835
|
|
|
17836
|
+
|
|
17837
|
+
|
|
17838
|
+
|
|
17839
|
+
|
|
17840
|
+
|
|
17841
|
+
|
|
17842
|
+
|
|
17843
|
+
|
|
17844
|
+
|
|
17845
|
+
|
|
17846
|
+
|
|
17847
|
+
|
|
17848
|
+
|
|
17849
|
+
|
|
17850
|
+
|
|
17851
|
+
|
|
16316
17852
|
|
|
16317
17853
|
|
|
16318
17854
|
|
|
@@ -16480,6 +18016,85 @@ var _TreeMultiMap = class _TreeMultiMap {
|
|
|
16480
18016
|
|
|
16481
18017
|
|
|
16482
18018
|
|
|
18019
|
+
|
|
18020
|
+
|
|
18021
|
+
|
|
18022
|
+
|
|
18023
|
+
|
|
18024
|
+
|
|
18025
|
+
|
|
18026
|
+
|
|
18027
|
+
|
|
18028
|
+
|
|
18029
|
+
|
|
18030
|
+
|
|
18031
|
+
|
|
18032
|
+
|
|
18033
|
+
|
|
18034
|
+
|
|
18035
|
+
|
|
18036
|
+
|
|
18037
|
+
|
|
18038
|
+
|
|
18039
|
+
|
|
18040
|
+
* @example
|
|
18041
|
+
* // Order-statistic on BST
|
|
18042
|
+
* const tree = new TreeMultiMap<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
18043
|
+
* console.log(tree.getByRank(0)); // 10;
|
|
18044
|
+
* console.log(tree.getByRank(4)); // 50;
|
|
18045
|
+
* console.log(tree.getRank(30)); // 2;
|
|
18046
|
+
*/
|
|
18047
|
+
// ─── Order-Statistic Methods ───────────────────────────
|
|
18048
|
+
getByRank(k) {
|
|
18049
|
+
var _a;
|
|
18050
|
+
const key = __privateGet(this, _core2).getByRank(k);
|
|
18051
|
+
if (key === void 0) return void 0;
|
|
18052
|
+
return [key, (_a = __privateGet(this, _core2).get(key)) != null ? _a : []];
|
|
18053
|
+
}
|
|
18054
|
+
/**
|
|
18055
|
+
* Get the rank of a key in sorted order
|
|
18056
|
+
* @example
|
|
18057
|
+
* // Get the rank of a key in sorted order
|
|
18058
|
+
* const tree = new TreeMultiMap<number>(
|
|
18059
|
+
* [10, 20, 30, 40, 50],
|
|
18060
|
+
* { enableOrderStatistic: true }
|
|
18061
|
+
* );
|
|
18062
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
18063
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
18064
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
18065
|
+
* console.log(tree.getRank(25)); // 2;
|
|
18066
|
+
*/
|
|
18067
|
+
getRank(key) {
|
|
18068
|
+
return __privateGet(this, _core2).getRank(key);
|
|
18069
|
+
}
|
|
18070
|
+
/**
|
|
18071
|
+
* Get elements by rank range
|
|
18072
|
+
|
|
18073
|
+
* @example
|
|
18074
|
+
* // Pagination with rangeByRank
|
|
18075
|
+
* const tree = new TreeMultiMap<number>(
|
|
18076
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
18077
|
+
* { enableOrderStatistic: true }
|
|
18078
|
+
* );
|
|
18079
|
+
* const pageSize = 3;
|
|
18080
|
+
*
|
|
18081
|
+
* // Page 1
|
|
18082
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
18083
|
+
* // Page 2
|
|
18084
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
18085
|
+
* // Page 3
|
|
18086
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
18087
|
+
*/
|
|
18088
|
+
rangeByRank(start, end) {
|
|
18089
|
+
const keys = __privateGet(this, _core2).rangeByRank(start, end);
|
|
18090
|
+
return keys.filter((k) => k !== void 0).map((k) => {
|
|
18091
|
+
var _a;
|
|
18092
|
+
return [k, (_a = __privateGet(this, _core2).get(k)) != null ? _a : []];
|
|
18093
|
+
});
|
|
18094
|
+
}
|
|
18095
|
+
/**
|
|
18096
|
+
* Deep copy
|
|
18097
|
+
|
|
16483
18098
|
|
|
16484
18099
|
|
|
16485
18100
|
|
|
@@ -16534,7 +18149,7 @@ var _TreeMap = class _TreeMap {
|
|
|
16534
18149
|
const toEntryFn = options.toEntryFn;
|
|
16535
18150
|
const comparator = (_a = options.comparator) != null ? _a : _TreeMap.createDefaultComparator();
|
|
16536
18151
|
__privateSet(this, _isDefaultComparator3, options.comparator === void 0);
|
|
16537
|
-
__privateSet(this, _core3, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
18152
|
+
__privateSet(this, _core3, new RedBlackTree([], { comparator, isMapMode: options.isMapMode, enableOrderStatistic: options.enableOrderStatistic }));
|
|
16538
18153
|
for (const item of entries) {
|
|
16539
18154
|
let k;
|
|
16540
18155
|
let v;
|
|
@@ -16542,7 +18157,7 @@ var _TreeMap = class _TreeMap {
|
|
|
16542
18157
|
[k, v] = toEntryFn(item);
|
|
16543
18158
|
} else {
|
|
16544
18159
|
if (!Array.isArray(item) || item.length < 2) {
|
|
16545
|
-
|
|
18160
|
+
raise(TypeError, ERR.invalidEntry("TreeMap"));
|
|
16546
18161
|
}
|
|
16547
18162
|
k = item[0];
|
|
16548
18163
|
v = item[1];
|
|
@@ -16563,7 +18178,7 @@ var _TreeMap = class _TreeMap {
|
|
|
16563
18178
|
static createDefaultComparator() {
|
|
16564
18179
|
return (a, b) => {
|
|
16565
18180
|
if (typeof a === "number" && typeof b === "number") {
|
|
16566
|
-
if (Number.isNaN(a) || Number.isNaN(b))
|
|
18181
|
+
if (Number.isNaN(a) || Number.isNaN(b)) raise(TypeError, ERR.invalidNaN("TreeMap"));
|
|
16567
18182
|
const aa = Object.is(a, -0) ? 0 : a;
|
|
16568
18183
|
const bb = Object.is(b, -0) ? 0 : b;
|
|
16569
18184
|
return aa > bb ? 1 : aa < bb ? -1 : 0;
|
|
@@ -16574,24 +18189,24 @@ var _TreeMap = class _TreeMap {
|
|
|
16574
18189
|
if (a instanceof Date && b instanceof Date) {
|
|
16575
18190
|
const ta = a.getTime();
|
|
16576
18191
|
const tb = b.getTime();
|
|
16577
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
18192
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate("TreeMap"));
|
|
16578
18193
|
return ta > tb ? 1 : ta < tb ? -1 : 0;
|
|
16579
18194
|
}
|
|
16580
|
-
|
|
18195
|
+
raise(TypeError, ERR.comparatorRequired("TreeMap"));
|
|
16581
18196
|
};
|
|
16582
18197
|
}
|
|
16583
18198
|
_validateKey(key) {
|
|
16584
18199
|
if (!__privateGet(this, _isDefaultComparator3)) return;
|
|
16585
18200
|
if (typeof key === "number") {
|
|
16586
|
-
if (Number.isNaN(key))
|
|
18201
|
+
if (Number.isNaN(key)) raise(TypeError, ERR.invalidNaN("TreeMap"));
|
|
16587
18202
|
return;
|
|
16588
18203
|
}
|
|
16589
18204
|
if (typeof key === "string") return;
|
|
16590
18205
|
if (key instanceof Date) {
|
|
16591
|
-
if (Number.isNaN(key.getTime()))
|
|
18206
|
+
if (Number.isNaN(key.getTime())) raise(TypeError, ERR.invalidDate("TreeMap"));
|
|
16592
18207
|
return;
|
|
16593
18208
|
}
|
|
16594
|
-
|
|
18209
|
+
raise(TypeError, ERR.comparatorRequired("TreeMap"));
|
|
16595
18210
|
}
|
|
16596
18211
|
/**
|
|
16597
18212
|
* Number of entries in the map.
|
|
@@ -16739,11 +18354,31 @@ var _TreeMap = class _TreeMap {
|
|
|
16739
18354
|
|
|
16740
18355
|
|
|
16741
18356
|
|
|
16742
|
-
|
|
16743
|
-
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
|
|
18357
|
+
|
|
18358
|
+
|
|
18359
|
+
|
|
18360
|
+
|
|
18361
|
+
|
|
18362
|
+
|
|
18363
|
+
|
|
18364
|
+
|
|
18365
|
+
|
|
18366
|
+
|
|
18367
|
+
|
|
18368
|
+
|
|
18369
|
+
|
|
18370
|
+
|
|
18371
|
+
|
|
18372
|
+
|
|
18373
|
+
|
|
18374
|
+
|
|
18375
|
+
|
|
18376
|
+
|
|
18377
|
+
* @example
|
|
18378
|
+
* // Check empty
|
|
18379
|
+
* console.log(new TreeMap().isEmpty()); // true;
|
|
18380
|
+
*/
|
|
18381
|
+
isEmpty() {
|
|
16747
18382
|
return this.size === 0;
|
|
16748
18383
|
}
|
|
16749
18384
|
/**
|
|
@@ -16875,6 +18510,26 @@ var _TreeMap = class _TreeMap {
|
|
|
16875
18510
|
|
|
16876
18511
|
|
|
16877
18512
|
|
|
18513
|
+
|
|
18514
|
+
|
|
18515
|
+
|
|
18516
|
+
|
|
18517
|
+
|
|
18518
|
+
|
|
18519
|
+
|
|
18520
|
+
|
|
18521
|
+
|
|
18522
|
+
|
|
18523
|
+
|
|
18524
|
+
|
|
18525
|
+
|
|
18526
|
+
|
|
18527
|
+
|
|
18528
|
+
|
|
18529
|
+
|
|
18530
|
+
|
|
18531
|
+
|
|
18532
|
+
|
|
16878
18533
|
|
|
16879
18534
|
|
|
16880
18535
|
|
|
@@ -17053,6 +18708,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17053
18708
|
|
|
17054
18709
|
|
|
17055
18710
|
|
|
18711
|
+
|
|
18712
|
+
|
|
18713
|
+
|
|
18714
|
+
|
|
18715
|
+
|
|
18716
|
+
|
|
18717
|
+
|
|
18718
|
+
|
|
18719
|
+
|
|
18720
|
+
|
|
18721
|
+
|
|
18722
|
+
|
|
18723
|
+
|
|
18724
|
+
|
|
18725
|
+
|
|
18726
|
+
|
|
18727
|
+
|
|
18728
|
+
|
|
18729
|
+
|
|
18730
|
+
|
|
17056
18731
|
|
|
17057
18732
|
|
|
17058
18733
|
|
|
@@ -17221,6 +18896,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17221
18896
|
|
|
17222
18897
|
|
|
17223
18898
|
|
|
18899
|
+
|
|
18900
|
+
|
|
18901
|
+
|
|
18902
|
+
|
|
18903
|
+
|
|
18904
|
+
|
|
18905
|
+
|
|
18906
|
+
|
|
18907
|
+
|
|
18908
|
+
|
|
18909
|
+
|
|
18910
|
+
|
|
18911
|
+
|
|
18912
|
+
|
|
18913
|
+
|
|
18914
|
+
|
|
18915
|
+
|
|
18916
|
+
|
|
18917
|
+
|
|
18918
|
+
|
|
17224
18919
|
|
|
17225
18920
|
|
|
17226
18921
|
|
|
@@ -17389,6 +19084,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17389
19084
|
|
|
17390
19085
|
|
|
17391
19086
|
|
|
19087
|
+
|
|
19088
|
+
|
|
19089
|
+
|
|
19090
|
+
|
|
19091
|
+
|
|
19092
|
+
|
|
19093
|
+
|
|
19094
|
+
|
|
19095
|
+
|
|
19096
|
+
|
|
19097
|
+
|
|
19098
|
+
|
|
19099
|
+
|
|
19100
|
+
|
|
19101
|
+
|
|
19102
|
+
|
|
19103
|
+
|
|
19104
|
+
|
|
19105
|
+
|
|
19106
|
+
|
|
17392
19107
|
|
|
17393
19108
|
|
|
17394
19109
|
|
|
@@ -17548,6 +19263,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17548
19263
|
|
|
17549
19264
|
|
|
17550
19265
|
|
|
19266
|
+
|
|
19267
|
+
|
|
19268
|
+
|
|
19269
|
+
|
|
19270
|
+
|
|
19271
|
+
|
|
19272
|
+
|
|
19273
|
+
|
|
19274
|
+
|
|
19275
|
+
|
|
19276
|
+
|
|
19277
|
+
|
|
19278
|
+
|
|
19279
|
+
|
|
19280
|
+
|
|
19281
|
+
|
|
19282
|
+
|
|
19283
|
+
|
|
19284
|
+
|
|
19285
|
+
|
|
17551
19286
|
|
|
17552
19287
|
|
|
17553
19288
|
|
|
@@ -17697,6 +19432,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17697
19432
|
|
|
17698
19433
|
|
|
17699
19434
|
|
|
19435
|
+
|
|
19436
|
+
|
|
19437
|
+
|
|
19438
|
+
|
|
19439
|
+
|
|
19440
|
+
|
|
19441
|
+
|
|
19442
|
+
|
|
19443
|
+
|
|
19444
|
+
|
|
19445
|
+
|
|
19446
|
+
|
|
19447
|
+
|
|
19448
|
+
|
|
19449
|
+
|
|
19450
|
+
|
|
19451
|
+
|
|
19452
|
+
|
|
19453
|
+
|
|
19454
|
+
|
|
17700
19455
|
|
|
17701
19456
|
|
|
17702
19457
|
|
|
@@ -17850,6 +19605,26 @@ var _TreeMap = class _TreeMap {
|
|
|
17850
19605
|
|
|
17851
19606
|
|
|
17852
19607
|
|
|
19608
|
+
|
|
19609
|
+
|
|
19610
|
+
|
|
19611
|
+
|
|
19612
|
+
|
|
19613
|
+
|
|
19614
|
+
|
|
19615
|
+
|
|
19616
|
+
|
|
19617
|
+
|
|
19618
|
+
|
|
19619
|
+
|
|
19620
|
+
|
|
19621
|
+
|
|
19622
|
+
|
|
19623
|
+
|
|
19624
|
+
|
|
19625
|
+
|
|
19626
|
+
|
|
19627
|
+
|
|
17853
19628
|
|
|
17854
19629
|
|
|
17855
19630
|
|
|
@@ -18000,6 +19775,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18000
19775
|
|
|
18001
19776
|
|
|
18002
19777
|
|
|
19778
|
+
|
|
19779
|
+
|
|
19780
|
+
|
|
19781
|
+
|
|
19782
|
+
|
|
19783
|
+
|
|
19784
|
+
|
|
19785
|
+
|
|
19786
|
+
|
|
19787
|
+
|
|
19788
|
+
|
|
19789
|
+
|
|
19790
|
+
|
|
19791
|
+
|
|
19792
|
+
|
|
19793
|
+
|
|
19794
|
+
|
|
19795
|
+
|
|
19796
|
+
|
|
19797
|
+
|
|
18003
19798
|
|
|
18004
19799
|
|
|
18005
19800
|
|
|
@@ -18153,6 +19948,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18153
19948
|
|
|
18154
19949
|
|
|
18155
19950
|
|
|
19951
|
+
|
|
19952
|
+
|
|
19953
|
+
|
|
19954
|
+
|
|
19955
|
+
|
|
19956
|
+
|
|
19957
|
+
|
|
19958
|
+
|
|
19959
|
+
|
|
19960
|
+
|
|
19961
|
+
|
|
19962
|
+
|
|
19963
|
+
|
|
19964
|
+
|
|
19965
|
+
|
|
19966
|
+
|
|
19967
|
+
|
|
19968
|
+
|
|
19969
|
+
|
|
19970
|
+
|
|
18156
19971
|
|
|
18157
19972
|
|
|
18158
19973
|
|
|
@@ -18306,6 +20121,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18306
20121
|
|
|
18307
20122
|
|
|
18308
20123
|
|
|
20124
|
+
|
|
20125
|
+
|
|
20126
|
+
|
|
20127
|
+
|
|
20128
|
+
|
|
20129
|
+
|
|
20130
|
+
|
|
20131
|
+
|
|
20132
|
+
|
|
20133
|
+
|
|
20134
|
+
|
|
20135
|
+
|
|
20136
|
+
|
|
20137
|
+
|
|
20138
|
+
|
|
20139
|
+
|
|
20140
|
+
|
|
20141
|
+
|
|
20142
|
+
|
|
20143
|
+
|
|
18309
20144
|
|
|
18310
20145
|
|
|
18311
20146
|
|
|
@@ -18462,6 +20297,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18462
20297
|
|
|
18463
20298
|
|
|
18464
20299
|
|
|
20300
|
+
|
|
20301
|
+
|
|
20302
|
+
|
|
20303
|
+
|
|
20304
|
+
|
|
20305
|
+
|
|
20306
|
+
|
|
20307
|
+
|
|
20308
|
+
|
|
20309
|
+
|
|
20310
|
+
|
|
20311
|
+
|
|
20312
|
+
|
|
20313
|
+
|
|
20314
|
+
|
|
20315
|
+
|
|
20316
|
+
|
|
20317
|
+
|
|
20318
|
+
|
|
20319
|
+
|
|
18465
20320
|
|
|
18466
20321
|
|
|
18467
20322
|
|
|
@@ -18639,17 +20494,37 @@ var _TreeMap = class _TreeMap {
|
|
|
18639
20494
|
|
|
18640
20495
|
|
|
18641
20496
|
|
|
18642
|
-
|
|
18643
|
-
|
|
18644
|
-
|
|
18645
|
-
|
|
18646
|
-
|
|
18647
|
-
|
|
18648
|
-
|
|
18649
|
-
|
|
18650
|
-
|
|
18651
|
-
|
|
18652
|
-
|
|
20497
|
+
|
|
20498
|
+
|
|
20499
|
+
|
|
20500
|
+
|
|
20501
|
+
|
|
20502
|
+
|
|
20503
|
+
|
|
20504
|
+
|
|
20505
|
+
|
|
20506
|
+
|
|
20507
|
+
|
|
20508
|
+
|
|
20509
|
+
|
|
20510
|
+
|
|
20511
|
+
|
|
20512
|
+
|
|
20513
|
+
|
|
20514
|
+
|
|
20515
|
+
|
|
20516
|
+
|
|
20517
|
+
* @example
|
|
20518
|
+
* // Aggregate values
|
|
20519
|
+
* const tm = new TreeMap<number, number>([[1, 10], [2, 20]]);
|
|
20520
|
+
* console.log(tm.reduce((acc, v) => acc + (v ?? 0), 0)); // 30;
|
|
20521
|
+
*/
|
|
20522
|
+
reduce(callbackfn, initialValue) {
|
|
20523
|
+
let acc = initialValue;
|
|
20524
|
+
let index = 0;
|
|
20525
|
+
for (const [k, v] of this) acc = callbackfn(acc, v, k, index++, this);
|
|
20526
|
+
return acc;
|
|
20527
|
+
}
|
|
18653
20528
|
/**
|
|
18654
20529
|
* Test whether all entries satisfy a predicate.
|
|
18655
20530
|
* @remarks Time O(n), Space O(1)
|
|
@@ -18768,6 +20643,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18768
20643
|
|
|
18769
20644
|
|
|
18770
20645
|
|
|
20646
|
+
|
|
20647
|
+
|
|
20648
|
+
|
|
20649
|
+
|
|
20650
|
+
|
|
20651
|
+
|
|
20652
|
+
|
|
20653
|
+
|
|
20654
|
+
|
|
20655
|
+
|
|
20656
|
+
|
|
20657
|
+
|
|
20658
|
+
|
|
20659
|
+
|
|
20660
|
+
|
|
20661
|
+
|
|
20662
|
+
|
|
20663
|
+
|
|
20664
|
+
|
|
20665
|
+
|
|
18771
20666
|
|
|
18772
20667
|
|
|
18773
20668
|
|
|
@@ -18920,6 +20815,26 @@ var _TreeMap = class _TreeMap {
|
|
|
18920
20815
|
|
|
18921
20816
|
|
|
18922
20817
|
|
|
20818
|
+
|
|
20819
|
+
|
|
20820
|
+
|
|
20821
|
+
|
|
20822
|
+
|
|
20823
|
+
|
|
20824
|
+
|
|
20825
|
+
|
|
20826
|
+
|
|
20827
|
+
|
|
20828
|
+
|
|
20829
|
+
|
|
20830
|
+
|
|
20831
|
+
|
|
20832
|
+
|
|
20833
|
+
|
|
20834
|
+
|
|
20835
|
+
|
|
20836
|
+
|
|
20837
|
+
|
|
18923
20838
|
|
|
18924
20839
|
|
|
18925
20840
|
|
|
@@ -19073,6 +20988,26 @@ var _TreeMap = class _TreeMap {
|
|
|
19073
20988
|
|
|
19074
20989
|
|
|
19075
20990
|
|
|
20991
|
+
|
|
20992
|
+
|
|
20993
|
+
|
|
20994
|
+
|
|
20995
|
+
|
|
20996
|
+
|
|
20997
|
+
|
|
20998
|
+
|
|
20999
|
+
|
|
21000
|
+
|
|
21001
|
+
|
|
21002
|
+
|
|
21003
|
+
|
|
21004
|
+
|
|
21005
|
+
|
|
21006
|
+
|
|
21007
|
+
|
|
21008
|
+
|
|
21009
|
+
|
|
21010
|
+
|
|
19076
21011
|
|
|
19077
21012
|
|
|
19078
21013
|
|
|
@@ -19227,6 +21162,26 @@ var _TreeMap = class _TreeMap {
|
|
|
19227
21162
|
|
|
19228
21163
|
|
|
19229
21164
|
|
|
21165
|
+
|
|
21166
|
+
|
|
21167
|
+
|
|
21168
|
+
|
|
21169
|
+
|
|
21170
|
+
|
|
21171
|
+
|
|
21172
|
+
|
|
21173
|
+
|
|
21174
|
+
|
|
21175
|
+
|
|
21176
|
+
|
|
21177
|
+
|
|
21178
|
+
|
|
21179
|
+
|
|
21180
|
+
|
|
21181
|
+
|
|
21182
|
+
|
|
21183
|
+
|
|
21184
|
+
|
|
19230
21185
|
|
|
19231
21186
|
|
|
19232
21187
|
|
|
@@ -19376,6 +21331,26 @@ var _TreeMap = class _TreeMap {
|
|
|
19376
21331
|
|
|
19377
21332
|
|
|
19378
21333
|
|
|
21334
|
+
|
|
21335
|
+
|
|
21336
|
+
|
|
21337
|
+
|
|
21338
|
+
|
|
21339
|
+
|
|
21340
|
+
|
|
21341
|
+
|
|
21342
|
+
|
|
21343
|
+
|
|
21344
|
+
|
|
21345
|
+
|
|
21346
|
+
|
|
21347
|
+
|
|
21348
|
+
|
|
21349
|
+
|
|
21350
|
+
|
|
21351
|
+
|
|
21352
|
+
|
|
21353
|
+
|
|
19379
21354
|
|
|
19380
21355
|
|
|
19381
21356
|
|
|
@@ -19435,6 +21410,10 @@ var _TreeMap = class _TreeMap {
|
|
|
19435
21410
|
|
|
19436
21411
|
|
|
19437
21412
|
|
|
21413
|
+
|
|
21414
|
+
|
|
21415
|
+
|
|
21416
|
+
|
|
19438
21417
|
|
|
19439
21418
|
|
|
19440
21419
|
|
|
@@ -19499,6 +21478,10 @@ var _TreeMap = class _TreeMap {
|
|
|
19499
21478
|
|
|
19500
21479
|
|
|
19501
21480
|
|
|
21481
|
+
|
|
21482
|
+
|
|
21483
|
+
|
|
21484
|
+
|
|
19502
21485
|
|
|
19503
21486
|
|
|
19504
21487
|
|
|
@@ -19547,6 +21530,10 @@ var _TreeMap = class _TreeMap {
|
|
|
19547
21530
|
|
|
19548
21531
|
|
|
19549
21532
|
|
|
21533
|
+
|
|
21534
|
+
|
|
21535
|
+
|
|
21536
|
+
|
|
19550
21537
|
|
|
19551
21538
|
|
|
19552
21539
|
|
|
@@ -19599,6 +21586,10 @@ var _TreeMap = class _TreeMap {
|
|
|
19599
21586
|
|
|
19600
21587
|
|
|
19601
21588
|
|
|
21589
|
+
|
|
21590
|
+
|
|
21591
|
+
|
|
21592
|
+
|
|
19602
21593
|
|
|
19603
21594
|
|
|
19604
21595
|
|
|
@@ -19726,6 +21717,22 @@ var _TreeMap = class _TreeMap {
|
|
|
19726
21717
|
|
|
19727
21718
|
|
|
19728
21719
|
|
|
21720
|
+
|
|
21721
|
+
|
|
21722
|
+
|
|
21723
|
+
|
|
21724
|
+
|
|
21725
|
+
|
|
21726
|
+
|
|
21727
|
+
|
|
21728
|
+
|
|
21729
|
+
|
|
21730
|
+
|
|
21731
|
+
|
|
21732
|
+
|
|
21733
|
+
|
|
21734
|
+
|
|
21735
|
+
|
|
19729
21736
|
|
|
19730
21737
|
|
|
19731
21738
|
|
|
@@ -19883,6 +21890,22 @@ var _TreeMap = class _TreeMap {
|
|
|
19883
21890
|
|
|
19884
21891
|
|
|
19885
21892
|
|
|
21893
|
+
|
|
21894
|
+
|
|
21895
|
+
|
|
21896
|
+
|
|
21897
|
+
|
|
21898
|
+
|
|
21899
|
+
|
|
21900
|
+
|
|
21901
|
+
|
|
21902
|
+
|
|
21903
|
+
|
|
21904
|
+
|
|
21905
|
+
|
|
21906
|
+
|
|
21907
|
+
|
|
21908
|
+
|
|
19886
21909
|
|
|
19887
21910
|
|
|
19888
21911
|
|
|
@@ -20024,6 +22047,22 @@ var _TreeMap = class _TreeMap {
|
|
|
20024
22047
|
|
|
20025
22048
|
|
|
20026
22049
|
|
|
22050
|
+
|
|
22051
|
+
|
|
22052
|
+
|
|
22053
|
+
|
|
22054
|
+
|
|
22055
|
+
|
|
22056
|
+
|
|
22057
|
+
|
|
22058
|
+
|
|
22059
|
+
|
|
22060
|
+
|
|
22061
|
+
|
|
22062
|
+
|
|
22063
|
+
|
|
22064
|
+
|
|
22065
|
+
|
|
20027
22066
|
|
|
20028
22067
|
|
|
20029
22068
|
|
|
@@ -20165,6 +22204,22 @@ var _TreeMap = class _TreeMap {
|
|
|
20165
22204
|
|
|
20166
22205
|
|
|
20167
22206
|
|
|
22207
|
+
|
|
22208
|
+
|
|
22209
|
+
|
|
22210
|
+
|
|
22211
|
+
|
|
22212
|
+
|
|
22213
|
+
|
|
22214
|
+
|
|
22215
|
+
|
|
22216
|
+
|
|
22217
|
+
|
|
22218
|
+
|
|
22219
|
+
|
|
22220
|
+
|
|
22221
|
+
|
|
22222
|
+
|
|
20168
22223
|
|
|
20169
22224
|
|
|
20170
22225
|
|
|
@@ -20307,6 +22362,22 @@ var _TreeMap = class _TreeMap {
|
|
|
20307
22362
|
|
|
20308
22363
|
|
|
20309
22364
|
|
|
22365
|
+
|
|
22366
|
+
|
|
22367
|
+
|
|
22368
|
+
|
|
22369
|
+
|
|
22370
|
+
|
|
22371
|
+
|
|
22372
|
+
|
|
22373
|
+
|
|
22374
|
+
|
|
22375
|
+
|
|
22376
|
+
|
|
22377
|
+
|
|
22378
|
+
|
|
22379
|
+
|
|
22380
|
+
|
|
20310
22381
|
|
|
20311
22382
|
|
|
20312
22383
|
|
|
@@ -20371,6 +22442,68 @@ var _TreeMap = class _TreeMap {
|
|
|
20371
22442
|
}
|
|
20372
22443
|
return out;
|
|
20373
22444
|
}
|
|
22445
|
+
// ─── Order-Statistic Methods ───────────────────────────
|
|
22446
|
+
/**
|
|
22447
|
+
* Returns the entry at the k-th position in tree order (0-indexed).
|
|
22448
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
22449
|
+
|
|
22450
|
+
|
|
22451
|
+
|
|
22452
|
+
* @example
|
|
22453
|
+
* // Find k-th entry in a TreeMap
|
|
22454
|
+
* const map = new TreeMap<string, number>(
|
|
22455
|
+
* [['alice', 95], ['bob', 87], ['charlie', 92]],
|
|
22456
|
+
* { enableOrderStatistic: true }
|
|
22457
|
+
* );
|
|
22458
|
+
* console.log(map.getByRank(0)); // 'alice';
|
|
22459
|
+
* console.log(map.getByRank(1)); // 'bob';
|
|
22460
|
+
* console.log(map.getByRank(2)); // 'charlie';
|
|
22461
|
+
*/
|
|
22462
|
+
getByRank(k) {
|
|
22463
|
+
const key = __privateGet(this, _core3).getByRank(k);
|
|
22464
|
+
if (key === void 0) return void 0;
|
|
22465
|
+
return [key, __privateGet(this, _core3).get(key)];
|
|
22466
|
+
}
|
|
22467
|
+
/**
|
|
22468
|
+
* Returns the 0-based rank of a key (number of elements that precede it in tree order).
|
|
22469
|
+
* @remarks Time O(log n). Requires `enableOrderStatistic: true`.
|
|
22470
|
+
* @example
|
|
22471
|
+
* // Get the rank of a key in sorted order
|
|
22472
|
+
* const tree = new TreeMap<number>(
|
|
22473
|
+
* [10, 20, 30, 40, 50],
|
|
22474
|
+
* { enableOrderStatistic: true }
|
|
22475
|
+
* );
|
|
22476
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
22477
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
22478
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
22479
|
+
* console.log(tree.getRank(25)); // 2;
|
|
22480
|
+
*/
|
|
22481
|
+
getRank(key) {
|
|
22482
|
+
return __privateGet(this, _core3).getRank(key);
|
|
22483
|
+
}
|
|
22484
|
+
/**
|
|
22485
|
+
* Returns keys by rank range (0-indexed, inclusive on both ends).
|
|
22486
|
+
* @remarks Time O(log n + k). Requires `enableOrderStatistic: true`.
|
|
22487
|
+
|
|
22488
|
+
* @example
|
|
22489
|
+
* // Pagination with rangeByRank
|
|
22490
|
+
* const tree = new TreeMap<number>(
|
|
22491
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
22492
|
+
* { enableOrderStatistic: true }
|
|
22493
|
+
* );
|
|
22494
|
+
* const pageSize = 3;
|
|
22495
|
+
*
|
|
22496
|
+
* // Page 1
|
|
22497
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
22498
|
+
* // Page 2
|
|
22499
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
22500
|
+
* // Page 3
|
|
22501
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
22502
|
+
*/
|
|
22503
|
+
rangeByRank(start, end) {
|
|
22504
|
+
const keys = __privateGet(this, _core3).rangeByRank(start, end);
|
|
22505
|
+
return keys.filter((k) => k !== void 0).map((k) => [k, __privateGet(this, _core3).get(k)]);
|
|
22506
|
+
}
|
|
20374
22507
|
/**
|
|
20375
22508
|
* Creates a shallow clone of this map.
|
|
20376
22509
|
* @remarks Time O(n log n), Space O(n)
|
|
@@ -20513,17 +22646,37 @@ var _TreeMap = class _TreeMap {
|
|
|
20513
22646
|
|
|
20514
22647
|
|
|
20515
22648
|
|
|
20516
|
-
|
|
20517
|
-
|
|
20518
|
-
|
|
20519
|
-
|
|
20520
|
-
|
|
20521
|
-
|
|
20522
|
-
|
|
20523
|
-
|
|
20524
|
-
|
|
20525
|
-
|
|
20526
|
-
|
|
22649
|
+
|
|
22650
|
+
|
|
22651
|
+
|
|
22652
|
+
|
|
22653
|
+
|
|
22654
|
+
|
|
22655
|
+
|
|
22656
|
+
|
|
22657
|
+
|
|
22658
|
+
|
|
22659
|
+
|
|
22660
|
+
|
|
22661
|
+
|
|
22662
|
+
|
|
22663
|
+
|
|
22664
|
+
|
|
22665
|
+
|
|
22666
|
+
|
|
22667
|
+
|
|
22668
|
+
|
|
22669
|
+
* @example
|
|
22670
|
+
* // Deep clone
|
|
22671
|
+
* const tm = new TreeMap<number, string>([[1, 'a'], [2, 'b']]);
|
|
22672
|
+
* const copy = tm.clone();
|
|
22673
|
+
* copy.delete(1);
|
|
22674
|
+
* console.log(tm.has(1)); // true;
|
|
22675
|
+
*/
|
|
22676
|
+
clone() {
|
|
22677
|
+
return new _TreeMap(this, {
|
|
22678
|
+
comparator: __privateGet(this, _isDefaultComparator3) ? void 0 : __privateGet(this, _userComparator2),
|
|
22679
|
+
isMapMode: __privateGet(this, _core3).isMapMode
|
|
20527
22680
|
});
|
|
20528
22681
|
}
|
|
20529
22682
|
};
|
|
@@ -20558,7 +22711,7 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20558
22711
|
const toElementFn = options.toElementFn;
|
|
20559
22712
|
const comparator = (_a = options.comparator) != null ? _a : TreeSet.createDefaultComparator();
|
|
20560
22713
|
__privateSet(this, _isDefaultComparator4, options.comparator === void 0);
|
|
20561
|
-
__privateSet(this, _core4, new RedBlackTree([], { comparator, isMapMode: options.isMapMode }));
|
|
22714
|
+
__privateSet(this, _core4, new RedBlackTree([], { comparator, isMapMode: options.isMapMode, enableOrderStatistic: options.enableOrderStatistic }));
|
|
20562
22715
|
for (const item of elements) {
|
|
20563
22716
|
const k = toElementFn ? toElementFn(item) : item;
|
|
20564
22717
|
this.add(k);
|
|
@@ -20571,22 +22724,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20571
22724
|
_validateKey(key) {
|
|
20572
22725
|
if (!__privateGet(this, _isDefaultComparator4)) return;
|
|
20573
22726
|
if (typeof key === "number") {
|
|
20574
|
-
if (Number.isNaN(key))
|
|
22727
|
+
if (Number.isNaN(key)) raise(TypeError, ERR.invalidNaN("TreeMultiSet"));
|
|
20575
22728
|
return;
|
|
20576
22729
|
}
|
|
20577
22730
|
if (typeof key === "string") return;
|
|
20578
22731
|
if (key instanceof Date) {
|
|
20579
|
-
if (Number.isNaN(key.getTime()))
|
|
22732
|
+
if (Number.isNaN(key.getTime())) raise(TypeError, ERR.invalidDate("TreeMultiSet"));
|
|
20580
22733
|
return;
|
|
20581
22734
|
}
|
|
20582
|
-
|
|
22735
|
+
raise(TypeError, ERR.comparatorRequired("TreeMultiSet"));
|
|
20583
22736
|
}
|
|
20584
22737
|
/**
|
|
20585
22738
|
* Validates that count is a non-negative safe integer.
|
|
20586
22739
|
* @remarks Time O(1), Space O(1)
|
|
20587
22740
|
*/
|
|
20588
22741
|
_validateCount(n) {
|
|
20589
|
-
if (!Number.isSafeInteger(n) || n < 0)
|
|
22742
|
+
if (!Number.isSafeInteger(n) || n < 0) raise(RangeError, ERR.invalidArgument("count must be a safe integer >= 0.", "TreeMultiSet"));
|
|
20590
22743
|
}
|
|
20591
22744
|
/**
|
|
20592
22745
|
* Total occurrences (sumCounts).
|
|
@@ -20615,6 +22768,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20615
22768
|
|
|
20616
22769
|
|
|
20617
22770
|
|
|
22771
|
+
|
|
22772
|
+
|
|
22773
|
+
|
|
22774
|
+
|
|
20618
22775
|
|
|
20619
22776
|
|
|
20620
22777
|
|
|
@@ -20750,6 +22907,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20750
22907
|
|
|
20751
22908
|
|
|
20752
22909
|
|
|
22910
|
+
|
|
22911
|
+
|
|
22912
|
+
|
|
22913
|
+
|
|
22914
|
+
|
|
22915
|
+
|
|
22916
|
+
|
|
22917
|
+
|
|
22918
|
+
|
|
22919
|
+
|
|
22920
|
+
|
|
22921
|
+
|
|
22922
|
+
|
|
22923
|
+
|
|
22924
|
+
|
|
22925
|
+
|
|
22926
|
+
|
|
22927
|
+
|
|
22928
|
+
|
|
22929
|
+
|
|
20753
22930
|
|
|
20754
22931
|
|
|
20755
22932
|
|
|
@@ -20901,6 +23078,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20901
23078
|
|
|
20902
23079
|
|
|
20903
23080
|
|
|
23081
|
+
|
|
23082
|
+
|
|
23083
|
+
|
|
23084
|
+
|
|
23085
|
+
|
|
23086
|
+
|
|
23087
|
+
|
|
23088
|
+
|
|
23089
|
+
|
|
23090
|
+
|
|
23091
|
+
|
|
23092
|
+
|
|
23093
|
+
|
|
23094
|
+
|
|
23095
|
+
|
|
23096
|
+
|
|
23097
|
+
|
|
23098
|
+
|
|
23099
|
+
|
|
23100
|
+
|
|
20904
23101
|
|
|
20905
23102
|
|
|
20906
23103
|
|
|
@@ -20953,6 +23150,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
20953
23150
|
|
|
20954
23151
|
|
|
20955
23152
|
|
|
23153
|
+
|
|
23154
|
+
|
|
23155
|
+
|
|
23156
|
+
|
|
20956
23157
|
|
|
20957
23158
|
|
|
20958
23159
|
|
|
@@ -21084,6 +23285,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21084
23285
|
|
|
21085
23286
|
|
|
21086
23287
|
|
|
23288
|
+
|
|
23289
|
+
|
|
23290
|
+
|
|
23291
|
+
|
|
23292
|
+
|
|
23293
|
+
|
|
23294
|
+
|
|
23295
|
+
|
|
23296
|
+
|
|
23297
|
+
|
|
23298
|
+
|
|
23299
|
+
|
|
23300
|
+
|
|
23301
|
+
|
|
23302
|
+
|
|
23303
|
+
|
|
23304
|
+
|
|
23305
|
+
|
|
23306
|
+
|
|
23307
|
+
|
|
21087
23308
|
|
|
21088
23309
|
|
|
21089
23310
|
|
|
@@ -21146,6 +23367,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21146
23367
|
|
|
21147
23368
|
|
|
21148
23369
|
|
|
23370
|
+
|
|
23371
|
+
|
|
23372
|
+
|
|
23373
|
+
|
|
21149
23374
|
|
|
21150
23375
|
|
|
21151
23376
|
|
|
@@ -21295,6 +23520,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21295
23520
|
|
|
21296
23521
|
|
|
21297
23522
|
|
|
23523
|
+
|
|
23524
|
+
|
|
23525
|
+
|
|
23526
|
+
|
|
23527
|
+
|
|
23528
|
+
|
|
23529
|
+
|
|
23530
|
+
|
|
23531
|
+
|
|
23532
|
+
|
|
23533
|
+
|
|
23534
|
+
|
|
23535
|
+
|
|
23536
|
+
|
|
23537
|
+
|
|
23538
|
+
|
|
23539
|
+
|
|
23540
|
+
|
|
23541
|
+
|
|
23542
|
+
|
|
21298
23543
|
|
|
21299
23544
|
|
|
21300
23545
|
|
|
@@ -21358,6 +23603,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21358
23603
|
|
|
21359
23604
|
|
|
21360
23605
|
|
|
23606
|
+
|
|
23607
|
+
|
|
23608
|
+
|
|
23609
|
+
|
|
21361
23610
|
|
|
21362
23611
|
|
|
21363
23612
|
|
|
@@ -21399,6 +23648,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21399
23648
|
|
|
21400
23649
|
|
|
21401
23650
|
|
|
23651
|
+
|
|
23652
|
+
|
|
23653
|
+
|
|
23654
|
+
|
|
21402
23655
|
|
|
21403
23656
|
|
|
21404
23657
|
|
|
@@ -21534,6 +23787,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21534
23787
|
|
|
21535
23788
|
|
|
21536
23789
|
|
|
23790
|
+
|
|
23791
|
+
|
|
23792
|
+
|
|
23793
|
+
|
|
23794
|
+
|
|
23795
|
+
|
|
23796
|
+
|
|
23797
|
+
|
|
23798
|
+
|
|
23799
|
+
|
|
23800
|
+
|
|
23801
|
+
|
|
23802
|
+
|
|
23803
|
+
|
|
23804
|
+
|
|
23805
|
+
|
|
23806
|
+
|
|
23807
|
+
|
|
23808
|
+
|
|
23809
|
+
|
|
21537
23810
|
|
|
21538
23811
|
|
|
21539
23812
|
|
|
@@ -21695,6 +23968,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21695
23968
|
|
|
21696
23969
|
|
|
21697
23970
|
|
|
23971
|
+
|
|
23972
|
+
|
|
23973
|
+
|
|
23974
|
+
|
|
23975
|
+
|
|
23976
|
+
|
|
23977
|
+
|
|
23978
|
+
|
|
23979
|
+
|
|
23980
|
+
|
|
23981
|
+
|
|
23982
|
+
|
|
23983
|
+
|
|
23984
|
+
|
|
23985
|
+
|
|
23986
|
+
|
|
23987
|
+
|
|
23988
|
+
|
|
23989
|
+
|
|
23990
|
+
|
|
21698
23991
|
|
|
21699
23992
|
|
|
21700
23993
|
|
|
@@ -21746,6 +24039,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21746
24039
|
|
|
21747
24040
|
|
|
21748
24041
|
|
|
24042
|
+
|
|
24043
|
+
|
|
24044
|
+
|
|
24045
|
+
|
|
21749
24046
|
|
|
21750
24047
|
|
|
21751
24048
|
|
|
@@ -21781,6 +24078,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21781
24078
|
|
|
21782
24079
|
|
|
21783
24080
|
|
|
24081
|
+
|
|
24082
|
+
|
|
24083
|
+
|
|
24084
|
+
|
|
21784
24085
|
|
|
21785
24086
|
|
|
21786
24087
|
|
|
@@ -21925,6 +24226,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21925
24226
|
|
|
21926
24227
|
|
|
21927
24228
|
|
|
24229
|
+
|
|
24230
|
+
|
|
24231
|
+
|
|
24232
|
+
|
|
24233
|
+
|
|
24234
|
+
|
|
24235
|
+
|
|
24236
|
+
|
|
24237
|
+
|
|
24238
|
+
|
|
24239
|
+
|
|
24240
|
+
|
|
24241
|
+
|
|
24242
|
+
|
|
24243
|
+
|
|
24244
|
+
|
|
24245
|
+
|
|
24246
|
+
|
|
24247
|
+
|
|
24248
|
+
|
|
21928
24249
|
|
|
21929
24250
|
|
|
21930
24251
|
|
|
@@ -21979,6 +24300,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
21979
24300
|
|
|
21980
24301
|
|
|
21981
24302
|
|
|
24303
|
+
|
|
24304
|
+
|
|
24305
|
+
|
|
24306
|
+
|
|
21982
24307
|
|
|
21983
24308
|
|
|
21984
24309
|
|
|
@@ -22015,6 +24340,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22015
24340
|
|
|
22016
24341
|
|
|
22017
24342
|
|
|
24343
|
+
|
|
24344
|
+
|
|
24345
|
+
|
|
24346
|
+
|
|
22018
24347
|
|
|
22019
24348
|
|
|
22020
24349
|
|
|
@@ -22051,6 +24380,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22051
24380
|
|
|
22052
24381
|
|
|
22053
24382
|
|
|
24383
|
+
|
|
24384
|
+
|
|
24385
|
+
|
|
24386
|
+
|
|
22054
24387
|
|
|
22055
24388
|
|
|
22056
24389
|
|
|
@@ -22091,6 +24424,10 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22091
24424
|
|
|
22092
24425
|
|
|
22093
24426
|
|
|
24427
|
+
|
|
24428
|
+
|
|
24429
|
+
|
|
24430
|
+
|
|
22094
24431
|
|
|
22095
24432
|
|
|
22096
24433
|
|
|
@@ -22205,6 +24542,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22205
24542
|
|
|
22206
24543
|
|
|
22207
24544
|
|
|
24545
|
+
|
|
24546
|
+
|
|
24547
|
+
|
|
24548
|
+
|
|
24549
|
+
|
|
24550
|
+
|
|
24551
|
+
|
|
24552
|
+
|
|
24553
|
+
|
|
24554
|
+
|
|
24555
|
+
|
|
24556
|
+
|
|
24557
|
+
|
|
24558
|
+
|
|
24559
|
+
|
|
24560
|
+
|
|
22208
24561
|
|
|
22209
24562
|
|
|
22210
24563
|
|
|
@@ -22330,6 +24683,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22330
24683
|
|
|
22331
24684
|
|
|
22332
24685
|
|
|
24686
|
+
|
|
24687
|
+
|
|
24688
|
+
|
|
24689
|
+
|
|
24690
|
+
|
|
24691
|
+
|
|
24692
|
+
|
|
24693
|
+
|
|
24694
|
+
|
|
24695
|
+
|
|
24696
|
+
|
|
24697
|
+
|
|
24698
|
+
|
|
24699
|
+
|
|
24700
|
+
|
|
24701
|
+
|
|
22333
24702
|
|
|
22334
24703
|
|
|
22335
24704
|
|
|
@@ -22455,6 +24824,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22455
24824
|
|
|
22456
24825
|
|
|
22457
24826
|
|
|
24827
|
+
|
|
24828
|
+
|
|
24829
|
+
|
|
24830
|
+
|
|
24831
|
+
|
|
24832
|
+
|
|
24833
|
+
|
|
24834
|
+
|
|
24835
|
+
|
|
24836
|
+
|
|
24837
|
+
|
|
24838
|
+
|
|
24839
|
+
|
|
24840
|
+
|
|
24841
|
+
|
|
24842
|
+
|
|
22458
24843
|
|
|
22459
24844
|
|
|
22460
24845
|
|
|
@@ -22579,6 +24964,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22579
24964
|
|
|
22580
24965
|
|
|
22581
24966
|
|
|
24967
|
+
|
|
24968
|
+
|
|
24969
|
+
|
|
24970
|
+
|
|
24971
|
+
|
|
24972
|
+
|
|
24973
|
+
|
|
24974
|
+
|
|
24975
|
+
|
|
24976
|
+
|
|
24977
|
+
|
|
24978
|
+
|
|
24979
|
+
|
|
24980
|
+
|
|
24981
|
+
|
|
24982
|
+
|
|
22582
24983
|
|
|
22583
24984
|
|
|
22584
24985
|
|
|
@@ -22729,6 +25130,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22729
25130
|
|
|
22730
25131
|
|
|
22731
25132
|
|
|
25133
|
+
|
|
25134
|
+
|
|
25135
|
+
|
|
25136
|
+
|
|
25137
|
+
|
|
25138
|
+
|
|
25139
|
+
|
|
25140
|
+
|
|
25141
|
+
|
|
25142
|
+
|
|
25143
|
+
|
|
25144
|
+
|
|
25145
|
+
|
|
25146
|
+
|
|
25147
|
+
|
|
25148
|
+
|
|
25149
|
+
|
|
25150
|
+
|
|
25151
|
+
|
|
25152
|
+
|
|
22732
25153
|
|
|
22733
25154
|
|
|
22734
25155
|
|
|
@@ -22885,6 +25306,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
22885
25306
|
|
|
22886
25307
|
|
|
22887
25308
|
|
|
25309
|
+
|
|
25310
|
+
|
|
25311
|
+
|
|
25312
|
+
|
|
25313
|
+
|
|
25314
|
+
|
|
25315
|
+
|
|
25316
|
+
|
|
25317
|
+
|
|
25318
|
+
|
|
25319
|
+
|
|
25320
|
+
|
|
25321
|
+
|
|
25322
|
+
|
|
25323
|
+
|
|
25324
|
+
|
|
25325
|
+
|
|
25326
|
+
|
|
25327
|
+
|
|
25328
|
+
|
|
22888
25329
|
|
|
22889
25330
|
|
|
22890
25331
|
|
|
@@ -23048,6 +25489,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23048
25489
|
|
|
23049
25490
|
|
|
23050
25491
|
|
|
25492
|
+
|
|
25493
|
+
|
|
25494
|
+
|
|
25495
|
+
|
|
25496
|
+
|
|
25497
|
+
|
|
25498
|
+
|
|
25499
|
+
|
|
25500
|
+
|
|
25501
|
+
|
|
25502
|
+
|
|
25503
|
+
|
|
25504
|
+
|
|
25505
|
+
|
|
25506
|
+
|
|
25507
|
+
|
|
25508
|
+
|
|
25509
|
+
|
|
25510
|
+
|
|
25511
|
+
|
|
23051
25512
|
|
|
23052
25513
|
|
|
23053
25514
|
|
|
@@ -23206,6 +25667,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23206
25667
|
|
|
23207
25668
|
|
|
23208
25669
|
|
|
25670
|
+
|
|
25671
|
+
|
|
25672
|
+
|
|
25673
|
+
|
|
25674
|
+
|
|
25675
|
+
|
|
25676
|
+
|
|
25677
|
+
|
|
25678
|
+
|
|
25679
|
+
|
|
25680
|
+
|
|
25681
|
+
|
|
25682
|
+
|
|
25683
|
+
|
|
25684
|
+
|
|
25685
|
+
|
|
25686
|
+
|
|
25687
|
+
|
|
25688
|
+
|
|
25689
|
+
|
|
23209
25690
|
|
|
23210
25691
|
|
|
23211
25692
|
|
|
@@ -23385,6 +25866,78 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23385
25866
|
|
|
23386
25867
|
|
|
23387
25868
|
|
|
25869
|
+
|
|
25870
|
+
|
|
25871
|
+
|
|
25872
|
+
|
|
25873
|
+
|
|
25874
|
+
|
|
25875
|
+
|
|
25876
|
+
|
|
25877
|
+
|
|
25878
|
+
|
|
25879
|
+
|
|
25880
|
+
|
|
25881
|
+
|
|
25882
|
+
|
|
25883
|
+
|
|
25884
|
+
|
|
25885
|
+
|
|
25886
|
+
|
|
25887
|
+
|
|
25888
|
+
|
|
25889
|
+
|
|
25890
|
+
* @example
|
|
25891
|
+
* // Order-statistic on BST
|
|
25892
|
+
* const tree = new TreeMultiSet<number>([30, 10, 50, 20, 40], { enableOrderStatistic: true });
|
|
25893
|
+
* console.log(tree.getByRank(0)); // 10;
|
|
25894
|
+
* console.log(tree.getByRank(4)); // 50;
|
|
25895
|
+
* console.log(tree.getRank(30)); // 2;
|
|
25896
|
+
*/
|
|
25897
|
+
// ─── Order-Statistic Methods ───────────────────────────
|
|
25898
|
+
getByRank(k) {
|
|
25899
|
+
return __privateGet(this, _core4).getByRank(k);
|
|
25900
|
+
}
|
|
25901
|
+
/**
|
|
25902
|
+
* Get the rank of a key in sorted order
|
|
25903
|
+
* @example
|
|
25904
|
+
* // Get the rank of a key in sorted order
|
|
25905
|
+
* const tree = new TreeMultiSet<number>(
|
|
25906
|
+
* [10, 20, 30, 40, 50],
|
|
25907
|
+
* { enableOrderStatistic: true }
|
|
25908
|
+
* );
|
|
25909
|
+
* console.log(tree.getRank(10)); // 0; // smallest → rank 0
|
|
25910
|
+
* console.log(tree.getRank(30)); // 2; // 2 elements before 30 in tree order
|
|
25911
|
+
* console.log(tree.getRank(50)); // 4; // largest → rank 4
|
|
25912
|
+
* console.log(tree.getRank(25)); // 2;
|
|
25913
|
+
*/
|
|
25914
|
+
getRank(key) {
|
|
25915
|
+
return __privateGet(this, _core4).getRank(key);
|
|
25916
|
+
}
|
|
25917
|
+
/**
|
|
25918
|
+
* Get elements by rank range
|
|
25919
|
+
|
|
25920
|
+
* @example
|
|
25921
|
+
* // Pagination with rangeByRank
|
|
25922
|
+
* const tree = new TreeMultiSet<number>(
|
|
25923
|
+
* [10, 20, 30, 40, 50, 60, 70, 80, 90],
|
|
25924
|
+
* { enableOrderStatistic: true }
|
|
25925
|
+
* );
|
|
25926
|
+
* const pageSize = 3;
|
|
25927
|
+
*
|
|
25928
|
+
* // Page 1
|
|
25929
|
+
* console.log(tree.rangeByRank(0, pageSize - 1)); // [10, 20, 30];
|
|
25930
|
+
* // Page 2
|
|
25931
|
+
* console.log(tree.rangeByRank(pageSize, 2 * pageSize - 1)); // [40, 50, 60];
|
|
25932
|
+
* // Page 3
|
|
25933
|
+
* console.log(tree.rangeByRank(2 * pageSize, 3 * pageSize - 1)); // [70, 80, 90];
|
|
25934
|
+
*/
|
|
25935
|
+
rangeByRank(start, end) {
|
|
25936
|
+
return __privateGet(this, _core4).rangeByRank(start, end).filter((k) => k !== void 0);
|
|
25937
|
+
}
|
|
25938
|
+
/**
|
|
25939
|
+
* Deep copy
|
|
25940
|
+
|
|
23388
25941
|
|
|
23389
25942
|
|
|
23390
25943
|
|
|
@@ -23503,6 +26056,22 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23503
26056
|
|
|
23504
26057
|
|
|
23505
26058
|
|
|
26059
|
+
|
|
26060
|
+
|
|
26061
|
+
|
|
26062
|
+
|
|
26063
|
+
|
|
26064
|
+
|
|
26065
|
+
|
|
26066
|
+
|
|
26067
|
+
|
|
26068
|
+
|
|
26069
|
+
|
|
26070
|
+
|
|
26071
|
+
|
|
26072
|
+
|
|
26073
|
+
|
|
26074
|
+
|
|
23506
26075
|
|
|
23507
26076
|
|
|
23508
26077
|
|
|
@@ -23654,6 +26223,26 @@ var _TreeMultiSet = class _TreeMultiSet {
|
|
|
23654
26223
|
|
|
23655
26224
|
|
|
23656
26225
|
|
|
26226
|
+
|
|
26227
|
+
|
|
26228
|
+
|
|
26229
|
+
|
|
26230
|
+
|
|
26231
|
+
|
|
26232
|
+
|
|
26233
|
+
|
|
26234
|
+
|
|
26235
|
+
|
|
26236
|
+
|
|
26237
|
+
|
|
26238
|
+
|
|
26239
|
+
|
|
26240
|
+
|
|
26241
|
+
|
|
26242
|
+
|
|
26243
|
+
|
|
26244
|
+
|
|
26245
|
+
|
|
23657
26246
|
|
|
23658
26247
|
|
|
23659
26248
|
|