binary-tree-typed 2.5.0 → 2.5.1
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 +609 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +609 -0
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +609 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +609 -0
- package/dist/esm-legacy/index.mjs.map +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 +252 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +294 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +527 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +505 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +399 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +126 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +2881 -382
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2867 -347
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2328 -312
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +2671 -277
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +210 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +189 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +241 -10
- package/dist/types/data-structures/heap/heap.d.ts +294 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +360 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +318 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +380 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -0
- package/dist/types/data-structures/queue/deque.d.ts +319 -4
- package/dist/types/data-structures/queue/queue.d.ts +252 -0
- package/dist/types/data-structures/stack/stack.d.ts +210 -0
- package/dist/types/data-structures/trie/trie.d.ts +256 -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/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 +609 -0
- 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/data-structures/base/index.ts +1 -0
- 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 +252 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +295 -1
- package/src/data-structures/binary-tree/binary-tree.ts +527 -2
- package/src/data-structures/binary-tree/bst.ts +505 -1
- package/src/data-structures/binary-tree/red-black-tree.ts +399 -0
- package/src/data-structures/binary-tree/segment-tree.ts +127 -2
- package/src/data-structures/binary-tree/tree-map.ts +2958 -459
- package/src/data-structures/binary-tree/tree-multi-map.ts +3069 -549
- package/src/data-structures/binary-tree/tree-multi-set.ts +2476 -460
- package/src/data-structures/binary-tree/tree-set.ts +2816 -422
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +210 -0
- package/src/data-structures/graph/undirected-graph.ts +189 -0
- package/src/data-structures/hash/hash-map.ts +246 -15
- package/src/data-structures/heap/heap.ts +294 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +360 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +318 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +380 -2
- package/src/data-structures/matrix/matrix.ts +169 -1
- package/src/data-structures/queue/deque.ts +320 -5
- package/src/data-structures/queue/queue.ts +252 -0
- package/src/data-structures/stack/stack.ts +210 -0
- package/src/data-structures/trie/trie.ts +257 -5
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- 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.1",
|
|
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.1"
|
|
182
182
|
}
|
|
183
183
|
}
|
|
@@ -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,90 @@ 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
|
+
|
|
378
462
|
|
|
379
463
|
|
|
380
464
|
|
|
@@ -432,6 +516,69 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
432
516
|
|
|
433
517
|
|
|
434
518
|
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
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
|
+
|
|
435
582
|
|
|
436
583
|
|
|
437
584
|
|
|
@@ -492,6 +639,48 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
492
639
|
|
|
493
640
|
|
|
494
641
|
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
495
684
|
* @example
|
|
496
685
|
* // Rebalance the tree
|
|
497
686
|
* const avl = new AVLTree<number>();
|
|
@@ -561,6 +750,69 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
|
|
|
561
750
|
|
|
562
751
|
|
|
563
752
|
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
|
|
776
|
+
|
|
777
|
+
|
|
778
|
+
|
|
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
|
+
|
|
564
816
|
|
|
565
817
|
|
|
566
818
|
* @example
|
|
@@ -70,6 +70,48 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
73
115
|
* @example
|
|
74
116
|
* // Add delta at index
|
|
75
117
|
* const bit = new BinaryIndexedTree([1, 2, 3, 4, 5]);
|
|
@@ -99,6 +141,48 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
99
141
|
|
|
100
142
|
|
|
101
143
|
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
102
186
|
* @example
|
|
103
187
|
* // Set value at index
|
|
104
188
|
* const bit = new BinaryIndexedTree([1, 2, 3]);
|
|
@@ -128,6 +212,48 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
128
212
|
|
|
129
213
|
|
|
130
214
|
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
131
257
|
* @example
|
|
132
258
|
* // Get value at index
|
|
133
259
|
* const bit = new BinaryIndexedTree([1, 2, 3]);
|
|
@@ -157,6 +283,48 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
157
283
|
|
|
158
284
|
|
|
159
285
|
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
160
328
|
* @example
|
|
161
329
|
* // Prefix sum
|
|
162
330
|
* const bit = new BinaryIndexedTree([1, 2, 3, 4]);
|
|
@@ -184,6 +352,48 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
184
352
|
|
|
185
353
|
|
|
186
354
|
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
187
397
|
* @example
|
|
188
398
|
* // Range sum
|
|
189
399
|
* const bit = new BinaryIndexedTree([1, 2, 3, 4]);
|
|
@@ -219,6 +429,48 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
219
429
|
|
|
220
430
|
|
|
221
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
|
+
|
|
222
474
|
* @example
|
|
223
475
|
* // Find index with prefix sum ≥ target
|
|
224
476
|
* const bit = new BinaryIndexedTree([1, 2, 3, 4]);
|
|
@@ -248,6 +500,27 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
248
500
|
* Time: O(log n)
|
|
249
501
|
|
|
250
502
|
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
251
524
|
* @example
|
|
252
525
|
* // Find index with prefix sum > target
|
|
253
526
|
* const bit = new BinaryIndexedTree([1, 2, 3, 4]);
|
|
@@ -293,6 +566,27 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
293
566
|
* Time: O(n log n)
|
|
294
567
|
|
|
295
568
|
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
296
590
|
* @example
|
|
297
591
|
* // Convert to array
|
|
298
592
|
* const bit = new BinaryIndexedTree([1, 2, 3]);
|
|
@@ -322,7 +616,7 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
322
616
|
if (i < size) {
|
|
323
617
|
return { value: self._pointQuery(i++ + 1), done: false };
|
|
324
618
|
}
|
|
325
|
-
return { value: undefined
|
|
619
|
+
return { value: undefined, done: true } as IteratorResult<number>;
|
|
326
620
|
}
|
|
327
621
|
};
|
|
328
622
|
}
|