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.
Files changed (90) hide show
  1. package/dist/cjs/index.cjs +771 -68
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +771 -68
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +771 -69
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +771 -69
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/common/error.d.ts +9 -0
  10. package/dist/types/common/index.d.ts +1 -1
  11. package/dist/types/data-structures/base/index.d.ts +1 -0
  12. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  13. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
  26. package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
  27. package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
  28. package/dist/types/data-structures/heap/heap.d.ts +336 -0
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
  32. package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
  33. package/dist/types/data-structures/queue/deque.d.ts +364 -4
  34. package/dist/types/data-structures/queue/queue.d.ts +288 -0
  35. package/dist/types/data-structures/stack/stack.d.ts +240 -0
  36. package/dist/types/data-structures/trie/trie.d.ts +292 -4
  37. package/dist/types/interfaces/graph.d.ts +1 -1
  38. package/dist/types/types/common.d.ts +2 -2
  39. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  40. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  41. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  42. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  43. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  44. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  45. package/dist/types/types/utils/validate-type.d.ts +4 -4
  46. package/dist/umd/binary-tree-typed.js +773 -71
  47. package/dist/umd/binary-tree-typed.js.map +1 -1
  48. package/dist/umd/binary-tree-typed.min.js +5 -5
  49. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/common/error.ts +19 -1
  52. package/src/common/index.ts +1 -1
  53. package/src/data-structures/base/index.ts +1 -0
  54. package/src/data-structures/base/iterable-element-base.ts +3 -2
  55. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  56. package/src/data-structures/base/linear-base.ts +3 -3
  57. package/src/data-structures/binary-tree/avl-tree.ts +299 -0
  58. package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
  59. package/src/data-structures/binary-tree/binary-tree.ts +606 -6
  60. package/src/data-structures/binary-tree/bst.ts +946 -7
  61. package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
  62. package/src/data-structures/binary-tree/segment-tree.ts +145 -2
  63. package/src/data-structures/binary-tree/tree-map.ts +3423 -499
  64. package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
  65. package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
  66. package/src/data-structures/binary-tree/tree-set.ts +3209 -413
  67. package/src/data-structures/graph/abstract-graph.ts +6 -6
  68. package/src/data-structures/graph/directed-graph.ts +240 -0
  69. package/src/data-structures/graph/undirected-graph.ts +216 -0
  70. package/src/data-structures/hash/hash-map.ts +281 -19
  71. package/src/data-structures/heap/heap.ts +340 -4
  72. package/src/data-structures/heap/max-heap.ts +2 -2
  73. package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
  74. package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
  75. package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
  76. package/src/data-structures/matrix/matrix.ts +202 -10
  77. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  78. package/src/data-structures/queue/deque.ts +365 -5
  79. package/src/data-structures/queue/queue.ts +288 -0
  80. package/src/data-structures/stack/stack.ts +240 -0
  81. package/src/data-structures/trie/trie.ts +295 -7
  82. package/src/interfaces/graph.ts +1 -1
  83. package/src/types/common.ts +2 -2
  84. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  85. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  86. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  87. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
  88. package/src/types/data-structures/heap/heap.ts +1 -0
  89. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  90. 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
- throw new Error(ERR.matrixDimensionMismatch('addition'));
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
- throw new Error(ERR.matrixDimensionMismatch('subtraction'));
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
- throw new Error(ERR.matrixDimensionMismatch('multiplication (A.cols must equal B.rows)'));
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
- throw new Error(ERR.matrixNotRectangular());
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
- throw new Error(ERR.matrixNotSquare());
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
- throw new Error(ERR.matrixSingular());
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
- throw new Error(ERR.matrixSingular());
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
- throw new Error(ERR.matrixDimensionMismatch('dot product (A.cols must equal B.rows)'));
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 as any, done: true };
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
- throw new TypeError(ERR.comparatorRequired('MaxPriorityQueue'));
89
+ raise(TypeError, ERR.comparatorRequired('MaxPriorityQueue'));
90
90
  }
91
91
  if (a < b) return 1;
92
92
  if (a > b) return -1;