binary-tree-typed 2.5.0 → 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/dist/cjs/index.cjs +771 -68
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +771 -68
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +771 -69
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +771 -69
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- 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/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/binary-tree-typed.js +773 -71
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +5 -5
- package/dist/umd/binary-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +299 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
- package/src/data-structures/binary-tree/binary-tree.ts +606 -6
- package/src/data-structures/binary-tree/bst.ts +946 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
- package/src/data-structures/binary-tree/segment-tree.ts +145 -2
- package/src/data-structures/binary-tree/tree-map.ts +3423 -499
- package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
- package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
- package/src/data-structures/binary-tree/tree-set.ts +3209 -413
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +240 -0
- package/src/data-structures/graph/undirected-graph.ts +216 -0
- package/src/data-structures/hash/hash-map.ts +281 -19
- package/src/data-structures/heap/heap.ts +340 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
- package/src/data-structures/matrix/matrix.ts +202 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +365 -5
- package/src/data-structures/queue/queue.ts +288 -0
- package/src/data-structures/stack/stack.ts +240 -0
- package/src/data-structures/trie/trie.ts +295 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -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
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "binary-tree-typed",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.2",
|
|
4
4
|
"description": "Binary Tree. Javascript & Typescript Data Structure.",
|
|
5
5
|
"browser": "dist/umd/binary-tree-typed.min.js",
|
|
6
6
|
"umd:main": "dist/umd/binary-tree-typed.min.js",
|
|
@@ -178,6 +178,6 @@
|
|
|
178
178
|
"typescript": "^4.9.5"
|
|
179
179
|
},
|
|
180
180
|
"dependencies": {
|
|
181
|
-
"data-structure-typed": "^2.5.
|
|
181
|
+
"data-structure-typed": "^2.5.2"
|
|
182
182
|
}
|
|
183
183
|
}
|
package/src/common/error.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized error dispatch.
|
|
3
|
+
* All library errors go through this function for consistent messaging and easy grep.
|
|
4
|
+
* @remarks Always throws — data structure errors are never recoverable.
|
|
5
|
+
* @param ErrorClass - The error constructor (Error, TypeError, RangeError, etc.)
|
|
6
|
+
* @param message - The error message.
|
|
7
|
+
*/
|
|
8
|
+
export function raise(
|
|
9
|
+
ErrorClass: new (msg: string) => Error,
|
|
10
|
+
message: string
|
|
11
|
+
): never {
|
|
12
|
+
throw new ErrorClass(message);
|
|
13
|
+
}
|
|
14
|
+
|
|
1
15
|
/**
|
|
2
16
|
* Centralized error message templates.
|
|
3
17
|
* Keep using native Error/TypeError/RangeError — this only standardizes messages.
|
|
@@ -56,5 +70,9 @@ export const ERR = {
|
|
|
56
70
|
'Matrix: Must be rectangular for transposition.',
|
|
57
71
|
|
|
58
72
|
matrixRowMismatch: (expected: number, got: number) =>
|
|
59
|
-
`Matrix: Expected row length ${expected}, but got ${got}
|
|
73
|
+
`Matrix: Expected row length ${expected}, but got ${got}.`,
|
|
74
|
+
|
|
75
|
+
// Order statistic
|
|
76
|
+
orderStatisticNotEnabled: (method: string, ctx?: string) =>
|
|
77
|
+
`${ctx ? ctx + ': ' : ''}${method}() requires enableOrderStatistic: true.`
|
|
60
78
|
} as const;
|
package/src/common/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
|
|
2
|
+
import { raise } from '../../common';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Base class that makes a data structure iterable and provides common
|
|
@@ -25,7 +26,7 @@ export abstract class IterableElementBase<E, R> implements Iterable<E> {
|
|
|
25
26
|
if (options) {
|
|
26
27
|
const { toElementFn } = options;
|
|
27
28
|
if (typeof toElementFn === 'function') this._toElementFn = toElementFn;
|
|
28
|
-
else if (toElementFn)
|
|
29
|
+
else if (toElementFn) raise(TypeError, 'toElementFn must be a function type');
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -224,7 +225,7 @@ export abstract class IterableElementBase<E, R> implements Iterable<E> {
|
|
|
224
225
|
acc = initialValue as U;
|
|
225
226
|
} else {
|
|
226
227
|
const first = iter.next();
|
|
227
|
-
if (first.done)
|
|
228
|
+
if (first.done) raise(TypeError, 'Reduce of empty structure with no initial value');
|
|
228
229
|
acc = first.value as unknown as U;
|
|
229
230
|
index = 1;
|
|
230
231
|
}
|
|
@@ -19,7 +19,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
19
19
|
* @returns Iterator of `[K, V]`.
|
|
20
20
|
* @remarks Time O(n) to iterate, Space O(1)
|
|
21
21
|
*/
|
|
22
|
-
*[Symbol.iterator](...args:
|
|
22
|
+
*[Symbol.iterator](...args: unknown[]): IterableIterator<[K, V]> {
|
|
23
23
|
yield* this._getIterator(...args);
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -63,7 +63,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
63
63
|
* @returns `true` if all pass; otherwise `false`.
|
|
64
64
|
* @remarks Time O(n), Space O(1)
|
|
65
65
|
*/
|
|
66
|
-
every(predicate: EntryCallback<K, V, boolean>, thisArg?:
|
|
66
|
+
every(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): boolean {
|
|
67
67
|
let index = 0;
|
|
68
68
|
for (const item of this) {
|
|
69
69
|
if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
@@ -80,7 +80,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
80
80
|
* @returns `true` if any passes; otherwise `false`.
|
|
81
81
|
* @remarks Time O(n), Space O(1)
|
|
82
82
|
*/
|
|
83
|
-
some(predicate: EntryCallback<K, V, boolean>, thisArg?:
|
|
83
|
+
some(predicate: EntryCallback<K, V, boolean>, thisArg?: unknown): boolean {
|
|
84
84
|
let index = 0;
|
|
85
85
|
for (const item of this) {
|
|
86
86
|
if (predicate.call(thisArg, item[1], item[0], index++, this)) {
|
|
@@ -96,7 +96,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
96
96
|
* @param thisArg - Optional `this` for callback.
|
|
97
97
|
* @remarks Time O(n), Space O(1)
|
|
98
98
|
*/
|
|
99
|
-
forEach(callbackfn: EntryCallback<K, V, void>, thisArg?:
|
|
99
|
+
forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: unknown): void {
|
|
100
100
|
let index = 0;
|
|
101
101
|
for (const item of this) {
|
|
102
102
|
const [key, value] = item;
|
|
@@ -111,7 +111,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
111
111
|
* @returns Matching `[key, value]` or `undefined`.
|
|
112
112
|
* @remarks Time O(n), Space O(1)
|
|
113
113
|
*/
|
|
114
|
-
find(callbackfn: EntryCallback<K, V, boolean>, thisArg?:
|
|
114
|
+
find(callbackfn: EntryCallback<K, V, boolean>, thisArg?: unknown): [K, V] | undefined {
|
|
115
115
|
let index = 0;
|
|
116
116
|
for (const item of this) {
|
|
117
117
|
const [key, value] = item;
|
|
@@ -228,19 +228,19 @@ export abstract class IterableEntryBase<K = any, V = any> {
|
|
|
228
228
|
* Map entries using an implementation-specific strategy.
|
|
229
229
|
* @remarks Time O(n), Space O(n)
|
|
230
230
|
*/
|
|
231
|
-
abstract map(...args:
|
|
231
|
+
abstract map(...args: unknown[]): unknown;
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
234
|
* Filter entries and return the same-species structure.
|
|
235
235
|
* @returns A new instance of the same concrete class (`this` type).
|
|
236
236
|
* @remarks Time O(n), Space O(n)
|
|
237
237
|
*/
|
|
238
|
-
abstract filter(...args:
|
|
238
|
+
abstract filter(...args: unknown[]): this;
|
|
239
239
|
|
|
240
240
|
/**
|
|
241
241
|
* Underlying iterator for the default iteration protocol.
|
|
242
242
|
* @returns Iterator of `[K, V]`.
|
|
243
243
|
* @remarks Time O(n), Space O(1)
|
|
244
244
|
*/
|
|
245
|
-
protected abstract _getIterator(...args:
|
|
245
|
+
protected abstract _getIterator(...args: unknown[]): IterableIterator<[K, V]>;
|
|
246
246
|
}
|
|
@@ -148,7 +148,7 @@ export abstract class LinearBase<
|
|
|
148
148
|
* @returns Index or `-1`.
|
|
149
149
|
* @remarks Time O(n), Space O(1)
|
|
150
150
|
*/
|
|
151
|
-
findIndex(predicate: ElementCallback<E, R, boolean>, thisArg?:
|
|
151
|
+
findIndex(predicate: ElementCallback<E, R, boolean>, thisArg?: unknown): number {
|
|
152
152
|
for (let i = 0; i < this.length; i++) {
|
|
153
153
|
const item = this.at(i);
|
|
154
154
|
if (item !== undefined && predicate.call(thisArg, item, i, this)) return i;
|
|
@@ -389,7 +389,7 @@ export abstract class LinearBase<
|
|
|
389
389
|
* @returns Iterator of elements from tail to head.
|
|
390
390
|
* @remarks Time O(n), Space O(1)
|
|
391
391
|
*/
|
|
392
|
-
protected abstract _getReverseIterator(...args:
|
|
392
|
+
protected abstract _getReverseIterator(...args: unknown[]): IterableIterator<E>;
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
/**
|
|
@@ -621,7 +621,7 @@ export abstract class LinearLinkedBase<
|
|
|
621
621
|
* @returns Iterator over nodes.
|
|
622
622
|
* @remarks Time O(n), Space O(1)
|
|
623
623
|
*/
|
|
624
|
-
protected abstract _getNodeIterator(...args:
|
|
624
|
+
protected abstract _getNodeIterator(...args: unknown[]): IterableIterator<NODE>;
|
|
625
625
|
|
|
626
626
|
/**
|
|
627
627
|
* Get previous node of a given node.
|
|
@@ -375,6 +375,102 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
375
375
|
|
|
376
376
|
|
|
377
377
|
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
378
474
|
|
|
379
475
|
|
|
380
476
|
|
|
@@ -432,6 +528,78 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
432
528
|
|
|
433
529
|
|
|
434
530
|
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
435
603
|
|
|
436
604
|
|
|
437
605
|
|
|
@@ -492,6 +660,54 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
492
660
|
|
|
493
661
|
|
|
494
662
|
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
|
|
495
711
|
* @example
|
|
496
712
|
* // Rebalance the tree
|
|
497
713
|
* const avl = new AVLTree<number>();
|
|
@@ -561,6 +777,78 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
561
777
|
|
|
562
778
|
|
|
563
779
|
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
564
852
|
|
|
565
853
|
|
|
566
854
|
* @example
|
|
@@ -718,6 +1006,8 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
718
1006
|
}
|
|
719
1007
|
this._updateHeight(A);
|
|
720
1008
|
if (B) this._updateHeight(B);
|
|
1009
|
+
this._updateCount(A);
|
|
1010
|
+
if (B) this._updateCount(B);
|
|
721
1011
|
}
|
|
722
1012
|
|
|
723
1013
|
/**
|
|
@@ -770,6 +1060,9 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
770
1060
|
this._updateHeight(A);
|
|
771
1061
|
if (B) this._updateHeight(B);
|
|
772
1062
|
if (C) this._updateHeight(C);
|
|
1063
|
+
this._updateCount(A);
|
|
1064
|
+
if (B) this._updateCount(B);
|
|
1065
|
+
if (C) this._updateCount(C);
|
|
773
1066
|
}
|
|
774
1067
|
|
|
775
1068
|
/**
|
|
@@ -809,6 +1102,8 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
809
1102
|
}
|
|
810
1103
|
this._updateHeight(A);
|
|
811
1104
|
if (B) this._updateHeight(B);
|
|
1105
|
+
this._updateCount(A);
|
|
1106
|
+
if (B) this._updateCount(B);
|
|
812
1107
|
}
|
|
813
1108
|
|
|
814
1109
|
/**
|
|
@@ -860,6 +1155,9 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
860
1155
|
this._updateHeight(A);
|
|
861
1156
|
if (B) this._updateHeight(B);
|
|
862
1157
|
if (C) this._updateHeight(C);
|
|
1158
|
+
this._updateCount(A);
|
|
1159
|
+
if (B) this._updateCount(B);
|
|
1160
|
+
if (C) this._updateCount(C);
|
|
863
1161
|
}
|
|
864
1162
|
|
|
865
1163
|
/**
|
|
@@ -878,6 +1176,7 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
878
1176
|
const A = path[i];
|
|
879
1177
|
if (A) {
|
|
880
1178
|
this._updateHeight(A);
|
|
1179
|
+
this._updateCount(A);
|
|
881
1180
|
|
|
882
1181
|
// Check the balance factor
|
|
883
1182
|
switch (this._balanceFactor(A)) {
|