data-structure-typed 2.5.1 → 2.5.3

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 (184) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/MIGRATION.md +169 -0
  3. package/README.md +135 -23
  4. package/README_CN.md +551 -143
  5. package/SPECIFICATION.md +20 -14
  6. package/SPECIFICATION.zh-CN.md +20 -14
  7. package/dist/cjs/binary-tree.cjs +6460 -1591
  8. package/dist/cjs/graph.cjs +440 -20
  9. package/dist/cjs/hash.cjs +125 -22
  10. package/dist/cjs/heap.cjs +196 -47
  11. package/dist/cjs/index.cjs +8486 -2429
  12. package/dist/cjs/linked-list.cjs +456 -31
  13. package/dist/cjs/matrix.cjs +79 -9
  14. package/dist/cjs/priority-queue.cjs +193 -44
  15. package/dist/cjs/queue.cjs +391 -2
  16. package/dist/cjs/stack.cjs +92 -6
  17. package/dist/cjs/trie.cjs +122 -28
  18. package/dist/cjs-legacy/binary-tree.cjs +6484 -1612
  19. package/dist/cjs-legacy/graph.cjs +440 -20
  20. package/dist/cjs-legacy/hash.cjs +125 -22
  21. package/dist/cjs-legacy/heap.cjs +196 -47
  22. package/dist/cjs-legacy/index.cjs +8654 -2594
  23. package/dist/cjs-legacy/linked-list.cjs +456 -31
  24. package/dist/cjs-legacy/matrix.cjs +79 -9
  25. package/dist/cjs-legacy/priority-queue.cjs +193 -44
  26. package/dist/cjs-legacy/queue.cjs +391 -2
  27. package/dist/cjs-legacy/stack.cjs +92 -6
  28. package/dist/cjs-legacy/trie.cjs +122 -28
  29. package/dist/esm/binary-tree.mjs +6460 -1591
  30. package/dist/esm/graph.mjs +440 -20
  31. package/dist/esm/hash.mjs +125 -22
  32. package/dist/esm/heap.mjs +196 -47
  33. package/dist/esm/index.mjs +8486 -2430
  34. package/dist/esm/linked-list.mjs +456 -31
  35. package/dist/esm/matrix.mjs +79 -9
  36. package/dist/esm/priority-queue.mjs +193 -44
  37. package/dist/esm/queue.mjs +391 -2
  38. package/dist/esm/stack.mjs +92 -6
  39. package/dist/esm/trie.mjs +122 -28
  40. package/dist/esm-legacy/binary-tree.mjs +6484 -1612
  41. package/dist/esm-legacy/graph.mjs +440 -20
  42. package/dist/esm-legacy/hash.mjs +125 -22
  43. package/dist/esm-legacy/heap.mjs +196 -47
  44. package/dist/esm-legacy/index.mjs +8654 -2595
  45. package/dist/esm-legacy/linked-list.mjs +456 -31
  46. package/dist/esm-legacy/matrix.mjs +79 -9
  47. package/dist/esm-legacy/priority-queue.mjs +193 -44
  48. package/dist/esm-legacy/queue.mjs +391 -2
  49. package/dist/esm-legacy/stack.mjs +92 -6
  50. package/dist/esm-legacy/trie.mjs +122 -28
  51. package/dist/types/common/error.d.ts +9 -0
  52. package/dist/types/common/index.d.ts +1 -1
  53. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +98 -2
  54. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +112 -0
  55. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +214 -13
  56. package/dist/types/data-structures/binary-tree/bst.d.ts +294 -3
  57. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +155 -8
  58. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +48 -0
  59. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1370 -323
  60. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1329 -316
  61. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +1116 -295
  62. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1330 -326
  63. package/dist/types/data-structures/graph/directed-graph.d.ts +80 -0
  64. package/dist/types/data-structures/graph/undirected-graph.d.ts +72 -0
  65. package/dist/types/data-structures/hash/hash-map.d.ts +95 -6
  66. package/dist/types/data-structures/heap/heap.d.ts +154 -12
  67. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +143 -0
  68. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +121 -1
  69. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +144 -0
  70. package/dist/types/data-structures/matrix/matrix.d.ts +64 -0
  71. package/dist/types/data-structures/queue/deque.d.ts +142 -0
  72. package/dist/types/data-structures/queue/queue.d.ts +109 -0
  73. package/dist/types/data-structures/stack/stack.d.ts +82 -2
  74. package/dist/types/data-structures/trie/trie.d.ts +96 -0
  75. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  76. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  77. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  78. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  79. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  80. package/dist/umd/data-structure-typed.js +8623 -2564
  81. package/dist/umd/data-structure-typed.min.js +5 -5
  82. package/docs-site-docusaurus/docs/api/classes/AVLTree.md +696 -194
  83. package/docs-site-docusaurus/docs/api/classes/AVLTreeNode.md +11 -11
  84. package/docs-site-docusaurus/docs/api/classes/AbstractGraph.md +71 -71
  85. package/docs-site-docusaurus/docs/api/classes/BST.md +639 -189
  86. package/docs-site-docusaurus/docs/api/classes/BSTNode.md +13 -13
  87. package/docs-site-docusaurus/docs/api/classes/BinaryIndexedTree.md +15 -15
  88. package/docs-site-docusaurus/docs/api/classes/BinaryTree.md +148 -160
  89. package/docs-site-docusaurus/docs/api/classes/BinaryTreeNode.md +13 -13
  90. package/docs-site-docusaurus/docs/api/classes/Deque.md +105 -91
  91. package/docs-site-docusaurus/docs/api/classes/DirectedGraph.md +82 -82
  92. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedList.md +104 -74
  93. package/docs-site-docusaurus/docs/api/classes/DoublyLinkedListNode.md +8 -8
  94. package/docs-site-docusaurus/docs/api/classes/FibonacciHeap.md +12 -12
  95. package/docs-site-docusaurus/docs/api/classes/FibonacciHeapNode.md +1 -1
  96. package/docs-site-docusaurus/docs/api/classes/HashMap.md +51 -51
  97. package/docs-site-docusaurus/docs/api/classes/Heap.md +96 -85
  98. package/docs-site-docusaurus/docs/api/classes/IterableElementBase.md +25 -25
  99. package/docs-site-docusaurus/docs/api/classes/IterableEntryBase.md +33 -33
  100. package/docs-site-docusaurus/docs/api/classes/LinearBase.md +50 -50
  101. package/docs-site-docusaurus/docs/api/classes/LinearLinkedBase.md +55 -55
  102. package/docs-site-docusaurus/docs/api/classes/LinkedHashMap.md +55 -55
  103. package/docs-site-docusaurus/docs/api/classes/LinkedListNode.md +6 -6
  104. package/docs-site-docusaurus/docs/api/classes/LinkedListQueue.md +78 -78
  105. package/docs-site-docusaurus/docs/api/classes/MapGraph.md +82 -82
  106. package/docs-site-docusaurus/docs/api/classes/Matrix.md +31 -31
  107. package/docs-site-docusaurus/docs/api/classes/MaxHeap.md +104 -89
  108. package/docs-site-docusaurus/docs/api/classes/MaxPriorityQueue.md +104 -89
  109. package/docs-site-docusaurus/docs/api/classes/MinHeap.md +104 -89
  110. package/docs-site-docusaurus/docs/api/classes/MinPriorityQueue.md +104 -89
  111. package/docs-site-docusaurus/docs/api/classes/Navigator.md +5 -5
  112. package/docs-site-docusaurus/docs/api/classes/PriorityQueue.md +103 -88
  113. package/docs-site-docusaurus/docs/api/classes/Queue.md +112 -60
  114. package/docs-site-docusaurus/docs/api/classes/RedBlackTree.md +708 -206
  115. package/docs-site-docusaurus/docs/api/classes/SegmentTree.md +10 -10
  116. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedList.md +79 -79
  117. package/docs-site-docusaurus/docs/api/classes/SinglyLinkedListNode.md +6 -6
  118. package/docs-site-docusaurus/docs/api/classes/SkipList.md +44 -44
  119. package/docs-site-docusaurus/docs/api/classes/Stack.md +42 -42
  120. package/docs-site-docusaurus/docs/api/classes/TreeMap.md +236 -33
  121. package/docs-site-docusaurus/docs/api/classes/TreeMultiMap.md +162 -46
  122. package/docs-site-docusaurus/docs/api/classes/TreeSet.md +232 -32
  123. package/docs-site-docusaurus/docs/api/classes/Trie.md +47 -47
  124. package/docs-site-docusaurus/docs/api/classes/TrieNode.md +8 -8
  125. package/docs-site-docusaurus/docs/api/classes/UndirectedGraph.md +81 -81
  126. package/docs-site-docusaurus/docs/guide/architecture.md +75 -5
  127. package/docs-site-docusaurus/docs/guide/concepts.md +53 -3
  128. package/docs-site-docusaurus/docs/guide/faq.md +233 -0
  129. package/docs-site-docusaurus/docs/guide/guides.md +43 -58
  130. package/docs-site-docusaurus/docs/guide/installation.md +2 -0
  131. package/docs-site-docusaurus/docs/guide/integrations.md +75 -176
  132. package/docs-site-docusaurus/docs/guide/overview.md +132 -11
  133. package/docs-site-docusaurus/docs/guide/performance.md +2 -0
  134. package/docs-site-docusaurus/docs/guide/quick-start.md +31 -0
  135. package/docs-site-docusaurus/docs/guide/use-cases/_category_.json +6 -0
  136. package/docs-site-docusaurus/docs/guide/use-cases/array-sort-alternative.md +158 -0
  137. package/docs-site-docusaurus/docs/guide/use-cases/heap-vs-sorting.md +92 -0
  138. package/docs-site-docusaurus/docs/guide/use-cases/map-vs-treemap.md +151 -0
  139. package/docs-site-docusaurus/docs/guide/use-cases/priority-queue-typescript.md +113 -0
  140. package/docs-site-docusaurus/docs/guide/use-cases/treemap-javascript.md +151 -0
  141. package/docs-site-docusaurus/docusaurus.config.ts +1 -1
  142. package/docs-site-docusaurus/src/pages/index.tsx +55 -2
  143. package/docs-site-docusaurus/static/llms.txt +37 -0
  144. package/docs-site-docusaurus/typedoc.json +1 -0
  145. package/llms.txt +37 -0
  146. package/package.json +65 -56
  147. package/src/common/error.ts +19 -1
  148. package/src/common/index.ts +1 -1
  149. package/src/data-structures/base/iterable-element-base.ts +3 -2
  150. package/src/data-structures/binary-tree/avl-tree.ts +99 -5
  151. package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
  152. package/src/data-structures/binary-tree/binary-tree.ts +239 -78
  153. package/src/data-structures/binary-tree/bst.ts +542 -13
  154. package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
  155. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  156. package/src/data-structures/binary-tree/tree-map.ts +1223 -261
  157. package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
  158. package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
  159. package/src/data-structures/binary-tree/tree-set.ts +1018 -99
  160. package/src/data-structures/graph/abstract-graph.ts +2 -2
  161. package/src/data-structures/graph/directed-graph.ts +71 -1
  162. package/src/data-structures/graph/undirected-graph.ts +64 -1
  163. package/src/data-structures/hash/hash-map.ts +102 -16
  164. package/src/data-structures/heap/heap.ts +153 -23
  165. package/src/data-structures/heap/max-heap.ts +2 -2
  166. package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
  167. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  168. package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
  169. package/src/data-structures/matrix/matrix.ts +65 -9
  170. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  171. package/src/data-structures/queue/deque.ts +130 -0
  172. package/src/data-structures/queue/queue.ts +109 -0
  173. package/src/data-structures/stack/stack.ts +75 -5
  174. package/src/data-structures/trie/trie.ts +86 -2
  175. package/src/interfaces/binary-tree.ts +1 -9
  176. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  177. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  178. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  179. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
  180. package/.vitepress/cache/deps_temp_51f5f1b0/chunk-7OIKW5WK.js +0 -12984
  181. package/.vitepress/cache/deps_temp_51f5f1b0/package.json +0 -3
  182. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vue_devtools-api.js +0 -4505
  183. package/.vitepress/cache/deps_temp_51f5f1b0/vitepress___@vueuse_core.js +0 -9731
  184. package/.vitepress/cache/deps_temp_51f5f1b0/vue.js +0 -347
@@ -2,6 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/common/error.ts
5
+ function raise(ErrorClass, message) {
6
+ throw new ErrorClass(message);
7
+ }
8
+ __name(raise, "raise");
5
9
  var ERR = {
6
10
  // Range / index
7
11
  indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
@@ -23,7 +27,9 @@ var ERR = {
23
27
  matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
24
28
  matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
25
29
  matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
26
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
30
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
31
+ // Order statistic
32
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
27
33
  };
28
34
 
29
35
  // src/data-structures/matrix/matrix.ts
@@ -136,6 +142,14 @@ var Matrix = class _Matrix {
136
142
 
137
143
 
138
144
 
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+
139
153
 
140
154
 
141
155
 
@@ -200,6 +214,14 @@ var Matrix = class _Matrix {
200
214
 
201
215
 
202
216
 
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
203
225
 
204
226
 
205
227
 
@@ -260,6 +282,14 @@ var Matrix = class _Matrix {
260
282
 
261
283
 
262
284
 
285
+
286
+
287
+
288
+
289
+
290
+
291
+
292
+
263
293
 
264
294
 
265
295
 
@@ -294,7 +324,7 @@ var Matrix = class _Matrix {
294
324
  */
295
325
  add(matrix) {
296
326
  if (!this.isMatchForCalculate(matrix)) {
297
- throw new Error(ERR.matrixDimensionMismatch("addition"));
327
+ raise(Error, ERR.matrixDimensionMismatch("addition"));
298
328
  }
299
329
  const resultData = [];
300
330
  for (let i = 0; i < this.rows; i++) {
@@ -342,6 +372,14 @@ var Matrix = class _Matrix {
342
372
 
343
373
 
344
374
 
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
345
383
 
346
384
 
347
385
 
@@ -360,7 +398,7 @@ var Matrix = class _Matrix {
360
398
  */
361
399
  subtract(matrix) {
362
400
  if (!this.isMatchForCalculate(matrix)) {
363
- throw new Error(ERR.matrixDimensionMismatch("subtraction"));
401
+ raise(Error, ERR.matrixDimensionMismatch("subtraction"));
364
402
  }
365
403
  const resultData = [];
366
404
  for (let i = 0; i < this.rows; i++) {
@@ -407,6 +445,14 @@ var Matrix = class _Matrix {
407
445
 
408
446
 
409
447
 
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
410
456
 
411
457
 
412
458
 
@@ -441,7 +487,7 @@ var Matrix = class _Matrix {
441
487
  */
442
488
  multiply(matrix) {
443
489
  if (this.cols !== matrix.rows) {
444
- throw new Error(ERR.matrixDimensionMismatch("multiplication (A.cols must equal B.rows)"));
490
+ raise(Error, ERR.matrixDimensionMismatch("multiplication (A.cols must equal B.rows)"));
445
491
  }
446
492
  const resultData = [];
447
493
  for (let i = 0; i < this.rows; i++) {
@@ -494,6 +540,14 @@ var Matrix = class _Matrix {
494
540
 
495
541
 
496
542
 
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
497
551
 
498
552
 
499
553
 
@@ -525,7 +579,7 @@ var Matrix = class _Matrix {
525
579
  */
526
580
  transpose() {
527
581
  if (this.data.some((row) => row.length !== this.cols)) {
528
- throw new Error(ERR.matrixNotRectangular());
582
+ raise(Error, ERR.matrixNotRectangular());
529
583
  }
530
584
  const resultData = [];
531
585
  for (let j = 0; j < this.cols; j++) {
@@ -568,6 +622,14 @@ var Matrix = class _Matrix {
568
622
 
569
623
 
570
624
 
625
+
626
+
627
+
628
+
629
+
630
+
631
+
632
+
571
633
 
572
634
 
573
635
 
@@ -591,7 +653,7 @@ var Matrix = class _Matrix {
591
653
  */
592
654
  inverse() {
593
655
  if (this.rows !== this.cols) {
594
- throw new Error(ERR.matrixNotSquare());
656
+ raise(Error, ERR.matrixNotSquare());
595
657
  }
596
658
  const augmentedMatrixData = [];
597
659
  for (let i = 0; i < this.rows; i++) {
@@ -613,12 +675,12 @@ var Matrix = class _Matrix {
613
675
  pivotRow++;
614
676
  }
615
677
  if (pivotRow === this.rows) {
616
- throw new Error(ERR.matrixSingular());
678
+ raise(Error, ERR.matrixSingular());
617
679
  }
618
680
  augmentedMatrix._swapRows(i, pivotRow);
619
681
  const pivotElement = augmentedMatrix.get(i, i) ?? 1;
620
682
  if (pivotElement === 0) {
621
- throw new Error(ERR.matrixSingular());
683
+ raise(Error, ERR.matrixSingular());
622
684
  }
623
685
  augmentedMatrix._scaleRow(i, 1 / pivotElement);
624
686
  for (let j = 0; j < this.rows; j++) {
@@ -667,6 +729,14 @@ var Matrix = class _Matrix {
667
729
 
668
730
 
669
731
 
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
670
740
 
671
741
 
672
742
 
@@ -685,7 +755,7 @@ var Matrix = class _Matrix {
685
755
  */
686
756
  dot(matrix) {
687
757
  if (this.cols !== matrix.rows) {
688
- throw new Error(ERR.matrixDimensionMismatch("dot product (A.cols must equal B.rows)"));
758
+ raise(Error, ERR.matrixDimensionMismatch("dot product (A.cols must equal B.rows)"));
689
759
  }
690
760
  const resultData = [];
691
761
  for (let i = 0; i < this.rows; i++) {
@@ -1,6 +1,37 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/common/error.ts
5
+ function raise(ErrorClass, message) {
6
+ throw new ErrorClass(message);
7
+ }
8
+ __name(raise, "raise");
9
+ var ERR = {
10
+ // Range / index
11
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
12
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
13
+ // Type / argument
14
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
15
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
16
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
17
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
18
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
19
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
20
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
21
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
22
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
23
+ // State / operation
24
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
25
+ // Matrix
26
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
27
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
28
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
29
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
30
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
31
+ // Order statistic
32
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
33
+ };
34
+
4
35
  // src/data-structures/base/iterable-element-base.ts
5
36
  var IterableElementBase = class {
6
37
  static {
@@ -19,7 +50,7 @@ var IterableElementBase = class {
19
50
  if (options) {
20
51
  const { toElementFn } = options;
21
52
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
22
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
53
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
23
54
  }
24
55
  }
25
56
  /**
@@ -182,7 +213,7 @@ var IterableElementBase = class {
182
213
  acc = initialValue;
183
214
  } else {
184
215
  const first = iter.next();
185
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
216
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
186
217
  acc = first.value;
187
218
  index = 1;
188
219
  }
@@ -224,31 +255,6 @@ var IterableElementBase = class {
224
255
  }
225
256
  };
226
257
 
227
- // src/common/error.ts
228
- var ERR = {
229
- // Range / index
230
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
231
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
232
- // Type / argument
233
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
234
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
235
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
236
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
237
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
238
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
239
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
240
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
241
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
242
- // State / operation
243
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
244
- // Matrix
245
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
246
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
247
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
248
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
249
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
250
- };
251
-
252
258
  // src/data-structures/heap/heap.ts
253
259
  var Heap = class _Heap extends IterableElementBase {
254
260
  static {
@@ -305,6 +311,14 @@ var Heap = class _Heap extends IterableElementBase {
305
311
 
306
312
 
307
313
 
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+
308
322
 
309
323
 
310
324
 
@@ -362,7 +376,7 @@ var Heap = class _Heap extends IterableElementBase {
362
376
  }
363
377
  /**
364
378
  * Insert an element.
365
- * @remarks Time O(1) amortized, Space O(1)
379
+ * @remarks Time O(log N) amortized, Space O(1)
366
380
  * @param element - Element to insert.
367
381
  * @returns True.
368
382
 
@@ -387,6 +401,14 @@ var Heap = class _Heap extends IterableElementBase {
387
401
 
388
402
 
389
403
 
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
390
412
 
391
413
 
392
414
 
@@ -440,6 +462,14 @@ var Heap = class _Heap extends IterableElementBase {
440
462
 
441
463
 
442
464
 
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
443
473
 
444
474
 
445
475
 
@@ -496,6 +526,13 @@ var Heap = class _Heap extends IterableElementBase {
496
526
 
497
527
 
498
528
 
529
+
530
+
531
+
532
+
533
+
534
+
535
+
499
536
 
500
537
 
501
538
 
@@ -504,6 +541,34 @@ var Heap = class _Heap extends IterableElementBase {
504
541
 
505
542
 
506
543
 
544
+ * @example
545
+ * // Heap with custom comparator (MaxHeap behavior)
546
+ * interface Task {
547
+ * id: number;
548
+ * priority: number;
549
+ * name: string;
550
+ * }
551
+ *
552
+ * // Custom comparator for max heap behavior (higher priority first)
553
+ * const tasks: Task[] = [
554
+ * { id: 1, priority: 5, name: 'Email' },
555
+ * { id: 2, priority: 3, name: 'Chat' },
556
+ * { id: 3, priority: 8, name: 'Alert' }
557
+ * ];
558
+ *
559
+ * const maxHeap = new Heap(tasks, {
560
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
561
+ * });
562
+ *
563
+ * console.log(maxHeap.size); // 3;
564
+ *
565
+ * // Peek returns highest priority task
566
+ * const topTask = maxHeap.peek();
567
+ * console.log(topTask?.priority); // 8;
568
+ * console.log(topTask?.name); // 'Alert';
569
+ */
570
+ /**
571
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
507
572
  * @example
508
573
  * // Heap with custom comparator (MaxHeap behavior)
509
574
  * interface Task {
@@ -531,6 +596,14 @@ var Heap = class _Heap extends IterableElementBase {
531
596
  * console.log(topTask?.name); // 'Alert';
532
597
  */
533
598
  poll() {
599
+ return this.pop();
600
+ }
601
+ /**
602
+ * Remove and return the top element (min or max depending on comparator).
603
+ * @remarks Time O(log N) amortized, Space O(1)
604
+ * @returns The removed top element, or undefined if empty.
605
+ */
606
+ pop() {
534
607
  if (this.elements.length === 0) return;
535
608
  const value = this.elements[0];
536
609
  const last = this.elements.pop();
@@ -566,6 +639,14 @@ var Heap = class _Heap extends IterableElementBase {
566
639
 
567
640
 
568
641
 
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
569
650
 
570
651
 
571
652
 
@@ -662,6 +743,14 @@ var Heap = class _Heap extends IterableElementBase {
662
743
 
663
744
 
664
745
 
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
665
754
 
666
755
 
667
756
 
@@ -705,6 +794,14 @@ var Heap = class _Heap extends IterableElementBase {
705
794
 
706
795
 
707
796
 
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+
708
805
 
709
806
 
710
807
 
@@ -723,16 +820,6 @@ var Heap = class _Heap extends IterableElementBase {
723
820
  clear() {
724
821
  this._elements = [];
725
822
  }
726
- /**
727
- * Replace the backing array and rebuild the heap.
728
- * @remarks Time O(N), Space O(N)
729
- * @param elements - Iterable used to refill the heap.
730
- * @returns Array of per-node results from fixing steps.
731
- */
732
- refill(elements) {
733
- this._elements = Array.from(elements);
734
- return this.fix();
735
- }
736
823
  /**
737
824
  * Check if an equal element exists in the heap.
738
825
  * @remarks Time O(N), Space O(1)
@@ -751,6 +838,14 @@ var Heap = class _Heap extends IterableElementBase {
751
838
 
752
839
 
753
840
 
841
+
842
+
843
+
844
+
845
+
846
+
847
+
848
+
754
849
 
755
850
 
756
851
 
@@ -794,6 +889,14 @@ var Heap = class _Heap extends IterableElementBase {
794
889
 
795
890
 
796
891
 
892
+
893
+
894
+
895
+
896
+
897
+
898
+
899
+
797
900
 
798
901
 
799
902
 
@@ -819,7 +922,7 @@ var Heap = class _Heap extends IterableElementBase {
819
922
  }
820
923
  if (index < 0) return false;
821
924
  if (index === 0) {
822
- this.poll();
925
+ this.pop();
823
926
  } else if (index === this.elements.length - 1) {
824
927
  this.elements.pop();
825
928
  } else {
@@ -829,13 +932,19 @@ var Heap = class _Heap extends IterableElementBase {
829
932
  }
830
933
  return true;
831
934
  }
935
+ /**
936
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
937
+ */
938
+ deleteBy(predicate) {
939
+ return this.deleteWhere(predicate);
940
+ }
832
941
  /**
833
942
  * Delete the first element that matches a predicate.
834
943
  * @remarks Time O(N), Space O(1)
835
944
  * @param predicate - Function (element, index, heap) → boolean.
836
945
  * @returns True if an element was removed.
837
946
  */
838
- deleteBy(predicate) {
947
+ deleteWhere(predicate) {
839
948
  let idx = -1;
840
949
  for (let i = 0; i < this.elements.length; i++) {
841
950
  if (predicate(this.elements[i], i, this)) {
@@ -845,7 +954,7 @@ var Heap = class _Heap extends IterableElementBase {
845
954
  }
846
955
  if (idx < 0) return false;
847
956
  if (idx === 0) {
848
- this.poll();
957
+ this.pop();
849
958
  } else if (idx === this.elements.length - 1) {
850
959
  this.elements.pop();
851
960
  } else {
@@ -883,6 +992,14 @@ var Heap = class _Heap extends IterableElementBase {
883
992
 
884
993
 
885
994
 
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+
1002
+
886
1003
 
887
1004
 
888
1005
 
@@ -959,6 +1076,14 @@ var Heap = class _Heap extends IterableElementBase {
959
1076
 
960
1077
 
961
1078
 
1079
+
1080
+
1081
+
1082
+
1083
+
1084
+
1085
+
1086
+
962
1087
 
963
1088
 
964
1089
 
@@ -1008,6 +1133,14 @@ var Heap = class _Heap extends IterableElementBase {
1008
1133
 
1009
1134
 
1010
1135
 
1136
+
1137
+
1138
+
1139
+
1140
+
1141
+
1142
+
1143
+
1011
1144
 
1012
1145
 
1013
1146
 
@@ -1056,6 +1189,14 @@ var Heap = class _Heap extends IterableElementBase {
1056
1189
 
1057
1190
 
1058
1191
 
1192
+
1193
+
1194
+
1195
+
1196
+
1197
+
1198
+
1199
+
1059
1200
 
1060
1201
 
1061
1202
 
@@ -1111,6 +1252,14 @@ var Heap = class _Heap extends IterableElementBase {
1111
1252
 
1112
1253
 
1113
1254
 
1255
+
1256
+
1257
+
1258
+
1259
+
1260
+
1261
+
1262
+
1114
1263
 
1115
1264
 
1116
1265
 
@@ -1128,7 +1277,7 @@ var Heap = class _Heap extends IterableElementBase {
1128
1277
  */
1129
1278
  map(callback, options, thisArg) {
1130
1279
  const { comparator, toElementFn, ...rest } = options ?? {};
1131
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1280
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1132
1281
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1133
1282
  let i = 0;
1134
1283
  for (const x of this) {
@@ -1155,7 +1304,7 @@ var Heap = class _Heap extends IterableElementBase {
1155
1304
  }
1156
1305
  _DEFAULT_COMPARATOR = /* @__PURE__ */ __name((a, b) => {
1157
1306
  if (typeof a === "object" || typeof b === "object") {
1158
- throw new TypeError(ERR.comparatorRequired("Heap"));
1307
+ raise(TypeError, ERR.comparatorRequired("Heap"));
1159
1308
  }
1160
1309
  if (a > b) return 1;
1161
1310
  if (a < b) return -1;
@@ -1280,7 +1429,7 @@ var MaxPriorityQueue = class extends PriorityQueue {
1280
1429
  super(elements, {
1281
1430
  comparator: /* @__PURE__ */ __name((a, b) => {
1282
1431
  if (typeof a === "object" || typeof b === "object") {
1283
- throw new TypeError(ERR.comparatorRequired("MaxPriorityQueue"));
1432
+ raise(TypeError, ERR.comparatorRequired("MaxPriorityQueue"));
1284
1433
  }
1285
1434
  if (a < b) return 1;
1286
1435
  if (a > b) return -1;