data-structure-typed 1.48.8 → 1.49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +58 -55
- package/README_zh-CN.md +58 -56
- package/benchmark/report.html +1 -46
- package/benchmark/report.json +23 -458
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +8 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +9 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +15 -10
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +55 -49
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +8 -1
- package/dist/cjs/data-structures/binary-tree/bst.js +9 -0
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +10 -16
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +16 -29
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +8 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +9 -0
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +0 -110
- package/dist/cjs/data-structures/queue/deque.js +1 -172
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +8 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +9 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +15 -10
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +55 -49
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +8 -1
- package/dist/mjs/data-structures/binary-tree/bst.js +9 -0
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +10 -16
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +16 -28
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +8 -1
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +9 -0
- package/dist/mjs/data-structures/queue/deque.d.ts +0 -110
- package/dist/mjs/data-structures/queue/deque.js +0 -170
- package/dist/umd/data-structure-typed.js +94 -239
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +11 -1
- package/src/data-structures/binary-tree/binary-tree.ts +65 -56
- package/src/data-structures/binary-tree/bst.ts +11 -1
- package/src/data-structures/binary-tree/rb-tree.ts +18 -32
- package/src/data-structures/binary-tree/tree-multimap.ts +17 -1
- package/src/data-structures/queue/deque.ts +1 -191
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +15 -8
- package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +5 -5
- package/test/unit/data-structures/queue/deque.test.ts +265 -367
- package/test/unit/data-structures/queue/queue.test.ts +158 -158
|
@@ -142,7 +142,6 @@ var dataStructureTyped = (() => {
|
|
|
142
142
|
MinHeap: () => MinHeap,
|
|
143
143
|
MinPriorityQueue: () => MinPriorityQueue,
|
|
144
144
|
Navigator: () => Navigator,
|
|
145
|
-
ObjectDeque: () => ObjectDeque,
|
|
146
145
|
PriorityQueue: () => PriorityQueue,
|
|
147
146
|
Queue: () => Queue,
|
|
148
147
|
RBTNColor: () => RBTNColor,
|
|
@@ -4374,171 +4373,6 @@ var dataStructureTyped = (() => {
|
|
|
4374
4373
|
return { bucketIndex, indexInBucket };
|
|
4375
4374
|
}
|
|
4376
4375
|
};
|
|
4377
|
-
var ObjectDeque = class {
|
|
4378
|
-
constructor(capacity) {
|
|
4379
|
-
__publicField(this, "_nodes", {});
|
|
4380
|
-
__publicField(this, "_capacity", Number.MAX_SAFE_INTEGER);
|
|
4381
|
-
__publicField(this, "_first", -1);
|
|
4382
|
-
__publicField(this, "_last", -1);
|
|
4383
|
-
__publicField(this, "_size", 0);
|
|
4384
|
-
if (capacity !== void 0)
|
|
4385
|
-
this._capacity = capacity;
|
|
4386
|
-
}
|
|
4387
|
-
get nodes() {
|
|
4388
|
-
return this._nodes;
|
|
4389
|
-
}
|
|
4390
|
-
get capacity() {
|
|
4391
|
-
return this._capacity;
|
|
4392
|
-
}
|
|
4393
|
-
get first() {
|
|
4394
|
-
return this._first;
|
|
4395
|
-
}
|
|
4396
|
-
get last() {
|
|
4397
|
-
return this._last;
|
|
4398
|
-
}
|
|
4399
|
-
get size() {
|
|
4400
|
-
return this._size;
|
|
4401
|
-
}
|
|
4402
|
-
/**
|
|
4403
|
-
* Time Complexity: O(1)
|
|
4404
|
-
* Space Complexity: O(1)
|
|
4405
|
-
*/
|
|
4406
|
-
/**
|
|
4407
|
-
* Time Complexity: O(1)
|
|
4408
|
-
* Space Complexity: O(1)
|
|
4409
|
-
*
|
|
4410
|
-
* The "addFirst" function adds an element to the beginning of an array-like data structure.
|
|
4411
|
-
* @param {E} element - The `element` parameter represents the element that you want to add to the beginning of the data
|
|
4412
|
-
* structure.
|
|
4413
|
-
*/
|
|
4414
|
-
addFirst(element) {
|
|
4415
|
-
if (this.size === 0) {
|
|
4416
|
-
const mid = Math.floor(this.capacity / 2);
|
|
4417
|
-
this._first = mid;
|
|
4418
|
-
this._last = mid;
|
|
4419
|
-
} else {
|
|
4420
|
-
this._first--;
|
|
4421
|
-
}
|
|
4422
|
-
this.nodes[this.first] = element;
|
|
4423
|
-
this._size++;
|
|
4424
|
-
}
|
|
4425
|
-
/**
|
|
4426
|
-
* Time Complexity: O(1)
|
|
4427
|
-
* Space Complexity: O(1)
|
|
4428
|
-
*/
|
|
4429
|
-
/**
|
|
4430
|
-
* Time Complexity: O(1)
|
|
4431
|
-
* Space Complexity: O(1)
|
|
4432
|
-
*
|
|
4433
|
-
* The addLast function adds an element to the end of an array-like data structure.
|
|
4434
|
-
* @param {E} element - The `element` parameter represents the element that you want to add to the end of the data structure.
|
|
4435
|
-
*/
|
|
4436
|
-
addLast(element) {
|
|
4437
|
-
if (this.size === 0) {
|
|
4438
|
-
const mid = Math.floor(this.capacity / 2);
|
|
4439
|
-
this._first = mid;
|
|
4440
|
-
this._last = mid;
|
|
4441
|
-
} else {
|
|
4442
|
-
this._last++;
|
|
4443
|
-
}
|
|
4444
|
-
this.nodes[this.last] = element;
|
|
4445
|
-
this._size++;
|
|
4446
|
-
}
|
|
4447
|
-
/**
|
|
4448
|
-
* Time Complexity: O(1)
|
|
4449
|
-
* Space Complexity: O(1)
|
|
4450
|
-
*/
|
|
4451
|
-
/**
|
|
4452
|
-
* Time Complexity: O(1)
|
|
4453
|
-
* Space Complexity: O(1)
|
|
4454
|
-
*
|
|
4455
|
-
* The function `pollFirst()` removes and returns the first element in a data structure.
|
|
4456
|
-
* @returns The element of the first element in the data structure.
|
|
4457
|
-
*/
|
|
4458
|
-
pollFirst() {
|
|
4459
|
-
if (!this.size)
|
|
4460
|
-
return;
|
|
4461
|
-
const element = this.getFirst();
|
|
4462
|
-
delete this.nodes[this.first];
|
|
4463
|
-
this._first++;
|
|
4464
|
-
this._size--;
|
|
4465
|
-
return element;
|
|
4466
|
-
}
|
|
4467
|
-
/**
|
|
4468
|
-
* Time Complexity: O(1)
|
|
4469
|
-
* Space Complexity: O(1)
|
|
4470
|
-
*/
|
|
4471
|
-
/**
|
|
4472
|
-
* Time Complexity: O(1)
|
|
4473
|
-
* Space Complexity: O(1)
|
|
4474
|
-
*
|
|
4475
|
-
* The `getFirst` function returns the first element in an array-like data structure if it exists.
|
|
4476
|
-
* @returns The element at the first position of the `_nodes` array.
|
|
4477
|
-
*/
|
|
4478
|
-
getFirst() {
|
|
4479
|
-
if (this.size)
|
|
4480
|
-
return this.nodes[this.first];
|
|
4481
|
-
}
|
|
4482
|
-
/**
|
|
4483
|
-
* Time Complexity: O(1)
|
|
4484
|
-
* Space Complexity: O(1)
|
|
4485
|
-
*/
|
|
4486
|
-
/**
|
|
4487
|
-
* Time Complexity: O(1)
|
|
4488
|
-
* Space Complexity: O(1)
|
|
4489
|
-
*
|
|
4490
|
-
* The `pollLast()` function removes and returns the last element in a data structure.
|
|
4491
|
-
* @returns The element that was removed from the data structure.
|
|
4492
|
-
*/
|
|
4493
|
-
pollLast() {
|
|
4494
|
-
if (!this.size)
|
|
4495
|
-
return;
|
|
4496
|
-
const element = this.getLast();
|
|
4497
|
-
delete this.nodes[this.last];
|
|
4498
|
-
this._last--;
|
|
4499
|
-
this._size--;
|
|
4500
|
-
return element;
|
|
4501
|
-
}
|
|
4502
|
-
/**
|
|
4503
|
-
* Time Complexity: O(1)
|
|
4504
|
-
* Space Complexity: O(1)
|
|
4505
|
-
*/
|
|
4506
|
-
/**
|
|
4507
|
-
* Time Complexity: O(1)
|
|
4508
|
-
* Space Complexity: O(1)
|
|
4509
|
-
*
|
|
4510
|
-
* The `getLast()` function returns the last element in an array-like data structure.
|
|
4511
|
-
* @returns The last element in the array "_nodes" is being returned.
|
|
4512
|
-
*/
|
|
4513
|
-
getLast() {
|
|
4514
|
-
if (this.size)
|
|
4515
|
-
return this.nodes[this.last];
|
|
4516
|
-
}
|
|
4517
|
-
/**
|
|
4518
|
-
* Time Complexity: O(1)
|
|
4519
|
-
* Space Complexity: O(1)
|
|
4520
|
-
*/
|
|
4521
|
-
/**
|
|
4522
|
-
* Time Complexity: O(1)
|
|
4523
|
-
* Space Complexity: O(1)
|
|
4524
|
-
*
|
|
4525
|
-
* The get function returns the element at the specified index in an array-like data structure.
|
|
4526
|
-
* @param {number} index - The index parameter is a number that represents the position of the element you want to
|
|
4527
|
-
* retrieve from the array.
|
|
4528
|
-
* @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
|
|
4529
|
-
* index, `undefined` is returned.
|
|
4530
|
-
*/
|
|
4531
|
-
get(index) {
|
|
4532
|
-
return this.nodes[this.first + index] || void 0;
|
|
4533
|
-
}
|
|
4534
|
-
/**
|
|
4535
|
-
* The function checks if the size of a data structure is less than or equal to zero.
|
|
4536
|
-
* @returns The method is returning a boolean element indicating whether the size of the object is less than or equal to 0.
|
|
4537
|
-
*/
|
|
4538
|
-
isEmpty() {
|
|
4539
|
-
return this.size <= 0;
|
|
4540
|
-
}
|
|
4541
|
-
};
|
|
4542
4376
|
|
|
4543
4377
|
// src/data-structures/heap/heap.ts
|
|
4544
4378
|
var Heap = class _Heap extends IterableElementBase {
|
|
@@ -7656,41 +7490,44 @@ var dataStructureTyped = (() => {
|
|
|
7656
7490
|
* @returns The function `add` returns either a node (`N`), `null`, or `undefined`.
|
|
7657
7491
|
*/
|
|
7658
7492
|
add(keyOrNodeOrEntry, value) {
|
|
7659
|
-
let inserted;
|
|
7660
7493
|
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
|
|
7661
7494
|
if (newNode === void 0)
|
|
7662
7495
|
return;
|
|
7663
|
-
if (
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7669
|
-
|
|
7670
|
-
|
|
7671
|
-
|
|
7672
|
-
|
|
7673
|
-
|
|
7674
|
-
|
|
7675
|
-
|
|
7676
|
-
|
|
7677
|
-
queue.push(cur.left);
|
|
7678
|
-
if (cur.right)
|
|
7679
|
-
queue.push(cur.right);
|
|
7496
|
+
if (!this.root) {
|
|
7497
|
+
this._root = newNode;
|
|
7498
|
+
this._size = 1;
|
|
7499
|
+
return newNode;
|
|
7500
|
+
}
|
|
7501
|
+
const queue = new Queue([this.root]);
|
|
7502
|
+
let potentialParent;
|
|
7503
|
+
while (queue.size > 0) {
|
|
7504
|
+
const cur = queue.shift();
|
|
7505
|
+
if (!cur)
|
|
7506
|
+
continue;
|
|
7507
|
+
if (newNode !== null && cur.key === newNode.key) {
|
|
7508
|
+
this._replaceNode(cur, newNode);
|
|
7509
|
+
return newNode;
|
|
7680
7510
|
}
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
this._size = 0;
|
|
7511
|
+
if (potentialParent === void 0 && (cur.left === void 0 || cur.right === void 0)) {
|
|
7512
|
+
potentialParent = cur;
|
|
7513
|
+
}
|
|
7514
|
+
if (cur.left !== null) {
|
|
7515
|
+
cur.left && queue.push(cur.left);
|
|
7516
|
+
}
|
|
7517
|
+
if (cur.right !== null) {
|
|
7518
|
+
cur.right && queue.push(cur.right);
|
|
7690
7519
|
}
|
|
7691
|
-
inserted = this.root;
|
|
7692
7520
|
}
|
|
7693
|
-
|
|
7521
|
+
if (potentialParent) {
|
|
7522
|
+
if (potentialParent.left === void 0) {
|
|
7523
|
+
potentialParent.left = newNode;
|
|
7524
|
+
} else if (potentialParent.right === void 0) {
|
|
7525
|
+
potentialParent.right = newNode;
|
|
7526
|
+
}
|
|
7527
|
+
this._size++;
|
|
7528
|
+
return newNode;
|
|
7529
|
+
}
|
|
7530
|
+
return void 0;
|
|
7694
7531
|
}
|
|
7695
7532
|
/**
|
|
7696
7533
|
* Time Complexity: O(k log n) - O(k * n)
|
|
@@ -8411,7 +8248,7 @@ var dataStructureTyped = (() => {
|
|
|
8411
8248
|
* @returns a boolean value.
|
|
8412
8249
|
*/
|
|
8413
8250
|
isRealNode(node) {
|
|
8414
|
-
return node instanceof BinaryTreeNode && node.key
|
|
8251
|
+
return node instanceof BinaryTreeNode && String(node.key) !== "NaN";
|
|
8415
8252
|
}
|
|
8416
8253
|
/**
|
|
8417
8254
|
* The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
|
|
@@ -8419,7 +8256,7 @@ var dataStructureTyped = (() => {
|
|
|
8419
8256
|
* @returns a boolean value.
|
|
8420
8257
|
*/
|
|
8421
8258
|
isNIL(node) {
|
|
8422
|
-
return node instanceof BinaryTreeNode && node.key
|
|
8259
|
+
return node instanceof BinaryTreeNode && String(node.key) === "NaN";
|
|
8423
8260
|
}
|
|
8424
8261
|
/**
|
|
8425
8262
|
* The function checks if a given node is a real node or null.
|
|
@@ -8430,7 +8267,7 @@ var dataStructureTyped = (() => {
|
|
|
8430
8267
|
return this.isRealNode(node) || node === null;
|
|
8431
8268
|
}
|
|
8432
8269
|
/**
|
|
8433
|
-
* The function "isNotNodeInstance" checks if a potential key is a
|
|
8270
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
8434
8271
|
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
8435
8272
|
* data type.
|
|
8436
8273
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
@@ -8698,19 +8535,23 @@ var dataStructureTyped = (() => {
|
|
|
8698
8535
|
return levelsNodes;
|
|
8699
8536
|
}
|
|
8700
8537
|
/**
|
|
8701
|
-
*
|
|
8702
|
-
*
|
|
8703
|
-
|
|
8704
|
-
|
|
8538
|
+
* Time Complexity: O(log n)
|
|
8539
|
+
* Space Complexity: O(1)
|
|
8540
|
+
*/
|
|
8541
|
+
/**
|
|
8542
|
+
* Time Complexity: O(log n)
|
|
8543
|
+
* Space Complexity: O(1)
|
|
8544
|
+
*
|
|
8545
|
+
* The function returns the predecessor of a given node in a tree.
|
|
8546
|
+
* @param {N} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
|
|
8547
|
+
* tree.
|
|
8548
|
+
* @returns the predecessor of the given 'node'.
|
|
8705
8549
|
*/
|
|
8706
8550
|
getPredecessor(node) {
|
|
8707
|
-
|
|
8708
|
-
if (!this.isRealNode(node))
|
|
8709
|
-
return void 0;
|
|
8710
|
-
if (node.left) {
|
|
8551
|
+
if (this.isRealNode(node.left)) {
|
|
8711
8552
|
let predecessor = node.left;
|
|
8712
8553
|
while (!this.isRealNode(predecessor) || this.isRealNode(predecessor.right) && predecessor.right !== node) {
|
|
8713
|
-
if (predecessor) {
|
|
8554
|
+
if (this.isRealNode(predecessor)) {
|
|
8714
8555
|
predecessor = predecessor.right;
|
|
8715
8556
|
}
|
|
8716
8557
|
}
|
|
@@ -8727,13 +8568,13 @@ var dataStructureTyped = (() => {
|
|
|
8727
8568
|
*/
|
|
8728
8569
|
getSuccessor(x) {
|
|
8729
8570
|
x = this.ensureNode(x);
|
|
8730
|
-
if (!x)
|
|
8571
|
+
if (!this.isRealNode(x))
|
|
8731
8572
|
return void 0;
|
|
8732
|
-
if (x.right) {
|
|
8573
|
+
if (this.isRealNode(x.right)) {
|
|
8733
8574
|
return this.getLeftMost(x.right);
|
|
8734
8575
|
}
|
|
8735
8576
|
let y = x.parent;
|
|
8736
|
-
while (y &&
|
|
8577
|
+
while (this.isRealNode(y) && x === y.right) {
|
|
8737
8578
|
x = y;
|
|
8738
8579
|
y = y.parent;
|
|
8739
8580
|
}
|
|
@@ -9462,6 +9303,15 @@ var dataStructureTyped = (() => {
|
|
|
9462
9303
|
}
|
|
9463
9304
|
}
|
|
9464
9305
|
}
|
|
9306
|
+
/**
|
|
9307
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
9308
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
9309
|
+
* data type.
|
|
9310
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
9311
|
+
*/
|
|
9312
|
+
isNotNodeInstance(potentialKey) {
|
|
9313
|
+
return !(potentialKey instanceof BSTNode);
|
|
9314
|
+
}
|
|
9465
9315
|
/**
|
|
9466
9316
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
9467
9317
|
* Space Complexity: O(log n) - Space for the recursive call stack in the worst case.
|
|
@@ -10235,6 +10085,15 @@ var dataStructureTyped = (() => {
|
|
|
10235
10085
|
isNode(exemplar) {
|
|
10236
10086
|
return exemplar instanceof AVLTreeNode;
|
|
10237
10087
|
}
|
|
10088
|
+
/**
|
|
10089
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
10090
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
10091
|
+
* data type.
|
|
10092
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
10093
|
+
*/
|
|
10094
|
+
isNotNodeInstance(potentialKey) {
|
|
10095
|
+
return !(potentialKey instanceof AVLTreeNode);
|
|
10096
|
+
}
|
|
10238
10097
|
/**
|
|
10239
10098
|
* Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
|
|
10240
10099
|
* Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
|
|
@@ -10666,6 +10525,15 @@ var dataStructureTyped = (() => {
|
|
|
10666
10525
|
isNode(exemplar) {
|
|
10667
10526
|
return exemplar instanceof RedBlackTreeNode;
|
|
10668
10527
|
}
|
|
10528
|
+
/**
|
|
10529
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
10530
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
10531
|
+
* data type.
|
|
10532
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
10533
|
+
*/
|
|
10534
|
+
isNotNodeInstance(potentialKey) {
|
|
10535
|
+
return !(potentialKey instanceof RedBlackTreeNode);
|
|
10536
|
+
}
|
|
10669
10537
|
/**
|
|
10670
10538
|
* The function `exemplarToNode` takes an exemplar and converts it into a node object if possible.
|
|
10671
10539
|
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where:
|
|
@@ -10830,7 +10698,9 @@ var dataStructureTyped = (() => {
|
|
|
10830
10698
|
* Space Complexity: O(1)
|
|
10831
10699
|
*/
|
|
10832
10700
|
isRealNode(node) {
|
|
10833
|
-
|
|
10701
|
+
if (node === this.Sentinel || node === void 0)
|
|
10702
|
+
return false;
|
|
10703
|
+
return node instanceof RedBlackTreeNode;
|
|
10834
10704
|
}
|
|
10835
10705
|
/**
|
|
10836
10706
|
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
|
|
@@ -10865,35 +10735,11 @@ var dataStructureTyped = (() => {
|
|
|
10865
10735
|
return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
|
|
10866
10736
|
}
|
|
10867
10737
|
/**
|
|
10868
|
-
* Time Complexity: O(log n)
|
|
10869
|
-
* Space Complexity: O(1)
|
|
10870
|
-
*/
|
|
10871
|
-
/**
|
|
10872
|
-
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
|
|
10873
|
-
* Space Complexity: O(1)
|
|
10874
|
-
*
|
|
10875
|
-
* The function returns the successor of a given node in a red-black tree.
|
|
10876
|
-
* @param {RedBlackTreeNode} x - RedBlackTreeNode - The node for which we want to find the successor.
|
|
10877
|
-
* @returns the successor of the given RedBlackTreeNode.
|
|
10878
|
-
*/
|
|
10879
|
-
getSuccessor(x) {
|
|
10880
|
-
var _a;
|
|
10881
|
-
if (x.right !== this.Sentinel) {
|
|
10882
|
-
return (_a = this.getLeftMost(x.right)) != null ? _a : void 0;
|
|
10883
|
-
}
|
|
10884
|
-
let y = x.parent;
|
|
10885
|
-
while (y !== this.Sentinel && y !== void 0 && x === y.right) {
|
|
10886
|
-
x = y;
|
|
10887
|
-
y = y.parent;
|
|
10888
|
-
}
|
|
10889
|
-
return y;
|
|
10890
|
-
}
|
|
10891
|
-
/**
|
|
10892
|
-
* Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
|
|
10738
|
+
* Time Complexity: O(log n)
|
|
10893
10739
|
* Space Complexity: O(1)
|
|
10894
10740
|
*/
|
|
10895
10741
|
/**
|
|
10896
|
-
* Time Complexity: O(log n)
|
|
10742
|
+
* Time Complexity: O(log n)
|
|
10897
10743
|
* Space Complexity: O(1)
|
|
10898
10744
|
*
|
|
10899
10745
|
* The function returns the predecessor of a given node in a red-black tree.
|
|
@@ -10902,11 +10748,11 @@ var dataStructureTyped = (() => {
|
|
|
10902
10748
|
* @returns the predecessor of the given RedBlackTreeNode 'x'.
|
|
10903
10749
|
*/
|
|
10904
10750
|
getPredecessor(x) {
|
|
10905
|
-
if (x.left
|
|
10751
|
+
if (this.isRealNode(x.left)) {
|
|
10906
10752
|
return this.getRightMost(x.left);
|
|
10907
10753
|
}
|
|
10908
10754
|
let y = x.parent;
|
|
10909
|
-
while (
|
|
10755
|
+
while (this.isRealNode(y) && x === y.left) {
|
|
10910
10756
|
x = y;
|
|
10911
10757
|
y = y.parent;
|
|
10912
10758
|
}
|
|
@@ -11210,6 +11056,15 @@ var dataStructureTyped = (() => {
|
|
|
11210
11056
|
isNode(exemplar) {
|
|
11211
11057
|
return exemplar instanceof TreeMultimapNode;
|
|
11212
11058
|
}
|
|
11059
|
+
/**
|
|
11060
|
+
* The function "isNotNodeInstance" checks if a potential key is a K.
|
|
11061
|
+
* @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
|
|
11062
|
+
* data type.
|
|
11063
|
+
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
11064
|
+
*/
|
|
11065
|
+
isNotNodeInstance(potentialKey) {
|
|
11066
|
+
return !(potentialKey instanceof TreeMultimapNode);
|
|
11067
|
+
}
|
|
11213
11068
|
/**
|
|
11214
11069
|
* The function `exemplarToNode` converts an exemplar object into a node object.
|
|
11215
11070
|
* @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, which means it
|