doubly-linked-list-typed 2.1.1 → 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 +1299 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +1294 -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 +11 -2
  44. package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
  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/doubly-linked-list-typed.js +1302 -0
  87. package/dist/umd/doubly-linked-list-typed.js.map +1 -0
  88. package/dist/umd/doubly-linked-list-typed.min.js +9 -0
  89. package/dist/umd/doubly-linked-list-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +4 -4
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  93. package/src/data-structures/binary-tree/avl-tree.ts +2 -2
  94. package/src/data-structures/binary-tree/binary-tree.ts +4 -4
  95. package/src/data-structures/binary-tree/bst.ts +1 -1
  96. package/src/data-structures/binary-tree/red-black-tree.ts +2 -2
  97. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +1 -1
  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 +1 -1
  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 -12
  192. package/dist/index.js +0 -28
  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
@@ -0,0 +1,1294 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+
6
+ // src/data-structures/base/iterable-element-base.ts
7
+ var _IterableElementBase = class _IterableElementBase {
8
+ /**
9
+ * Create a new iterable base.
10
+ *
11
+ * @param options Optional behavior overrides. When provided, a `toElementFn`
12
+ * is used to convert a raw element (`R`) into a public element (`E`).
13
+ *
14
+ * @remarks
15
+ * Time O(1), Space O(1).
16
+ */
17
+ constructor(options) {
18
+ /**
19
+ * The converter used to transform a raw element (`R`) into a public element (`E`).
20
+ *
21
+ * @remarks
22
+ * Time O(1), Space O(1).
23
+ */
24
+ __publicField(this, "_toElementFn");
25
+ if (options) {
26
+ const { toElementFn } = options;
27
+ if (typeof toElementFn === "function") this._toElementFn = toElementFn;
28
+ else if (toElementFn) throw new TypeError("toElementFn must be a function type");
29
+ }
30
+ }
31
+ /**
32
+ * Exposes the current `toElementFn`, if configured.
33
+ *
34
+ * @returns The converter function or `undefined` when not set.
35
+ * @remarks
36
+ * Time O(1), Space O(1).
37
+ */
38
+ get toElementFn() {
39
+ return this._toElementFn;
40
+ }
41
+ /**
42
+ * Returns an iterator over the structure's elements.
43
+ *
44
+ * @param args Optional iterator arguments forwarded to the internal iterator.
45
+ * @returns An `IterableIterator<E>` that yields the elements in traversal order.
46
+ *
47
+ * @remarks
48
+ * Producing the iterator is O(1); consuming the entire iterator is Time O(n) with O(1) extra space.
49
+ */
50
+ *[Symbol.iterator](...args) {
51
+ yield* this._getIterator(...args);
52
+ }
53
+ /**
54
+ * Returns an iterator over the values (alias of the default iterator).
55
+ *
56
+ * @returns An `IterableIterator<E>` over all elements.
57
+ * @remarks
58
+ * Creating the iterator is O(1); full iteration is Time O(n), Space O(1).
59
+ */
60
+ *values() {
61
+ for (const item of this) yield item;
62
+ }
63
+ /**
64
+ * Tests whether all elements satisfy the predicate.
65
+ *
66
+ * @template TReturn
67
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
68
+ * @param thisArg Optional `this` binding for the predicate.
69
+ * @returns `true` if every element passes; otherwise `false`.
70
+ *
71
+ * @remarks
72
+ * Time O(n) in the worst case; may exit early when the first failure is found. Space O(1).
73
+ */
74
+ every(predicate, thisArg) {
75
+ let index = 0;
76
+ for (const item of this) {
77
+ if (thisArg === void 0) {
78
+ if (!predicate(item, index++, this)) return false;
79
+ } else {
80
+ const fn = predicate;
81
+ if (!fn.call(thisArg, item, index++, this)) return false;
82
+ }
83
+ }
84
+ return true;
85
+ }
86
+ /**
87
+ * Tests whether at least one element satisfies the predicate.
88
+ *
89
+ * @param predicate Function invoked for each element with signature `(value, index, self)`.
90
+ * @param thisArg Optional `this` binding for the predicate.
91
+ * @returns `true` if any element passes; otherwise `false`.
92
+ *
93
+ * @remarks
94
+ * Time O(n) in the worst case; may exit early on first success. Space O(1).
95
+ */
96
+ some(predicate, thisArg) {
97
+ let index = 0;
98
+ for (const item of this) {
99
+ if (thisArg === void 0) {
100
+ if (predicate(item, index++, this)) return true;
101
+ } else {
102
+ const fn = predicate;
103
+ if (fn.call(thisArg, item, index++, this)) return true;
104
+ }
105
+ }
106
+ return false;
107
+ }
108
+ /**
109
+ * Invokes a callback for each element in iteration order.
110
+ *
111
+ * @param callbackfn Function invoked per element with signature `(value, index, self)`.
112
+ * @param thisArg Optional `this` binding for the callback.
113
+ * @returns `void`.
114
+ *
115
+ * @remarks
116
+ * Time O(n), Space O(1).
117
+ */
118
+ forEach(callbackfn, thisArg) {
119
+ let index = 0;
120
+ for (const item of this) {
121
+ if (thisArg === void 0) {
122
+ callbackfn(item, index++, this);
123
+ } else {
124
+ const fn = callbackfn;
125
+ fn.call(thisArg, item, index++, this);
126
+ }
127
+ }
128
+ }
129
+ // Implementation signature
130
+ find(predicate, thisArg) {
131
+ let index = 0;
132
+ for (const item of this) {
133
+ if (thisArg === void 0) {
134
+ if (predicate(item, index++, this)) return item;
135
+ } else {
136
+ const fn = predicate;
137
+ if (fn.call(thisArg, item, index++, this)) return item;
138
+ }
139
+ }
140
+ return;
141
+ }
142
+ /**
143
+ * Checks whether a strictly-equal element exists in the structure.
144
+ *
145
+ * @param element The element to test with `===` equality.
146
+ * @returns `true` if an equal element is found; otherwise `false`.
147
+ *
148
+ * @remarks
149
+ * Time O(n) in the worst case. Space O(1).
150
+ */
151
+ has(element) {
152
+ for (const ele of this) if (ele === element) return true;
153
+ return false;
154
+ }
155
+ /**
156
+ * Reduces all elements to a single accumulated value.
157
+ *
158
+ * @overload
159
+ * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`. The first element is used as the initial accumulator.
160
+ * @returns The final accumulated value typed as `E`.
161
+ *
162
+ * @overload
163
+ * @param callbackfn Reducer of signature `(acc, value, index, self) => nextAcc`.
164
+ * @param initialValue The initial accumulator value of type `E`.
165
+ * @returns The final accumulated value typed as `E`.
166
+ *
167
+ * @overload
168
+ * @template U The accumulator type when it differs from `E`.
169
+ * @param callbackfn Reducer of signature `(acc: U, value, index, self) => U`.
170
+ * @param initialValue The initial accumulator value of type `U`.
171
+ * @returns The final accumulated value typed as `U`.
172
+ *
173
+ * @remarks
174
+ * Time O(n), Space O(1). Throws if called on an empty structure without `initialValue`.
175
+ */
176
+ reduce(callbackfn, initialValue) {
177
+ let index = 0;
178
+ const iter = this[Symbol.iterator]();
179
+ let acc;
180
+ if (arguments.length >= 2) {
181
+ acc = initialValue;
182
+ } else {
183
+ const first = iter.next();
184
+ if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
185
+ acc = first.value;
186
+ index = 1;
187
+ }
188
+ for (const value of iter) {
189
+ acc = callbackfn(acc, value, index++, this);
190
+ }
191
+ return acc;
192
+ }
193
+ /**
194
+ * Materializes the elements into a new array.
195
+ *
196
+ * @returns A shallow array copy of the iteration order.
197
+ * @remarks
198
+ * Time O(n), Space O(n).
199
+ */
200
+ toArray() {
201
+ return [...this];
202
+ }
203
+ /**
204
+ * Returns a representation of the structure suitable for quick visualization.
205
+ * Defaults to an array of elements; subclasses may override to provide richer visuals.
206
+ *
207
+ * @returns A visual representation (array by default).
208
+ * @remarks
209
+ * Time O(n), Space O(n).
210
+ */
211
+ toVisual() {
212
+ return [...this];
213
+ }
214
+ /**
215
+ * Prints `toVisual()` to the console. Intended for quick debugging.
216
+ *
217
+ * @returns `void`.
218
+ * @remarks
219
+ * Time O(n) due to materialization, Space O(n) for the intermediate representation.
220
+ */
221
+ print() {
222
+ console.log(this.toVisual());
223
+ }
224
+ };
225
+ __name(_IterableElementBase, "IterableElementBase");
226
+ var IterableElementBase = _IterableElementBase;
227
+
228
+ // src/data-structures/base/linear-base.ts
229
+ var _LinkedListNode = class _LinkedListNode {
230
+ /**
231
+ * Initialize a node.
232
+ * @param value - Element value.
233
+ * @remarks Time O(1), Space O(1)
234
+ */
235
+ constructor(value) {
236
+ __publicField(this, "_value");
237
+ __publicField(this, "_next");
238
+ this._value = value;
239
+ this._next = void 0;
240
+ }
241
+ /**
242
+ * Element payload getter.
243
+ * @returns Element value.
244
+ * @remarks Time O(1), Space O(1)
245
+ */
246
+ get value() {
247
+ return this._value;
248
+ }
249
+ /**
250
+ * Element payload setter.
251
+ * @param value - New value.
252
+ * @remarks Time O(1), Space O(1)
253
+ */
254
+ set value(value) {
255
+ this._value = value;
256
+ }
257
+ /**
258
+ * Next node getter.
259
+ * @returns Next node or `undefined`.
260
+ * @remarks Time O(1), Space O(1)
261
+ */
262
+ get next() {
263
+ return this._next;
264
+ }
265
+ /**
266
+ * Next node setter.
267
+ * @param value - Next node or `undefined`.
268
+ * @remarks Time O(1), Space O(1)
269
+ */
270
+ set next(value) {
271
+ this._next = value;
272
+ }
273
+ };
274
+ __name(_LinkedListNode, "LinkedListNode");
275
+ var LinkedListNode = _LinkedListNode;
276
+ var _LinearBase = class _LinearBase extends IterableElementBase {
277
+ /**
278
+ * Construct a linear container with runtime options.
279
+ * @param options - `{ maxLen?, ... }` bounds/behavior options.
280
+ * @remarks Time O(1), Space O(1)
281
+ */
282
+ constructor(options) {
283
+ super(options);
284
+ __publicField(this, "_maxLen", -1);
285
+ if (options) {
286
+ const { maxLen } = options;
287
+ if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
288
+ }
289
+ }
290
+ /**
291
+ * Upper bound for length (if positive), or `-1` when unbounded.
292
+ * @returns Maximum allowed length.
293
+ * @remarks Time O(1), Space O(1)
294
+ */
295
+ get maxLen() {
296
+ return this._maxLen;
297
+ }
298
+ /**
299
+ * First index of a value from the left.
300
+ * @param searchElement - Value to match.
301
+ * @param fromIndex - Start position (supports negative index).
302
+ * @returns Index or `-1` if not found.
303
+ * @remarks Time O(n), Space O(1)
304
+ */
305
+ indexOf(searchElement, fromIndex = 0) {
306
+ if (this.length === 0) return -1;
307
+ if (fromIndex < 0) fromIndex = this.length + fromIndex;
308
+ if (fromIndex < 0) fromIndex = 0;
309
+ for (let i = fromIndex; i < this.length; i++) {
310
+ const element = this.at(i);
311
+ if (element === searchElement) return i;
312
+ }
313
+ return -1;
314
+ }
315
+ /**
316
+ * Last index of a value from the right.
317
+ * @param searchElement - Value to match.
318
+ * @param fromIndex - Start position (supports negative index).
319
+ * @returns Index or `-1` if not found.
320
+ * @remarks Time O(n), Space O(1)
321
+ */
322
+ lastIndexOf(searchElement, fromIndex = this.length - 1) {
323
+ if (this.length === 0) return -1;
324
+ if (fromIndex >= this.length) fromIndex = this.length - 1;
325
+ if (fromIndex < 0) fromIndex = this.length + fromIndex;
326
+ for (let i = fromIndex; i >= 0; i--) {
327
+ const element = this.at(i);
328
+ if (element === searchElement) return i;
329
+ }
330
+ return -1;
331
+ }
332
+ /**
333
+ * Find the first index matching a predicate.
334
+ * @param predicate - `(element, index, self) => boolean`.
335
+ * @param thisArg - Optional `this` for callback.
336
+ * @returns Index or `-1`.
337
+ * @remarks Time O(n), Space O(1)
338
+ */
339
+ findIndex(predicate, thisArg) {
340
+ for (let i = 0; i < this.length; i++) {
341
+ const item = this.at(i);
342
+ if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
343
+ }
344
+ return -1;
345
+ }
346
+ /**
347
+ * Concatenate elements and/or containers.
348
+ * @param items - Elements or other containers.
349
+ * @returns New container with combined elements (`this` type).
350
+ * @remarks Time O(sum(length)), Space O(sum(length))
351
+ */
352
+ concat(...items) {
353
+ const newList = this.clone();
354
+ for (const item of items) {
355
+ if (item instanceof _LinearBase) {
356
+ newList.pushMany(item);
357
+ } else {
358
+ newList.push(item);
359
+ }
360
+ }
361
+ return newList;
362
+ }
363
+ /**
364
+ * In-place stable order via array sort semantics.
365
+ * @param compareFn - Comparator `(a, b) => number`.
366
+ * @returns This container.
367
+ * @remarks Time O(n log n), Space O(n) (materializes to array temporarily)
368
+ */
369
+ sort(compareFn) {
370
+ const arr = this.toArray();
371
+ arr.sort(compareFn);
372
+ this.clear();
373
+ for (const item of arr) this.push(item);
374
+ return this;
375
+ }
376
+ /**
377
+ * Remove and/or insert elements at a position (array-compatible).
378
+ * @param start - Start index (supports negative index).
379
+ * @param deleteCount - How many to remove.
380
+ * @param items - Elements to insert.
381
+ * @returns Removed elements as a new list (`this` type).
382
+ * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
383
+ */
384
+ splice(start, deleteCount = 0, ...items) {
385
+ const removedList = this._createInstance();
386
+ start = start < 0 ? this.length + start : start;
387
+ start = Math.max(0, Math.min(start, this.length));
388
+ deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
389
+ for (let i = 0; i < deleteCount; i++) {
390
+ const removed = this.deleteAt(start);
391
+ if (removed !== void 0) {
392
+ removedList.push(removed);
393
+ }
394
+ }
395
+ for (let i = 0; i < items.length; i++) {
396
+ this.addAt(start + i, items[i]);
397
+ }
398
+ return removedList;
399
+ }
400
+ /**
401
+ * Join all elements into a string.
402
+ * @param separator - Separator string.
403
+ * @returns Concatenated string.
404
+ * @remarks Time O(n), Space O(n)
405
+ */
406
+ join(separator = ",") {
407
+ return this.toArray().join(separator);
408
+ }
409
+ /**
410
+ * Snapshot elements into a reversed array.
411
+ * @returns New reversed array.
412
+ * @remarks Time O(n), Space O(n)
413
+ */
414
+ toReversedArray() {
415
+ const array = [];
416
+ for (let i = this.length - 1; i >= 0; i--) {
417
+ array.push(this.at(i));
418
+ }
419
+ return array;
420
+ }
421
+ reduceRight(callbackfn, initialValue) {
422
+ let accumulator = initialValue != null ? initialValue : 0;
423
+ for (let i = this.length - 1; i >= 0; i--) {
424
+ accumulator = callbackfn(accumulator, this.at(i), i, this);
425
+ }
426
+ return accumulator;
427
+ }
428
+ /**
429
+ * Create a shallow copy of a subrange.
430
+ * @param start - Inclusive start (supports negative index).
431
+ * @param end - Exclusive end (supports negative index).
432
+ * @returns New list with the range (`this` type).
433
+ * @remarks Time O(n), Space O(n)
434
+ */
435
+ slice(start = 0, end = this.length) {
436
+ start = start < 0 ? this.length + start : start;
437
+ end = end < 0 ? this.length + end : end;
438
+ const newList = this._createInstance();
439
+ for (let i = start; i < end; i++) {
440
+ newList.push(this.at(i));
441
+ }
442
+ return newList;
443
+ }
444
+ /**
445
+ * Fill a range with a value.
446
+ * @param value - Value to set.
447
+ * @param start - Inclusive start.
448
+ * @param end - Exclusive end.
449
+ * @returns This list.
450
+ * @remarks Time O(n), Space O(1)
451
+ */
452
+ fill(value, start = 0, end = this.length) {
453
+ start = start < 0 ? this.length + start : start;
454
+ end = end < 0 ? this.length + end : end;
455
+ if (start < 0) start = 0;
456
+ if (end > this.length) end = this.length;
457
+ if (start >= end) return this;
458
+ for (let i = start; i < end; i++) {
459
+ this.setAt(i, value);
460
+ }
461
+ return this;
462
+ }
463
+ };
464
+ __name(_LinearBase, "LinearBase");
465
+ var LinearBase = _LinearBase;
466
+ var _LinearLinkedBase = class _LinearLinkedBase extends LinearBase {
467
+ constructor(options) {
468
+ super(options);
469
+ if (options) {
470
+ const { maxLen } = options;
471
+ if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
472
+ }
473
+ }
474
+ /**
475
+ * Linked-list optimized `indexOf` (forwards scan).
476
+ * @param searchElement - Value to match.
477
+ * @param fromIndex - Start position.
478
+ * @returns Index or `-1`.
479
+ * @remarks Time O(n), Space O(1)
480
+ */
481
+ indexOf(searchElement, fromIndex = 0) {
482
+ const iterator = this._getIterator();
483
+ let current = iterator.next();
484
+ let index = 0;
485
+ while (index < fromIndex) {
486
+ current = iterator.next();
487
+ index++;
488
+ }
489
+ while (!current.done) {
490
+ if (current.value === searchElement) return index;
491
+ current = iterator.next();
492
+ index++;
493
+ }
494
+ return -1;
495
+ }
496
+ /**
497
+ * Linked-list optimized `lastIndexOf` (reverse scan).
498
+ * @param searchElement - Value to match.
499
+ * @param fromIndex - Start position.
500
+ * @returns Index or `-1`.
501
+ * @remarks Time O(n), Space O(1)
502
+ */
503
+ lastIndexOf(searchElement, fromIndex = this.length - 1) {
504
+ const iterator = this._getReverseIterator();
505
+ let current = iterator.next();
506
+ let index = this.length - 1;
507
+ while (index > fromIndex) {
508
+ current = iterator.next();
509
+ index--;
510
+ }
511
+ while (!current.done) {
512
+ if (current.value === searchElement) return index;
513
+ current = iterator.next();
514
+ index--;
515
+ }
516
+ return -1;
517
+ }
518
+ concat(...items) {
519
+ const newList = this.clone();
520
+ for (const item of items) {
521
+ if (item instanceof LinearBase) {
522
+ newList.pushMany(item);
523
+ } else {
524
+ newList.push(item);
525
+ }
526
+ }
527
+ return newList;
528
+ }
529
+ /**
530
+ * Slice via forward iteration (no random access required).
531
+ * @param start - Inclusive start (supports negative index).
532
+ * @param end - Exclusive end (supports negative index).
533
+ * @returns New list (`this` type).
534
+ * @remarks Time O(n), Space O(n)
535
+ */
536
+ slice(start = 0, end = this.length) {
537
+ start = start < 0 ? this.length + start : start;
538
+ end = end < 0 ? this.length + end : end;
539
+ const newList = this._createInstance();
540
+ const iterator = this._getIterator();
541
+ let current = iterator.next();
542
+ let c = 0;
543
+ while (c < start) {
544
+ current = iterator.next();
545
+ c++;
546
+ }
547
+ for (let i = start; i < end; i++) {
548
+ newList.push(current.value);
549
+ current = iterator.next();
550
+ }
551
+ return newList;
552
+ }
553
+ /**
554
+ * Splice by walking node iterators from the start index.
555
+ * @param start - Start index.
556
+ * @param deleteCount - How many elements to remove.
557
+ * @param items - Elements to insert after the splice point.
558
+ * @returns Removed elements as a new list (`this` type).
559
+ * @remarks Time O(n + m), Space O(min(n, m)) where `m = items.length`
560
+ */
561
+ splice(start, deleteCount = 0, ...items) {
562
+ const removedList = this._createInstance();
563
+ start = start < 0 ? this.length + start : start;
564
+ start = Math.max(0, Math.min(start, this.length));
565
+ deleteCount = Math.max(0, deleteCount);
566
+ let currentIndex = 0;
567
+ let currentNode = void 0;
568
+ let previousNode = void 0;
569
+ const iterator = this._getNodeIterator();
570
+ for (const node of iterator) {
571
+ if (currentIndex === start) {
572
+ currentNode = node;
573
+ break;
574
+ }
575
+ previousNode = node;
576
+ currentIndex++;
577
+ }
578
+ for (let i = 0; i < deleteCount && currentNode; i++) {
579
+ removedList.push(currentNode.value);
580
+ const nextNode = currentNode.next;
581
+ this.delete(currentNode);
582
+ currentNode = nextNode;
583
+ }
584
+ for (let i = 0; i < items.length; i++) {
585
+ if (previousNode) {
586
+ this.addAfter(previousNode, items[i]);
587
+ previousNode = previousNode.next;
588
+ } else {
589
+ this.addAt(0, items[i]);
590
+ previousNode = this._getNodeIterator().next().value;
591
+ }
592
+ }
593
+ return removedList;
594
+ }
595
+ reduceRight(callbackfn, initialValue) {
596
+ let accumulator = initialValue != null ? initialValue : 0;
597
+ let index = this.length - 1;
598
+ for (const item of this._getReverseIterator()) {
599
+ accumulator = callbackfn(accumulator, item, index--, this);
600
+ }
601
+ return accumulator;
602
+ }
603
+ };
604
+ __name(_LinearLinkedBase, "LinearLinkedBase");
605
+ var LinearLinkedBase = _LinearLinkedBase;
606
+
607
+ // src/data-structures/linked-list/doubly-linked-list.ts
608
+ var _DoublyLinkedListNode = class _DoublyLinkedListNode extends LinkedListNode {
609
+ /**
610
+ * Create a node.
611
+ * @remarks Time O(1), Space O(1)
612
+ * @param value - Element value to store.
613
+ * @returns New node instance.
614
+ */
615
+ constructor(value) {
616
+ super(value);
617
+ __publicField(this, "_next");
618
+ __publicField(this, "_prev");
619
+ this._value = value;
620
+ this._next = void 0;
621
+ this._prev = void 0;
622
+ }
623
+ /**
624
+ * Get the next node link.
625
+ * @remarks Time O(1), Space O(1)
626
+ * @returns Next node or undefined.
627
+ */
628
+ get next() {
629
+ return this._next;
630
+ }
631
+ /**
632
+ * Set the next node link.
633
+ * @remarks Time O(1), Space O(1)
634
+ * @param value - Next node or undefined.
635
+ * @returns void
636
+ */
637
+ set next(value) {
638
+ this._next = value;
639
+ }
640
+ /**
641
+ * Get the previous node link.
642
+ * @remarks Time O(1), Space O(1)
643
+ * @returns Previous node or undefined.
644
+ */
645
+ get prev() {
646
+ return this._prev;
647
+ }
648
+ /**
649
+ * Set the previous node link.
650
+ * @remarks Time O(1), Space O(1)
651
+ * @param value - Previous node or undefined.
652
+ * @returns void
653
+ */
654
+ set prev(value) {
655
+ this._prev = value;
656
+ }
657
+ };
658
+ __name(_DoublyLinkedListNode, "DoublyLinkedListNode");
659
+ var DoublyLinkedListNode = _DoublyLinkedListNode;
660
+ var _DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
661
+ /**
662
+ * Create a DoublyLinkedList and optionally bulk-insert elements.
663
+ * @remarks Time O(N), Space O(N)
664
+ * @param [elements] - Iterable of elements or nodes (or raw records if toElementFn is provided).
665
+ * @param [options] - Options such as maxLen and toElementFn.
666
+ * @returns New DoublyLinkedList instance.
667
+ */
668
+ constructor(elements = [], options) {
669
+ super(options);
670
+ __publicField(this, "_equals", Object.is);
671
+ __publicField(this, "_head");
672
+ __publicField(this, "_tail");
673
+ __publicField(this, "_length", 0);
674
+ this._head = void 0;
675
+ this._tail = void 0;
676
+ this._length = 0;
677
+ if ((options == null ? void 0 : options.maxLen) && Number.isInteger(options.maxLen) && options.maxLen > 0) {
678
+ this._maxLen = options.maxLen;
679
+ }
680
+ this.pushMany(elements);
681
+ }
682
+ /**
683
+ * Get the head node.
684
+ * @remarks Time O(1), Space O(1)
685
+ * @returns Head node or undefined.
686
+ */
687
+ get head() {
688
+ return this._head;
689
+ }
690
+ /**
691
+ * Get the tail node.
692
+ * @remarks Time O(1), Space O(1)
693
+ * @returns Tail node or undefined.
694
+ */
695
+ get tail() {
696
+ return this._tail;
697
+ }
698
+ /**
699
+ * Get the number of elements.
700
+ * @remarks Time O(1), Space O(1)
701
+ * @returns Current length.
702
+ */
703
+ get length() {
704
+ return this._length;
705
+ }
706
+ /**
707
+ * Get the first element value.
708
+ * @remarks Time O(1), Space O(1)
709
+ * @returns First element or undefined.
710
+ */
711
+ get first() {
712
+ var _a;
713
+ return (_a = this.head) == null ? void 0 : _a.value;
714
+ }
715
+ /**
716
+ * Get the last element value.
717
+ * @remarks Time O(1), Space O(1)
718
+ * @returns Last element or undefined.
719
+ */
720
+ get last() {
721
+ var _a;
722
+ return (_a = this.tail) == null ? void 0 : _a.value;
723
+ }
724
+ /**
725
+ * Create a new list from an array of elements.
726
+ * @remarks Time O(N), Space O(N)
727
+ * @template E
728
+ * @template R
729
+ * @param this - The constructor (subclass) to instantiate.
730
+ * @param data - Array of elements to insert.
731
+ * @returns A new list populated with the array's elements.
732
+ */
733
+ static fromArray(data) {
734
+ return new this(data);
735
+ }
736
+ /**
737
+ * Type guard: check whether the input is a DoublyLinkedListNode.
738
+ * @remarks Time O(1), Space O(1)
739
+ * @param elementNodeOrPredicate - Element, node, or predicate.
740
+ * @returns True if the value is a DoublyLinkedListNode.
741
+ */
742
+ isNode(elementNodeOrPredicate) {
743
+ return elementNodeOrPredicate instanceof DoublyLinkedListNode;
744
+ }
745
+ /**
746
+ * Append an element/node to the tail.
747
+ * @remarks Time O(1), Space O(1)
748
+ * @param elementOrNode - Element or node to append.
749
+ * @returns True when appended.
750
+ */
751
+ push(elementOrNode) {
752
+ const newNode = this._ensureNode(elementOrNode);
753
+ if (!this.head) {
754
+ this._head = newNode;
755
+ this._tail = newNode;
756
+ } else {
757
+ newNode.prev = this.tail;
758
+ this.tail.next = newNode;
759
+ this._tail = newNode;
760
+ }
761
+ this._length++;
762
+ if (this._maxLen > 0 && this.length > this._maxLen) this.shift();
763
+ return true;
764
+ }
765
+ /**
766
+ * Remove and return the tail element.
767
+ * @remarks Time O(1), Space O(1)
768
+ * @returns Removed element or undefined.
769
+ */
770
+ pop() {
771
+ if (!this.tail) return void 0;
772
+ const removed = this.tail;
773
+ if (this.head === this.tail) {
774
+ this._head = void 0;
775
+ this._tail = void 0;
776
+ } else {
777
+ this._tail = removed.prev;
778
+ this.tail.next = void 0;
779
+ }
780
+ this._length--;
781
+ return removed.value;
782
+ }
783
+ /**
784
+ * Remove and return the head element.
785
+ * @remarks Time O(1), Space O(1)
786
+ * @returns Removed element or undefined.
787
+ */
788
+ shift() {
789
+ if (!this.head) return void 0;
790
+ const removed = this.head;
791
+ if (this.head === this.tail) {
792
+ this._head = void 0;
793
+ this._tail = void 0;
794
+ } else {
795
+ this._head = removed.next;
796
+ this.head.prev = void 0;
797
+ }
798
+ this._length--;
799
+ return removed.value;
800
+ }
801
+ /**
802
+ * Prepend an element/node to the head.
803
+ * @remarks Time O(1), Space O(1)
804
+ * @param elementOrNode - Element or node to prepend.
805
+ * @returns True when prepended.
806
+ */
807
+ unshift(elementOrNode) {
808
+ const newNode = this._ensureNode(elementOrNode);
809
+ if (!this.head) {
810
+ this._head = newNode;
811
+ this._tail = newNode;
812
+ } else {
813
+ newNode.next = this.head;
814
+ this.head.prev = newNode;
815
+ this._head = newNode;
816
+ }
817
+ this._length++;
818
+ if (this._maxLen > 0 && this._length > this._maxLen) this.pop();
819
+ return true;
820
+ }
821
+ /**
822
+ * Append a sequence of elements/nodes.
823
+ * @remarks Time O(N), Space O(1)
824
+ * @param elements - Iterable of elements or nodes (or raw records if toElementFn is provided).
825
+ * @returns Array of per-element success flags.
826
+ */
827
+ pushMany(elements) {
828
+ const ans = [];
829
+ for (const el of elements) {
830
+ if (this.toElementFn) ans.push(this.push(this.toElementFn(el)));
831
+ else ans.push(this.push(el));
832
+ }
833
+ return ans;
834
+ }
835
+ /**
836
+ * Prepend a sequence of elements/nodes.
837
+ * @remarks Time O(N), Space O(1)
838
+ * @param elements - Iterable of elements or nodes (or raw records if toElementFn is provided).
839
+ * @returns Array of per-element success flags.
840
+ */
841
+ unshiftMany(elements) {
842
+ const ans = [];
843
+ for (const el of elements) {
844
+ if (this.toElementFn) ans.push(this.unshift(this.toElementFn(el)));
845
+ else ans.push(this.unshift(el));
846
+ }
847
+ return ans;
848
+ }
849
+ /**
850
+ * Get the element at a given index.
851
+ * @remarks Time O(N), Space O(1)
852
+ * @param index - Zero-based index.
853
+ * @returns Element or undefined.
854
+ */
855
+ at(index) {
856
+ if (index < 0 || index >= this._length) return void 0;
857
+ let current = this.head;
858
+ for (let i = 0; i < index; i++) current = current.next;
859
+ return current.value;
860
+ }
861
+ /**
862
+ * Get the node reference at a given index.
863
+ * @remarks Time O(N), Space O(1)
864
+ * @param index - Zero-based index.
865
+ * @returns Node or undefined.
866
+ */
867
+ getNodeAt(index) {
868
+ if (index < 0 || index >= this._length) return void 0;
869
+ let current = this.head;
870
+ for (let i = 0; i < index; i++) current = current.next;
871
+ return current;
872
+ }
873
+ /**
874
+ * Find a node by value, reference, or predicate.
875
+ * @remarks Time O(N), Space O(1)
876
+ * @param [elementNodeOrPredicate] - Element, node, or predicate to match.
877
+ * @returns Matching node or undefined.
878
+ */
879
+ getNode(elementNodeOrPredicate) {
880
+ if (elementNodeOrPredicate === void 0) return;
881
+ if (this.isNode(elementNodeOrPredicate)) {
882
+ const target = elementNodeOrPredicate;
883
+ let cur = this.head;
884
+ while (cur) {
885
+ if (cur === target) return target;
886
+ cur = cur.next;
887
+ }
888
+ const isMatch = /* @__PURE__ */ __name((node) => this._equals(node.value, target.value), "isMatch");
889
+ cur = this.head;
890
+ while (cur) {
891
+ if (isMatch(cur)) return cur;
892
+ cur = cur.next;
893
+ }
894
+ return void 0;
895
+ }
896
+ const predicate = this._ensurePredicate(elementNodeOrPredicate);
897
+ let current = this.head;
898
+ while (current) {
899
+ if (predicate(current)) return current;
900
+ current = current.next;
901
+ }
902
+ return void 0;
903
+ }
904
+ /**
905
+ * Insert a new element/node at an index, shifting following nodes.
906
+ * @remarks Time O(N), Space O(1)
907
+ * @param index - Zero-based index.
908
+ * @param newElementOrNode - Element or node to insert.
909
+ * @returns True if inserted.
910
+ */
911
+ addAt(index, newElementOrNode) {
912
+ if (index < 0 || index > this._length) return false;
913
+ if (index === 0) return this.unshift(newElementOrNode);
914
+ if (index === this._length) return this.push(newElementOrNode);
915
+ const newNode = this._ensureNode(newElementOrNode);
916
+ const prevNode = this.getNodeAt(index - 1);
917
+ const nextNode = prevNode.next;
918
+ newNode.prev = prevNode;
919
+ newNode.next = nextNode;
920
+ prevNode.next = newNode;
921
+ nextNode.prev = newNode;
922
+ this._length++;
923
+ return true;
924
+ }
925
+ /**
926
+ * Insert a new element/node before an existing one.
927
+ * @remarks Time O(N), Space O(1)
928
+ * @param existingElementOrNode - Existing element or node.
929
+ * @param newElementOrNode - Element or node to insert.
930
+ * @returns True if inserted.
931
+ */
932
+ addBefore(existingElementOrNode, newElementOrNode) {
933
+ const existingNode = this.isNode(existingElementOrNode) ? existingElementOrNode : this.getNode(existingElementOrNode);
934
+ if (!existingNode) return false;
935
+ const newNode = this._ensureNode(newElementOrNode);
936
+ newNode.prev = existingNode.prev;
937
+ if (existingNode.prev) existingNode.prev.next = newNode;
938
+ newNode.next = existingNode;
939
+ existingNode.prev = newNode;
940
+ if (existingNode === this.head) this._head = newNode;
941
+ this._length++;
942
+ return true;
943
+ }
944
+ /**
945
+ * Insert a new element/node after an existing one.
946
+ * @remarks Time O(N), Space O(1)
947
+ * @param existingElementOrNode - Existing element or node.
948
+ * @param newElementOrNode - Element or node to insert.
949
+ * @returns True if inserted.
950
+ */
951
+ addAfter(existingElementOrNode, newElementOrNode) {
952
+ const existingNode = this.isNode(existingElementOrNode) ? existingElementOrNode : this.getNode(existingElementOrNode);
953
+ if (!existingNode) return false;
954
+ const newNode = this._ensureNode(newElementOrNode);
955
+ newNode.next = existingNode.next;
956
+ if (existingNode.next) existingNode.next.prev = newNode;
957
+ newNode.prev = existingNode;
958
+ existingNode.next = newNode;
959
+ if (existingNode === this.tail) this._tail = newNode;
960
+ this._length++;
961
+ return true;
962
+ }
963
+ /**
964
+ * Set the element value at an index.
965
+ * @remarks Time O(N), Space O(1)
966
+ * @param index - Zero-based index.
967
+ * @param value - New value.
968
+ * @returns True if updated.
969
+ */
970
+ setAt(index, value) {
971
+ const node = this.getNodeAt(index);
972
+ if (!node) return false;
973
+ node.value = value;
974
+ return true;
975
+ }
976
+ /**
977
+ * Delete the element at an index.
978
+ * @remarks Time O(N), Space O(1)
979
+ * @param index - Zero-based index.
980
+ * @returns Removed element or undefined.
981
+ */
982
+ deleteAt(index) {
983
+ if (index < 0 || index >= this._length) return;
984
+ if (index === 0) return this.shift();
985
+ if (index === this._length - 1) return this.pop();
986
+ const removedNode = this.getNodeAt(index);
987
+ const prevNode = removedNode.prev;
988
+ const nextNode = removedNode.next;
989
+ prevNode.next = nextNode;
990
+ nextNode.prev = prevNode;
991
+ this._length--;
992
+ return removedNode.value;
993
+ }
994
+ /**
995
+ * Delete the first match by value/node.
996
+ * @remarks Time O(N), Space O(1)
997
+ * @param [elementOrNode] - Element or node to remove.
998
+ * @returns True if removed.
999
+ */
1000
+ delete(elementOrNode) {
1001
+ const node = this.getNode(elementOrNode);
1002
+ if (!node) return false;
1003
+ if (node === this.head) this.shift();
1004
+ else if (node === this.tail) this.pop();
1005
+ else {
1006
+ const prevNode = node.prev;
1007
+ const nextNode = node.next;
1008
+ prevNode.next = nextNode;
1009
+ nextNode.prev = prevNode;
1010
+ this._length--;
1011
+ }
1012
+ return true;
1013
+ }
1014
+ /**
1015
+ * Check whether the list is empty.
1016
+ * @remarks Time O(1), Space O(1)
1017
+ * @returns True if length is 0.
1018
+ */
1019
+ isEmpty() {
1020
+ return this._length === 0;
1021
+ }
1022
+ /**
1023
+ * Remove all nodes and reset length.
1024
+ * @remarks Time O(N), Space O(1)
1025
+ * @returns void
1026
+ */
1027
+ clear() {
1028
+ this._head = void 0;
1029
+ this._tail = void 0;
1030
+ this._length = 0;
1031
+ }
1032
+ /**
1033
+ * Find the first value matching a predicate scanning forward.
1034
+ * @remarks Time O(N), Space O(1)
1035
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
1036
+ * @returns Matched value or undefined.
1037
+ */
1038
+ search(elementNodeOrPredicate) {
1039
+ const predicate = this._ensurePredicate(elementNodeOrPredicate);
1040
+ let current = this.head;
1041
+ while (current) {
1042
+ if (predicate(current)) return current.value;
1043
+ current = current.next;
1044
+ }
1045
+ return void 0;
1046
+ }
1047
+ /**
1048
+ * Find the first value matching a predicate scanning backward.
1049
+ * @remarks Time O(N), Space O(1)
1050
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
1051
+ * @returns Matched value or undefined.
1052
+ */
1053
+ getBackward(elementNodeOrPredicate) {
1054
+ const predicate = this._ensurePredicate(elementNodeOrPredicate);
1055
+ let current = this.tail;
1056
+ while (current) {
1057
+ if (predicate(current)) return current.value;
1058
+ current = current.prev;
1059
+ }
1060
+ return void 0;
1061
+ }
1062
+ /**
1063
+ * Reverse the list in place.
1064
+ * @remarks Time O(N), Space O(1)
1065
+ * @returns This list.
1066
+ */
1067
+ reverse() {
1068
+ let current = this.head;
1069
+ [this._head, this._tail] = [this.tail, this.head];
1070
+ while (current) {
1071
+ const next = current.next;
1072
+ [current.prev, current.next] = [current.next, current.prev];
1073
+ current = next;
1074
+ }
1075
+ return this;
1076
+ }
1077
+ /**
1078
+ * Set the equality comparator used to compare values.
1079
+ * @remarks Time O(1), Space O(1)
1080
+ * @param equals - Equality predicate (a, b) → boolean.
1081
+ * @returns This list.
1082
+ */
1083
+ setEquality(equals) {
1084
+ this._equals = equals;
1085
+ return this;
1086
+ }
1087
+ /**
1088
+ * Deep clone this list (values are copied by reference).
1089
+ * @remarks Time O(N), Space O(N)
1090
+ * @returns A new list with the same element sequence.
1091
+ */
1092
+ clone() {
1093
+ const out = this._createInstance({ toElementFn: this._toElementFn, maxLen: this._maxLen });
1094
+ for (const v of this) out.push(v);
1095
+ return out;
1096
+ }
1097
+ /**
1098
+ * Filter values into a new list of the same class.
1099
+ * @remarks Time O(N), Space O(N)
1100
+ * @param callback - Predicate (value, index, list) → boolean to keep value.
1101
+ * @param [thisArg] - Value for `this` inside the callback.
1102
+ * @returns A new list with kept values.
1103
+ */
1104
+ filter(callback, thisArg) {
1105
+ const out = this._createInstance({ toElementFn: this._toElementFn, maxLen: this._maxLen });
1106
+ let index = 0;
1107
+ for (const v of this) if (callback.call(thisArg, v, index++, this)) out.push(v);
1108
+ return out;
1109
+ }
1110
+ /**
1111
+ * Map values into a new list of the same class.
1112
+ * @remarks Time O(N), Space O(N)
1113
+ * @param callback - Mapping function (value, index, list) → newValue.
1114
+ * @param [thisArg] - Value for `this` inside the callback.
1115
+ * @returns A new list with mapped values.
1116
+ */
1117
+ mapSame(callback, thisArg) {
1118
+ const out = this._createInstance({ toElementFn: this._toElementFn, maxLen: this._maxLen });
1119
+ let index = 0;
1120
+ for (const v of this) {
1121
+ const mv = thisArg === void 0 ? callback(v, index++, this) : callback.call(thisArg, v, index++, this);
1122
+ out.push(mv);
1123
+ }
1124
+ return out;
1125
+ }
1126
+ /**
1127
+ * Map values into a new list (possibly different element type).
1128
+ * @remarks Time O(N), Space O(N)
1129
+ * @template EM
1130
+ * @template RM
1131
+ * @param callback - Mapping function (value, index, list) → newElement.
1132
+ * @param [options] - Options for the output list (e.g., maxLen, toElementFn).
1133
+ * @param [thisArg] - Value for `this` inside the callback.
1134
+ * @returns A new DoublyLinkedList with mapped values.
1135
+ */
1136
+ map(callback, options, thisArg) {
1137
+ const out = this._createLike([], { ...options != null ? options : {}, maxLen: this._maxLen });
1138
+ let index = 0;
1139
+ for (const v of this) out.push(callback.call(thisArg, v, index++, this));
1140
+ return out;
1141
+ }
1142
+ /**
1143
+ * (Protected) Create or return a node for the given input (node or raw element).
1144
+ * @remarks Time O(1), Space O(1)
1145
+ * @param elementOrNode - Element value or node to normalize.
1146
+ * @returns A DoublyLinkedListNode for the provided input.
1147
+ */
1148
+ _ensureNode(elementOrNode) {
1149
+ if (this.isNode(elementOrNode)) return elementOrNode;
1150
+ return new DoublyLinkedListNode(elementOrNode);
1151
+ }
1152
+ /**
1153
+ * (Protected) Normalize input into a predicate over nodes.
1154
+ * @remarks Time O(1), Space O(1)
1155
+ * @param elementNodeOrPredicate - Element, node, or node predicate.
1156
+ * @returns A predicate function taking a node and returning true/false.
1157
+ */
1158
+ _ensurePredicate(elementNodeOrPredicate) {
1159
+ if (this.isNode(elementNodeOrPredicate)) {
1160
+ const target = elementNodeOrPredicate;
1161
+ return (node) => node === target;
1162
+ }
1163
+ if (typeof elementNodeOrPredicate === "function") {
1164
+ return elementNodeOrPredicate;
1165
+ }
1166
+ const value = elementNodeOrPredicate;
1167
+ return (node) => this._equals(node.value, value);
1168
+ }
1169
+ /**
1170
+ * (Protected) Get the previous node of a given node.
1171
+ * @remarks Time O(1), Space O(1)
1172
+ * @param node - A node in the list.
1173
+ * @returns Previous node or undefined.
1174
+ */
1175
+ _getPrevNode(node) {
1176
+ return node.prev;
1177
+ }
1178
+ /**
1179
+ * (Protected) Create an empty instance of the same concrete class.
1180
+ * @remarks Time O(1), Space O(1)
1181
+ * @param [options] - Options forwarded to the constructor.
1182
+ * @returns An empty like-kind list instance.
1183
+ */
1184
+ _createInstance(options) {
1185
+ const Ctor = this.constructor;
1186
+ return new Ctor([], options);
1187
+ }
1188
+ /**
1189
+ * (Protected) Create a like-kind instance and seed it from an iterable.
1190
+ * @remarks Time O(N), Space O(N)
1191
+ * @template EM
1192
+ * @template RM
1193
+ * @param [elements] - Iterable used to seed the new list.
1194
+ * @param [options] - Options forwarded to the constructor.
1195
+ * @returns A like-kind DoublyLinkedList instance.
1196
+ */
1197
+ _createLike(elements = [], options) {
1198
+ const Ctor = this.constructor;
1199
+ return new Ctor(elements, options);
1200
+ }
1201
+ *_getIterator() {
1202
+ let current = this.head;
1203
+ while (current) {
1204
+ yield current.value;
1205
+ current = current.next;
1206
+ }
1207
+ }
1208
+ *_getReverseIterator() {
1209
+ let current = this.tail;
1210
+ while (current) {
1211
+ yield current.value;
1212
+ current = current.prev;
1213
+ }
1214
+ }
1215
+ *_getNodeIterator() {
1216
+ let current = this.head;
1217
+ while (current) {
1218
+ yield current;
1219
+ current = current.next;
1220
+ }
1221
+ }
1222
+ };
1223
+ __name(_DoublyLinkedList, "DoublyLinkedList");
1224
+ var DoublyLinkedList = _DoublyLinkedList;
1225
+
1226
+ // src/utils/utils.ts
1227
+ function isPrimitiveComparable(value) {
1228
+ const valueType = typeof value;
1229
+ if (valueType === "number") return true;
1230
+ return valueType === "bigint" || valueType === "string" || valueType === "boolean";
1231
+ }
1232
+ __name(isPrimitiveComparable, "isPrimitiveComparable");
1233
+ function tryObjectToPrimitive(obj) {
1234
+ if (typeof obj.valueOf === "function") {
1235
+ const valueOfResult = obj.valueOf();
1236
+ if (valueOfResult !== obj) {
1237
+ if (isPrimitiveComparable(valueOfResult)) return valueOfResult;
1238
+ if (typeof valueOfResult === "object" && valueOfResult !== null) return tryObjectToPrimitive(valueOfResult);
1239
+ }
1240
+ }
1241
+ if (typeof obj.toString === "function") {
1242
+ const stringResult = obj.toString();
1243
+ if (stringResult !== "[object Object]") return stringResult;
1244
+ }
1245
+ return null;
1246
+ }
1247
+ __name(tryObjectToPrimitive, "tryObjectToPrimitive");
1248
+ function isComparable(value, isForceObjectComparable = false) {
1249
+ if (value === null || value === void 0) return false;
1250
+ if (isPrimitiveComparable(value)) return true;
1251
+ if (typeof value !== "object") return false;
1252
+ if (value instanceof Date) return true;
1253
+ if (isForceObjectComparable) return true;
1254
+ const comparableValue = tryObjectToPrimitive(value);
1255
+ if (comparableValue === null || comparableValue === void 0) return false;
1256
+ return isPrimitiveComparable(comparableValue);
1257
+ }
1258
+ __name(isComparable, "isComparable");
1259
+
1260
+ // src/common/index.ts
1261
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
1262
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
1263
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
1264
+ return DFSOperation2;
1265
+ })(DFSOperation || {});
1266
+ var _Range = class _Range {
1267
+ constructor(low, high, includeLow = true, includeHigh = true) {
1268
+ this.low = low;
1269
+ this.high = high;
1270
+ this.includeLow = includeLow;
1271
+ this.includeHigh = includeHigh;
1272
+ if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
1273
+ if (low > high) throw new RangeError("low must be less than or equal to high");
1274
+ }
1275
+ // Determine whether a key is within the range
1276
+ isInRange(key, comparator) {
1277
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
1278
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
1279
+ return lowCheck && highCheck;
1280
+ }
1281
+ };
1282
+ __name(_Range, "Range");
1283
+ var Range = _Range;
1284
+ /**
1285
+ * data-structure-typed
1286
+ *
1287
+ * @author Pablo Zeng
1288
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
1289
+ * @license MIT License
1290
+ */
1291
+
1292
+ export { DFSOperation, DoublyLinkedList, DoublyLinkedListNode, Range };
1293
+ //# sourceMappingURL=index.mjs.map
1294
+ //# sourceMappingURL=index.mjs.map