max-priority-queue-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/dist/cjs/index.cjs +104 -55
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +103 -54
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +104 -56
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +103 -55
- 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/binary-tree/avl-tree.d.ts +36 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
- package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
- package/dist/types/data-structures/heap/heap.d.ts +42 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
- package/dist/types/data-structures/queue/deque.d.ts +45 -0
- package/dist/types/data-structures/queue/queue.d.ts +36 -0
- package/dist/types/data-structures/stack/stack.d.ts +30 -0
- package/dist/types/data-structures/trie/trie.d.ts +36 -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/max-priority-queue-typed.js +101 -53
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js +1 -1
- package/dist/umd/max-priority-queue-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/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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import { ERR } from '../../common';
|
|
8
|
+
import { ERR, raise } from '../../common';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Binary Indexed Tree (Fenwick Tree).
|
|
@@ -44,7 +44,7 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
44
44
|
}
|
|
45
45
|
} else {
|
|
46
46
|
if (!Number.isInteger(sizeOrElements) || sizeOrElements < 0) {
|
|
47
|
-
|
|
47
|
+
raise(RangeError, ERR.invalidArgument('size must be a non-negative integer', 'BinaryIndexedTree'));
|
|
48
48
|
}
|
|
49
49
|
this._size = sizeOrElements;
|
|
50
50
|
this._tree = new Array(this._size + 1).fill(0);
|
|
@@ -105,6 +105,12 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
105
105
|
|
|
106
106
|
|
|
107
107
|
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
108
114
|
|
|
109
115
|
|
|
110
116
|
|
|
@@ -176,6 +182,12 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
176
182
|
|
|
177
183
|
|
|
178
184
|
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
179
191
|
|
|
180
192
|
|
|
181
193
|
|
|
@@ -247,6 +259,12 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
247
259
|
|
|
248
260
|
|
|
249
261
|
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
250
268
|
|
|
251
269
|
|
|
252
270
|
|
|
@@ -318,6 +336,12 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
318
336
|
|
|
319
337
|
|
|
320
338
|
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
321
345
|
|
|
322
346
|
|
|
323
347
|
|
|
@@ -387,6 +411,12 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
387
411
|
|
|
388
412
|
|
|
389
413
|
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
390
420
|
|
|
391
421
|
|
|
392
422
|
|
|
@@ -464,6 +494,12 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
464
494
|
|
|
465
495
|
|
|
466
496
|
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
467
503
|
|
|
468
504
|
|
|
469
505
|
|
|
@@ -517,6 +553,9 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
517
553
|
|
|
518
554
|
|
|
519
555
|
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
520
559
|
|
|
521
560
|
|
|
522
561
|
|
|
@@ -583,6 +622,9 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
583
622
|
|
|
584
623
|
|
|
585
624
|
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
586
628
|
|
|
587
629
|
|
|
588
630
|
|
|
@@ -665,10 +707,10 @@ export class BinaryIndexedTree implements Iterable<number> {
|
|
|
665
707
|
|
|
666
708
|
protected _checkIndex(index: number): void {
|
|
667
709
|
if (!Number.isInteger(index)) {
|
|
668
|
-
|
|
710
|
+
raise(TypeError, ERR.invalidIndex('BinaryIndexedTree'));
|
|
669
711
|
}
|
|
670
712
|
if (index < 0 || index >= this._size) {
|
|
671
|
-
|
|
713
|
+
raise(RangeError, ERR.indexOutOfRange(index, 0, this._size - 1, 'BinaryIndexedTree'));
|
|
672
714
|
}
|
|
673
715
|
}
|
|
674
716
|
|
|
@@ -28,7 +28,7 @@ import { IBinaryTree } from '../../interfaces';
|
|
|
28
28
|
import { isComparable, makeTrampoline, makeTrampolineThunk } from '../../utils';
|
|
29
29
|
import { Queue } from '../queue';
|
|
30
30
|
import { IterableEntryBase } from '../base';
|
|
31
|
-
import { DFSOperation, ERR, Range } from '../../common';
|
|
31
|
+
import { DFSOperation, ERR, raise, Range } from '../../common';
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* @template K - The type of the key.
|
|
@@ -216,7 +216,7 @@ export class BinaryTreeNode<K = any, V = any> {
|
|
|
216
216
|
* node?: BinaryTreeNode<string> | null,
|
|
217
217
|
* conditions?: { [key: string]: boolean }
|
|
218
218
|
* ): string {
|
|
219
|
-
* if (!node)
|
|
219
|
+
* if (!node) raise(Error, 'Invalid node');
|
|
220
220
|
*
|
|
221
221
|
* // If it's a leaf node, return the decision result
|
|
222
222
|
* if (!node.left && !node.right) return node.key;
|
|
@@ -261,7 +261,7 @@ export class BinaryTreeNode<K = any, V = any> {
|
|
|
261
261
|
* case '/':
|
|
262
262
|
* return rightValue !== 0 ? leftValue / rightValue : 0; // Handle division by zero
|
|
263
263
|
* default:
|
|
264
|
-
*
|
|
264
|
+
* raise(Error, `Unsupported operator: ${node.key}`);
|
|
265
265
|
* }
|
|
266
266
|
* }
|
|
267
267
|
*
|
|
@@ -293,7 +293,7 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
293
293
|
if (isMapMode !== undefined) this._isMapMode = isMapMode;
|
|
294
294
|
if (isDuplicate !== undefined) this._isDuplicate = isDuplicate;
|
|
295
295
|
if (typeof toEntryFn === 'function') this._toEntryFn = toEntryFn;
|
|
296
|
-
else if (toEntryFn)
|
|
296
|
+
else if (toEntryFn) raise(TypeError, ERR.notAFunction('toEntryFn', 'BinaryTree'));
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
|
|
@@ -589,6 +589,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
589
589
|
|
|
590
590
|
|
|
591
591
|
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
592
595
|
|
|
593
596
|
|
|
594
597
|
|
|
@@ -643,6 +646,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
643
646
|
|
|
644
647
|
|
|
645
648
|
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
|
|
646
652
|
|
|
647
653
|
|
|
648
654
|
|
|
@@ -759,6 +765,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
759
765
|
|
|
760
766
|
|
|
761
767
|
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
762
771
|
|
|
763
772
|
|
|
764
773
|
|
|
@@ -803,6 +812,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
803
812
|
|
|
804
813
|
|
|
805
814
|
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
|
|
806
818
|
|
|
807
819
|
|
|
808
820
|
|
|
@@ -873,6 +885,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
873
885
|
|
|
874
886
|
|
|
875
887
|
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
|
|
876
891
|
|
|
877
892
|
|
|
878
893
|
|
|
@@ -939,6 +954,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
939
954
|
|
|
940
955
|
|
|
941
956
|
|
|
957
|
+
|
|
958
|
+
|
|
959
|
+
|
|
942
960
|
|
|
943
961
|
|
|
944
962
|
|
|
@@ -1035,6 +1053,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1035
1053
|
|
|
1036
1054
|
|
|
1037
1055
|
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1038
1059
|
|
|
1039
1060
|
|
|
1040
1061
|
|
|
@@ -1168,6 +1189,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1168
1189
|
|
|
1169
1190
|
|
|
1170
1191
|
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
|
|
1171
1195
|
|
|
1172
1196
|
|
|
1173
1197
|
|
|
@@ -1240,6 +1264,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1240
1264
|
|
|
1241
1265
|
|
|
1242
1266
|
|
|
1267
|
+
|
|
1268
|
+
|
|
1269
|
+
|
|
1243
1270
|
|
|
1244
1271
|
|
|
1245
1272
|
|
|
@@ -1306,6 +1333,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1306
1333
|
|
|
1307
1334
|
|
|
1308
1335
|
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
|
|
1309
1339
|
|
|
1310
1340
|
|
|
1311
1341
|
|
|
@@ -1365,6 +1395,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1365
1395
|
|
|
1366
1396
|
|
|
1367
1397
|
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
|
|
1368
1401
|
|
|
1369
1402
|
|
|
1370
1403
|
|
|
@@ -1460,6 +1493,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1460
1493
|
|
|
1461
1494
|
|
|
1462
1495
|
|
|
1496
|
+
|
|
1497
|
+
|
|
1498
|
+
|
|
1463
1499
|
|
|
1464
1500
|
|
|
1465
1501
|
|
|
@@ -1506,6 +1542,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1506
1542
|
|
|
1507
1543
|
|
|
1508
1544
|
|
|
1545
|
+
|
|
1546
|
+
|
|
1547
|
+
|
|
1509
1548
|
|
|
1510
1549
|
|
|
1511
1550
|
|
|
@@ -1564,6 +1603,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1564
1603
|
|
|
1565
1604
|
|
|
1566
1605
|
|
|
1606
|
+
|
|
1607
|
+
|
|
1608
|
+
|
|
1567
1609
|
|
|
1568
1610
|
|
|
1569
1611
|
|
|
@@ -1652,6 +1694,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1652
1694
|
|
|
1653
1695
|
|
|
1654
1696
|
|
|
1697
|
+
|
|
1698
|
+
|
|
1699
|
+
|
|
1655
1700
|
|
|
1656
1701
|
|
|
1657
1702
|
|
|
@@ -1714,6 +1759,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
1714
1759
|
|
|
1715
1760
|
|
|
1716
1761
|
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
|
|
1717
1765
|
|
|
1718
1766
|
|
|
1719
1767
|
|
|
@@ -2017,6 +2065,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2017
2065
|
|
|
2018
2066
|
|
|
2019
2067
|
|
|
2068
|
+
|
|
2069
|
+
|
|
2070
|
+
|
|
2020
2071
|
|
|
2021
2072
|
|
|
2022
2073
|
|
|
@@ -2102,6 +2153,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2102
2153
|
|
|
2103
2154
|
|
|
2104
2155
|
|
|
2156
|
+
|
|
2157
|
+
|
|
2158
|
+
|
|
2105
2159
|
|
|
2106
2160
|
|
|
2107
2161
|
|
|
@@ -2246,6 +2300,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2246
2300
|
|
|
2247
2301
|
|
|
2248
2302
|
|
|
2303
|
+
|
|
2304
|
+
|
|
2305
|
+
|
|
2249
2306
|
|
|
2250
2307
|
|
|
2251
2308
|
|
|
@@ -2343,6 +2400,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2343
2400
|
|
|
2344
2401
|
|
|
2345
2402
|
|
|
2403
|
+
|
|
2404
|
+
|
|
2405
|
+
|
|
2346
2406
|
|
|
2347
2407
|
|
|
2348
2408
|
|
|
@@ -2458,6 +2518,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2458
2518
|
|
|
2459
2519
|
|
|
2460
2520
|
|
|
2521
|
+
|
|
2522
|
+
|
|
2523
|
+
|
|
2461
2524
|
|
|
2462
2525
|
|
|
2463
2526
|
|
|
@@ -2617,6 +2680,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2617
2680
|
|
|
2618
2681
|
|
|
2619
2682
|
|
|
2683
|
+
|
|
2684
|
+
|
|
2685
|
+
|
|
2620
2686
|
|
|
2621
2687
|
|
|
2622
2688
|
|
|
@@ -2667,6 +2733,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2667
2733
|
|
|
2668
2734
|
|
|
2669
2735
|
|
|
2736
|
+
|
|
2737
|
+
|
|
2738
|
+
|
|
2670
2739
|
|
|
2671
2740
|
|
|
2672
2741
|
|
|
@@ -2721,6 +2790,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2721
2790
|
|
|
2722
2791
|
|
|
2723
2792
|
|
|
2793
|
+
|
|
2794
|
+
|
|
2795
|
+
|
|
2724
2796
|
|
|
2725
2797
|
|
|
2726
2798
|
|
|
@@ -2808,6 +2880,9 @@ export class BinaryTree<K = any, V = any, R = any>
|
|
|
2808
2880
|
|
|
2809
2881
|
|
|
2810
2882
|
|
|
2883
|
+
|
|
2884
|
+
|
|
2885
|
+
|
|
2811
2886
|
|
|
2812
2887
|
|
|
2813
2888
|
|