data-structure-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.
Files changed (172) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/README.md +75 -17
  3. package/dist/cjs/binary-tree.cjs +2723 -139
  4. package/dist/cjs/graph.cjs +192 -6
  5. package/dist/cjs/hash.cjs +63 -15
  6. package/dist/cjs/heap.cjs +93 -31
  7. package/dist/cjs/index.cjs +3514 -379
  8. package/dist/cjs/linked-list.cjs +237 -31
  9. package/dist/cjs/matrix.cjs +47 -9
  10. package/dist/cjs/priority-queue.cjs +92 -30
  11. package/dist/cjs/queue.cjs +176 -2
  12. package/dist/cjs/stack.cjs +48 -2
  13. package/dist/cjs/trie.cjs +78 -28
  14. package/dist/cjs-legacy/binary-tree.cjs +2725 -136
  15. package/dist/cjs-legacy/graph.cjs +192 -6
  16. package/dist/cjs-legacy/hash.cjs +63 -15
  17. package/dist/cjs-legacy/heap.cjs +93 -31
  18. package/dist/cjs-legacy/index.cjs +3389 -249
  19. package/dist/cjs-legacy/linked-list.cjs +237 -31
  20. package/dist/cjs-legacy/matrix.cjs +47 -9
  21. package/dist/cjs-legacy/priority-queue.cjs +92 -30
  22. package/dist/cjs-legacy/queue.cjs +176 -2
  23. package/dist/cjs-legacy/stack.cjs +48 -2
  24. package/dist/cjs-legacy/trie.cjs +78 -28
  25. package/dist/esm/binary-tree.mjs +2723 -139
  26. package/dist/esm/graph.mjs +192 -6
  27. package/dist/esm/hash.mjs +63 -15
  28. package/dist/esm/heap.mjs +93 -31
  29. package/dist/esm/index.mjs +3514 -380
  30. package/dist/esm/linked-list.mjs +237 -31
  31. package/dist/esm/matrix.mjs +47 -9
  32. package/dist/esm/priority-queue.mjs +92 -30
  33. package/dist/esm/queue.mjs +176 -2
  34. package/dist/esm/stack.mjs +48 -2
  35. package/dist/esm/trie.mjs +78 -28
  36. package/dist/esm-legacy/binary-tree.mjs +2725 -136
  37. package/dist/esm-legacy/graph.mjs +192 -6
  38. package/dist/esm-legacy/hash.mjs +63 -15
  39. package/dist/esm-legacy/heap.mjs +93 -31
  40. package/dist/esm-legacy/index.mjs +3389 -250
  41. package/dist/esm-legacy/linked-list.mjs +237 -31
  42. package/dist/esm-legacy/matrix.mjs +47 -9
  43. package/dist/esm-legacy/priority-queue.mjs +92 -30
  44. package/dist/esm-legacy/queue.mjs +176 -2
  45. package/dist/esm-legacy/stack.mjs +48 -2
  46. package/dist/esm-legacy/trie.mjs +78 -28
  47. package/dist/types/common/error.d.ts +9 -0
  48. package/dist/types/common/index.d.ts +1 -1
  49. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +48 -0
  50. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
  51. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +102 -2
  52. package/dist/types/data-structures/binary-tree/bst.d.ts +195 -0
  53. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +76 -0
  54. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
  55. package/dist/types/data-structures/binary-tree/tree-map.d.ts +528 -0
  56. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +531 -6
  57. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +435 -6
  58. package/dist/types/data-structures/binary-tree/tree-set.d.ts +505 -0
  59. package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
  60. package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
  61. package/dist/types/data-structures/hash/hash-map.d.ts +44 -0
  62. package/dist/types/data-structures/heap/heap.d.ts +56 -0
  63. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +68 -0
  64. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +60 -0
  65. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
  66. package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
  67. package/dist/types/data-structures/queue/deque.d.ts +60 -0
  68. package/dist/types/data-structures/queue/queue.d.ts +48 -0
  69. package/dist/types/data-structures/stack/stack.d.ts +40 -0
  70. package/dist/types/data-structures/trie/trie.d.ts +48 -0
  71. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  72. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  73. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  74. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  75. package/dist/umd/data-structure-typed.js +3404 -265
  76. package/dist/umd/data-structure-typed.min.js +5 -5
  77. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +650 -136
  78. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
  79. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +71 -71
  80. package/docs-site-docusaurus/docs/api/classes/BST.md +591 -129
  81. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
  82. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
  83. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +107 -107
  84. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
  85. package/docs-site-docusaurus/docs/api/classes/Deque.md +82 -82
  86. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +82 -82
  87. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +74 -74
  88. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
  89. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +9 -9
  90. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
  91. package/docs-site-docusaurus/docs/api/classes/HashMap.md +47 -47
  92. package/docs-site-docusaurus/docs/api/classes/Heap.md +45 -45
  93. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
  94. package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +33 -33
  95. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +50 -50
  96. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +55 -55
  97. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +49 -49
  98. package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
  99. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +78 -78
  100. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +82 -82
  101. package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
  102. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +45 -45
  103. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +45 -45
  104. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +45 -45
  105. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +45 -45
  106. package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
  107. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +44 -44
  108. package/docs-site-docusaurus/docs/api/classes/Queue.md +60 -60
  109. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +660 -146
  110. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
  111. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +78 -78
  112. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
  113. package/docs-site-docusaurus/docs/api/classes/SkipList.md +44 -44
  114. package/docs-site-docusaurus/docs/api/classes/Stack.md +39 -39
  115. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +165 -33
  116. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +162 -46
  117. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +161 -32
  118. package/docs-site-docusaurus/docs/api/classes/Trie.md +47 -47
  119. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
  120. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +81 -81
  121. package/docs-site-docusaurus/docs/guide/architecture.md +2 -0
  122. package/docs-site-docusaurus/docs/guide/concepts.md +32 -1
  123. package/docs-site-docusaurus/docs/guide/faq.md +180 -0
  124. package/docs-site-docusaurus/docs/guide/guides.md +40 -54
  125. package/docs-site-docusaurus/docs/guide/installation.md +2 -0
  126. package/docs-site-docusaurus/docs/guide/integrations.md +2 -0
  127. package/docs-site-docusaurus/docs/guide/overview.md +7 -0
  128. package/docs-site-docusaurus/docs/guide/performance.md +2 -0
  129. package/docs-site-docusaurus/docs/guide/quick-start.md +31 -0
  130. package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
  131. package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
  132. package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
  133. package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
  134. package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
  135. package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
  136. package/docs-site-docusaurus/docusaurus.config.ts +1 -1
  137. package/docs-site-docusaurus/src/pages/index.tsx +51 -2
  138. package/docs-site-docusaurus/static/llms.txt +37 -0
  139. package/llms.txt +37 -0
  140. package/package.json +64 -56
  141. package/src/common/error.ts +19 -1
  142. package/src/common/index.ts +1 -1
  143. package/src/data-structures/base/iterable-element-base.ts +3 -2
  144. package/src/data-structures/binary-tree/avl-tree.ts +47 -0
  145. package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
  146. package/src/data-structures/binary-tree/binary-tree.ts +79 -4
  147. package/src/data-structures/binary-tree/bst.ts +441 -6
  148. package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
  149. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  150. package/src/data-structures/binary-tree/tree-map.ts +434 -9
  151. package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
  152. package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
  153. package/src/data-structures/binary-tree/tree-set.ts +410 -8
  154. package/src/data-structures/graph/abstract-graph.ts +2 -2
  155. package/src/data-structures/graph/directed-graph.ts +30 -0
  156. package/src/data-structures/graph/undirected-graph.ts +27 -0
  157. package/src/data-structures/hash/hash-map.ts +35 -4
  158. package/src/data-structures/heap/heap.ts +46 -4
  159. package/src/data-structures/heap/max-heap.ts +2 -2
  160. package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
  161. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  162. package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
  163. package/src/data-structures/matrix/matrix.ts +33 -9
  164. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  165. package/src/data-structures/queue/deque.ts +45 -0
  166. package/src/data-structures/queue/queue.ts +36 -0
  167. package/src/data-structures/stack/stack.ts +30 -0
  168. package/src/data-structures/trie/trie.ts +38 -2
  169. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  170. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  171. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  172. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
@@ -4,6 +4,10 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
 
6
6
  // src/common/error.ts
7
+ function raise(ErrorClass, message) {
8
+ throw new ErrorClass(message);
9
+ }
10
+ __name(raise, "raise");
7
11
  var ERR = {
8
12
  // Range / index
9
13
  indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
@@ -25,7 +29,9 @@ var ERR = {
25
29
  matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
26
30
  matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
27
31
  matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
28
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
32
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
33
+ // Order statistic
34
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
29
35
  };
30
36
 
31
37
  // src/data-structures/matrix/matrix.ts
@@ -140,6 +146,10 @@ var _Matrix = class _Matrix {
140
146
 
141
147
 
142
148
 
149
+
150
+
151
+
152
+
143
153
 
144
154
 
145
155
 
@@ -204,6 +214,10 @@ var _Matrix = class _Matrix {
204
214
 
205
215
 
206
216
 
217
+
218
+
219
+
220
+
207
221
 
208
222
 
209
223
 
@@ -264,6 +278,10 @@ var _Matrix = class _Matrix {
264
278
 
265
279
 
266
280
 
281
+
282
+
283
+
284
+
267
285
 
268
286
 
269
287
 
@@ -295,7 +313,7 @@ var _Matrix = class _Matrix {
295
313
  add(matrix) {
296
314
  var _a;
297
315
  if (!this.isMatchForCalculate(matrix)) {
298
- throw new Error(ERR.matrixDimensionMismatch("addition"));
316
+ raise(Error, ERR.matrixDimensionMismatch("addition"));
299
317
  }
300
318
  const resultData = [];
301
319
  for (let i = 0; i < this.rows; i++) {
@@ -347,6 +365,10 @@ var _Matrix = class _Matrix {
347
365
 
348
366
 
349
367
 
368
+
369
+
370
+
371
+
350
372
 
351
373
 
352
374
 
@@ -362,7 +384,7 @@ var _Matrix = class _Matrix {
362
384
  subtract(matrix) {
363
385
  var _a;
364
386
  if (!this.isMatchForCalculate(matrix)) {
365
- throw new Error(ERR.matrixDimensionMismatch("subtraction"));
387
+ raise(Error, ERR.matrixDimensionMismatch("subtraction"));
366
388
  }
367
389
  const resultData = [];
368
390
  for (let i = 0; i < this.rows; i++) {
@@ -413,6 +435,10 @@ var _Matrix = class _Matrix {
413
435
 
414
436
 
415
437
 
438
+
439
+
440
+
441
+
416
442
 
417
443
 
418
444
 
@@ -443,7 +469,7 @@ var _Matrix = class _Matrix {
443
469
  */
444
470
  multiply(matrix) {
445
471
  if (this.cols !== matrix.rows) {
446
- throw new Error(ERR.matrixDimensionMismatch("multiplication (A.cols must equal B.rows)"));
472
+ raise(Error, ERR.matrixDimensionMismatch("multiplication (A.cols must equal B.rows)"));
447
473
  }
448
474
  const resultData = [];
449
475
  for (let i = 0; i < this.rows; i++) {
@@ -500,6 +526,10 @@ var _Matrix = class _Matrix {
500
526
 
501
527
 
502
528
 
529
+
530
+
531
+
532
+
503
533
 
504
534
 
505
535
 
@@ -527,7 +557,7 @@ var _Matrix = class _Matrix {
527
557
  */
528
558
  transpose() {
529
559
  if (this.data.some((row) => row.length !== this.cols)) {
530
- throw new Error(ERR.matrixNotRectangular());
560
+ raise(Error, ERR.matrixNotRectangular());
531
561
  }
532
562
  const resultData = [];
533
563
  for (let j = 0; j < this.cols; j++) {
@@ -574,6 +604,10 @@ var _Matrix = class _Matrix {
574
604
 
575
605
 
576
606
 
607
+
608
+
609
+
610
+
577
611
 
578
612
 
579
613
 
@@ -594,7 +628,7 @@ var _Matrix = class _Matrix {
594
628
  inverse() {
595
629
  var _a;
596
630
  if (this.rows !== this.cols) {
597
- throw new Error(ERR.matrixNotSquare());
631
+ raise(Error, ERR.matrixNotSquare());
598
632
  }
599
633
  const augmentedMatrixData = [];
600
634
  for (let i = 0; i < this.rows; i++) {
@@ -616,12 +650,12 @@ var _Matrix = class _Matrix {
616
650
  pivotRow++;
617
651
  }
618
652
  if (pivotRow === this.rows) {
619
- throw new Error(ERR.matrixSingular());
653
+ raise(Error, ERR.matrixSingular());
620
654
  }
621
655
  augmentedMatrix._swapRows(i, pivotRow);
622
656
  const pivotElement = (_a = augmentedMatrix.get(i, i)) != null ? _a : 1;
623
657
  if (pivotElement === 0) {
624
- throw new Error(ERR.matrixSingular());
658
+ raise(Error, ERR.matrixSingular());
625
659
  }
626
660
  augmentedMatrix._scaleRow(i, 1 / pivotElement);
627
661
  for (let j = 0; j < this.rows; j++) {
@@ -674,6 +708,10 @@ var _Matrix = class _Matrix {
674
708
 
675
709
 
676
710
 
711
+
712
+
713
+
714
+
677
715
 
678
716
 
679
717
 
@@ -688,7 +726,7 @@ var _Matrix = class _Matrix {
688
726
  */
689
727
  dot(matrix) {
690
728
  if (this.cols !== matrix.rows) {
691
- throw new Error(ERR.matrixDimensionMismatch("dot product (A.cols must equal B.rows)"));
729
+ raise(Error, ERR.matrixDimensionMismatch("dot product (A.cols must equal B.rows)"));
692
730
  }
693
731
  const resultData = [];
694
732
  for (let i = 0; i < this.rows; i++) {
@@ -3,6 +3,37 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
5
 
6
+ // src/common/error.ts
7
+ function raise(ErrorClass, message) {
8
+ throw new ErrorClass(message);
9
+ }
10
+ __name(raise, "raise");
11
+ var ERR = {
12
+ // Range / index
13
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
14
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
15
+ // Type / argument
16
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
17
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
18
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
19
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
20
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
21
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
22
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
23
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
24
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
25
+ // State / operation
26
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
27
+ // Matrix
28
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
29
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
30
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
31
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
32
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
33
+ // Order statistic
34
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
35
+ };
36
+
6
37
  // src/data-structures/base/iterable-element-base.ts
7
38
  var _IterableElementBase = class _IterableElementBase {
8
39
  /**
@@ -25,7 +56,7 @@ var _IterableElementBase = class _IterableElementBase {
25
56
  if (options) {
26
57
  const { toElementFn } = options;
27
58
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
28
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
59
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
29
60
  }
30
61
  }
31
62
  /**
@@ -181,7 +212,7 @@ var _IterableElementBase = class _IterableElementBase {
181
212
  acc = initialValue;
182
213
  } else {
183
214
  const first = iter.next();
184
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
215
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
185
216
  acc = first.value;
186
217
  index = 1;
187
218
  }
@@ -225,31 +256,6 @@ var _IterableElementBase = class _IterableElementBase {
225
256
  __name(_IterableElementBase, "IterableElementBase");
226
257
  var IterableElementBase = _IterableElementBase;
227
258
 
228
- // src/common/error.ts
229
- var ERR = {
230
- // Range / index
231
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
232
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
233
- // Type / argument
234
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
235
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
236
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
237
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
238
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
239
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
240
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
241
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
242
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
243
- // State / operation
244
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
245
- // Matrix
246
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
247
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
248
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
249
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
250
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
251
- };
252
-
253
259
  // src/data-structures/heap/heap.ts
254
260
  var _Heap = class _Heap extends IterableElementBase {
255
261
  /**
@@ -265,7 +271,7 @@ var _Heap = class _Heap extends IterableElementBase {
265
271
  __publicField(this, "_elements", []);
266
272
  __publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
267
273
  if (typeof a === "object" || typeof b === "object") {
268
- throw new TypeError(ERR.comparatorRequired("Heap"));
274
+ raise(TypeError, ERR.comparatorRequired("Heap"));
269
275
  }
270
276
  if (a > b) return 1;
271
277
  if (a < b) return -1;
@@ -316,6 +322,10 @@ var _Heap = class _Heap extends IterableElementBase {
316
322
 
317
323
 
318
324
 
325
+
326
+
327
+
328
+
319
329
 
320
330
 
321
331
 
@@ -399,6 +409,10 @@ var _Heap = class _Heap extends IterableElementBase {
399
409
 
400
410
 
401
411
 
412
+
413
+
414
+
415
+
402
416
 
403
417
 
404
418
 
@@ -452,6 +466,10 @@ var _Heap = class _Heap extends IterableElementBase {
452
466
 
453
467
 
454
468
 
469
+
470
+
471
+
472
+
455
473
 
456
474
 
457
475
 
@@ -507,6 +525,10 @@ var _Heap = class _Heap extends IterableElementBase {
507
525
 
508
526
 
509
527
 
528
+
529
+
530
+
531
+
510
532
 
511
533
 
512
534
 
@@ -578,6 +600,10 @@ var _Heap = class _Heap extends IterableElementBase {
578
600
 
579
601
 
580
602
 
603
+
604
+
605
+
606
+
581
607
 
582
608
 
583
609
 
@@ -674,6 +700,10 @@ var _Heap = class _Heap extends IterableElementBase {
674
700
 
675
701
 
676
702
 
703
+
704
+
705
+
706
+
677
707
 
678
708
 
679
709
 
@@ -717,6 +747,10 @@ var _Heap = class _Heap extends IterableElementBase {
717
747
 
718
748
 
719
749
 
750
+
751
+
752
+
753
+
720
754
 
721
755
 
722
756
 
@@ -763,6 +797,10 @@ var _Heap = class _Heap extends IterableElementBase {
763
797
 
764
798
 
765
799
 
800
+
801
+
802
+
803
+
766
804
 
767
805
 
768
806
 
@@ -806,6 +844,10 @@ var _Heap = class _Heap extends IterableElementBase {
806
844
 
807
845
 
808
846
 
847
+
848
+
849
+
850
+
809
851
 
810
852
 
811
853
 
@@ -895,6 +937,10 @@ var _Heap = class _Heap extends IterableElementBase {
895
937
 
896
938
 
897
939
 
940
+
941
+
942
+
943
+
898
944
 
899
945
 
900
946
 
@@ -971,6 +1017,10 @@ var _Heap = class _Heap extends IterableElementBase {
971
1017
 
972
1018
 
973
1019
 
1020
+
1021
+
1022
+
1023
+
974
1024
 
975
1025
 
976
1026
 
@@ -1020,6 +1070,10 @@ var _Heap = class _Heap extends IterableElementBase {
1020
1070
 
1021
1071
 
1022
1072
 
1073
+
1074
+
1075
+
1076
+
1023
1077
 
1024
1078
 
1025
1079
 
@@ -1068,6 +1122,10 @@ var _Heap = class _Heap extends IterableElementBase {
1068
1122
 
1069
1123
 
1070
1124
 
1125
+
1126
+
1127
+
1128
+
1071
1129
 
1072
1130
 
1073
1131
 
@@ -1123,6 +1181,10 @@ var _Heap = class _Heap extends IterableElementBase {
1123
1181
 
1124
1182
 
1125
1183
 
1184
+
1185
+
1186
+
1187
+
1126
1188
 
1127
1189
 
1128
1190
 
@@ -1136,7 +1198,7 @@ var _Heap = class _Heap extends IterableElementBase {
1136
1198
  */
1137
1199
  map(callback, options, thisArg) {
1138
1200
  const { comparator, toElementFn, ...rest } = options != null ? options : {};
1139
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1201
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1140
1202
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1141
1203
  let i = 0;
1142
1204
  for (const x of this) {
@@ -1276,7 +1338,7 @@ var _MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
1276
1338
  super(elements, {
1277
1339
  comparator: /* @__PURE__ */ __name((a, b) => {
1278
1340
  if (typeof a === "object" || typeof b === "object") {
1279
- throw new TypeError(ERR.comparatorRequired("MaxPriorityQueue"));
1341
+ raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
1280
1342
  }
1281
1343
  if (a < b) return 1;
1282
1344
  if (a > b) return -1;