data-structure-typed 1.51.8 → 1.52.0

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 (216) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +13 -13
  3. package/benchmark/report.html +13 -13
  4. package/benchmark/report.json +152 -152
  5. package/dist/cjs/data-structures/base/index.d.ts +2 -1
  6. package/dist/cjs/data-structures/base/index.js +2 -1
  7. package/dist/cjs/data-structures/base/index.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +171 -0
  9. package/dist/cjs/data-structures/base/iterable-element-base.js +226 -0
  10. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -0
  11. package/dist/cjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  12. package/dist/cjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +13 -190
  13. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -0
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +82 -62
  18. package/dist/cjs/data-structures/binary-tree/avl-tree.js +78 -59
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +318 -226
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.js +475 -363
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/bst.d.ts +192 -202
  24. package/dist/cjs/data-structures/binary-tree/bst.js +207 -249
  25. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
  27. package/dist/cjs/data-structures/binary-tree/rb-tree.js +107 -98
  28. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
  30. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -93
  31. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  32. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +10 -15
  33. package/dist/cjs/data-structures/graph/abstract-graph.js +10 -15
  34. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  35. package/dist/cjs/data-structures/hash/hash-map.d.ts +33 -40
  36. package/dist/cjs/data-structures/hash/hash-map.js +40 -55
  37. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/heap.d.ts +43 -114
  39. package/dist/cjs/data-structures/heap/heap.js +59 -127
  40. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  41. package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
  42. package/dist/cjs/data-structures/heap/max-heap.js +76 -10
  43. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  44. package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
  45. package/dist/cjs/data-structures/heap/min-heap.js +68 -11
  46. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  49. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
  52. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  53. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  54. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
  55. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  56. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  57. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  58. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  59. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  60. package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
  61. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  62. package/dist/cjs/data-structures/queue/deque.d.ts +21 -20
  63. package/dist/cjs/data-structures/queue/deque.js +29 -23
  64. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  65. package/dist/cjs/data-structures/queue/queue.d.ts +8 -28
  66. package/dist/cjs/data-structures/queue/queue.js +15 -31
  67. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  68. package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
  69. package/dist/cjs/data-structures/stack/stack.js +25 -24
  70. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  71. package/dist/cjs/data-structures/trie/trie.d.ts +19 -14
  72. package/dist/cjs/data-structures/trie/trie.js +27 -16
  73. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  74. package/dist/cjs/interfaces/binary-tree.d.ts +7 -7
  75. package/dist/cjs/types/common.d.ts +1 -2
  76. package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
  77. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  78. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  79. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  80. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +4 -5
  81. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  82. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  83. package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
  84. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  85. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  86. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  87. package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -2
  88. package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
  89. package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
  90. package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
  91. package/dist/cjs/utils/utils.js +3 -5
  92. package/dist/cjs/utils/utils.js.map +1 -1
  93. package/dist/mjs/data-structures/base/index.d.ts +2 -1
  94. package/dist/mjs/data-structures/base/index.js +2 -1
  95. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
  96. package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
  97. package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  98. package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
  99. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
  100. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  101. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +82 -62
  102. package/dist/mjs/data-structures/binary-tree/avl-tree.js +78 -59
  103. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +318 -226
  104. package/dist/mjs/data-structures/binary-tree/binary-tree.js +476 -364
  105. package/dist/mjs/data-structures/binary-tree/bst.d.ts +192 -202
  106. package/dist/mjs/data-structures/binary-tree/bst.js +211 -255
  107. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
  108. package/dist/mjs/data-structures/binary-tree/rb-tree.js +107 -98
  109. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
  110. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +105 -93
  111. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +10 -15
  112. package/dist/mjs/data-structures/graph/abstract-graph.js +10 -15
  113. package/dist/mjs/data-structures/hash/hash-map.d.ts +33 -40
  114. package/dist/mjs/data-structures/hash/hash-map.js +41 -55
  115. package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
  116. package/dist/mjs/data-structures/heap/heap.js +60 -128
  117. package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
  118. package/dist/mjs/data-structures/heap/max-heap.js +79 -10
  119. package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
  120. package/dist/mjs/data-structures/heap/min-heap.js +68 -11
  121. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  122. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  123. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  124. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
  125. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  126. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
  127. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  128. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  129. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  130. package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
  131. package/dist/mjs/data-structures/queue/deque.d.ts +21 -20
  132. package/dist/mjs/data-structures/queue/deque.js +29 -23
  133. package/dist/mjs/data-structures/queue/queue.d.ts +8 -28
  134. package/dist/mjs/data-structures/queue/queue.js +15 -31
  135. package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
  136. package/dist/mjs/data-structures/stack/stack.js +25 -24
  137. package/dist/mjs/data-structures/trie/trie.d.ts +19 -14
  138. package/dist/mjs/data-structures/trie/trie.js +27 -16
  139. package/dist/mjs/interfaces/binary-tree.d.ts +7 -7
  140. package/dist/mjs/types/common.d.ts +1 -2
  141. package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
  142. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  143. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  144. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  145. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +4 -5
  146. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  147. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  148. package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
  149. package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  150. package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  151. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  152. package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -2
  153. package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
  154. package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
  155. package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
  156. package/dist/mjs/utils/utils.js +3 -5
  157. package/dist/umd/data-structure-typed.js +1949 -1481
  158. package/dist/umd/data-structure-typed.min.js +2 -2
  159. package/dist/umd/data-structure-typed.min.js.map +1 -1
  160. package/package.json +6 -6
  161. package/src/data-structures/base/index.ts +2 -1
  162. package/src/data-structures/base/iterable-element-base.ts +250 -0
  163. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  164. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
  165. package/src/data-structures/binary-tree/avl-tree.ts +96 -69
  166. package/src/data-structures/binary-tree/binary-tree.ts +535 -403
  167. package/src/data-structures/binary-tree/bst.ts +247 -277
  168. package/src/data-structures/binary-tree/rb-tree.ts +123 -103
  169. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
  170. package/src/data-structures/graph/abstract-graph.ts +10 -10
  171. package/src/data-structures/hash/hash-map.ts +46 -53
  172. package/src/data-structures/heap/heap.ts +71 -152
  173. package/src/data-structures/heap/max-heap.ts +88 -13
  174. package/src/data-structures/heap/min-heap.ts +78 -15
  175. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  176. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  177. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  178. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  179. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  180. package/src/data-structures/queue/deque.ts +37 -26
  181. package/src/data-structures/queue/queue.ts +23 -36
  182. package/src/data-structures/stack/stack.ts +31 -26
  183. package/src/data-structures/trie/trie.ts +35 -20
  184. package/src/interfaces/binary-tree.ts +9 -9
  185. package/src/types/common.ts +1 -2
  186. package/src/types/data-structures/base/base.ts +14 -6
  187. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
  188. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
  189. package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
  190. package/src/types/data-structures/binary-tree/bst.ts +4 -5
  191. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
  192. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
  193. package/src/types/data-structures/heap/heap.ts +4 -1
  194. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  195. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  196. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  197. package/src/types/data-structures/queue/deque.ts +3 -1
  198. package/src/types/data-structures/queue/queue.ts +3 -1
  199. package/src/types/data-structures/stack/stack.ts +3 -1
  200. package/src/types/data-structures/trie/trie.ts +3 -1
  201. package/src/utils/utils.ts +3 -3
  202. package/test/integration/avl-tree.test.ts +2 -2
  203. package/test/integration/bst.test.ts +3 -3
  204. package/test/integration/index.html +25 -11
  205. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +68 -0
  206. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +56 -0
  207. package/test/unit/data-structures/graph/directed-graph.test.ts +2 -2
  208. package/test/unit/data-structures/heap/heap.test.ts +80 -0
  209. package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
  210. package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
  211. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
  212. package/test/unit/data-structures/queue/deque.test.ts +30 -0
  213. package/test/unit/data-structures/queue/queue.test.ts +56 -0
  214. package/test/utils/big-o.ts +12 -6
  215. package/tsconfig-base.json +1 -0
  216. package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C,MAAa,oBAAoB;IAC/B;;;;OAIG;IACH,YAAY,KAAQ;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;IACzB,CAAC;IAID;;;OAGG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI,KAAK,CAAC,KAAQ;QAChB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAID;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;;;OAKG;IACH,IAAI,IAAI,CAAC,KAA0C;QACjD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAjDD,oDAiDC;AAED,MAAa,gBAA0B,SAAQ,0BAAsB;IACnE;;;;;OAKG;IACH,YAAY,WAAwB,EAAE;QACpC,KAAK,EAAE,CAAC;QA4CA,UAAK,GAAW,CAAC,CAAC;QA3C1B,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,MAAM,EAAE,IAAI,QAA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;;;;OAgBG;IACH,MAAM,CAAC,QAAqC,EAAE,OAAa;QACzD,MAAM,YAAY,GAAG,IAAI,gBAAgB,EAAK,CAAC;QAC/C,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;gBACjD,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7B,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAI,QAA+B,EAAE,OAAa;QACnD,MAAM,UAAU,GAAG,IAAI,gBAAgB,EAAK,CAAC;QAC7C,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YAC9D,KAAK,EAAE,CAAC;QACV,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;OAEG;IACM,CAAE,YAAY;QACrB,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE,CAAC;YACf,MAAM,OAAO,CAAC,KAAK,CAAC;YACpB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AAprBD,4CAorBC"}
1
+ {"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C,MAAa,oBAAoB;IAC/B;;;;OAIG;IACH,YAAY,KAAQ;QAClB,IAAI,CAAC,MAAM,GAA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AC,OAAO,CAAC,CAAC;YAC7B,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;IAED;;;OAGG;IAEH;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CACD,QAA2D,EAC3D,WAAoC,EACpC,OAAa;QAEb,MAAM,UAAU,GAAG,IAAI,gBAAgB,CAAS,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;QACrE,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YAC9D,KAAK,EAAE,CAAC;QACV,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;OAEG;IACM,CAAE,YAAY;QACrB,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE,CAAC;YACf,MAAM,OAAO,CAAC,KAAK,CAAC;YACpB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AA5rBD,4CA4rBC"}
@@ -5,9 +5,9 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { PriorityQueueOptions } from '../../types';
8
+ import type { Comparator, ElementCallback, PriorityQueueOptions } from '../../types';
9
9
  import { PriorityQueue } from './priority-queue';
10
- export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
10
+ export declare class MaxPriorityQueue<E = any, R = any> extends PriorityQueue<E, R> {
11
11
  /**
12
12
  * The constructor initializes a PriorityQueue with optional elements and options, including a
13
13
  * comparator function.
@@ -15,8 +15,54 @@ export declare class MaxPriorityQueue<E = any> extends PriorityQueue<E> {
15
15
  * elements to be added to the priority queue. It is optional and defaults to an empty array if not
16
16
  * provided.
17
17
  * @param options - The `options` parameter is an object that contains additional configuration
18
- * options for the priority queue. In this case, it has a property called `comparator` which is a
18
+ * options for the priority queue. In this case, it has a property called `comparator,` which is a
19
19
  * function used to compare elements in the priority queue.
20
20
  */
21
- constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
21
+ constructor(elements?: Iterable<E> | Iterable<R>, options?: PriorityQueueOptions<E, R>);
22
+ /**
23
+ * The `clone` function returns a new instance of the `MaxPriorityQueue` class with the same
24
+ * comparator and toElementFn as the current instance.
25
+ * @returns The method is returning a new instance of the MaxPriorityQueue class with the same
26
+ * comparator and toElementFn as the current instance.
27
+ */
28
+ clone(): MaxPriorityQueue<E, R>;
29
+ /**
30
+ * Time Complexity: O(n)
31
+ * Space Complexity: O(n)
32
+ *
33
+ * The `filter` function creates a new MaxPriorityQueue object containing elements that pass a given callback
34
+ * function.
35
+ * @param callback - The `callback` parameter is a function that will be called for each element in
36
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
37
+ * heap itself. The callback function should return a boolean value indicating whether the current
38
+ * element should be included in the filtered list
39
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
40
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
41
+ * passed as the `this` value to the `callback` function. If `thisArg` is
42
+ * @returns The `filter` method is returning a new `MaxPriorityQueue` object that contains the elements that pass
43
+ * the filter condition specified by the `callback` function.
44
+ */
45
+ filter(callback: ElementCallback<E, R, boolean, MaxPriorityQueue<E, R>>, thisArg?: any): MaxPriorityQueue<E, R>;
46
+ /**
47
+ * Time Complexity: O(n log n)
48
+ * Space Complexity: O(n)
49
+ *
50
+ * The `map` function creates a new heap by applying a callback function to each element of the
51
+ * original heap.
52
+ * @param callback - The `callback` parameter is a function that will be called for each element in
53
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
54
+ * element), and `this` (the heap itself). The callback function should return a value of
55
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
56
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
57
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
58
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
59
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
60
+ * returns a value of type `T`. This function is used to transform the elements of the original
61
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
62
+ * specify the value of `this` within the callback function. It is used to set the context or scope
63
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
64
+ * value of
65
+ * @returns a new instance of the `MaxPriorityQueue` class with the mapped elements.
66
+ */
67
+ map<EM, RM>(callback: ElementCallback<E, R, EM, MaxPriorityQueue<E, R>>, comparator: Comparator<EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): MaxPriorityQueue<EM, RM>;
22
68
  }
@@ -10,20 +10,89 @@ class MaxPriorityQueue extends priority_queue_1.PriorityQueue {
10
10
  * elements to be added to the priority queue. It is optional and defaults to an empty array if not
11
11
  * provided.
12
12
  * @param options - The `options` parameter is an object that contains additional configuration
13
- * options for the priority queue. In this case, it has a property called `comparator` which is a
13
+ * options for the priority queue. In this case, it has a property called `comparator,` which is a
14
14
  * function used to compare elements in the priority queue.
15
15
  */
16
- constructor(elements = [], options = {
17
- comparator: (a, b) => {
18
- if (!(typeof a === 'number' && typeof b === 'number')) {
19
- throw new Error('The a, b params of compare function must be number');
20
- }
21
- else {
22
- return b - a;
16
+ constructor(elements = [], options) {
17
+ super(elements, Object.assign({ comparator: (a, b) => {
18
+ if (typeof a === 'object' || typeof b === 'object') {
19
+ throw TypeError(`When comparing object types, a custom comparator must be defined in the constructor's options parameter.`);
20
+ }
21
+ if (a < b)
22
+ return 1;
23
+ if (a > b)
24
+ return -1;
25
+ return 0;
26
+ } }, options));
27
+ }
28
+ /**
29
+ * The `clone` function returns a new instance of the `MaxPriorityQueue` class with the same
30
+ * comparator and toElementFn as the current instance.
31
+ * @returns The method is returning a new instance of the MaxPriorityQueue class with the same
32
+ * comparator and toElementFn as the current instance.
33
+ */
34
+ clone() {
35
+ return new MaxPriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
36
+ }
37
+ /**
38
+ * Time Complexity: O(n)
39
+ * Space Complexity: O(n)
40
+ *
41
+ * The `filter` function creates a new MaxPriorityQueue object containing elements that pass a given callback
42
+ * function.
43
+ * @param callback - The `callback` parameter is a function that will be called for each element in
44
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
45
+ * heap itself. The callback function should return a boolean value indicating whether the current
46
+ * element should be included in the filtered list
47
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
48
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
49
+ * passed as the `this` value to the `callback` function. If `thisArg` is
50
+ * @returns The `filter` method is returning a new `MaxPriorityQueue` object that contains the elements that pass
51
+ * the filter condition specified by the `callback` function.
52
+ */
53
+ filter(callback, thisArg) {
54
+ const filteredPriorityQueue = new MaxPriorityQueue([], {
55
+ toElementFn: this.toElementFn,
56
+ comparator: this.comparator
57
+ });
58
+ let index = 0;
59
+ for (const current of this) {
60
+ if (callback.call(thisArg, current, index, this)) {
61
+ filteredPriorityQueue.add(current);
23
62
  }
63
+ index++;
64
+ }
65
+ return filteredPriorityQueue;
66
+ }
67
+ /**
68
+ * Time Complexity: O(n log n)
69
+ * Space Complexity: O(n)
70
+ *
71
+ * The `map` function creates a new heap by applying a callback function to each element of the
72
+ * original heap.
73
+ * @param callback - The `callback` parameter is a function that will be called for each element in
74
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
75
+ * element), and `this` (the heap itself). The callback function should return a value of
76
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
77
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
78
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
79
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
80
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
81
+ * returns a value of type `T`. This function is used to transform the elements of the original
82
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
83
+ * specify the value of `this` within the callback function. It is used to set the context or scope
84
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
85
+ * value of
86
+ * @returns a new instance of the `MaxPriorityQueue` class with the mapped elements.
87
+ */
88
+ map(callback, comparator, toElementFn, thisArg) {
89
+ const mappedPriorityQueue = new MaxPriorityQueue([], { comparator, toElementFn });
90
+ let index = 0;
91
+ for (const el of this) {
92
+ mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
93
+ index++;
24
94
  }
25
- }) {
26
- super(elements, options);
95
+ return mappedPriorityQueue;
27
96
  }
28
97
  }
29
98
  exports.MaxPriorityQueue = MaxPriorityQueue;
@@ -1 +1 @@
1
- {"version":3,"file":"max-priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/max-priority-queue.ts"],"names":[],"mappings":";;;AAQA,qDAAiD;AAEjD,MAAa,gBAA0B,SAAQ,8BAAgB;IAC7D;;;;;;;;;OASG;IACH,YACE,WAAwB,EAAE,EAC1B,UAAmC;QACjC,UAAU,EAAE,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;YACzB,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE,CAAC;gBACtD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACxE,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,CAAC;YACf,CAAC;QACH,CAAC;KACF;QAED,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF;AAzBD,4CAyBC"}
1
+ {"version":3,"file":"max-priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/max-priority-queue.ts"],"names":[],"mappings":";;;AAQA,qDAAiD;AAEjD,MAAa,gBAAmC,SAAQ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QAA2D,EAC3D,UAA0B,EAC1B,WAAoC,EACpC,OAAa;QAEb,MAAM,mBAAmB,GAAG,IAAI,gBAAgB,CAAS,EAAE,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QAC1F,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;YACtB,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACjE,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,mBAAmB,CAAC;IAC7B,CAAC;CACF;AA1GD,4CA0GC"}
@@ -5,9 +5,9 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { PriorityQueueOptions } from '../../types';
8
+ import type { Comparator, ElementCallback, PriorityQueueOptions } from '../../types';
9
9
  import { PriorityQueue } from './priority-queue';
10
- export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
10
+ export declare class MinPriorityQueue<E = any, R = any> extends PriorityQueue<E, R> {
11
11
  /**
12
12
  * The constructor initializes a PriorityQueue with optional elements and options, including a
13
13
  * comparator function.
@@ -15,9 +15,55 @@ export declare class MinPriorityQueue<E = any> extends PriorityQueue<E> {
15
15
  * elements to be added to the priority queue. It is optional and defaults to an empty array if not
16
16
  * provided.
17
17
  * @param options - The `options` parameter is an object that contains additional configuration
18
- * options for the priority queue. In this case, it has a property called `comparator` which is a
18
+ * options for the priority queue. In this case, it has a property called `comparator,` which is a
19
19
  * function used to compare elements in the priority queue. The `comparator` function takes two
20
- * parameters `a` and `b`,
20
+ * parameters `a` and `b`
21
21
  */
22
- constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
22
+ constructor(elements?: Iterable<E> | Iterable<R>, options?: PriorityQueueOptions<E, R>);
23
+ /**
24
+ * The `clone` function returns a new instance of the `MinPriorityQueue` class with the same
25
+ * comparator and toElementFn as the original instance.
26
+ * @returns The method is returning a new instance of the `MinPriorityQueue` class with the same
27
+ * properties as the current instance.
28
+ */
29
+ clone(): MinPriorityQueue<E, R>;
30
+ /**
31
+ * Time Complexity: O(n)
32
+ * Space Complexity: O(n)
33
+ *
34
+ * The `filter` function creates a new MinPriorityQueue object containing elements that pass a given callback
35
+ * function.
36
+ * @param callback - The `callback` parameter is a function that will be called for each element in
37
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
38
+ * heap itself. The callback function should return a boolean value indicating whether the current
39
+ * element should be included in the filtered list
40
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
41
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
42
+ * passed as the `this` value to the `callback` function. If `thisArg` is
43
+ * @returns The `filter` method is returning a new `MinPriorityQueue` object that contains the elements that pass
44
+ * the filter condition specified by the `callback` function.
45
+ */
46
+ filter(callback: ElementCallback<E, R, boolean, MinPriorityQueue<E, R>>, thisArg?: any): MinPriorityQueue<E, R>;
47
+ /**
48
+ * Time Complexity: O(n log n)
49
+ * Space Complexity: O(n)
50
+ *
51
+ * The `map` function creates a new heap by applying a callback function to each element of the
52
+ * original heap.
53
+ * @param callback - The `callback` parameter is a function that will be called for each element in
54
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
55
+ * element), and `this` (the heap itself). The callback function should return a value of
56
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
57
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
58
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
59
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
60
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
61
+ * returns a value of type `T`. This function is used to transform the elements of the original
62
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
63
+ * specify the value of `this` within the callback function. It is used to set the context or scope
64
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
65
+ * value of
66
+ * @returns a new instance of the `MinPriorityQueue` class with the mapped elements.
67
+ */
68
+ map<EM, RM>(callback: ElementCallback<E, R, EM, MinPriorityQueue<E, R>>, comparator: Comparator<EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): MinPriorityQueue<EM, RM>;
23
69
  }
@@ -10,21 +10,81 @@ class MinPriorityQueue extends priority_queue_1.PriorityQueue {
10
10
  * elements to be added to the priority queue. It is optional and defaults to an empty array if not
11
11
  * provided.
12
12
  * @param options - The `options` parameter is an object that contains additional configuration
13
- * options for the priority queue. In this case, it has a property called `comparator` which is a
13
+ * options for the priority queue. In this case, it has a property called `comparator,` which is a
14
14
  * function used to compare elements in the priority queue. The `comparator` function takes two
15
- * parameters `a` and `b`,
15
+ * parameters `a` and `b`
16
16
  */
17
- constructor(elements = [], options = {
18
- comparator: (a, b) => {
19
- if (!(typeof a === 'number' && typeof b === 'number')) {
20
- throw new Error('The a, b params of compare function must be number');
21
- }
22
- else {
23
- return a - b;
17
+ constructor(elements = [], options) {
18
+ super(elements, options);
19
+ }
20
+ /**
21
+ * The `clone` function returns a new instance of the `MinPriorityQueue` class with the same
22
+ * comparator and toElementFn as the original instance.
23
+ * @returns The method is returning a new instance of the `MinPriorityQueue` class with the same
24
+ * properties as the current instance.
25
+ */
26
+ clone() {
27
+ return new MinPriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
28
+ }
29
+ /**
30
+ * Time Complexity: O(n)
31
+ * Space Complexity: O(n)
32
+ *
33
+ * The `filter` function creates a new MinPriorityQueue object containing elements that pass a given callback
34
+ * function.
35
+ * @param callback - The `callback` parameter is a function that will be called for each element in
36
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
37
+ * heap itself. The callback function should return a boolean value indicating whether the current
38
+ * element should be included in the filtered list
39
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
40
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
41
+ * passed as the `this` value to the `callback` function. If `thisArg` is
42
+ * @returns The `filter` method is returning a new `MinPriorityQueue` object that contains the elements that pass
43
+ * the filter condition specified by the `callback` function.
44
+ */
45
+ filter(callback, thisArg) {
46
+ const filteredPriorityQueue = new MinPriorityQueue([], {
47
+ toElementFn: this.toElementFn,
48
+ comparator: this.comparator
49
+ });
50
+ let index = 0;
51
+ for (const current of this) {
52
+ if (callback.call(thisArg, current, index, this)) {
53
+ filteredPriorityQueue.add(current);
24
54
  }
55
+ index++;
25
56
  }
26
- }) {
27
- super(elements, options);
57
+ return filteredPriorityQueue;
58
+ }
59
+ /**
60
+ * Time Complexity: O(n log n)
61
+ * Space Complexity: O(n)
62
+ *
63
+ * The `map` function creates a new heap by applying a callback function to each element of the
64
+ * original heap.
65
+ * @param callback - The `callback` parameter is a function that will be called for each element in
66
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
67
+ * element), and `this` (the heap itself). The callback function should return a value of
68
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
69
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
70
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
71
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
72
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
73
+ * returns a value of type `T`. This function is used to transform the elements of the original
74
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
75
+ * specify the value of `this` within the callback function. It is used to set the context or scope
76
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
77
+ * value of
78
+ * @returns a new instance of the `MinPriorityQueue` class with the mapped elements.
79
+ */
80
+ map(callback, comparator, toElementFn, thisArg) {
81
+ const mappedPriorityQueue = new MinPriorityQueue([], { comparator, toElementFn });
82
+ let index = 0;
83
+ for (const el of this) {
84
+ mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
85
+ index++;
86
+ }
87
+ return mappedPriorityQueue;
28
88
  }
29
89
  }
30
90
  exports.MinPriorityQueue = MinPriorityQueue;
@@ -1 +1 @@
1
- {"version":3,"file":"min-priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/min-priority-queue.ts"],"names":[],"mappings":";;;AAQA,qDAAiD;AAEjD,MAAa,gBAA0B,SAAQ,8BAAgB;IAC7D;;;;;;;;;;OAUG;IACH,YACE,WAAwB,EAAE,EAC1B,UAAmC;QACjC,UAAU,EAAE,CAAC,CAAI,EAAE,CAAI,EAAE,EAAE;YACzB,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC,EAAE,CAAC;gBACtD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;YACxE,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,CAAC;YACf,CAAC;QACH,CAAC;KACF;QAED,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF;AA1BD,4CA0BC"}
1
+ {"version":3,"file":"min-priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/min-priority-queue.ts"],"names":[],"mappings":";;;AAQA,qDAAiD;AAEjD,MAAa,gBAAmC,SAAQ,8BAAmB;IACzE;;;;;;;;;;OAUG;IACH,YAAY,WAAsC,EAAE,EAAE,OAAoC;QACxF,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACM,KAAK;QACZ,OAAO,IAAI,gBAAgB,CAAO,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1G,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACM,MAAM,CACb,QAAgE,EAChE,OAAa;QAEb,MAAM,qBAAqB,GAAG,IAAI,gBAAgB,CAAO,EAAE,EAAE;YAC3D,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;QACH,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;gBACjD,qBAAqB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACrC,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACM,GAAG,CACV,QAA2D,EAC3D,UAA0B,EAC1B,WAAoC,EACpC,OAAa;QAEb,MAAM,mBAAmB,GAA6B,IAAI,gBAAgB,CAAS,EAAE,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;QACpH,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;YACtB,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACjE,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,mBAAmB,CAAC;IAC7B,CAAC;CACF;AA/FD,4CA+FC"}
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { PriorityQueueOptions } from '../../types';
8
+ import type { Comparator, ElementCallback, PriorityQueueOptions } from '../../types';
9
9
  import { Heap } from '../heap';
10
10
  /**
11
11
  * 1. Element Priority: In a PriorityQueue, elements are sorted according to their priority. Each dequeue (element removal) operation removes the element with the highest priority. The priority can be determined based on the natural ordering of the elements or through a provided comparator (Comparator).
@@ -15,14 +15,60 @@ import { Heap } from '../heap';
15
15
  * 5. Huffman Coding: Used to select the smallest node combination when constructing a Huffman tree.
16
16
  * 6. Kth Largest Element in a Data Stream: Used to maintain a min-heap of size K for quickly finding the Kth largest element in stream data
17
17
  */
18
- export declare class PriorityQueue<E = any> extends Heap<E> {
18
+ export declare class PriorityQueue<E = any, R = any> extends Heap<E, R> {
19
19
  /**
20
20
  * The constructor initializes a priority queue with optional elements and options.
21
21
  * @param elements - The `elements` parameter is an iterable object that contains the initial
22
- * elements to be added to the priority queue. It is an optional parameter and if not provided, the
22
+ * elements to be added to the priority queue. It is an optional parameter, and if not provided, the
23
23
  * priority queue will be initialized as empty.
24
24
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
25
25
  * behavior of the priority queue. It can contain the following properties:
26
26
  */
27
- constructor(elements?: Iterable<E>, options?: PriorityQueueOptions<E>);
27
+ constructor(elements?: Iterable<E> | Iterable<R>, options?: PriorityQueueOptions<E, R>);
28
+ /**
29
+ * The `clone` function returns a new instance of the `PriorityQueue` class with the same comparator
30
+ * and toElementFn as the original instance.
31
+ * @returns The method is returning a new instance of the `PriorityQueue` class with the same
32
+ * elements and properties as the current instance.
33
+ */
34
+ clone(): PriorityQueue<E, R>;
35
+ /**
36
+ * Time Complexity: O(n)
37
+ * Space Complexity: O(n)
38
+ *
39
+ * The `filter` function creates a new PriorityQueue object containing elements that pass a given callback
40
+ * function.
41
+ * @param callback - The `callback` parameter is a function that will be called for each element in
42
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
43
+ * heap itself. The callback function should return a boolean value indicating whether the current
44
+ * element should be included in the filtered list
45
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
46
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
47
+ * passed as the `this` value to the `callback` function. If `thisArg` is
48
+ * @returns The `filter` method is returning a new `PriorityQueue` object that contains the elements that pass
49
+ * the filter condition specified by the `callback` function.
50
+ */
51
+ filter(callback: ElementCallback<E, R, boolean, PriorityQueue<E, R>>, thisArg?: any): PriorityQueue<E, R>;
52
+ /**
53
+ * Time Complexity: O(n log n)
54
+ * Space Complexity: O(n)
55
+ *
56
+ * The `map` function creates a new heap by applying a callback function to each element of the
57
+ * original heap.
58
+ * @param callback - The `callback` parameter is a function that will be called for each element in
59
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
60
+ * element), and `this` (the heap itself). The callback function should return a value of
61
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
62
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
63
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
64
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
65
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
66
+ * returns a value of type `T`. This function is used to transform the elements of the original
67
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
68
+ * specify the value of `this` within the callback function. It is used to set the context or scope
69
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
70
+ * value of
71
+ * @returns a new instance of the `PriorityQueue` class with the mapped elements.
72
+ */
73
+ map<EM, RM>(callback: ElementCallback<E, R, EM, PriorityQueue<E, R>>, comparator: Comparator<EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): PriorityQueue<EM, RM>;
28
74
  }
@@ -14,7 +14,7 @@ class PriorityQueue extends heap_1.Heap {
14
14
  /**
15
15
  * The constructor initializes a priority queue with optional elements and options.
16
16
  * @param elements - The `elements` parameter is an iterable object that contains the initial
17
- * elements to be added to the priority queue. It is an optional parameter and if not provided, the
17
+ * elements to be added to the priority queue. It is an optional parameter, and if not provided, the
18
18
  * priority queue will be initialized as empty.
19
19
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
20
20
  * behavior of the priority queue. It can contain the following properties:
@@ -22,6 +22,75 @@ class PriorityQueue extends heap_1.Heap {
22
22
  constructor(elements = [], options) {
23
23
  super(elements, options);
24
24
  }
25
+ /**
26
+ * The `clone` function returns a new instance of the `PriorityQueue` class with the same comparator
27
+ * and toElementFn as the original instance.
28
+ * @returns The method is returning a new instance of the `PriorityQueue` class with the same
29
+ * elements and properties as the current instance.
30
+ */
31
+ clone() {
32
+ return new PriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
33
+ }
34
+ /**
35
+ * Time Complexity: O(n)
36
+ * Space Complexity: O(n)
37
+ *
38
+ * The `filter` function creates a new PriorityQueue object containing elements that pass a given callback
39
+ * function.
40
+ * @param callback - The `callback` parameter is a function that will be called for each element in
41
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
42
+ * heap itself. The callback function should return a boolean value indicating whether the current
43
+ * element should be included in the filtered list
44
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
45
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
46
+ * passed as the `this` value to the `callback` function. If `thisArg` is
47
+ * @returns The `filter` method is returning a new `PriorityQueue` object that contains the elements that pass
48
+ * the filter condition specified by the `callback` function.
49
+ */
50
+ filter(callback, thisArg) {
51
+ const filteredPriorityQueue = new PriorityQueue([], {
52
+ toElementFn: this.toElementFn,
53
+ comparator: this.comparator
54
+ });
55
+ let index = 0;
56
+ for (const current of this) {
57
+ if (callback.call(thisArg, current, index, this)) {
58
+ filteredPriorityQueue.add(current);
59
+ }
60
+ index++;
61
+ }
62
+ return filteredPriorityQueue;
63
+ }
64
+ /**
65
+ * Time Complexity: O(n log n)
66
+ * Space Complexity: O(n)
67
+ *
68
+ * The `map` function creates a new heap by applying a callback function to each element of the
69
+ * original heap.
70
+ * @param callback - The `callback` parameter is a function that will be called for each element in
71
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
72
+ * element), and `this` (the heap itself). The callback function should return a value of
73
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
74
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
75
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
76
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
77
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
78
+ * returns a value of type `T`. This function is used to transform the elements of the original
79
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
80
+ * specify the value of `this` within the callback function. It is used to set the context or scope
81
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
82
+ * value of
83
+ * @returns a new instance of the `PriorityQueue` class with the mapped elements.
84
+ */
85
+ map(callback, comparator, toElementFn, thisArg) {
86
+ const mappedPriorityQueue = new PriorityQueue([], { comparator, toElementFn });
87
+ let index = 0;
88
+ for (const el of this) {
89
+ mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
90
+ index++;
91
+ }
92
+ return mappedPriorityQueue;
93
+ }
25
94
  }
26
95
  exports.PriorityQueue = PriorityQueue;
27
96
  //# sourceMappingURL=priority-queue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/priority-queue.ts"],"names":[],"mappings":";;;AAQA,kCAA+B;AAE/B;;;;;;;GAOG;AACH,MAAa,aAAuB,SAAQ,WAAO;IACjD;;;;;;;OAOG;IACH,YAAY,WAAwB,EAAE,EAAE,OAAiC;QACvE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF;AAZD,sCAYC"}
1
+ {"version":3,"file":"priority-queue.js","sourceRoot":"","sources":["../../../../src/data-structures/priority-queue/priority-queue.ts"],"names":[],"mappings":";;;AAQA,kCAA+B;AAE/B;;;;;;;GAOG;AACH,MAAa,aAAgC,SAAQ,WAAU;IAC7D;;;;;;;OAOG;IACH,YAAY,WAAsC,EAAE,EAAE,OAAoC;QACxF,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;;;;OAKG;IACM,KAAK;QACZ,OAAO,IAAI,aAAa,CAAO,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,CA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