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