binary-tree-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 +146 -52
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +145 -51
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +146 -53
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +145 -52
- 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/binary-tree-typed.js +143 -50
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +3 -3
- 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/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
|
@@ -324,6 +324,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
324
324
|
|
|
325
325
|
|
|
326
326
|
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
327
330
|
|
|
328
331
|
|
|
329
332
|
|
|
@@ -390,6 +393,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
390
393
|
|
|
391
394
|
|
|
392
395
|
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
393
399
|
|
|
394
400
|
|
|
395
401
|
|
|
@@ -461,6 +467,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
461
467
|
|
|
462
468
|
|
|
463
469
|
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
464
473
|
|
|
465
474
|
|
|
466
475
|
|
|
@@ -514,6 +523,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
514
523
|
|
|
515
524
|
|
|
516
525
|
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
517
529
|
|
|
518
530
|
|
|
519
531
|
|
|
@@ -636,6 +648,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
636
648
|
|
|
637
649
|
|
|
638
650
|
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
639
654
|
|
|
640
655
|
|
|
641
656
|
|
|
@@ -698,6 +713,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
698
713
|
|
|
699
714
|
|
|
700
715
|
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
701
719
|
|
|
702
720
|
|
|
703
721
|
|
|
@@ -745,6 +763,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
745
763
|
|
|
746
764
|
|
|
747
765
|
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
748
769
|
|
|
749
770
|
|
|
750
771
|
|
|
@@ -798,6 +819,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
798
819
|
|
|
799
820
|
|
|
800
821
|
|
|
822
|
+
|
|
823
|
+
|
|
824
|
+
|
|
801
825
|
|
|
802
826
|
|
|
803
827
|
|
|
@@ -857,6 +881,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
857
881
|
|
|
858
882
|
|
|
859
883
|
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
860
887
|
|
|
861
888
|
|
|
862
889
|
|
|
@@ -925,6 +952,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
925
952
|
|
|
926
953
|
|
|
927
954
|
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
928
958
|
|
|
929
959
|
|
|
930
960
|
|
|
@@ -968,6 +998,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
968
998
|
|
|
969
999
|
|
|
970
1000
|
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
|
|
971
1004
|
|
|
972
1005
|
|
|
973
1006
|
|
|
@@ -1017,6 +1050,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
1017
1050
|
|
|
1018
1051
|
|
|
1019
1052
|
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
|
|
1020
1056
|
|
|
1021
1057
|
|
|
1022
1058
|
|
|
@@ -1260,6 +1296,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
1260
1296
|
|
|
1261
1297
|
|
|
1262
1298
|
|
|
1299
|
+
|
|
1300
|
+
|
|
1301
|
+
|
|
1263
1302
|
|
|
1264
1303
|
|
|
1265
1304
|
|
|
@@ -1313,6 +1352,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
1313
1352
|
|
|
1314
1353
|
|
|
1315
1354
|
|
|
1355
|
+
|
|
1356
|
+
|
|
1357
|
+
|
|
1316
1358
|
|
|
1317
1359
|
|
|
1318
1360
|
|
|
@@ -1396,6 +1438,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
|
|
|
1396
1438
|
|
|
1397
1439
|
|
|
1398
1440
|
|
|
1441
|
+
|
|
1442
|
+
|
|
1443
|
+
|
|
1399
1444
|
|
|
1400
1445
|
|
|
1401
1446
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { Comparator, EntryCallback } from '../../types';
|
|
10
|
-
import { ERR } from '../../common';
|
|
10
|
+
import { ERR, raise } from '../../common';
|
|
11
11
|
import { IterableEntryBase } from '../base';
|
|
12
12
|
|
|
13
13
|
export class SkipListNode<K, V> {
|
|
@@ -72,7 +72,7 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
72
72
|
[k, v] = toEntryFn(item as R);
|
|
73
73
|
} else {
|
|
74
74
|
if (!Array.isArray(item) || item.length < 2) {
|
|
75
|
-
|
|
75
|
+
raise(TypeError, ERR.invalidEntry('SkipList'));
|
|
76
76
|
}
|
|
77
77
|
[k, v] = item as [K, V];
|
|
78
78
|
}
|
|
@@ -86,7 +86,7 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
86
86
|
static createDefaultComparator<K>(): Comparator<K> {
|
|
87
87
|
return (a: K, b: K): number => {
|
|
88
88
|
if (typeof a === 'number' && typeof b === 'number') {
|
|
89
|
-
if (Number.isNaN(a) || Number.isNaN(b))
|
|
89
|
+
if (Number.isNaN(a) || Number.isNaN(b)) raise(TypeError, ERR.invalidNaN('SkipList'));
|
|
90
90
|
return a - b;
|
|
91
91
|
}
|
|
92
92
|
if (typeof a === 'string' && typeof b === 'string') {
|
|
@@ -95,13 +95,13 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
95
95
|
if (a instanceof Date && b instanceof Date) {
|
|
96
96
|
const ta = a.getTime(),
|
|
97
97
|
tb = b.getTime();
|
|
98
|
-
if (Number.isNaN(ta) || Number.isNaN(tb))
|
|
98
|
+
if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate('SkipList'));
|
|
99
99
|
return ta - tb;
|
|
100
100
|
}
|
|
101
101
|
if (typeof a === 'bigint' && typeof b === 'bigint') {
|
|
102
102
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
raise(TypeError, ERR.comparatorRequired('SkipList'));
|
|
105
105
|
};
|
|
106
106
|
}
|
|
107
107
|
|
|
@@ -162,6 +162,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
162
162
|
|
|
163
163
|
|
|
164
164
|
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
165
168
|
|
|
166
169
|
|
|
167
170
|
|
|
@@ -202,6 +205,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
202
205
|
|
|
203
206
|
|
|
204
207
|
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
205
211
|
|
|
206
212
|
|
|
207
213
|
|
|
@@ -245,6 +251,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
245
251
|
|
|
246
252
|
|
|
247
253
|
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
248
257
|
|
|
249
258
|
|
|
250
259
|
|
|
@@ -297,6 +306,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
297
306
|
|
|
298
307
|
|
|
299
308
|
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
300
312
|
|
|
301
313
|
|
|
302
314
|
|
|
@@ -379,6 +391,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
379
391
|
|
|
380
392
|
|
|
381
393
|
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
|
|
382
397
|
|
|
383
398
|
|
|
384
399
|
|
|
@@ -440,6 +455,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
440
455
|
|
|
441
456
|
|
|
442
457
|
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
443
461
|
|
|
444
462
|
|
|
445
463
|
|
|
@@ -484,6 +502,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
484
502
|
|
|
485
503
|
|
|
486
504
|
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
487
508
|
|
|
488
509
|
|
|
489
510
|
|
|
@@ -553,6 +574,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
553
574
|
|
|
554
575
|
|
|
555
576
|
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
556
580
|
|
|
557
581
|
|
|
558
582
|
|
|
@@ -597,6 +621,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
597
621
|
|
|
598
622
|
|
|
599
623
|
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
600
627
|
|
|
601
628
|
|
|
602
629
|
|
|
@@ -643,6 +670,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
643
670
|
|
|
644
671
|
|
|
645
672
|
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
646
676
|
|
|
647
677
|
|
|
648
678
|
|
|
@@ -687,6 +717,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
687
717
|
|
|
688
718
|
|
|
689
719
|
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
690
723
|
|
|
691
724
|
|
|
692
725
|
|
|
@@ -734,6 +767,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
734
767
|
|
|
735
768
|
|
|
736
769
|
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
|
|
737
773
|
|
|
738
774
|
|
|
739
775
|
|
|
@@ -786,6 +822,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
786
822
|
|
|
787
823
|
|
|
788
824
|
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
|
|
789
828
|
|
|
790
829
|
|
|
791
830
|
|
|
@@ -838,6 +877,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
838
877
|
|
|
839
878
|
|
|
840
879
|
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
|
|
841
883
|
|
|
842
884
|
|
|
843
885
|
|
|
@@ -887,6 +929,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
887
929
|
|
|
888
930
|
|
|
889
931
|
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
890
935
|
|
|
891
936
|
|
|
892
937
|
|
|
@@ -942,6 +987,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
942
987
|
|
|
943
988
|
|
|
944
989
|
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
945
993
|
|
|
946
994
|
|
|
947
995
|
|
|
@@ -1012,6 +1060,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
1012
1060
|
|
|
1013
1061
|
|
|
1014
1062
|
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
|
|
1015
1066
|
|
|
1016
1067
|
|
|
1017
1068
|
|
|
@@ -1062,6 +1113,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
|
|
|
1062
1113
|
|
|
1063
1114
|
|
|
1064
1115
|
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1065
1119
|
|
|
1066
1120
|
|
|
1067
1121
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { MatrixOptions } from '../../types';
|
|
9
|
-
import { ERR } from '../../common';
|
|
9
|
+
import { ERR, raise } from '../../common';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
*
|
|
@@ -217,6 +217,9 @@ export class Matrix {
|
|
|
217
217
|
|
|
218
218
|
|
|
219
219
|
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
220
223
|
|
|
221
224
|
|
|
222
225
|
|
|
@@ -283,6 +286,9 @@ export class Matrix {
|
|
|
283
286
|
|
|
284
287
|
|
|
285
288
|
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
286
292
|
|
|
287
293
|
|
|
288
294
|
|
|
@@ -346,6 +352,9 @@ export class Matrix {
|
|
|
346
352
|
|
|
347
353
|
|
|
348
354
|
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
349
358
|
|
|
350
359
|
|
|
351
360
|
|
|
@@ -375,7 +384,7 @@ export class Matrix {
|
|
|
375
384
|
*/
|
|
376
385
|
add(matrix: Matrix): Matrix | undefined {
|
|
377
386
|
if (!this.isMatchForCalculate(matrix)) {
|
|
378
|
-
|
|
387
|
+
raise(Error, ERR.matrixDimensionMismatch('addition'));
|
|
379
388
|
}
|
|
380
389
|
|
|
381
390
|
const resultData: number[][] = [];
|
|
@@ -433,6 +442,9 @@ export class Matrix {
|
|
|
433
442
|
|
|
434
443
|
|
|
435
444
|
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
436
448
|
|
|
437
449
|
|
|
438
450
|
|
|
@@ -446,7 +458,7 @@ export class Matrix {
|
|
|
446
458
|
*/
|
|
447
459
|
subtract(matrix: Matrix): Matrix | undefined {
|
|
448
460
|
if (!this.isMatchForCalculate(matrix)) {
|
|
449
|
-
|
|
461
|
+
raise(Error, ERR.matrixDimensionMismatch('subtraction'));
|
|
450
462
|
}
|
|
451
463
|
|
|
452
464
|
const resultData: number[][] = [];
|
|
@@ -503,6 +515,9 @@ export class Matrix {
|
|
|
503
515
|
|
|
504
516
|
|
|
505
517
|
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
506
521
|
|
|
507
522
|
|
|
508
523
|
|
|
@@ -532,7 +547,7 @@ export class Matrix {
|
|
|
532
547
|
*/
|
|
533
548
|
multiply(matrix: Matrix): Matrix | undefined {
|
|
534
549
|
if (this.cols !== matrix.rows) {
|
|
535
|
-
|
|
550
|
+
raise(Error, ERR.matrixDimensionMismatch('multiplication (A.cols must equal B.rows)'));
|
|
536
551
|
}
|
|
537
552
|
|
|
538
553
|
const resultData: number[][] = [];
|
|
@@ -595,6 +610,9 @@ export class Matrix {
|
|
|
595
610
|
|
|
596
611
|
|
|
597
612
|
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
598
616
|
|
|
599
617
|
|
|
600
618
|
|
|
@@ -621,7 +639,7 @@ export class Matrix {
|
|
|
621
639
|
*/
|
|
622
640
|
transpose(): Matrix {
|
|
623
641
|
if (this.data.some(row => row.length !== this.cols)) {
|
|
624
|
-
|
|
642
|
+
raise(Error, ERR.matrixNotRectangular());
|
|
625
643
|
}
|
|
626
644
|
|
|
627
645
|
const resultData: number[][] = [];
|
|
@@ -674,6 +692,9 @@ export class Matrix {
|
|
|
674
692
|
|
|
675
693
|
|
|
676
694
|
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
677
698
|
|
|
678
699
|
|
|
679
700
|
|
|
@@ -693,7 +714,7 @@ export class Matrix {
|
|
|
693
714
|
inverse(): Matrix | undefined {
|
|
694
715
|
// Check if the matrix is square
|
|
695
716
|
if (this.rows !== this.cols) {
|
|
696
|
-
|
|
717
|
+
raise(Error, ERR.matrixNotSquare());
|
|
697
718
|
}
|
|
698
719
|
|
|
699
720
|
// Create an augmented matrix [this | I]
|
|
@@ -723,7 +744,7 @@ export class Matrix {
|
|
|
723
744
|
|
|
724
745
|
if (pivotRow === this.rows) {
|
|
725
746
|
// Matrix is singular, and its inverse does not exist
|
|
726
|
-
|
|
747
|
+
raise(Error, ERR.matrixSingular());
|
|
727
748
|
}
|
|
728
749
|
|
|
729
750
|
// Swap rows to make the pivot the current row
|
|
@@ -734,7 +755,7 @@ export class Matrix {
|
|
|
734
755
|
|
|
735
756
|
if (pivotElement === 0) {
|
|
736
757
|
// Handle division by zero
|
|
737
|
-
|
|
758
|
+
raise(Error, ERR.matrixSingular());
|
|
738
759
|
}
|
|
739
760
|
|
|
740
761
|
augmentedMatrix._scaleRow(i, 1 / pivotElement);
|
|
@@ -797,6 +818,9 @@ export class Matrix {
|
|
|
797
818
|
|
|
798
819
|
|
|
799
820
|
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
|
|
800
824
|
|
|
801
825
|
|
|
802
826
|
|
|
@@ -810,7 +834,7 @@ export class Matrix {
|
|
|
810
834
|
*/
|
|
811
835
|
dot(matrix: Matrix): Matrix | undefined {
|
|
812
836
|
if (this.cols !== matrix.rows) {
|
|
813
|
-
|
|
837
|
+
raise(Error, ERR.matrixDimensionMismatch('dot product (A.cols must equal B.rows)'));
|
|
814
838
|
}
|
|
815
839
|
|
|
816
840
|
const resultData: number[][] = [];
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { PriorityQueueOptions } from '../../types';
|
|
9
9
|
import { PriorityQueue } from './priority-queue';
|
|
10
|
-
import { ERR } from '../../common';
|
|
10
|
+
import { ERR, raise } from '../../common';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Max-oriented priority queue (max-heap) built on {@link PriorityQueue}.
|
|
@@ -86,7 +86,7 @@ export class MaxPriorityQueue<E = any, R = any> extends PriorityQueue<E, R> {
|
|
|
86
86
|
super(elements, {
|
|
87
87
|
comparator: (a: E, b: E): number => {
|
|
88
88
|
if (typeof a === 'object' || typeof b === 'object') {
|
|
89
|
-
|
|
89
|
+
raise(TypeError, ERR.comparatorRequired('MaxPriorityQueue'));
|
|
90
90
|
}
|
|
91
91
|
if (a < b) return 1;
|
|
92
92
|
if (a > b) return -1;
|
|
@@ -277,6 +277,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
277
277
|
|
|
278
278
|
|
|
279
279
|
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
280
283
|
|
|
281
284
|
|
|
282
285
|
|
|
@@ -334,6 +337,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
334
337
|
|
|
335
338
|
|
|
336
339
|
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
337
343
|
|
|
338
344
|
|
|
339
345
|
|
|
@@ -405,6 +411,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
405
411
|
|
|
406
412
|
|
|
407
413
|
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
408
417
|
|
|
409
418
|
|
|
410
419
|
|
|
@@ -480,6 +489,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
480
489
|
|
|
481
490
|
|
|
482
491
|
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
483
495
|
|
|
484
496
|
|
|
485
497
|
|
|
@@ -542,6 +554,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
542
554
|
|
|
543
555
|
|
|
544
556
|
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
545
560
|
|
|
546
561
|
|
|
547
562
|
|
|
@@ -605,6 +620,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
605
620
|
|
|
606
621
|
|
|
607
622
|
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
608
626
|
|
|
609
627
|
|
|
610
628
|
|
|
@@ -713,6 +731,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
713
731
|
|
|
714
732
|
|
|
715
733
|
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
|
|
716
737
|
|
|
717
738
|
|
|
718
739
|
|
|
@@ -757,6 +778,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
757
778
|
|
|
758
779
|
|
|
759
780
|
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
|
|
760
784
|
|
|
761
785
|
|
|
762
786
|
|
|
@@ -805,6 +829,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
805
829
|
|
|
806
830
|
|
|
807
831
|
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
|
|
808
835
|
|
|
809
836
|
|
|
810
837
|
|
|
@@ -1026,6 +1053,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
1026
1053
|
|
|
1027
1054
|
|
|
1028
1055
|
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1029
1059
|
|
|
1030
1060
|
|
|
1031
1061
|
|
|
@@ -1116,6 +1146,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
1116
1146
|
|
|
1117
1147
|
|
|
1118
1148
|
|
|
1149
|
+
|
|
1150
|
+
|
|
1151
|
+
|
|
1119
1152
|
|
|
1120
1153
|
|
|
1121
1154
|
|
|
@@ -1233,6 +1266,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
1233
1266
|
|
|
1234
1267
|
|
|
1235
1268
|
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
|
|
1236
1272
|
|
|
1237
1273
|
|
|
1238
1274
|
|
|
@@ -1303,6 +1339,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
1303
1339
|
|
|
1304
1340
|
|
|
1305
1341
|
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
|
|
1306
1345
|
|
|
1307
1346
|
|
|
1308
1347
|
|
|
@@ -1356,6 +1395,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
1356
1395
|
|
|
1357
1396
|
|
|
1358
1397
|
|
|
1398
|
+
|
|
1399
|
+
|
|
1400
|
+
|
|
1359
1401
|
|
|
1360
1402
|
|
|
1361
1403
|
|
|
@@ -1431,6 +1473,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
|
|
|
1431
1473
|
|
|
1432
1474
|
|
|
1433
1475
|
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
|
|
1434
1479
|
|
|
1435
1480
|
|
|
1436
1481
|
|