min-heap-typed 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/dist/cjs/index.cjs +987 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +980 -0
  4. package/dist/esm/index.mjs.map +1 -0
  5. package/dist/types/data-structures/base/index.d.ts +2 -1
  6. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
  7. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
  8. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
  9. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
  12. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  15. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
  17. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  18. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  19. package/dist/types/data-structures/graph/index.d.ts +2 -1
  20. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  21. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  22. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  23. package/dist/types/data-structures/hash/index.d.ts +0 -1
  24. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  25. package/dist/types/data-structures/heap/index.d.ts +2 -0
  26. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  27. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  28. package/dist/types/data-structures/index.d.ts +7 -7
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  32. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  33. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  34. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  35. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  36. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  37. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  38. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  39. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  40. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  41. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  43. package/dist/types/index.d.ts +13 -2
  44. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +3 -3
  45. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  46. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  47. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  48. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  49. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  51. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  52. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  53. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  54. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  55. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  56. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  57. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  58. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  59. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  60. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  61. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  62. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  63. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  64. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  65. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  66. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  67. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  68. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  69. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  70. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  71. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  72. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  73. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  74. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  75. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  76. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  77. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  78. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  79. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  80. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  81. package/dist/types/types/index.d.ts +3 -0
  82. package/dist/types/types/utils/index.d.ts +2 -0
  83. package/dist/types/types/utils/utils.d.ts +22 -0
  84. package/dist/types/utils/index.d.ts +1 -1
  85. package/dist/types/utils/utils.d.ts +209 -22
  86. package/dist/umd/max-heap-typed.js +992 -0
  87. package/dist/umd/max-heap-typed.js.map +1 -0
  88. package/dist/umd/max-heap-typed.min.js +16 -0
  89. package/dist/umd/max-heap-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
  93. package/src/data-structures/binary-tree/avl-tree.ts +6 -8
  94. package/src/data-structures/binary-tree/binary-tree.ts +13 -15
  95. package/src/data-structures/binary-tree/bst.ts +6 -11
  96. package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
  97. package/src/data-structures/binary-tree/tree-counter.ts +8 -13
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
  99. package/src/data-structures/heap/heap.ts +5 -5
  100. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  101. package/src/interfaces/binary-tree.ts +3 -3
  102. package/tsconfig.base.json +23 -0
  103. package/tsconfig.json +8 -34
  104. package/tsconfig.test.json +8 -0
  105. package/tsconfig.types.json +15 -0
  106. package/tsup.config.js +28 -0
  107. package/tsup.node.config.js +37 -0
  108. package/dist/common/index.js +0 -28
  109. package/dist/constants/index.js +0 -8
  110. package/dist/data-structures/base/index.d.ts +0 -2
  111. package/dist/data-structures/base/index.js +0 -18
  112. package/dist/data-structures/base/iterable-element-base.js +0 -243
  113. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  114. package/dist/data-structures/base/linear-base.js +0 -415
  115. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  116. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  117. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  118. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  119. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  120. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  121. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  122. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  123. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  124. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  125. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  126. package/dist/data-structures/binary-tree/bst.js +0 -903
  127. package/dist/data-structures/binary-tree/index.js +0 -26
  128. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  129. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  130. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  131. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  132. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  133. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  134. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  135. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  136. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  137. package/dist/data-structures/graph/abstract-graph.js +0 -896
  138. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  139. package/dist/data-structures/graph/directed-graph.js +0 -525
  140. package/dist/data-structures/graph/index.js +0 -20
  141. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  142. package/dist/data-structures/graph/map-graph.js +0 -107
  143. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  144. package/dist/data-structures/graph/undirected-graph.js +0 -424
  145. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  146. package/dist/data-structures/hash/hash-map.js +0 -692
  147. package/dist/data-structures/hash/index.d.ts +0 -1
  148. package/dist/data-structures/hash/index.js +0 -17
  149. package/dist/data-structures/heap/heap.d.ts +0 -503
  150. package/dist/data-structures/heap/heap.js +0 -901
  151. package/dist/data-structures/heap/index.d.ts +0 -3
  152. package/dist/data-structures/heap/index.js +0 -19
  153. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  154. package/dist/data-structures/heap/max-heap.js +0 -40
  155. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  156. package/dist/data-structures/heap/min-heap.js +0 -31
  157. package/dist/data-structures/index.js +0 -28
  158. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  159. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  160. package/dist/data-structures/linked-list/index.js +0 -19
  161. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  162. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  163. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  164. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  165. package/dist/data-structures/matrix/index.js +0 -18
  166. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  167. package/dist/data-structures/matrix/matrix.js +0 -448
  168. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  169. package/dist/data-structures/matrix/navigator.js +0 -111
  170. package/dist/data-structures/priority-queue/index.js +0 -19
  171. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  172. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  173. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  174. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  175. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  176. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  177. package/dist/data-structures/queue/deque.d.ts +0 -431
  178. package/dist/data-structures/queue/deque.js +0 -879
  179. package/dist/data-structures/queue/index.js +0 -18
  180. package/dist/data-structures/queue/queue.d.ts +0 -308
  181. package/dist/data-structures/queue/queue.js +0 -473
  182. package/dist/data-structures/stack/index.js +0 -17
  183. package/dist/data-structures/stack/stack.d.ts +0 -306
  184. package/dist/data-structures/stack/stack.js +0 -401
  185. package/dist/data-structures/tree/index.js +0 -17
  186. package/dist/data-structures/tree/tree.d.ts +0 -62
  187. package/dist/data-structures/tree/tree.js +0 -107
  188. package/dist/data-structures/trie/index.js +0 -17
  189. package/dist/data-structures/trie/trie.d.ts +0 -350
  190. package/dist/data-structures/trie/trie.js +0 -610
  191. package/dist/index.d.ts +0 -14
  192. package/dist/index.js +0 -30
  193. package/dist/interfaces/binary-tree.js +0 -2
  194. package/dist/interfaces/doubly-linked-list.js +0 -2
  195. package/dist/interfaces/graph.js +0 -2
  196. package/dist/interfaces/heap.js +0 -2
  197. package/dist/interfaces/index.js +0 -24
  198. package/dist/interfaces/navigator.js +0 -2
  199. package/dist/interfaces/priority-queue.js +0 -2
  200. package/dist/interfaces/segment-tree.js +0 -2
  201. package/dist/interfaces/singly-linked-list.js +0 -2
  202. package/dist/types/common.js +0 -2
  203. package/dist/types/data-structures/base/base.js +0 -2
  204. package/dist/types/data-structures/base/index.js +0 -17
  205. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  206. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  207. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  208. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  209. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  210. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  211. package/dist/types/data-structures/binary-tree/index.js +0 -25
  212. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  213. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  214. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  215. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  216. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  217. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  218. package/dist/types/data-structures/graph/index.js +0 -19
  219. package/dist/types/data-structures/graph/map-graph.js +0 -2
  220. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  221. package/dist/types/data-structures/hash/hash-map.js +0 -2
  222. package/dist/types/data-structures/hash/index.js +0 -17
  223. package/dist/types/data-structures/heap/heap.js +0 -2
  224. package/dist/types/data-structures/heap/index.js +0 -17
  225. package/dist/types/data-structures/heap/max-heap.js +0 -2
  226. package/dist/types/data-structures/heap/min-heap.js +0 -2
  227. package/dist/types/data-structures/index.js +0 -28
  228. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  229. package/dist/types/data-structures/linked-list/index.js +0 -19
  230. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  231. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  232. package/dist/types/data-structures/matrix/index.js +0 -18
  233. package/dist/types/data-structures/matrix/matrix.js +0 -2
  234. package/dist/types/data-structures/matrix/navigator.js +0 -2
  235. package/dist/types/data-structures/priority-queue/index.js +0 -19
  236. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  237. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  238. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  239. package/dist/types/data-structures/queue/deque.js +0 -2
  240. package/dist/types/data-structures/queue/index.js +0 -18
  241. package/dist/types/data-structures/queue/queue.js +0 -2
  242. package/dist/types/data-structures/stack/index.js +0 -17
  243. package/dist/types/data-structures/stack/stack.js +0 -2
  244. package/dist/types/data-structures/tree/index.js +0 -17
  245. package/dist/types/data-structures/tree/tree.js +0 -2
  246. package/dist/types/data-structures/trie/index.js +0 -17
  247. package/dist/types/data-structures/trie/trie.js +0 -2
  248. package/dist/types/index.js +0 -19
  249. package/dist/types/utils/index.js +0 -18
  250. package/dist/types/utils/utils.js +0 -2
  251. package/dist/types/utils/validate-type.js +0 -2
  252. package/dist/utils/index.d.ts +0 -2
  253. package/dist/utils/index.js +0 -18
  254. package/dist/utils/number.js +0 -24
  255. package/dist/utils/utils.d.ts +0 -209
  256. package/dist/utils/utils.js +0 -353
  257. package/dist/{common → types/common}/index.d.ts +0 -0
  258. package/dist/{constants → types/constants}/index.d.ts +0 -0
  259. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  260. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  261. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  262. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  263. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  264. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  265. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  266. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  267. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  268. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  270. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  271. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  272. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  273. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  274. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  275. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  276. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  277. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  278. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  279. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  280. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  281. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Range = exports.DFSOperation = void 0;
4
- const utils_1 = require("../utils");
5
- var DFSOperation;
6
- (function (DFSOperation) {
7
- DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
8
- DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS";
9
- })(DFSOperation = exports.DFSOperation || (exports.DFSOperation = {}));
10
- class Range {
11
- constructor(low, high, includeLow = true, includeHigh = true) {
12
- this.low = low;
13
- this.high = high;
14
- this.includeLow = includeLow;
15
- this.includeHigh = includeHigh;
16
- if (!((0, utils_1.isComparable)(low) && (0, utils_1.isComparable)(high)))
17
- throw new RangeError('low or high is not comparable');
18
- if (low > high)
19
- throw new RangeError('low must be less than or equal to high');
20
- }
21
- // Determine whether a key is within the range
22
- isInRange(key, comparator) {
23
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
24
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
25
- return lowCheck && highCheck;
26
- }
27
- }
28
- exports.Range = Range;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DFSOperation = void 0;
4
- var DFSOperation;
5
- (function (DFSOperation) {
6
- DFSOperation[DFSOperation["VISIT"] = 0] = "VISIT";
7
- DFSOperation[DFSOperation["PROCESS"] = 1] = "PROCESS";
8
- })(DFSOperation = exports.DFSOperation || (exports.DFSOperation = {}));
@@ -1,2 +0,0 @@
1
- export * from './iterable-entry-base';
2
- export * from './iterable-element-base';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./iterable-entry-base"), exports);
18
- __exportStar(require("./iterable-element-base"), exports);
@@ -1,243 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IterableElementBase = void 0;
4
- /**
5
- * Base class that makes a data structure iterable and provides common
6
- * element-wise utilities (e.g., map/filter/reduce/find).
7
- *
8
- * @template E The public element type yielded by the structure.
9
- * @template R The underlying "raw" element type used internally or by converters.
10
- *
11
- * @remarks
12
- * This class implements the JavaScript iteration protocol (via `Symbol.iterator`)
13
- * and offers array-like helpers with predictable time/space complexity.
14
- */
15
- class IterableElementBase {
16
- /**
17
- * Create a new iterable base.
18
- *
19
- * @param options Optional behavior overrides. When provided, a `toElementFn`
20
- * is used to convert a raw element (`R`) into a public element (`E`).
21
- *
22
- * @remarks
23
- * Time O(1), Space O(1).
24
- */
25
- constructor(options) {
26
- if (options) {
27
- const { toElementFn } = options;
28
- if (typeof toElementFn === 'function')
29
- this._toElementFn = toElementFn;
30
- else if (toElementFn)
31
- throw new TypeError('toElementFn must be a function type');
32
- }
33
- }
34
- /**
35
- * Exposes the current `toElementFn`, if configured.
36
- *
37
- * @returns The converter function or `undefined` when not set.
38
- * @remarks
39
- * Time O(1), Space O(1).
40
- */
41
- get toElementFn() {
42
- return this._toElementFn;
43
- }
44
- /**
45
- * Returns an iterator over the structure's elements.
46
- *
47
- * @param args Optional iterator arguments forwarded to the internal iterator.
48
- * @returns An `IterableIterator<E>` that yields the elements in traversal order.
49
- *
50
- * @remarks
51
- * Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.
52
- */
53
- *[Symbol.iterator](...args) {
54
- yield* this._getIterator(...args);
55
- }
56
- /**
57
- * Returns an iterator over the values (alias of the default iterator).
58
- *
59
- * @returns An `IterableIterator<E>` over all elements.
60
- * @remarks
61
- * Creating the iterator is O(1); full iteration is Time O(n), Space O(1).
62
- */
63
- *values() {
64
- for (const item of this)
65
- yield item;
66
- }
67
- /**
68
- * Tests whether all elements satisfy the predicate.
69
- *
70
- * @template TReturn
71
- * @param predicate Function invoked for each element with signature `(value, index, self)`.
72
- * @param thisArg Optional `this` binding for the predicate.
73
- * @returns `true` if every element passes; otherwise `false`.
74
- *
75
- * @remarks
76
- * Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).
77
- */
78
- every(predicate, thisArg) {
79
- let index = 0;
80
- for (const item of this) {
81
- if (thisArg === undefined) {
82
- if (!predicate(item, index++, this))
83
- return false;
84
- }
85
- else {
86
- const fn = predicate;
87
- if (!fn.call(thisArg, item, index++, this))
88
- return false;
89
- }
90
- }
91
- return true;
92
- }
93
- /**
94
- * Tests whether at least one element satisfies the predicate.
95
- *
96
- * @param predicate Function invoked for each element with signature `(value, index, self)`.
97
- * @param thisArg Optional `this` binding for the predicate.
98
- * @returns `true` if any element passes; otherwise `false`.
99
- *
100
- * @remarks
101
- * Time O(n) in the worst case; may exit early on first success. Space O(1).
102
- */
103
- some(predicate, thisArg) {
104
- let index = 0;
105
- for (const item of this) {
106
- if (thisArg === undefined) {
107
- if (predicate(item, index++, this))
108
- return true;
109
- }
110
- else {
111
- const fn = predicate;
112
- if (fn.call(thisArg, item, index++, this))
113
- return true;
114
- }
115
- }
116
- return false;
117
- }
118
- /**
119
- * Invokes a callback for each element in iteration order.
120
- *
121
- * @param callbackfn Function invoked per element with signature `(value, index, self)`.
122
- * @param thisArg Optional `this` binding for the callback.
123
- * @returns `void`.
124
- *
125
- * @remarks
126
- * Time O(n), Space O(1).
127
- */
128
- forEach(callbackfn, thisArg) {
129
- let index = 0;
130
- for (const item of this) {
131
- if (thisArg === undefined) {
132
- callbackfn(item, index++, this);
133
- }
134
- else {
135
- const fn = callbackfn;
136
- fn.call(thisArg, item, index++, this);
137
- }
138
- }
139
- }
140
- // Implementation signature
141
- find(predicate, thisArg) {
142
- let index = 0;
143
- for (const item of this) {
144
- if (thisArg === undefined) {
145
- if (predicate(item, index++, this))
146
- return item;
147
- }
148
- else {
149
- const fn = predicate;
150
- if (fn.call(thisArg, item, index++, this))
151
- return item;
152
- }
153
- }
154
- return;
155
- }
156
- /**
157
- * Checks whether a strictly-equal element exists in the structure.
158
- *
159
- * @param element The element to test with `===` equality.
160
- * @returns `true` if an equal element is found; otherwise `false`.
161
- *
162
- * @remarks
163
- * Time O(n) in the worst case. Space O(1).
164
- */
165
- has(element) {
166
- for (const ele of this)
167
- if (ele === element)
168
- return true;
169
- return false;
170
- }
171
- /**
172
- * Reduces all elements to a single accumulated value.
173
- *
174
- * @overload
175
- * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`. The first element is used as the initial accumulator.
176
- * @returns The final accumulated value typed as `E`.
177
- *
178
- * @overload
179
- * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`.
180
- * @param initialValue The initial accumulator value of type `E`.
181
- * @returns The final accumulated value typed as `E`.
182
- *
183
- * @overload
184
- * @template U The accumulator type when it differs from `E`.
185
- * @param callbackfn Reducer of signature `(acc: U, value, index, self) => U`.
186
- * @param initialValue The initial accumulator value of type `U`.
187
- * @returns The final accumulated value typed as `U`.
188
- *
189
- * @remarks
190
- * Time O(n), Space O(1). Throws if called on an empty structure without `initialValue`.
191
- */
192
- reduce(callbackfn, initialValue) {
193
- let index = 0;
194
- const iter = this[Symbol.iterator]();
195
- let acc;
196
- if (arguments.length >= 2) {
197
- acc = initialValue;
198
- }
199
- else {
200
- const first = iter.next();
201
- if (first.done)
202
- throw new TypeError('Reduce of empty structure with no initial value');
203
- acc = first.value;
204
- index = 1;
205
- }
206
- for (const value of iter) {
207
- acc = callbackfn(acc, value, index++, this);
208
- }
209
- return acc;
210
- }
211
- /**
212
- * Materializes the elements into a new array.
213
- *
214
- * @returns A shallow array copy of the iteration order.
215
- * @remarks
216
- * Time O(n), Space O(n).
217
- */
218
- toArray() {
219
- return [...this];
220
- }
221
- /**
222
- * Returns a representation of the structure suitable for quick visualization.
223
- * Defaults to an array of elements; subclasses may override to provide richer visuals.
224
- *
225
- * @returns A visual representation (array by default).
226
- * @remarks
227
- * Time O(n), Space O(n).
228
- */
229
- toVisual() {
230
- return [...this];
231
- }
232
- /**
233
- * Prints `toVisual()` to the console. Intended for quick debugging.
234
- *
235
- * @returns `void`.
236
- * @remarks
237
- * Time O(n) due to materialization, Space O(n) for the intermediate representation.
238
- */
239
- print() {
240
- console.log(this.toVisual());
241
- }
242
- }
243
- exports.IterableElementBase = IterableElementBase;
@@ -1,183 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IterableEntryBase = void 0;
4
- /**
5
- * Iterable view over key-value entries.
6
- * @template K - Key type.
7
- * @template V - Value type.
8
- * @remarks Time O(1), Space O(1)
9
- */
10
- class IterableEntryBase {
11
- /**
12
- * Default iterator yielding `[key, value]` entries.
13
- * @returns Iterator of `[K, V]`.
14
- * @remarks Time O(n) to iterate, Space O(1)
15
- */
16
- *[Symbol.iterator](...args) {
17
- yield* this._getIterator(...args);
18
- }
19
- /**
20
- * Iterate over `[key, value]` pairs (may yield `undefined` values).
21
- * @returns Iterator of `[K, V | undefined]`.
22
- * @remarks Time O(n), Space O(1)
23
- */
24
- *entries() {
25
- for (const item of this) {
26
- yield item;
27
- }
28
- }
29
- /**
30
- * Iterate over keys only.
31
- * @returns Iterator of keys.
32
- * @remarks Time O(n), Space O(1)
33
- */
34
- *keys() {
35
- for (const item of this) {
36
- yield item[0];
37
- }
38
- }
39
- /**
40
- * Iterate over values only.
41
- * @returns Iterator of values.
42
- * @remarks Time O(n), Space O(1)
43
- */
44
- *values() {
45
- for (const item of this) {
46
- yield item[1];
47
- }
48
- }
49
- /**
50
- * Test whether all entries satisfy the predicate.
51
- * @param predicate - `(key, value, index, self) => boolean`.
52
- * @param thisArg - Optional `this` for callback.
53
- * @returns `true` if all pass; otherwise `false`.
54
- * @remarks Time O(n), Space O(1)
55
- */
56
- every(predicate, thisArg) {
57
- let index = 0;
58
- for (const item of this) {
59
- if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
60
- return false;
61
- }
62
- }
63
- return true;
64
- }
65
- /**
66
- * Test whether any entry satisfies the predicate.
67
- * @param predicate - `(key, value, index, self) => boolean`.
68
- * @param thisArg - Optional `this` for callback.
69
- * @returns `true` if any passes; otherwise `false`.
70
- * @remarks Time O(n), Space O(1)
71
- */
72
- some(predicate, thisArg) {
73
- let index = 0;
74
- for (const item of this) {
75
- if (predicate.call(thisArg, item[0], item[1], index++, this)) {
76
- return true;
77
- }
78
- }
79
- return false;
80
- }
81
- /**
82
- * Visit each entry, left-to-right.
83
- * @param callbackfn - `(key, value, index, self) => void`.
84
- * @param thisArg - Optional `this` for callback.
85
- * @remarks Time O(n), Space O(1)
86
- */
87
- forEach(callbackfn, thisArg) {
88
- let index = 0;
89
- for (const item of this) {
90
- const [key, value] = item;
91
- callbackfn.call(thisArg, key, value, index++, this);
92
- }
93
- }
94
- /**
95
- * Find the first entry that matches a predicate.
96
- * @param callbackfn - `(key, value, index, self) => boolean`.
97
- * @param thisArg - Optional `this` for callback.
98
- * @returns Matching `[key, value]` or `undefined`.
99
- * @remarks Time O(n), Space O(1)
100
- */
101
- find(callbackfn, thisArg) {
102
- let index = 0;
103
- for (const item of this) {
104
- const [key, value] = item;
105
- if (callbackfn.call(thisArg, key, value, index++, this))
106
- return item;
107
- }
108
- return;
109
- }
110
- /**
111
- * Whether the given key exists.
112
- * @param key - Key to test.
113
- * @returns `true` if found; otherwise `false`.
114
- * @remarks Time O(n) generic, Space O(1)
115
- */
116
- has(key) {
117
- for (const item of this) {
118
- const [itemKey] = item;
119
- if (itemKey === key)
120
- return true;
121
- }
122
- return false;
123
- }
124
- /**
125
- * Whether there exists an entry with the given value.
126
- * @param value - Value to test.
127
- * @returns `true` if found; otherwise `false`.
128
- * @remarks Time O(n), Space O(1)
129
- */
130
- hasValue(value) {
131
- for (const [, elementValue] of this) {
132
- if (elementValue === value)
133
- return true;
134
- }
135
- return false;
136
- }
137
- /**
138
- * Get the value under a key.
139
- * @param key - Key to look up.
140
- * @returns Value or `undefined`.
141
- * @remarks Time O(n) generic, Space O(1)
142
- */
143
- get(key) {
144
- for (const item of this) {
145
- const [itemKey, value] = item;
146
- if (itemKey === key)
147
- return value;
148
- }
149
- return;
150
- }
151
- /**
152
- * Reduce entries into a single accumulator.
153
- * @param callbackfn - `(acc, value, key, index, self) => acc`.
154
- * @param initialValue - Initial accumulator.
155
- * @returns Final accumulator.
156
- * @remarks Time O(n), Space O(1)
157
- */
158
- reduce(callbackfn, initialValue) {
159
- let accumulator = initialValue;
160
- let index = 0;
161
- for (const item of this) {
162
- const [key, value] = item;
163
- accumulator = callbackfn(accumulator, value, key, index++, this);
164
- }
165
- return accumulator;
166
- }
167
- /**
168
- * Visualize the iterable as an array of `[key, value]` pairs (or a custom string).
169
- * @returns Array of entries (default) or a string.
170
- * @remarks Time O(n), Space O(n)
171
- */
172
- toVisual() {
173
- return [...this];
174
- }
175
- /**
176
- * Print a human-friendly representation to the console.
177
- * @remarks Time O(n), Space O(n)
178
- */
179
- print() {
180
- console.log(this.toVisual());
181
- }
182
- }
183
- exports.IterableEntryBase = IterableEntryBase;