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
@@ -5,6 +5,37 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
5
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
6
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
7
 
8
+ // src/common/error.ts
9
+ function raise(ErrorClass, message) {
10
+ throw new ErrorClass(message);
11
+ }
12
+ __name(raise, "raise");
13
+ var ERR = {
14
+ // Range / index
15
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
16
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
17
+ // Type / argument
18
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
19
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
20
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
21
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
22
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
23
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
24
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
25
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
26
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
27
+ // State / operation
28
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
29
+ // Matrix
30
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
31
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
32
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
33
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
34
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
35
+ // Order statistic
36
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
37
+ };
38
+
8
39
  // src/data-structures/base/iterable-element-base.ts
9
40
  var _IterableElementBase = class _IterableElementBase {
10
41
  /**
@@ -27,7 +58,7 @@ var _IterableElementBase = class _IterableElementBase {
27
58
  if (options) {
28
59
  const { toElementFn } = options;
29
60
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
30
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
61
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
31
62
  }
32
63
  }
33
64
  /**
@@ -183,7 +214,7 @@ var _IterableElementBase = class _IterableElementBase {
183
214
  acc = initialValue;
184
215
  } else {
185
216
  const first = iter.next();
186
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
217
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
187
218
  acc = first.value;
188
219
  index = 1;
189
220
  }
@@ -227,31 +258,6 @@ var _IterableElementBase = class _IterableElementBase {
227
258
  __name(_IterableElementBase, "IterableElementBase");
228
259
  var IterableElementBase = _IterableElementBase;
229
260
 
230
- // src/common/error.ts
231
- var ERR = {
232
- // Range / index
233
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
234
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
235
- // Type / argument
236
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
237
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
238
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
239
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
240
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
241
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
242
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
243
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
244
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
245
- // State / operation
246
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
247
- // Matrix
248
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
249
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
250
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
251
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
252
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
253
- };
254
-
255
261
  // src/data-structures/heap/heap.ts
256
262
  var _Heap = class _Heap extends IterableElementBase {
257
263
  /**
@@ -267,7 +273,7 @@ var _Heap = class _Heap extends IterableElementBase {
267
273
  __publicField(this, "_elements", []);
268
274
  __publicField(this, "_DEFAULT_COMPARATOR", /* @__PURE__ */ __name((a, b) => {
269
275
  if (typeof a === "object" || typeof b === "object") {
270
- throw new TypeError(ERR.comparatorRequired("Heap"));
276
+ raise(TypeError, ERR.comparatorRequired("Heap"));
271
277
  }
272
278
  if (a > b) return 1;
273
279
  if (a < b) return -1;
@@ -314,6 +320,14 @@ var _Heap = class _Heap extends IterableElementBase {
314
320
 
315
321
 
316
322
 
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
317
331
 
318
332
 
319
333
 
@@ -372,7 +386,7 @@ var _Heap = class _Heap extends IterableElementBase {
372
386
  }
373
387
  /**
374
388
  * Insert an element.
375
- * @remarks Time O(1) amortized, Space O(1)
389
+ * @remarks Time O(log N) amortized, Space O(1)
376
390
  * @param element - Element to insert.
377
391
  * @returns True.
378
392
 
@@ -397,6 +411,14 @@ var _Heap = class _Heap extends IterableElementBase {
397
411
 
398
412
 
399
413
 
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
400
422
 
401
423
 
402
424
 
@@ -450,6 +472,14 @@ var _Heap = class _Heap extends IterableElementBase {
450
472
 
451
473
 
452
474
 
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
453
483
 
454
484
 
455
485
 
@@ -506,6 +536,13 @@ var _Heap = class _Heap extends IterableElementBase {
506
536
 
507
537
 
508
538
 
539
+
540
+
541
+
542
+
543
+
544
+
545
+
509
546
 
510
547
 
511
548
 
@@ -514,6 +551,34 @@ var _Heap = class _Heap extends IterableElementBase {
514
551
 
515
552
 
516
553
 
554
+ * @example
555
+ * // Heap with custom comparator (MaxHeap behavior)
556
+ * interface Task {
557
+ * id: number;
558
+ * priority: number;
559
+ * name: string;
560
+ * }
561
+ *
562
+ * // Custom comparator for max heap behavior (higher priority first)
563
+ * const tasks: Task[] = [
564
+ * { id: 1, priority: 5, name: 'Email' },
565
+ * { id: 2, priority: 3, name: 'Chat' },
566
+ * { id: 3, priority: 8, name: 'Alert' }
567
+ * ];
568
+ *
569
+ * const maxHeap = new Heap(tasks, {
570
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
571
+ * });
572
+ *
573
+ * console.log(maxHeap.size); // 3;
574
+ *
575
+ * // Peek returns highest priority task
576
+ * const topTask = maxHeap.peek();
577
+ * console.log(topTask?.priority); // 8;
578
+ * console.log(topTask?.name); // 'Alert';
579
+ */
580
+ /**
581
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
517
582
  * @example
518
583
  * // Heap with custom comparator (MaxHeap behavior)
519
584
  * interface Task {
@@ -541,6 +606,14 @@ var _Heap = class _Heap extends IterableElementBase {
541
606
  * console.log(topTask?.name); // 'Alert';
542
607
  */
543
608
  poll() {
609
+ return this.pop();
610
+ }
611
+ /**
612
+ * Remove and return the top element (min or max depending on comparator).
613
+ * @remarks Time O(log N) amortized, Space O(1)
614
+ * @returns The removed top element, or undefined if empty.
615
+ */
616
+ pop() {
544
617
  if (this.elements.length === 0) return;
545
618
  const value = this.elements[0];
546
619
  const last = this.elements.pop();
@@ -576,6 +649,14 @@ var _Heap = class _Heap extends IterableElementBase {
576
649
 
577
650
 
578
651
 
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
579
660
 
580
661
 
581
662
 
@@ -672,6 +753,14 @@ var _Heap = class _Heap extends IterableElementBase {
672
753
 
673
754
 
674
755
 
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
675
764
 
676
765
 
677
766
 
@@ -715,6 +804,14 @@ var _Heap = class _Heap extends IterableElementBase {
715
804
 
716
805
 
717
806
 
807
+
808
+
809
+
810
+
811
+
812
+
813
+
814
+
718
815
 
719
816
 
720
817
 
@@ -733,16 +830,6 @@ var _Heap = class _Heap extends IterableElementBase {
733
830
  clear() {
734
831
  this._elements = [];
735
832
  }
736
- /**
737
- * Replace the backing array and rebuild the heap.
738
- * @remarks Time O(N), Space O(N)
739
- * @param elements - Iterable used to refill the heap.
740
- * @returns Array of per-node results from fixing steps.
741
- */
742
- refill(elements) {
743
- this._elements = Array.from(elements);
744
- return this.fix();
745
- }
746
833
  /**
747
834
  * Check if an equal element exists in the heap.
748
835
  * @remarks Time O(N), Space O(1)
@@ -761,6 +848,14 @@ var _Heap = class _Heap extends IterableElementBase {
761
848
 
762
849
 
763
850
 
851
+
852
+
853
+
854
+
855
+
856
+
857
+
858
+
764
859
 
765
860
 
766
861
 
@@ -804,6 +899,14 @@ var _Heap = class _Heap extends IterableElementBase {
804
899
 
805
900
 
806
901
 
902
+
903
+
904
+
905
+
906
+
907
+
908
+
909
+
807
910
 
808
911
 
809
912
 
@@ -829,7 +932,7 @@ var _Heap = class _Heap extends IterableElementBase {
829
932
  }
830
933
  if (index < 0) return false;
831
934
  if (index === 0) {
832
- this.poll();
935
+ this.pop();
833
936
  } else if (index === this.elements.length - 1) {
834
937
  this.elements.pop();
835
938
  } else {
@@ -839,13 +942,19 @@ var _Heap = class _Heap extends IterableElementBase {
839
942
  }
840
943
  return true;
841
944
  }
945
+ /**
946
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
947
+ */
948
+ deleteBy(predicate) {
949
+ return this.deleteWhere(predicate);
950
+ }
842
951
  /**
843
952
  * Delete the first element that matches a predicate.
844
953
  * @remarks Time O(N), Space O(1)
845
954
  * @param predicate - Function (element, index, heap) → boolean.
846
955
  * @returns True if an element was removed.
847
956
  */
848
- deleteBy(predicate) {
957
+ deleteWhere(predicate) {
849
958
  let idx = -1;
850
959
  for (let i = 0; i < this.elements.length; i++) {
851
960
  if (predicate(this.elements[i], i, this)) {
@@ -855,7 +964,7 @@ var _Heap = class _Heap extends IterableElementBase {
855
964
  }
856
965
  if (idx < 0) return false;
857
966
  if (idx === 0) {
858
- this.poll();
967
+ this.pop();
859
968
  } else if (idx === this.elements.length - 1) {
860
969
  this.elements.pop();
861
970
  } else {
@@ -893,6 +1002,14 @@ var _Heap = class _Heap extends IterableElementBase {
893
1002
 
894
1003
 
895
1004
 
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
896
1013
 
897
1014
 
898
1015
 
@@ -969,6 +1086,14 @@ var _Heap = class _Heap extends IterableElementBase {
969
1086
 
970
1087
 
971
1088
 
1089
+
1090
+
1091
+
1092
+
1093
+
1094
+
1095
+
1096
+
972
1097
 
973
1098
 
974
1099
 
@@ -1018,6 +1143,14 @@ var _Heap = class _Heap extends IterableElementBase {
1018
1143
 
1019
1144
 
1020
1145
 
1146
+
1147
+
1148
+
1149
+
1150
+
1151
+
1152
+
1153
+
1021
1154
 
1022
1155
 
1023
1156
 
@@ -1066,6 +1199,14 @@ var _Heap = class _Heap extends IterableElementBase {
1066
1199
 
1067
1200
 
1068
1201
 
1202
+
1203
+
1204
+
1205
+
1206
+
1207
+
1208
+
1209
+
1069
1210
 
1070
1211
 
1071
1212
 
@@ -1121,6 +1262,14 @@ var _Heap = class _Heap extends IterableElementBase {
1121
1262
 
1122
1263
 
1123
1264
 
1265
+
1266
+
1267
+
1268
+
1269
+
1270
+
1271
+
1272
+
1124
1273
 
1125
1274
 
1126
1275
 
@@ -1138,7 +1287,7 @@ var _Heap = class _Heap extends IterableElementBase {
1138
1287
  */
1139
1288
  map(callback, options, thisArg) {
1140
1289
  const { comparator, toElementFn, ...rest } = options != null ? options : {};
1141
- if (!comparator) throw new TypeError(ERR.comparatorRequired("Heap.map"));
1290
+ if (!comparator) raise(TypeError, ERR.comparatorRequired("Heap.map"));
1142
1291
  const out = this._createLike([], { ...rest, comparator, toElementFn });
1143
1292
  let i = 0;
1144
1293
  for (const x of this) {
@@ -1270,7 +1419,7 @@ var _FibonacciHeap = class _FibonacciHeap {
1270
1419
  __publicField(this, "_comparator");
1271
1420
  this.clear();
1272
1421
  this._comparator = comparator || this._defaultComparator;
1273
- if (typeof this.comparator !== "function") throw new TypeError(ERR.notAFunction("comparator", "FibonacciHeap"));
1422
+ if (typeof this.comparator !== "function") raise(TypeError, ERR.notAFunction("comparator", "FibonacciHeap"));
1274
1423
  }
1275
1424
  /**
1276
1425
  * Get the circular root list head.
@@ -1307,7 +1456,7 @@ var _FibonacciHeap = class _FibonacciHeap {
1307
1456
  * Push an element into the root list.
1308
1457
  * @remarks Time O(1) amortized, Space O(1)
1309
1458
  * @param element - Element to insert.
1310
- * @returns This heap.
1459
+ * @returns True when the element is added.
1311
1460
  */
1312
1461
  push(element) {
1313
1462
  const node = this.createNode(element);
@@ -1316,7 +1465,7 @@ var _FibonacciHeap = class _FibonacciHeap {
1316
1465
  this.mergeWithRoot(node);
1317
1466
  if (!this.min || this.comparator(node.element, this.min.element) <= 0) this._min = node;
1318
1467
  this._size++;
1319
- return this;
1468
+ return true;
1320
1469
  }
1321
1470
  peek() {
1322
1471
  return this.min ? this.min.element : void 0;
@@ -1481,7 +1630,7 @@ var _MaxHeap = class _MaxHeap extends Heap {
1481
1630
  super(elements, {
1482
1631
  comparator: /* @__PURE__ */ __name((a, b) => {
1483
1632
  if (typeof a === "object" || typeof b === "object") {
1484
- throw new TypeError(ERR.comparatorRequired("MaxHeap"));
1633
+ raise(TypeError, ERR.comparatorRequired("MaxHeap"));
1485
1634
  }
1486
1635
  if (a < b) return 1;
1487
1636
  if (a > b) return -1;