max-priority-queue-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 +398 -55
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +397 -54
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +398 -56
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +397 -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/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/max-priority-queue-typed.js +395 -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/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
|
@@ -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
|
*
|
|
@@ -200,6 +200,30 @@ export class Matrix {
|
|
|
200
200
|
|
|
201
201
|
|
|
202
202
|
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
203
227
|
* @example
|
|
204
228
|
* // Get and set individual cells
|
|
205
229
|
* const m = new Matrix([
|
|
@@ -245,6 +269,30 @@ export class Matrix {
|
|
|
245
269
|
|
|
246
270
|
|
|
247
271
|
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
248
296
|
* @example
|
|
249
297
|
* // Modify individual cells
|
|
250
298
|
* const m = Matrix.zeros(2, 2);
|
|
@@ -287,6 +335,30 @@ export class Matrix {
|
|
|
287
335
|
|
|
288
336
|
|
|
289
337
|
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
290
362
|
* @example
|
|
291
363
|
* // Basic matrix arithmetic
|
|
292
364
|
* const a = new Matrix([
|
|
@@ -312,7 +384,7 @@ export class Matrix {
|
|
|
312
384
|
*/
|
|
313
385
|
add(matrix: Matrix): Matrix | undefined {
|
|
314
386
|
if (!this.isMatchForCalculate(matrix)) {
|
|
315
|
-
|
|
387
|
+
raise(Error, ERR.matrixDimensionMismatch('addition'));
|
|
316
388
|
}
|
|
317
389
|
|
|
318
390
|
const resultData: number[][] = [];
|
|
@@ -353,6 +425,30 @@ export class Matrix {
|
|
|
353
425
|
|
|
354
426
|
|
|
355
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
|
+
|
|
356
452
|
* @example
|
|
357
453
|
* // Element-wise subtraction
|
|
358
454
|
* const a = Matrix.from([[5, 6], [7, 8]]);
|
|
@@ -362,7 +458,7 @@ export class Matrix {
|
|
|
362
458
|
*/
|
|
363
459
|
subtract(matrix: Matrix): Matrix | undefined {
|
|
364
460
|
if (!this.isMatchForCalculate(matrix)) {
|
|
365
|
-
|
|
461
|
+
raise(Error, ERR.matrixDimensionMismatch('subtraction'));
|
|
366
462
|
}
|
|
367
463
|
|
|
368
464
|
const resultData: number[][] = [];
|
|
@@ -402,6 +498,30 @@ export class Matrix {
|
|
|
402
498
|
|
|
403
499
|
|
|
404
500
|
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
405
525
|
* @example
|
|
406
526
|
* // Matrix multiplication for transformations
|
|
407
527
|
* // 2x3 matrix * 3x2 matrix = 2x2 matrix
|
|
@@ -427,7 +547,7 @@ export class Matrix {
|
|
|
427
547
|
*/
|
|
428
548
|
multiply(matrix: Matrix): Matrix | undefined {
|
|
429
549
|
if (this.cols !== matrix.rows) {
|
|
430
|
-
|
|
550
|
+
raise(Error, ERR.matrixDimensionMismatch('multiplication (A.cols must equal B.rows)'));
|
|
431
551
|
}
|
|
432
552
|
|
|
433
553
|
const resultData: number[][] = [];
|
|
@@ -473,6 +593,30 @@ export class Matrix {
|
|
|
473
593
|
|
|
474
594
|
|
|
475
595
|
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
476
620
|
* @example
|
|
477
621
|
* // Matrix transpose (square matrix)
|
|
478
622
|
* const m = new Matrix([
|
|
@@ -495,7 +639,7 @@ export class Matrix {
|
|
|
495
639
|
*/
|
|
496
640
|
transpose(): Matrix {
|
|
497
641
|
if (this.data.some(row => row.length !== this.cols)) {
|
|
498
|
-
|
|
642
|
+
raise(Error, ERR.matrixNotRectangular());
|
|
499
643
|
}
|
|
500
644
|
|
|
501
645
|
const resultData: number[][] = [];
|
|
@@ -531,6 +675,30 @@ export class Matrix {
|
|
|
531
675
|
|
|
532
676
|
|
|
533
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
|
+
|
|
534
702
|
* @example
|
|
535
703
|
* // Compute the inverse of a 2x2 matrix
|
|
536
704
|
* const m = Matrix.from([[4, 7], [2, 6]]);
|
|
@@ -546,7 +714,7 @@ export class Matrix {
|
|
|
546
714
|
inverse(): Matrix | undefined {
|
|
547
715
|
// Check if the matrix is square
|
|
548
716
|
if (this.rows !== this.cols) {
|
|
549
|
-
|
|
717
|
+
raise(Error, ERR.matrixNotSquare());
|
|
550
718
|
}
|
|
551
719
|
|
|
552
720
|
// Create an augmented matrix [this | I]
|
|
@@ -576,7 +744,7 @@ export class Matrix {
|
|
|
576
744
|
|
|
577
745
|
if (pivotRow === this.rows) {
|
|
578
746
|
// Matrix is singular, and its inverse does not exist
|
|
579
|
-
|
|
747
|
+
raise(Error, ERR.matrixSingular());
|
|
580
748
|
}
|
|
581
749
|
|
|
582
750
|
// Swap rows to make the pivot the current row
|
|
@@ -587,7 +755,7 @@ export class Matrix {
|
|
|
587
755
|
|
|
588
756
|
if (pivotElement === 0) {
|
|
589
757
|
// Handle division by zero
|
|
590
|
-
|
|
758
|
+
raise(Error, ERR.matrixSingular());
|
|
591
759
|
}
|
|
592
760
|
|
|
593
761
|
augmentedMatrix._scaleRow(i, 1 / pivotElement);
|
|
@@ -633,6 +801,30 @@ export class Matrix {
|
|
|
633
801
|
|
|
634
802
|
|
|
635
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
|
+
|
|
636
828
|
* @example
|
|
637
829
|
* // Dot product of two matrices
|
|
638
830
|
* const a = Matrix.from([[1, 2], [3, 4]]);
|
|
@@ -642,7 +834,7 @@ export class Matrix {
|
|
|
642
834
|
*/
|
|
643
835
|
dot(matrix: Matrix): Matrix | undefined {
|
|
644
836
|
if (this.cols !== matrix.rows) {
|
|
645
|
-
|
|
837
|
+
raise(Error, ERR.matrixDimensionMismatch('dot product (A.cols must equal B.rows)'));
|
|
646
838
|
}
|
|
647
839
|
|
|
648
840
|
const resultData: number[][] = [];
|
|
@@ -749,7 +941,7 @@ export class Matrix {
|
|
|
749
941
|
if (i < data.length) {
|
|
750
942
|
return { value: [...data[i++]], done: false };
|
|
751
943
|
}
|
|
752
|
-
return { value: undefined
|
|
944
|
+
return { value: undefined, done: true } as IteratorResult<number[]>;
|
|
753
945
|
}
|
|
754
946
|
};
|
|
755
947
|
}
|
|
@@ -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;
|