heap-typed 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/dist/cjs/index.cjs +1020 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +1012 -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 +3 -3
  45. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  46. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  47. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  48. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  49. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  50. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  51. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  52. package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
  53. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  54. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  55. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  56. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  57. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  58. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  59. package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
  60. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  61. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  62. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  63. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  64. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  65. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  66. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  67. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  68. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  69. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  70. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  71. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  72. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  73. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  74. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  75. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  76. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  77. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  78. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  79. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  80. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  81. package/dist/types/types/index.d.ts +3 -0
  82. package/dist/types/types/utils/index.d.ts +2 -0
  83. package/dist/types/types/utils/utils.d.ts +22 -0
  84. package/dist/types/utils/index.d.ts +1 -1
  85. package/dist/types/utils/utils.d.ts +209 -22
  86. package/dist/umd/heap-typed.js +1023 -0
  87. package/dist/umd/heap-typed.js.map +1 -0
  88. package/dist/umd/heap-typed.min.js +22 -0
  89. package/dist/umd/heap-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +8 -11
  92. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +6 -11
  93. package/src/data-structures/binary-tree/avl-tree.ts +6 -8
  94. package/src/data-structures/binary-tree/binary-tree.ts +13 -15
  95. package/src/data-structures/binary-tree/bst.ts +6 -11
  96. package/src/data-structures/binary-tree/red-black-tree.ts +6 -11
  97. package/src/data-structures/binary-tree/tree-counter.ts +8 -13
  98. package/src/data-structures/binary-tree/tree-multi-map.ts +6 -11
  99. package/src/data-structures/heap/heap.ts +5 -5
  100. package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
  101. package/src/interfaces/binary-tree.ts +3 -3
  102. package/tsconfig.base.json +23 -0
  103. package/tsconfig.json +8 -34
  104. package/tsconfig.test.json +8 -0
  105. package/tsconfig.types.json +15 -0
  106. package/tsup.config.js +28 -0
  107. package/tsup.node.config.js +37 -0
  108. package/dist/common/index.js +0 -28
  109. package/dist/constants/index.js +0 -8
  110. package/dist/data-structures/base/index.d.ts +0 -2
  111. package/dist/data-structures/base/index.js +0 -18
  112. package/dist/data-structures/base/iterable-element-base.js +0 -243
  113. package/dist/data-structures/base/iterable-entry-base.js +0 -183
  114. package/dist/data-structures/base/linear-base.js +0 -415
  115. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
  116. package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
  117. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
  118. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
  119. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
  120. package/dist/data-structures/binary-tree/avl-tree.js +0 -611
  121. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  122. package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
  123. package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
  124. package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
  125. package/dist/data-structures/binary-tree/bst.d.ts +0 -413
  126. package/dist/data-structures/binary-tree/bst.js +0 -903
  127. package/dist/data-structures/binary-tree/index.js +0 -26
  128. package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
  129. package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
  130. package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
  131. package/dist/data-structures/binary-tree/segment-tree.js +0 -297
  132. package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
  133. package/dist/data-structures/binary-tree/tree-counter.js +0 -413
  134. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
  135. package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
  136. package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
  137. package/dist/data-structures/graph/abstract-graph.js +0 -896
  138. package/dist/data-structures/graph/directed-graph.d.ts +0 -207
  139. package/dist/data-structures/graph/directed-graph.js +0 -525
  140. package/dist/data-structures/graph/index.js +0 -20
  141. package/dist/data-structures/graph/map-graph.d.ts +0 -78
  142. package/dist/data-structures/graph/map-graph.js +0 -107
  143. package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
  144. package/dist/data-structures/graph/undirected-graph.js +0 -424
  145. package/dist/data-structures/hash/hash-map.d.ts +0 -345
  146. package/dist/data-structures/hash/hash-map.js +0 -692
  147. package/dist/data-structures/hash/index.d.ts +0 -1
  148. package/dist/data-structures/hash/index.js +0 -17
  149. package/dist/data-structures/heap/heap.d.ts +0 -503
  150. package/dist/data-structures/heap/heap.js +0 -901
  151. package/dist/data-structures/heap/index.d.ts +0 -3
  152. package/dist/data-structures/heap/index.js +0 -19
  153. package/dist/data-structures/heap/max-heap.d.ts +0 -32
  154. package/dist/data-structures/heap/max-heap.js +0 -40
  155. package/dist/data-structures/heap/min-heap.d.ts +0 -33
  156. package/dist/data-structures/heap/min-heap.js +0 -31
  157. package/dist/data-structures/index.js +0 -28
  158. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
  159. package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
  160. package/dist/data-structures/linked-list/index.js +0 -19
  161. package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
  162. package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
  163. package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
  164. package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
  165. package/dist/data-structures/matrix/index.js +0 -18
  166. package/dist/data-structures/matrix/matrix.d.ts +0 -168
  167. package/dist/data-structures/matrix/matrix.js +0 -448
  168. package/dist/data-structures/matrix/navigator.d.ts +0 -55
  169. package/dist/data-structures/matrix/navigator.js +0 -111
  170. package/dist/data-structures/priority-queue/index.js +0 -19
  171. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
  172. package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
  173. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
  174. package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
  175. package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
  176. package/dist/data-structures/priority-queue/priority-queue.js +0 -20
  177. package/dist/data-structures/queue/deque.d.ts +0 -431
  178. package/dist/data-structures/queue/deque.js +0 -879
  179. package/dist/data-structures/queue/index.js +0 -18
  180. package/dist/data-structures/queue/queue.d.ts +0 -308
  181. package/dist/data-structures/queue/queue.js +0 -473
  182. package/dist/data-structures/stack/index.js +0 -17
  183. package/dist/data-structures/stack/stack.d.ts +0 -306
  184. package/dist/data-structures/stack/stack.js +0 -401
  185. package/dist/data-structures/tree/index.js +0 -17
  186. package/dist/data-structures/tree/tree.d.ts +0 -62
  187. package/dist/data-structures/tree/tree.js +0 -107
  188. package/dist/data-structures/trie/index.js +0 -17
  189. package/dist/data-structures/trie/trie.d.ts +0 -350
  190. package/dist/data-structures/trie/trie.js +0 -610
  191. package/dist/index.d.ts +0 -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
@@ -1,2 +1,769 @@
1
- import { LinearBaseOptions } from '../base';
2
- export type DoublyLinkedListOptions<E, R> = LinearBaseOptions<E, R> & {};
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ import type { DoublyLinkedListOptions, ElementCallback, LinearBaseOptions } from '../../types';
9
+ import { LinearLinkedBase, LinkedListNode } from '../base/linear-base';
10
+ /**
11
+ * Node of a doubly linked list; stores value and prev/next links.
12
+ * @remarks Time O(1), Space O(1)
13
+ * @template E
14
+ */
15
+ export declare class DoublyLinkedListNode<E = any> extends LinkedListNode<E> {
16
+ /**
17
+ * Create a node.
18
+ * @remarks Time O(1), Space O(1)
19
+ * @param value - Element value to store.
20
+ * @returns New node instance.
21
+ */
22
+ constructor(value: E);
23
+ protected _next: DoublyLinkedListNode<E> | undefined;
24
+ /**
25
+ * Get the next node link.
26
+ * @remarks Time O(1), Space O(1)
27
+ * @returns Next node or undefined.
28
+ */
29
+ get next(): DoublyLinkedListNode<E> | undefined;
30
+ /**
31
+ * Set the next node link.
32
+ * @remarks Time O(1), Space O(1)
33
+ * @param value - Next node or undefined.
34
+ * @returns void
35
+ */
36
+ set next(value: DoublyLinkedListNode<E> | undefined);
37
+ protected _prev: DoublyLinkedListNode<E> | undefined;
38
+ /**
39
+ * Get the previous node link.
40
+ * @remarks Time O(1), Space O(1)
41
+ * @returns Previous node or undefined.
42
+ */
43
+ get prev(): DoublyLinkedListNode<E> | undefined;
44
+ /**
45
+ * Set the previous node link.
46
+ * @remarks Time O(1), Space O(1)
47
+ * @param value - Previous node or undefined.
48
+ * @returns void
49
+ */
50
+ set prev(value: DoublyLinkedListNode<E> | undefined);
51
+ }
52
+ /**
53
+ * Doubly linked list with O(1) push/pop/unshift/shift and linear scans.
54
+ * @remarks Time O(1), Space O(1)
55
+ * @template E
56
+ * @template R
57
+ * 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
58
+ * 2. Bidirectional Traversal: Unlike singly linked lists, doubly linked lists can be easily traversed forwards or backwards. This makes insertions and deletions in the list more flexible and efficient.
59
+ * 3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
60
+ * 4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
61
+ * Caution: Although our linked list classes provide methods such as at, setAt, addAt, and indexOf that are based on array indices, their time complexity, like that of the native Array.lastIndexOf, is 𝑂(𝑛). If you need to use these methods frequently, you might want to consider other data structures, such as Deque or Queue (designed for random access). Similarly, since the native Array.shift method has a time complexity of 𝑂(𝑛), using an array to simulate a queue can be inefficient. In such cases, you should use Queue or Deque, as these data structures leverage deferred array rearrangement, effectively reducing the average time complexity to 𝑂(1).
62
+ * @example
63
+ * // text editor operation history
64
+ * const actions = [
65
+ * { type: 'insert', content: 'first line of text' },
66
+ * { type: 'insert', content: 'second line of text' },
67
+ * { type: 'delete', content: 'delete the first line' }
68
+ * ];
69
+ * const editorHistory = new DoublyLinkedList<{ type: string; content: string }>(actions);
70
+ *
71
+ * console.log(editorHistory.last?.type); // 'delete'
72
+ * console.log(editorHistory.pop()?.content); // 'delete the first line'
73
+ * console.log(editorHistory.last?.type); // 'insert'
74
+ * @example
75
+ * // Browser history
76
+ * const browserHistory = new DoublyLinkedList<string>();
77
+ *
78
+ * browserHistory.push('home page');
79
+ * browserHistory.push('search page');
80
+ * browserHistory.push('details page');
81
+ *
82
+ * console.log(browserHistory.last); // 'details page'
83
+ * console.log(browserHistory.pop()); // 'details page'
84
+ * console.log(browserHistory.last); // 'search page'
85
+ * @example
86
+ * // Use DoublyLinkedList to implement music player
87
+ * // Define the Song interface
88
+ * interface Song {
89
+ * title: string;
90
+ * artist: string;
91
+ * duration: number; // duration in seconds
92
+ * }
93
+ *
94
+ * class Player {
95
+ * private playlist: DoublyLinkedList<Song>;
96
+ * private currentSong: ReturnType<typeof this.playlist.getNodeAt> | undefined;
97
+ *
98
+ * constructor(songs: Song[]) {
99
+ * this.playlist = new DoublyLinkedList<Song>();
100
+ * songs.forEach(song => this.playlist.push(song));
101
+ * this.currentSong = this.playlist.head;
102
+ * }
103
+ *
104
+ * // Play the next song in the playlist
105
+ * playNext(): Song | undefined {
106
+ * if (!this.currentSong?.next) {
107
+ * this.currentSong = this.playlist.head; // Loop to the first song
108
+ * } else {
109
+ * this.currentSong = this.currentSong.next;
110
+ * }
111
+ * return this.currentSong?.value;
112
+ * }
113
+ *
114
+ * // Play the previous song in the playlist
115
+ * playPrevious(): Song | undefined {
116
+ * if (!this.currentSong?.prev) {
117
+ * this.currentSong = this.playlist.tail; // Loop to the last song
118
+ * } else {
119
+ * this.currentSong = this.currentSong.prev;
120
+ * }
121
+ * return this.currentSong?.value;
122
+ * }
123
+ *
124
+ * // Get the current song
125
+ * getCurrentSong(): Song | undefined {
126
+ * return this.currentSong?.value;
127
+ * }
128
+ *
129
+ * // Loop through the playlist twice
130
+ * loopThroughPlaylist(): Song[] {
131
+ * const playedSongs: Song[] = [];
132
+ * const initialNode = this.currentSong;
133
+ *
134
+ * // Loop through the playlist twice
135
+ * for (let i = 0; i < this.playlist.length * 2; i++) {
136
+ * playedSongs.push(this.currentSong!.value);
137
+ * this.currentSong = this.currentSong!.next || this.playlist.head; // Loop back to the start if needed
138
+ * }
139
+ *
140
+ * // Reset the current song to the initial song
141
+ * this.currentSong = initialNode;
142
+ * return playedSongs;
143
+ * }
144
+ * }
145
+ *
146
+ * const songs = [
147
+ * { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 },
148
+ * { title: 'Hotel California', artist: 'Eagles', duration: 391 },
149
+ * { title: 'Shape of You', artist: 'Ed Sheeran', duration: 233 },
150
+ * { title: 'Billie Jean', artist: 'Michael Jackson', duration: 294 }
151
+ * ];
152
+ * let player = new Player(songs);
153
+ * // should play the next song
154
+ * player = new Player(songs);
155
+ * const firstSong = player.getCurrentSong();
156
+ * const nextSong = player.playNext();
157
+ *
158
+ * // Expect the next song to be "Hotel California by Eagles"
159
+ * console.log(nextSong); // { title: 'Hotel California', artist: 'Eagles', duration: 391 }
160
+ * console.log(firstSong); // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 }
161
+ *
162
+ * // should play the previous song
163
+ * player = new Player(songs);
164
+ * player.playNext(); // Move to the second song
165
+ * const currentSong = player.getCurrentSong();
166
+ * const previousSong = player.playPrevious();
167
+ *
168
+ * // Expect the previous song to be "Bohemian Rhapsody by Queen"
169
+ * console.log(previousSong); // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 }
170
+ * console.log(currentSong); // { title: 'Hotel California', artist: 'Eagles', duration: 391 }
171
+ *
172
+ * // should loop to the first song when playing next from the last song
173
+ * player = new Player(songs);
174
+ * player.playNext(); // Move to the second song
175
+ * player.playNext(); // Move to the third song
176
+ * player.playNext(); // Move to the fourth song
177
+ *
178
+ * const nextSongToFirst = player.playNext(); // Should loop to the first song
179
+ *
180
+ * // Expect the next song to be "Bohemian Rhapsody by Queen"
181
+ * console.log(nextSongToFirst); // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 }
182
+ *
183
+ * // should loop to the last song when playing previous from the first song
184
+ * player = new Player(songs);
185
+ * player.playNext(); // Move to the first song
186
+ * player.playNext(); // Move to the second song
187
+ * player.playNext(); // Move to the third song
188
+ * player.playNext(); // Move to the fourth song
189
+ *
190
+ * const previousToLast = player.playPrevious(); // Should loop to the last song
191
+ *
192
+ * // Expect the previous song to be "Billie Jean by Michael Jackson"
193
+ * console.log(previousToLast); // { title: 'Billie Jean', artist: 'Michael Jackson', duration: 294 }
194
+ *
195
+ * // should loop through the entire playlist
196
+ * player = new Player(songs);
197
+ * const playedSongs = player.loopThroughPlaylist();
198
+ *
199
+ * // The expected order of songs for two loops
200
+ * console.log(playedSongs); // [
201
+ * // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 },
202
+ * // { title: 'Hotel California', artist: 'Eagles', duration: 391 },
203
+ * // { title: 'Shape of You', artist: 'Ed Sheeran', duration: 233 },
204
+ * // { title: 'Billie Jean', artist: 'Michael Jackson', duration: 294 },
205
+ * // { title: 'Bohemian Rhapsody', artist: 'Queen', duration: 354 },
206
+ * // { title: 'Hotel California', artist: 'Eagles', duration: 391 },
207
+ * // { title: 'Shape of You', artist: 'Ed Sheeran', duration: 233 },
208
+ * // { title: 'Billie Jean', artist: 'Michael Jackson', duration: 294 }
209
+ * // ]
210
+ * @example
211
+ * // Use DoublyLinkedList to implement LRU cache
212
+ * interface CacheEntry<K, V> {
213
+ * key: K;
214
+ * value: V;
215
+ * }
216
+ *
217
+ * class LRUCache<K = string, V = any> {
218
+ * private readonly capacity: number;
219
+ * private list: DoublyLinkedList<CacheEntry<K, V>>;
220
+ * private map: Map<K, DoublyLinkedListNode<CacheEntry<K, V>>>;
221
+ *
222
+ * constructor(capacity: number) {
223
+ * if (capacity <= 0) {
224
+ * throw new Error('lru cache capacity must be greater than 0');
225
+ * }
226
+ * this.capacity = capacity;
227
+ * this.list = new DoublyLinkedList<CacheEntry<K, V>>();
228
+ * this.map = new Map<K, DoublyLinkedListNode<CacheEntry<K, V>>>();
229
+ * }
230
+ *
231
+ * // Get the current cache length
232
+ * get length(): number {
233
+ * return this.list.length;
234
+ * }
235
+ *
236
+ * // Check if it is empty
237
+ * get isEmpty(): boolean {
238
+ * return this.list.isEmpty();
239
+ * }
240
+ *
241
+ * // Get cached value
242
+ * get(key: K): V | undefined {
243
+ * const node = this.map.get(key);
244
+ *
245
+ * if (!node) return undefined;
246
+ *
247
+ * // Move the visited node to the head of the linked list (most recently used)
248
+ * this.moveToFront(node);
249
+ *
250
+ * return node.value.value;
251
+ * }
252
+ *
253
+ * // Set cache value
254
+ * set(key: K, value: V): void {
255
+ * // Check if it already exists
256
+ * const node = this.map.get(key);
257
+ *
258
+ * if (node) {
259
+ * // Update value and move to head
260
+ * node.value.value = value;
261
+ * this.moveToFront(node);
262
+ * return;
263
+ * }
264
+ *
265
+ * // Check capacity
266
+ * if (this.list.length >= this.capacity) {
267
+ * // Delete the least recently used element (the tail of the linked list)
268
+ * const removedNode = this.list.tail;
269
+ * if (removedNode) {
270
+ * this.map.delete(removedNode.value.key);
271
+ * this.list.pop();
272
+ * }
273
+ * }
274
+ *
275
+ * // Create new node and add to head
276
+ * const newEntry: CacheEntry<K, V> = { key, value };
277
+ * this.list.unshift(newEntry);
278
+ *
279
+ * // Save node reference in map
280
+ * const newNode = this.list.head;
281
+ * if (newNode) {
282
+ * this.map.set(key, newNode);
283
+ * }
284
+ * }
285
+ *
286
+ * // Delete specific key
287
+ * delete(key: K): boolean {
288
+ * const node = this.map.get(key);
289
+ * if (!node) return false;
290
+ *
291
+ * // Remove from linked list
292
+ * this.list.delete(node);
293
+ * // Remove from map
294
+ * this.map.delete(key);
295
+ *
296
+ * return true;
297
+ * }
298
+ *
299
+ * // Clear cache
300
+ * clear(): void {
301
+ * this.list.clear();
302
+ * this.map.clear();
303
+ * }
304
+ *
305
+ * // Move the node to the head of the linked list
306
+ * private moveToFront(node: DoublyLinkedListNode<CacheEntry<K, V>>): void {
307
+ * this.list.delete(node);
308
+ * this.list.unshift(node.value);
309
+ * }
310
+ * }
311
+ *
312
+ * // should set and get values correctly
313
+ * const cache = new LRUCache<string, number>(3);
314
+ * cache.set('a', 1);
315
+ * cache.set('b', 2);
316
+ * cache.set('c', 3);
317
+ *
318
+ * console.log(cache.get('a')); // 1
319
+ * console.log(cache.get('b')); // 2
320
+ * console.log(cache.get('c')); // 3
321
+ *
322
+ * // The least recently used element should be evicted when capacity is exceeded
323
+ * cache.clear();
324
+ * cache.set('a', 1);
325
+ * cache.set('b', 2);
326
+ * cache.set('c', 3);
327
+ * cache.set('d', 4); // This will eliminate 'a'
328
+ *
329
+ * console.log(cache.get('a')); // undefined
330
+ * console.log(cache.get('b')); // 2
331
+ * console.log(cache.get('c')); // 3
332
+ * console.log(cache.get('d')); // 4
333
+ *
334
+ * // The priority of an element should be updated when it is accessed
335
+ * cache.clear();
336
+ * cache.set('a', 1);
337
+ * cache.set('b', 2);
338
+ * cache.set('c', 3);
339
+ *
340
+ * cache.get('a'); // access 'a'
341
+ * cache.set('d', 4); // This will eliminate 'b'
342
+ *
343
+ * console.log(cache.get('a')); // 1
344
+ * console.log(cache.get('b')); // undefined
345
+ * console.log(cache.get('c')); // 3
346
+ * console.log(cache.get('d')); // 4
347
+ *
348
+ * // Should support updating existing keys
349
+ * cache.clear();
350
+ * cache.set('a', 1);
351
+ * cache.set('a', 10);
352
+ *
353
+ * console.log(cache.get('a')); // 10
354
+ *
355
+ * // Should support deleting specified keys
356
+ * cache.clear();
357
+ * cache.set('a', 1);
358
+ * cache.set('b', 2);
359
+ *
360
+ * console.log(cache.delete('a')); // true
361
+ * console.log(cache.get('a')); // undefined
362
+ * console.log(cache.length); // 1
363
+ *
364
+ * // Should support clearing cache
365
+ * cache.clear();
366
+ * cache.set('a', 1);
367
+ * cache.set('b', 2);
368
+ * cache.clear();
369
+ *
370
+ * console.log(cache.length); // 0
371
+ * console.log(cache.isEmpty); // true
372
+ * @example
373
+ * // finding lyrics by timestamp in Coldplay's "Fix You"
374
+ * // Create a DoublyLinkedList to store song lyrics with timestamps
375
+ * const lyricsList = new DoublyLinkedList<{ time: number; text: string }>();
376
+ *
377
+ * // Detailed lyrics with precise timestamps (in milliseconds)
378
+ * const lyrics = [
379
+ * { time: 0, text: "When you try your best, but you don't succeed" },
380
+ * { time: 4000, text: 'When you get what you want, but not what you need' },
381
+ * { time: 8000, text: "When you feel so tired, but you can't sleep" },
382
+ * { time: 12000, text: 'Stuck in reverse' },
383
+ * { time: 16000, text: 'And the tears come streaming down your face' },
384
+ * { time: 20000, text: "When you lose something you can't replace" },
385
+ * { time: 24000, text: 'When you love someone, but it goes to waste' },
386
+ * { time: 28000, text: 'Could it be worse?' },
387
+ * { time: 32000, text: 'Lights will guide you home' },
388
+ * { time: 36000, text: 'And ignite your bones' },
389
+ * { time: 40000, text: 'And I will try to fix you' }
390
+ * ];
391
+ *
392
+ * // Populate the DoublyLinkedList with lyrics
393
+ * lyrics.forEach(lyric => lyricsList.push(lyric));
394
+ *
395
+ * // Test different scenarios of lyric synchronization
396
+ *
397
+ * // 1. Find lyric at exact timestamp
398
+ * const exactTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 36000);
399
+ * console.log(exactTimeLyric?.text); // 'And ignite your bones'
400
+ *
401
+ * // 2. Find lyric between timestamps
402
+ * const betweenTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 22000);
403
+ * console.log(betweenTimeLyric?.text); // "When you lose something you can't replace"
404
+ *
405
+ * // 3. Find first lyric when timestamp is less than first entry
406
+ * const earlyTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= -1000);
407
+ * console.log(earlyTimeLyric); // undefined
408
+ *
409
+ * // 4. Find last lyric when timestamp is after last entry
410
+ * const lateTimeLyric = lyricsList.getBackward(lyric => lyric.value.time <= 50000);
411
+ * console.log(lateTimeLyric?.text); // 'And I will try to fix you'
412
+ * @example
413
+ * // cpu process schedules
414
+ * class Process {
415
+ * constructor(
416
+ * public id: number,
417
+ * public priority: number
418
+ * ) {}
419
+ *
420
+ * execute(): string {
421
+ * return `Process ${this.id} executed.`;
422
+ * }
423
+ * }
424
+ *
425
+ * class Scheduler {
426
+ * private queue: DoublyLinkedList<Process>;
427
+ *
428
+ * constructor() {
429
+ * this.queue = new DoublyLinkedList<Process>();
430
+ * }
431
+ *
432
+ * addProcess(process: Process): void {
433
+ * // Insert processes into a queue based on priority, keeping priority in descending order
434
+ * let current = this.queue.head;
435
+ * while (current && current.value.priority >= process.priority) {
436
+ * current = current.next;
437
+ * }
438
+ *
439
+ * if (!current) {
440
+ * this.queue.push(process);
441
+ * } else {
442
+ * this.queue.addBefore(current, process);
443
+ * }
444
+ * }
445
+ *
446
+ * executeNext(): string | undefined {
447
+ * // Execute tasks at the head of the queue in order
448
+ * const process = this.queue.shift();
449
+ * return process ? process.execute() : undefined;
450
+ * }
451
+ *
452
+ * listProcesses(): string[] {
453
+ * return this.queue.toArray().map(process => `Process ${process.id} (Priority: ${process.priority})`);
454
+ * }
455
+ *
456
+ * clear(): void {
457
+ * this.queue.clear();
458
+ * }
459
+ * }
460
+ *
461
+ * // should add processes based on priority
462
+ * let scheduler = new Scheduler();
463
+ * scheduler.addProcess(new Process(1, 10));
464
+ * scheduler.addProcess(new Process(2, 20));
465
+ * scheduler.addProcess(new Process(3, 15));
466
+ *
467
+ * console.log(scheduler.listProcesses()); // [
468
+ * // 'Process 2 (Priority: 20)',
469
+ * // 'Process 3 (Priority: 15)',
470
+ * // 'Process 1 (Priority: 10)'
471
+ * // ]
472
+ *
473
+ * // should execute the highest priority process
474
+ * scheduler = new Scheduler();
475
+ * scheduler.addProcess(new Process(1, 10));
476
+ * scheduler.addProcess(new Process(2, 20));
477
+ *
478
+ * console.log(scheduler.executeNext()); // 'Process 2 executed.'
479
+ * console.log(scheduler.listProcesses()); // ['Process 1 (Priority: 10)']
480
+ *
481
+ * // should clear all processes
482
+ * scheduler = new Scheduler();
483
+ * scheduler.addProcess(new Process(1, 10));
484
+ * scheduler.addProcess(new Process(2, 20));
485
+ *
486
+ * scheduler.clear();
487
+ * console.log(scheduler.listProcesses()); // []
488
+ */
489
+ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, DoublyLinkedListNode<E>> {
490
+ protected _equals: (a: E, b: E) => boolean;
491
+ /**
492
+ * Create a DoublyLinkedList and optionally bulk-insert elements.
493
+ * @remarks Time O(N), Space O(N)
494
+ * @param [elements] - Iterable of elements or nodes (or raw records if toElementFn is provided).
495
+ * @param [options] - Options such as maxLen and toElementFn.
496
+ * @returns New DoublyLinkedList instance.
497
+ */
498
+ constructor(elements?: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>, options?: DoublyLinkedListOptions<E, R>);
499
+ protected _head: DoublyLinkedListNode<E> | undefined;
500
+ /**
501
+ * Get the head node.
502
+ * @remarks Time O(1), Space O(1)
503
+ * @returns Head node or undefined.
504
+ */
505
+ get head(): DoublyLinkedListNode<E> | undefined;
506
+ protected _tail: DoublyLinkedListNode<E> | undefined;
507
+ /**
508
+ * Get the tail node.
509
+ * @remarks Time O(1), Space O(1)
510
+ * @returns Tail node or undefined.
511
+ */
512
+ get tail(): DoublyLinkedListNode<E> | undefined;
513
+ protected _length: number;
514
+ /**
515
+ * Get the number of elements.
516
+ * @remarks Time O(1), Space O(1)
517
+ * @returns Current length.
518
+ */
519
+ get length(): number;
520
+ /**
521
+ * Get the first element value.
522
+ * @remarks Time O(1), Space O(1)
523
+ * @returns First element or undefined.
524
+ */
525
+ get first(): E | undefined;
526
+ /**
527
+ * Get the last element value.
528
+ * @remarks Time O(1), Space O(1)
529
+ * @returns Last element or undefined.
530
+ */
531
+ get last(): E | undefined;
532
+ /**
533
+ * Create a new list from an array of elements.
534
+ * @remarks Time O(N), Space O(N)
535
+ * @template E
536
+ * @template R
537
+ * @param this - The constructor (subclass) to instantiate.
538
+ * @param data - Array of elements to insert.
539
+ * @returns A new list populated with the array's elements.
540
+ */
541
+ static fromArray<E, R = any>(this: new (elements?: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>, options?: DoublyLinkedListOptions<E, R>) => any, data: E[]): any;
542
+ /**
543
+ * Type guard: check whether the input is a DoublyLinkedListNode.
544
+ * @remarks Time O(1), Space O(1)
545
+ * @param elementNodeOrPredicate - Element, node, or predicate.
546
+ * @returns True if the value is a DoublyLinkedListNode.
547
+ */
548
+ isNode(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): elementNodeOrPredicate is DoublyLinkedListNode<E>;
549
+ /**
550
+ * Append an element/node to the tail.
551
+ * @remarks Time O(1), Space O(1)
552
+ * @param elementOrNode - Element or node to append.
553
+ * @returns True when appended.
554
+ */
555
+ push(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
556
+ /**
557
+ * Remove and return the tail element.
558
+ * @remarks Time O(1), Space O(1)
559
+ * @returns Removed element or undefined.
560
+ */
561
+ pop(): E | undefined;
562
+ /**
563
+ * Remove and return the head element.
564
+ * @remarks Time O(1), Space O(1)
565
+ * @returns Removed element or undefined.
566
+ */
567
+ shift(): E | undefined;
568
+ /**
569
+ * Prepend an element/node to the head.
570
+ * @remarks Time O(1), Space O(1)
571
+ * @param elementOrNode - Element or node to prepend.
572
+ * @returns True when prepended.
573
+ */
574
+ unshift(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
575
+ /**
576
+ * Append a sequence of elements/nodes.
577
+ * @remarks Time O(N), Space O(1)
578
+ * @param elements - Iterable of elements or nodes (or raw records if toElementFn is provided).
579
+ * @returns Array of per-element success flags.
580
+ */
581
+ pushMany(elements: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>): boolean[];
582
+ /**
583
+ * Prepend a sequence of elements/nodes.
584
+ * @remarks Time O(N), Space O(1)
585
+ * @param elements - Iterable of elements or nodes (or raw records if toElementFn is provided).
586
+ * @returns Array of per-element success flags.
587
+ */
588
+ unshiftMany(elements: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>): boolean[];
589
+ /**
590
+ * Get the element at a given index.
591
+ * @remarks Time O(N), Space O(1)
592
+ * @param index - Zero-based index.
593
+ * @returns Element or undefined.
594
+ */
595
+ at(index: number): E | undefined;
596
+ /**
597
+ * Get the node reference at a given index.
598
+ * @remarks Time O(N), Space O(1)
599
+ * @param index - Zero-based index.
600
+ * @returns Node or undefined.
601
+ */
602
+ getNodeAt(index: number): DoublyLinkedListNode<E> | undefined;
603
+ /**
604
+ * Find a node by value, reference, or predicate.
605
+ * @remarks Time O(N), Space O(1)
606
+ * @param [elementNodeOrPredicate] - Element, node, or predicate to match.
607
+ * @returns Matching node or undefined.
608
+ */
609
+ getNode(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean) | undefined): DoublyLinkedListNode<E> | undefined;
610
+ /**
611
+ * Insert a new element/node at an index, shifting following nodes.
612
+ * @remarks Time O(N), Space O(1)
613
+ * @param index - Zero-based index.
614
+ * @param newElementOrNode - Element or node to insert.
615
+ * @returns True if inserted.
616
+ */
617
+ addAt(index: number, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
618
+ /**
619
+ * Insert a new element/node before an existing one.
620
+ * @remarks Time O(N), Space O(1)
621
+ * @param existingElementOrNode - Existing element or node.
622
+ * @param newElementOrNode - Element or node to insert.
623
+ * @returns True if inserted.
624
+ */
625
+ addBefore(existingElementOrNode: E | DoublyLinkedListNode<E>, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
626
+ /**
627
+ * Insert a new element/node after an existing one.
628
+ * @remarks Time O(N), Space O(1)
629
+ * @param existingElementOrNode - Existing element or node.
630
+ * @param newElementOrNode - Element or node to insert.
631
+ * @returns True if inserted.
632
+ */
633
+ addAfter(existingElementOrNode: E | DoublyLinkedListNode<E>, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
634
+ /**
635
+ * Set the element value at an index.
636
+ * @remarks Time O(N), Space O(1)
637
+ * @param index - Zero-based index.
638
+ * @param value - New value.
639
+ * @returns True if updated.
640
+ */
641
+ setAt(index: number, value: E): boolean;
642
+ /**
643
+ * Delete the element at an index.
644
+ * @remarks Time O(N), Space O(1)
645
+ * @param index - Zero-based index.
646
+ * @returns Removed element or undefined.
647
+ */
648
+ deleteAt(index: number): E | undefined;
649
+ /**
650
+ * Delete the first match by value/node.
651
+ * @remarks Time O(N), Space O(1)
652
+ * @param [elementOrNode] - Element or node to remove.
653
+ * @returns True if removed.
654
+ */
655
+ delete(elementOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
656
+ /**
657
+ * Check whether the list is empty.
658
+ * @remarks Time O(1), Space O(1)
659
+ * @returns True if length is 0.
660
+ */
661
+ isEmpty(): boolean;
662
+ /**
663
+ * Remove all nodes and reset length.
664
+ * @remarks Time O(N), Space O(1)
665
+ * @returns void
666
+ */
667
+ clear(): void;
668
+ /**
669
+ * Find the first value matching a predicate scanning forward.
670
+ * @remarks Time O(N), Space O(1)
671
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
672
+ * @returns Matched value or undefined.
673
+ */
674
+ search(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
675
+ /**
676
+ * Find the first value matching a predicate scanning backward.
677
+ * @remarks Time O(N), Space O(1)
678
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
679
+ * @returns Matched value or undefined.
680
+ */
681
+ getBackward(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
682
+ /**
683
+ * Reverse the list in place.
684
+ * @remarks Time O(N), Space O(1)
685
+ * @returns This list.
686
+ */
687
+ reverse(): this;
688
+ /**
689
+ * Set the equality comparator used to compare values.
690
+ * @remarks Time O(1), Space O(1)
691
+ * @param equals - Equality predicate (a, b) → boolean.
692
+ * @returns This list.
693
+ */
694
+ setEquality(equals: (a: E, b: E) => boolean): this;
695
+ /**
696
+ * Deep clone this list (values are copied by reference).
697
+ * @remarks Time O(N), Space O(N)
698
+ * @returns A new list with the same element sequence.
699
+ */
700
+ clone(): this;
701
+ /**
702
+ * Filter values into a new list of the same class.
703
+ * @remarks Time O(N), Space O(N)
704
+ * @param callback - Predicate (value, index, list) → boolean to keep value.
705
+ * @param [thisArg] - Value for `this` inside the callback.
706
+ * @returns A new list with kept values.
707
+ */
708
+ filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): this;
709
+ /**
710
+ * Map values into a new list of the same class.
711
+ * @remarks Time O(N), Space O(N)
712
+ * @param callback - Mapping function (value, index, list) → newValue.
713
+ * @param [thisArg] - Value for `this` inside the callback.
714
+ * @returns A new list with mapped values.
715
+ */
716
+ mapSame(callback: ElementCallback<E, R, E>, thisArg?: any): this;
717
+ /**
718
+ * Map values into a new list (possibly different element type).
719
+ * @remarks Time O(N), Space O(N)
720
+ * @template EM
721
+ * @template RM
722
+ * @param callback - Mapping function (value, index, list) → newElement.
723
+ * @param [options] - Options for the output list (e.g., maxLen, toElementFn).
724
+ * @param [thisArg] - Value for `this` inside the callback.
725
+ * @returns A new DoublyLinkedList with mapped values.
726
+ */
727
+ map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: DoublyLinkedListOptions<EM, RM>, thisArg?: any): DoublyLinkedList<EM, RM>;
728
+ /**
729
+ * (Protected) Create or return a node for the given input (node or raw element).
730
+ * @remarks Time O(1), Space O(1)
731
+ * @param elementOrNode - Element value or node to normalize.
732
+ * @returns A DoublyLinkedListNode for the provided input.
733
+ */
734
+ protected _ensureNode(elementOrNode: E | DoublyLinkedListNode<E>): DoublyLinkedListNode<E>;
735
+ /**
736
+ * (Protected) Normalize input into a predicate over nodes.
737
+ * @remarks Time O(1), Space O(1)
738
+ * @param elementNodeOrPredicate - Element, node, or node predicate.
739
+ * @returns A predicate function taking a node and returning true/false.
740
+ */
741
+ protected _ensurePredicate(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): (node: DoublyLinkedListNode<E>) => boolean;
742
+ /**
743
+ * (Protected) Get the previous node of a given node.
744
+ * @remarks Time O(1), Space O(1)
745
+ * @param node - A node in the list.
746
+ * @returns Previous node or undefined.
747
+ */
748
+ protected _getPrevNode(node: DoublyLinkedListNode<E>): DoublyLinkedListNode<E> | undefined;
749
+ /**
750
+ * (Protected) Create an empty instance of the same concrete class.
751
+ * @remarks Time O(1), Space O(1)
752
+ * @param [options] - Options forwarded to the constructor.
753
+ * @returns An empty like-kind list instance.
754
+ */
755
+ protected _createInstance(options?: LinearBaseOptions<E, R>): this;
756
+ /**
757
+ * (Protected) Create a like-kind instance and seed it from an iterable.
758
+ * @remarks Time O(N), Space O(N)
759
+ * @template EM
760
+ * @template RM
761
+ * @param [elements] - Iterable used to seed the new list.
762
+ * @param [options] - Options forwarded to the constructor.
763
+ * @returns A like-kind DoublyLinkedList instance.
764
+ */
765
+ protected _createLike<EM = E, RM = R>(elements?: Iterable<EM> | Iterable<RM> | Iterable<DoublyLinkedListNode<EM>>, options?: DoublyLinkedListOptions<EM, RM>): DoublyLinkedList<EM, RM>;
766
+ protected _getIterator(): IterableIterator<E>;
767
+ protected _getReverseIterator(): IterableIterator<E>;
768
+ protected _getNodeIterator(): IterableIterator<DoublyLinkedListNode<E>>;
769
+ }