trie-typed 2.1.1 → 2.2.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 (288) hide show
  1. package/dist/cjs/index.cjs +797 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/cjs-legacy/index.cjs +795 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -0
  5. package/dist/esm/index.mjs +792 -0
  6. package/dist/esm/index.mjs.map +1 -0
  7. package/dist/esm-legacy/index.mjs +790 -0
  8. package/dist/esm-legacy/index.mjs.map +1 -0
  9. package/dist/types/data-structures/base/index.d.ts +2 -1
  10. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +236 -2
  11. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +197 -2
  12. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +345 -2
  13. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
  14. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
  15. package/dist/types/data-structures/binary-tree/bst.d.ts +467 -12
  16. package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
  17. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +262 -3
  18. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
  19. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +244 -2
  20. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +332 -2
  21. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
  22. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
  23. package/dist/types/data-structures/graph/index.d.ts +2 -1
  24. package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
  25. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
  26. package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
  27. package/dist/types/data-structures/hash/index.d.ts +0 -1
  28. package/dist/types/data-structures/heap/heap.d.ts +503 -5
  29. package/dist/types/data-structures/heap/index.d.ts +2 -0
  30. package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
  31. package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
  32. package/dist/types/data-structures/index.d.ts +7 -7
  33. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
  34. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
  35. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
  36. package/dist/types/data-structures/matrix/index.d.ts +1 -1
  37. package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
  38. package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
  39. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
  40. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
  41. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
  42. package/dist/types/data-structures/queue/deque.d.ts +431 -4
  43. package/dist/types/data-structures/queue/queue.d.ts +308 -4
  44. package/dist/types/data-structures/stack/stack.d.ts +306 -2
  45. package/dist/types/data-structures/tree/tree.d.ts +62 -1
  46. package/dist/types/data-structures/trie/trie.d.ts +350 -4
  47. package/dist/types/index.d.ts +11 -2
  48. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
  49. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  51. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  52. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  53. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  54. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  55. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  56. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  57. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  58. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  59. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  60. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  61. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  62. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  63. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  64. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  65. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  66. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  67. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  68. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  69. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  70. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  71. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  72. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  73. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  74. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  75. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  76. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  77. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  78. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  79. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  80. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  81. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  82. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  83. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  84. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  85. package/dist/types/types/index.d.ts +3 -0
  86. package/dist/types/types/utils/index.d.ts +2 -0
  87. package/dist/types/types/utils/utils.d.ts +22 -0
  88. package/dist/types/utils/index.d.ts +1 -1
  89. package/dist/types/utils/utils.d.ts +209 -22
  90. package/dist/umd/trie-typed.js +802 -0
  91. package/dist/umd/trie-typed.js.map +1 -0
  92. package/dist/umd/trie-typed.min.js +9 -0
  93. package/dist/umd/trie-typed.min.js.map +1 -0
  94. package/package.json +43 -5
  95. package/src/data-structures/binary-tree/avl-tree-counter.ts +106 -15
  96. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
  97. package/src/data-structures/binary-tree/avl-tree.ts +107 -16
  98. package/src/data-structures/binary-tree/binary-tree.ts +4 -4
  99. package/src/data-structures/binary-tree/bst.ts +103 -12
  100. package/src/data-structures/binary-tree/red-black-tree.ts +110 -20
  101. package/src/data-structures/binary-tree/tree-counter.ts +105 -14
  102. package/src/data-structures/binary-tree/tree-multi-map.ts +123 -12
  103. package/src/data-structures/graph/abstract-graph.ts +5 -5
  104. package/src/data-structures/graph/directed-graph.ts +5 -5
  105. package/src/data-structures/graph/undirected-graph.ts +5 -5
  106. package/src/data-structures/heap/heap.ts +5 -5
  107. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  108. package/src/interfaces/binary-tree.ts +1 -1
  109. package/tsconfig.base.json +23 -0
  110. package/tsconfig.json +8 -34
  111. package/tsconfig.test.json +8 -0
  112. package/tsconfig.types.json +15 -0
  113. package/tsup.config.js +28 -0
  114. package/tsup.node.config.js +71 -0
  115. package/dist/common/index.js +0 -28
  116. package/dist/constants/index.js +0 -8
  117. package/dist/data-structures/base/index.d.ts +0 -2
  118. package/dist/data-structures/base/index.js +0 -18
  119. package/dist/data-structures/base/iterable-element-base.js +0 -243
  120. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  121. package/dist/data-structures/base/linear-base.js +0 -415
  122. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  123. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  124. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  125. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  126. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  127. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  128. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  129. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  130. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  131. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  132. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  133. package/dist/data-structures/binary-tree/bst.js +0 -903
  134. package/dist/data-structures/binary-tree/index.js +0 -26
  135. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  136. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  137. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  138. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  139. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  140. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  141. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  142. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  143. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  144. package/dist/data-structures/graph/abstract-graph.js +0 -896
  145. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  146. package/dist/data-structures/graph/directed-graph.js +0 -525
  147. package/dist/data-structures/graph/index.js +0 -20
  148. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  149. package/dist/data-structures/graph/map-graph.js +0 -107
  150. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  151. package/dist/data-structures/graph/undirected-graph.js +0 -424
  152. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  153. package/dist/data-structures/hash/hash-map.js +0 -692
  154. package/dist/data-structures/hash/index.d.ts +0 -1
  155. package/dist/data-structures/hash/index.js +0 -17
  156. package/dist/data-structures/heap/heap.d.ts +0 -503
  157. package/dist/data-structures/heap/heap.js +0 -901
  158. package/dist/data-structures/heap/index.d.ts +0 -3
  159. package/dist/data-structures/heap/index.js +0 -19
  160. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  161. package/dist/data-structures/heap/max-heap.js +0 -40
  162. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  163. package/dist/data-structures/heap/min-heap.js +0 -31
  164. package/dist/data-structures/index.js +0 -28
  165. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  166. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  167. package/dist/data-structures/linked-list/index.js +0 -19
  168. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  169. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  170. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  171. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  172. package/dist/data-structures/matrix/index.js +0 -18
  173. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  174. package/dist/data-structures/matrix/matrix.js +0 -448
  175. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  176. package/dist/data-structures/matrix/navigator.js +0 -111
  177. package/dist/data-structures/priority-queue/index.js +0 -19
  178. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  179. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  180. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  181. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  182. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  183. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  184. package/dist/data-structures/queue/deque.d.ts +0 -431
  185. package/dist/data-structures/queue/deque.js +0 -879
  186. package/dist/data-structures/queue/index.js +0 -18
  187. package/dist/data-structures/queue/queue.d.ts +0 -308
  188. package/dist/data-structures/queue/queue.js +0 -473
  189. package/dist/data-structures/stack/index.js +0 -17
  190. package/dist/data-structures/stack/stack.d.ts +0 -306
  191. package/dist/data-structures/stack/stack.js +0 -401
  192. package/dist/data-structures/tree/index.js +0 -17
  193. package/dist/data-structures/tree/tree.d.ts +0 -62
  194. package/dist/data-structures/tree/tree.js +0 -107
  195. package/dist/data-structures/trie/index.js +0 -17
  196. package/dist/data-structures/trie/trie.d.ts +0 -350
  197. package/dist/data-structures/trie/trie.js +0 -610
  198. package/dist/index.d.ts +0 -12
  199. package/dist/index.js +0 -28
  200. package/dist/interfaces/binary-tree.js +0 -2
  201. package/dist/interfaces/doubly-linked-list.js +0 -2
  202. package/dist/interfaces/graph.js +0 -2
  203. package/dist/interfaces/heap.js +0 -2
  204. package/dist/interfaces/index.js +0 -24
  205. package/dist/interfaces/navigator.js +0 -2
  206. package/dist/interfaces/priority-queue.js +0 -2
  207. package/dist/interfaces/segment-tree.js +0 -2
  208. package/dist/interfaces/singly-linked-list.js +0 -2
  209. package/dist/types/common.js +0 -2
  210. package/dist/types/data-structures/base/base.js +0 -2
  211. package/dist/types/data-structures/base/index.js +0 -17
  212. package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  213. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  214. package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
  215. package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  216. package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
  217. package/dist/types/data-structures/binary-tree/bst.js +0 -2
  218. package/dist/types/data-structures/binary-tree/index.js +0 -25
  219. package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
  220. package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
  221. package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
  222. package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  223. package/dist/types/data-structures/graph/abstract-graph.js +0 -2
  224. package/dist/types/data-structures/graph/directed-graph.js +0 -2
  225. package/dist/types/data-structures/graph/index.js +0 -19
  226. package/dist/types/data-structures/graph/map-graph.js +0 -2
  227. package/dist/types/data-structures/graph/undirected-graph.js +0 -2
  228. package/dist/types/data-structures/hash/hash-map.js +0 -2
  229. package/dist/types/data-structures/hash/index.js +0 -17
  230. package/dist/types/data-structures/heap/heap.js +0 -2
  231. package/dist/types/data-structures/heap/index.js +0 -17
  232. package/dist/types/data-structures/heap/max-heap.js +0 -2
  233. package/dist/types/data-structures/heap/min-heap.js +0 -2
  234. package/dist/types/data-structures/index.js +0 -28
  235. package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  236. package/dist/types/data-structures/linked-list/index.js +0 -19
  237. package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
  238. package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
  239. package/dist/types/data-structures/matrix/index.js +0 -18
  240. package/dist/types/data-structures/matrix/matrix.js +0 -2
  241. package/dist/types/data-structures/matrix/navigator.js +0 -2
  242. package/dist/types/data-structures/priority-queue/index.js +0 -19
  243. package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  244. package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  245. package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
  246. package/dist/types/data-structures/queue/deque.js +0 -2
  247. package/dist/types/data-structures/queue/index.js +0 -18
  248. package/dist/types/data-structures/queue/queue.js +0 -2
  249. package/dist/types/data-structures/stack/index.js +0 -17
  250. package/dist/types/data-structures/stack/stack.js +0 -2
  251. package/dist/types/data-structures/tree/index.js +0 -17
  252. package/dist/types/data-structures/tree/tree.js +0 -2
  253. package/dist/types/data-structures/trie/index.js +0 -17
  254. package/dist/types/data-structures/trie/trie.js +0 -2
  255. package/dist/types/index.js +0 -19
  256. package/dist/types/utils/index.js +0 -18
  257. package/dist/types/utils/utils.js +0 -2
  258. package/dist/types/utils/validate-type.js +0 -2
  259. package/dist/utils/index.d.ts +0 -2
  260. package/dist/utils/index.js +0 -18
  261. package/dist/utils/number.js +0 -24
  262. package/dist/utils/utils.d.ts +0 -209
  263. package/dist/utils/utils.js +0 -353
  264. package/dist/{common → types/common}/index.d.ts +0 -0
  265. package/dist/{constants → types/constants}/index.d.ts +0 -0
  266. package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
  267. package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
  268. package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
  269. package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
  270. package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
  271. package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
  272. package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
  273. package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
  274. package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
  275. package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
  276. package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
  277. package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
  278. package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
  279. package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
  280. package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
  281. package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
  282. /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
  283. /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
  284. /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
  285. /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
  286. /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
  287. /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
  288. /package/dist/{utils → types/utils}/number.d.ts +0 -0
@@ -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;
@@ -1,415 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LinearLinkedBase = exports.LinearBase = exports.LinkedListNode = void 0;
4
- const iterable_element_base_1 = require("./iterable-element-base");
5
- /**
6
- * Singly-linked list node.
7
- * @template E - Element type.
8
- * @remarks Time O(1), Space O(1)
9
- */
10
- class LinkedListNode {
11
- /**
12
- * Initialize a node.
13
- * @param value - Element value.
14
- * @remarks Time O(1), Space O(1)
15
- */
16
- constructor(value) {
17
- this._value = value;
18
- this._next = undefined;
19
- }
20
- /**
21
- * Element payload getter.
22
- * @returns Element value.
23
- * @remarks Time O(1), Space O(1)
24
- */
25
- get value() {
26
- return this._value;
27
- }
28
- /**
29
- * Element payload setter.
30
- * @param value - New value.
31
- * @remarks Time O(1), Space O(1)
32
- */
33
- set value(value) {
34
- this._value = value;
35
- }
36
- /**
37
- * Next node getter.
38
- * @returns Next node or `undefined`.
39
- * @remarks Time O(1), Space O(1)
40
- */
41
- get next() {
42
- return this._next;
43
- }
44
- /**
45
- * Next node setter.
46
- * @param value - Next node or `undefined`.
47
- * @remarks Time O(1), Space O(1)
48
- */
49
- set next(value) {
50
- this._next = value;
51
- }
52
- }
53
- exports.LinkedListNode = LinkedListNode;
54
- /**
55
- * Abstract linear container with array-like utilities.
56
- * @template E - Element type.
57
- * @template R - Return type for mapped/derived views.
58
- * @template NODE - Linked node type used by some implementations.
59
- * @remarks Time O(1), Space O(1)
60
- */
61
- class LinearBase extends iterable_element_base_1.IterableElementBase {
62
- /**
63
- * Construct a linear container with runtime options.
64
- * @param options - `{ maxLen?, ... }` bounds/behavior options.
65
- * @remarks Time O(1), Space O(1)
66
- */
67
- constructor(options) {
68
- super(options);
69
- this._maxLen = -1;
70
- if (options) {
71
- const { maxLen } = options;
72
- if (typeof maxLen === 'number' && maxLen > 0 && maxLen % 1 === 0)
73
- this._maxLen = maxLen;
74
- }
75
- }
76
- /**
77
- * Upper bound for length (if positive), or `-1` when unbounded.
78
- * @returns Maximum allowed length.
79
- * @remarks Time O(1), Space O(1)
80
- */
81
- get maxLen() {
82
- return this._maxLen;
83
- }
84
- /**
85
- * First index of a value from the left.
86
- * @param searchElement - Value to match.
87
- * @param fromIndex - Start position (supports negative index).
88
- * @returns Index or `-1` if not found.
89
- * @remarks Time O(n), Space O(1)
90
- */
91
- indexOf(searchElement, fromIndex = 0) {
92
- if (this.length === 0)
93
- return -1;
94
- if (fromIndex < 0)
95
- fromIndex = this.length + fromIndex;
96
- if (fromIndex < 0)
97
- fromIndex = 0;
98
- for (let i = fromIndex; i < this.length; i++) {
99
- const element = this.at(i);
100
- if (element === searchElement)
101
- return i;
102
- }
103
- return -1;
104
- }
105
- /**
106
- * Last index of a value from the right.
107
- * @param searchElement - Value to match.
108
- * @param fromIndex - Start position (supports negative index).
109
- * @returns Index or `-1` if not found.
110
- * @remarks Time O(n), Space O(1)
111
- */
112
- lastIndexOf(searchElement, fromIndex = this.length - 1) {
113
- if (this.length === 0)
114
- return -1;
115
- if (fromIndex >= this.length)
116
- fromIndex = this.length - 1;
117
- if (fromIndex < 0)
118
- fromIndex = this.length + fromIndex;
119
- for (let i = fromIndex; i >= 0; i--) {
120
- const element = this.at(i);
121
- if (element === searchElement)
122
- return i;
123
- }
124
- return -1;
125
- }
126
- /**
127
- * Find the first index matching a predicate.
128
- * @param predicate - `(element, index, self) => boolean`.
129
- * @param thisArg - Optional `this` for callback.
130
- * @returns Index or `-1`.
131
- * @remarks Time O(n), Space O(1)
132
- */
133
- findIndex(predicate, thisArg) {
134
- for (let i = 0; i < this.length; i++) {
135
- const item = this.at(i);
136
- if (item !== undefined && predicate.call(thisArg, item, i, this))
137
- return i;
138
- }
139
- return -1;
140
- }
141
- /**
142
- * Concatenate elements and/or containers.
143
- * @param items - Elements or other containers.
144
- * @returns New container with combined elements (`this` type).
145
- * @remarks Time O(sum(length)), Space O(sum(length))
146
- */
147
- concat(...items) {
148
- const newList = this.clone();
149
- for (const item of items) {
150
- if (item instanceof LinearBase) {
151
- newList.pushMany(item);
152
- }
153
- else {
154
- newList.push(item);
155
- }
156
- }
157
- return newList;
158
- }
159
- /**
160
- * In-place stable order via array sort semantics.
161
- * @param compareFn - Comparator `(a, b) => number`.
162
- * @returns This container.
163
- * @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
164
- */
165
- sort(compareFn) {
166
- const arr = this.toArray();
167
- arr.sort(compareFn);
168
- this.clear();
169
- for (const item of arr)
170
- this.push(item);
171
- return this;
172
- }
173
- /**
174
- * Remove and/or insert elements at a position (array-compatible).
175
- * @param start - Start index (supports negative index).
176
- * @param deleteCount - How many to remove.
177
- * @param items - Elements to insert.
178
- * @returns Removed elements as a new list (`this` type).
179
- * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
180
- */
181
- splice(start, deleteCount = 0, ...items) {
182
- const removedList = this._createInstance();
183
- start = start < 0 ? this.length + start : start;
184
- start = Math.max(0, Math.min(start, this.length));
185
- deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
186
- for (let i = 0; i < deleteCount; i++) {
187
- const removed = this.deleteAt(start);
188
- if (removed !== undefined) {
189
- removedList.push(removed);
190
- }
191
- }
192
- for (let i = 0; i < items.length; i++) {
193
- this.addAt(start + i, items[i]);
194
- }
195
- return removedList;
196
- }
197
- /**
198
- * Join all elements into a string.
199
- * @param separator - Separator string.
200
- * @returns Concatenated string.
201
- * @remarks Time O(n), Space O(n)
202
- */
203
- join(separator = ',') {
204
- return this.toArray().join(separator);
205
- }
206
- /**
207
- * Snapshot elements into a reversed array.
208
- * @returns New reversed array.
209
- * @remarks Time O(n), Space O(n)
210
- */
211
- toReversedArray() {
212
- const array = [];
213
- for (let i = this.length - 1; i >= 0; i--) {
214
- array.push(this.at(i));
215
- }
216
- return array;
217
- }
218
- reduceRight(callbackfn, initialValue) {
219
- let accumulator = initialValue !== null && initialValue !== void 0 ? initialValue : 0;
220
- for (let i = this.length - 1; i >= 0; i--) {
221
- accumulator = callbackfn(accumulator, this.at(i), i, this);
222
- }
223
- return accumulator;
224
- }
225
- /**
226
- * Create a shallow copy of a subrange.
227
- * @param start - Inclusive start (supports negative index).
228
- * @param end - Exclusive end (supports negative index).
229
- * @returns New list with the range (`this` type).
230
- * @remarks Time O(n), Space O(n)
231
- */
232
- slice(start = 0, end = this.length) {
233
- start = start < 0 ? this.length + start : start;
234
- end = end < 0 ? this.length + end : end;
235
- const newList = this._createInstance();
236
- for (let i = start; i < end; i++) {
237
- newList.push(this.at(i));
238
- }
239
- return newList;
240
- }
241
- /**
242
- * Fill a range with a value.
243
- * @param value - Value to set.
244
- * @param start - Inclusive start.
245
- * @param end - Exclusive end.
246
- * @returns This list.
247
- * @remarks Time O(n), Space O(1)
248
- */
249
- fill(value, start = 0, end = this.length) {
250
- start = start < 0 ? this.length + start : start;
251
- end = end < 0 ? this.length + end : end;
252
- if (start < 0)
253
- start = 0;
254
- if (end > this.length)
255
- end = this.length;
256
- if (start >= end)
257
- return this;
258
- for (let i = start; i < end; i++) {
259
- this.setAt(i, value);
260
- }
261
- return this;
262
- }
263
- }
264
- exports.LinearBase = LinearBase;
265
- /**
266
- * Linked-list specialized linear container.
267
- * @template E - Element type.
268
- * @template R - Return type for mapped/derived views.
269
- * @template NODE - Linked node type.
270
- * @remarks Time O(1), Space O(1)
271
- */
272
- class LinearLinkedBase extends LinearBase {
273
- constructor(options) {
274
- super(options);
275
- if (options) {
276
- const { maxLen } = options;
277
- if (typeof maxLen === 'number' && maxLen > 0 && maxLen % 1 === 0)
278
- this._maxLen = maxLen;
279
- }
280
- }
281
- /**
282
- * Linked-list optimized `indexOf` (forwards scan).
283
- * @param searchElement - Value to match.
284
- * @param fromIndex - Start position.
285
- * @returns Index or `-1`.
286
- * @remarks Time O(n), Space O(1)
287
- */
288
- indexOf(searchElement, fromIndex = 0) {
289
- const iterator = this._getIterator();
290
- let current = iterator.next();
291
- let index = 0;
292
- while (index < fromIndex) {
293
- current = iterator.next();
294
- index++;
295
- }
296
- while (!current.done) {
297
- if (current.value === searchElement)
298
- return index;
299
- current = iterator.next();
300
- index++;
301
- }
302
- return -1;
303
- }
304
- /**
305
- * Linked-list optimized `lastIndexOf` (reverse scan).
306
- * @param searchElement - Value to match.
307
- * @param fromIndex - Start position.
308
- * @returns Index or `-1`.
309
- * @remarks Time O(n), Space O(1)
310
- */
311
- lastIndexOf(searchElement, fromIndex = this.length - 1) {
312
- const iterator = this._getReverseIterator();
313
- let current = iterator.next();
314
- let index = this.length - 1;
315
- while (index > fromIndex) {
316
- current = iterator.next();
317
- index--;
318
- }
319
- while (!current.done) {
320
- if (current.value === searchElement)
321
- return index;
322
- current = iterator.next();
323
- index--;
324
- }
325
- return -1;
326
- }
327
- concat(...items) {
328
- const newList = this.clone();
329
- for (const item of items) {
330
- if (item instanceof LinearBase) {
331
- newList.pushMany(item);
332
- }
333
- else {
334
- newList.push(item);
335
- }
336
- }
337
- return newList;
338
- }
339
- /**
340
- * Slice via forward iteration (no random access required).
341
- * @param start - Inclusive start (supports negative index).
342
- * @param end - Exclusive end (supports negative index).
343
- * @returns New list (`this` type).
344
- * @remarks Time O(n), Space O(n)
345
- */
346
- slice(start = 0, end = this.length) {
347
- start = start < 0 ? this.length + start : start;
348
- end = end < 0 ? this.length + end : end;
349
- const newList = this._createInstance();
350
- const iterator = this._getIterator();
351
- let current = iterator.next();
352
- let c = 0;
353
- while (c < start) {
354
- current = iterator.next();
355
- c++;
356
- }
357
- for (let i = start; i < end; i++) {
358
- newList.push(current.value);
359
- current = iterator.next();
360
- }
361
- return newList;
362
- }
363
- /**
364
- * Splice by walking node iterators from the start index.
365
- * @param start - Start index.
366
- * @param deleteCount - How many elements to remove.
367
- * @param items - Elements to insert after the splice point.
368
- * @returns Removed elements as a new list (`this` type).
369
- * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
370
- */
371
- splice(start, deleteCount = 0, ...items) {
372
- const removedList = this._createInstance();
373
- start = start < 0 ? this.length + start : start;
374
- start = Math.max(0, Math.min(start, this.length));
375
- deleteCount = Math.max(0, deleteCount);
376
- let currentIndex = 0;
377
- let currentNode = undefined;
378
- let previousNode = undefined;
379
- const iterator = this._getNodeIterator();
380
- for (const node of iterator) {
381
- if (currentIndex === start) {
382
- currentNode = node;
383
- break;
384
- }
385
- previousNode = node;
386
- currentIndex++;
387
- }
388
- for (let i = 0; i < deleteCount && currentNode; i++) {
389
- removedList.push(currentNode.value);
390
- const nextNode = currentNode.next;
391
- this.delete(currentNode);
392
- currentNode = nextNode;
393
- }
394
- for (let i = 0; i < items.length; i++) {
395
- if (previousNode) {
396
- this.addAfter(previousNode, items[i]);
397
- previousNode = previousNode.next;
398
- }
399
- else {
400
- this.addAt(0, items[i]);
401
- previousNode = this._getNodeIterator().next().value;
402
- }
403
- }
404
- return removedList;
405
- }
406
- reduceRight(callbackfn, initialValue) {
407
- let accumulator = initialValue !== null && initialValue !== void 0 ? initialValue : 0;
408
- let index = this.length - 1;
409
- for (const item of this._getReverseIterator()) {
410
- accumulator = callbackfn(accumulator, item, index--, this);
411
- }
412
- return accumulator;
413
- }
414
- }
415
- exports.LinearLinkedBase = LinearLinkedBase;