tree-set-typed 2.3.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 (273) hide show
  1. package/.eslintrc.js +61 -0
  2. package/.prettierignore +6 -0
  3. package/.prettierrc.js +16 -0
  4. package/LICENSE +21 -0
  5. package/README.md +482 -0
  6. package/coverage/clover.xml +13 -0
  7. package/coverage/coverage-final.json +96 -0
  8. package/coverage/coverage-summary.json +60 -0
  9. package/coverage/lcov-report/base.css +403 -0
  10. package/coverage/lcov-report/block-navigation.js +87 -0
  11. package/coverage/lcov-report/favicon.png +0 -0
  12. package/coverage/lcov-report/index.html +119 -0
  13. package/coverage/lcov-report/index.ts.html +109 -0
  14. package/coverage/lcov-report/prettify.css +1 -0
  15. package/coverage/lcov-report/prettify.js +2 -0
  16. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  17. package/coverage/lcov-report/sorter.js +206 -0
  18. package/coverage/lcov.info +14 -0
  19. package/dist/cjs/index.cjs +12 -0
  20. package/dist/cjs/index.cjs.map +1 -0
  21. package/dist/cjs-legacy/index.cjs +12 -0
  22. package/dist/cjs-legacy/index.cjs.map +1 -0
  23. package/dist/esm/index.mjs +3 -0
  24. package/dist/esm/index.mjs.map +1 -0
  25. package/dist/esm-legacy/index.mjs +3 -0
  26. package/dist/esm-legacy/index.mjs.map +1 -0
  27. package/dist/types/common/index.d.ts +12 -0
  28. package/dist/types/constants/index.d.ts +4 -0
  29. package/dist/types/data-structures/base/index.d.ts +2 -0
  30. package/dist/types/data-structures/base/iterable-element-base.d.ts +219 -0
  31. package/dist/types/data-structures/base/iterable-entry-base.d.ts +150 -0
  32. package/dist/types/data-structures/base/linear-base.d.ts +335 -0
  33. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +236 -0
  34. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +197 -0
  35. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +440 -0
  36. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -0
  37. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +807 -0
  38. package/dist/types/data-structures/binary-tree/bst.d.ts +645 -0
  39. package/dist/types/data-structures/binary-tree/index.d.ts +10 -0
  40. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +312 -0
  41. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -0
  42. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +243 -0
  43. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +333 -0
  44. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -0
  45. package/dist/types/data-structures/graph/directed-graph.d.ts +332 -0
  46. package/dist/types/data-structures/graph/index.d.ts +4 -0
  47. package/dist/types/data-structures/graph/map-graph.d.ts +78 -0
  48. package/dist/types/data-structures/graph/undirected-graph.d.ts +347 -0
  49. package/dist/types/data-structures/hash/hash-map.d.ts +428 -0
  50. package/dist/types/data-structures/hash/index.d.ts +1 -0
  51. package/dist/types/data-structures/heap/heap.d.ts +552 -0
  52. package/dist/types/data-structures/heap/index.d.ts +3 -0
  53. package/dist/types/data-structures/heap/max-heap.d.ts +32 -0
  54. package/dist/types/data-structures/heap/min-heap.d.ts +33 -0
  55. package/dist/types/data-structures/index.d.ts +12 -0
  56. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +437 -0
  57. package/dist/types/data-structures/linked-list/index.d.ts +3 -0
  58. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +567 -0
  59. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -0
  60. package/dist/types/data-structures/matrix/index.d.ts +2 -0
  61. package/dist/types/data-structures/matrix/matrix.d.ts +168 -0
  62. package/dist/types/data-structures/matrix/navigator.d.ts +55 -0
  63. package/dist/types/data-structures/priority-queue/index.d.ts +3 -0
  64. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -0
  65. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -0
  66. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -0
  67. package/dist/types/data-structures/queue/deque.d.ts +459 -0
  68. package/dist/types/data-structures/queue/index.d.ts +2 -0
  69. package/dist/types/data-structures/queue/queue.d.ts +364 -0
  70. package/dist/types/data-structures/stack/index.d.ts +1 -0
  71. package/dist/types/data-structures/stack/stack.d.ts +324 -0
  72. package/dist/types/data-structures/tree/index.d.ts +1 -0
  73. package/dist/types/data-structures/tree/tree.d.ts +62 -0
  74. package/dist/types/data-structures/trie/index.d.ts +1 -0
  75. package/dist/types/data-structures/trie/trie.d.ts +412 -0
  76. package/dist/types/index.d.ts +23 -0
  77. package/dist/types/interfaces/binary-tree.d.ts +60 -0
  78. package/dist/types/interfaces/doubly-linked-list.d.ts +1 -0
  79. package/dist/types/interfaces/graph.d.ts +21 -0
  80. package/dist/types/interfaces/heap.d.ts +1 -0
  81. package/dist/types/interfaces/index.d.ts +8 -0
  82. package/dist/types/interfaces/navigator.d.ts +1 -0
  83. package/dist/types/interfaces/priority-queue.d.ts +1 -0
  84. package/dist/types/interfaces/segment-tree.d.ts +1 -0
  85. package/dist/types/interfaces/singly-linked-list.d.ts +1 -0
  86. package/dist/types/types/common.d.ts +15 -0
  87. package/dist/types/types/data-structures/base/base.d.ts +13 -0
  88. package/dist/types/types/data-structures/base/index.d.ts +1 -0
  89. package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
  90. package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
  91. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
  92. package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
  93. package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
  94. package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
  95. package/dist/types/types/data-structures/binary-tree/index.d.ts +9 -0
  96. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
  97. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
  98. package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
  99. package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
  100. package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
  101. package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
  102. package/dist/types/types/data-structures/graph/index.d.ts +3 -0
  103. package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
  104. package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
  105. package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
  106. package/dist/types/types/data-structures/hash/index.d.ts +2 -0
  107. package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
  108. package/dist/types/types/data-structures/heap/index.d.ts +1 -0
  109. package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
  110. package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
  111. package/dist/types/types/data-structures/index.d.ts +12 -0
  112. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
  113. package/dist/types/types/data-structures/linked-list/index.d.ts +3 -0
  114. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
  115. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
  116. package/dist/types/types/data-structures/matrix/index.d.ts +2 -0
  117. package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
  118. package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
  119. package/dist/types/types/data-structures/priority-queue/index.d.ts +3 -0
  120. package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
  121. package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
  122. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
  123. package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
  124. package/dist/types/types/data-structures/queue/index.d.ts +2 -0
  125. package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
  126. package/dist/types/types/data-structures/stack/index.d.ts +1 -0
  127. package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
  128. package/dist/types/types/data-structures/tree/index.d.ts +1 -0
  129. package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
  130. package/dist/types/types/data-structures/trie/index.d.ts +1 -0
  131. package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
  132. package/dist/types/types/index.d.ts +3 -0
  133. package/dist/types/types/utils/index.d.ts +2 -0
  134. package/dist/types/types/utils/utils.d.ts +22 -0
  135. package/dist/types/types/utils/validate-type.d.ts +19 -0
  136. package/dist/types/utils/index.d.ts +2 -0
  137. package/dist/types/utils/number.d.ts +14 -0
  138. package/dist/types/utils/utils.d.ts +209 -0
  139. package/dist/umd/red-black-tree-typed.js +14578 -0
  140. package/dist/umd/red-black-tree-typed.js.map +1 -0
  141. package/dist/umd/red-black-tree-typed.min.js +44 -0
  142. package/dist/umd/red-black-tree-typed.min.js.map +1 -0
  143. package/docs/.nojekyll +1 -0
  144. package/docs/assets/highlight.css +92 -0
  145. package/docs/assets/main.js +59 -0
  146. package/docs/assets/navigation.js +1 -0
  147. package/docs/assets/search.js +1 -0
  148. package/docs/assets/style.css +1383 -0
  149. package/docs/classes/AVLTree.html +2046 -0
  150. package/docs/classes/AVLTreeNode.html +263 -0
  151. package/docs/index.html +523 -0
  152. package/docs/modules.html +45 -0
  153. package/jest.config.js +8 -0
  154. package/package.json +113 -0
  155. package/src/common/index.ts +23 -0
  156. package/src/constants/index.ts +4 -0
  157. package/src/data-structures/base/index.ts +2 -0
  158. package/src/data-structures/base/iterable-element-base.ts +352 -0
  159. package/src/data-structures/base/iterable-entry-base.ts +246 -0
  160. package/src/data-structures/base/linear-base.ts +643 -0
  161. package/src/data-structures/binary-tree/avl-tree-counter.ts +539 -0
  162. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +438 -0
  163. package/src/data-structures/binary-tree/avl-tree.ts +840 -0
  164. package/src/data-structures/binary-tree/binary-indexed-tree.ts +331 -0
  165. package/src/data-structures/binary-tree/binary-tree.ts +2492 -0
  166. package/src/data-structures/binary-tree/bst.ts +2024 -0
  167. package/src/data-structures/binary-tree/index.ts +10 -0
  168. package/src/data-structures/binary-tree/red-black-tree.ts +767 -0
  169. package/src/data-structures/binary-tree/segment-tree.ts +324 -0
  170. package/src/data-structures/binary-tree/tree-counter.ts +575 -0
  171. package/src/data-structures/binary-tree/tree-multi-map.ts +549 -0
  172. package/src/data-structures/graph/abstract-graph.ts +1081 -0
  173. package/src/data-structures/graph/directed-graph.ts +715 -0
  174. package/src/data-structures/graph/index.ts +4 -0
  175. package/src/data-structures/graph/map-graph.ts +132 -0
  176. package/src/data-structures/graph/undirected-graph.ts +626 -0
  177. package/src/data-structures/hash/hash-map.ts +813 -0
  178. package/src/data-structures/hash/index.ts +1 -0
  179. package/src/data-structures/heap/heap.ts +1020 -0
  180. package/src/data-structures/heap/index.ts +3 -0
  181. package/src/data-structures/heap/max-heap.ts +47 -0
  182. package/src/data-structures/heap/min-heap.ts +36 -0
  183. package/src/data-structures/index.ts +12 -0
  184. package/src/data-structures/linked-list/doubly-linked-list.ts +876 -0
  185. package/src/data-structures/linked-list/index.ts +3 -0
  186. package/src/data-structures/linked-list/singly-linked-list.ts +1050 -0
  187. package/src/data-structures/linked-list/skip-linked-list.ts +173 -0
  188. package/src/data-structures/matrix/index.ts +2 -0
  189. package/src/data-structures/matrix/matrix.ts +491 -0
  190. package/src/data-structures/matrix/navigator.ts +124 -0
  191. package/src/data-structures/priority-queue/index.ts +3 -0
  192. package/src/data-structures/priority-queue/max-priority-queue.ts +42 -0
  193. package/src/data-structures/priority-queue/min-priority-queue.ts +29 -0
  194. package/src/data-structures/priority-queue/priority-queue.ts +19 -0
  195. package/src/data-structures/queue/deque.ts +1001 -0
  196. package/src/data-structures/queue/index.ts +2 -0
  197. package/src/data-structures/queue/queue.ts +592 -0
  198. package/src/data-structures/stack/index.ts +1 -0
  199. package/src/data-structures/stack/stack.ts +469 -0
  200. package/src/data-structures/tree/index.ts +1 -0
  201. package/src/data-structures/tree/tree.ts +115 -0
  202. package/src/data-structures/trie/index.ts +1 -0
  203. package/src/data-structures/trie/trie.ts +756 -0
  204. package/src/index.ts +24 -0
  205. package/src/interfaces/binary-tree.ts +252 -0
  206. package/src/interfaces/doubly-linked-list.ts +1 -0
  207. package/src/interfaces/graph.ts +44 -0
  208. package/src/interfaces/heap.ts +1 -0
  209. package/src/interfaces/index.ts +8 -0
  210. package/src/interfaces/navigator.ts +1 -0
  211. package/src/interfaces/priority-queue.ts +1 -0
  212. package/src/interfaces/segment-tree.ts +1 -0
  213. package/src/interfaces/singly-linked-list.ts +1 -0
  214. package/src/types/common.ts +25 -0
  215. package/src/types/data-structures/base/base.ts +34 -0
  216. package/src/types/data-structures/base/index.ts +1 -0
  217. package/src/types/data-structures/binary-tree/avl-tree-counter.ts +3 -0
  218. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -0
  219. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -0
  220. package/src/types/data-structures/binary-tree/binary-indexed-tree.ts +1 -0
  221. package/src/types/data-structures/binary-tree/binary-tree.ts +31 -0
  222. package/src/types/data-structures/binary-tree/bst.ts +19 -0
  223. package/src/types/data-structures/binary-tree/index.ts +9 -0
  224. package/src/types/data-structures/binary-tree/red-black-tree.ts +5 -0
  225. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -0
  226. package/src/types/data-structures/binary-tree/tree-counter.ts +3 -0
  227. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -0
  228. package/src/types/data-structures/graph/abstract-graph.ts +18 -0
  229. package/src/types/data-structures/graph/directed-graph.ts +2 -0
  230. package/src/types/data-structures/graph/index.ts +3 -0
  231. package/src/types/data-structures/graph/map-graph.ts +1 -0
  232. package/src/types/data-structures/graph/undirected-graph.ts +1 -0
  233. package/src/types/data-structures/hash/hash-map.ts +19 -0
  234. package/src/types/data-structures/hash/index.ts +3 -0
  235. package/src/types/data-structures/heap/heap.ts +6 -0
  236. package/src/types/data-structures/heap/index.ts +1 -0
  237. package/src/types/data-structures/heap/max-heap.ts +1 -0
  238. package/src/types/data-structures/heap/min-heap.ts +1 -0
  239. package/src/types/data-structures/index.ts +12 -0
  240. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -0
  241. package/src/types/data-structures/linked-list/index.ts +3 -0
  242. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -0
  243. package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -0
  244. package/src/types/data-structures/matrix/index.ts +2 -0
  245. package/src/types/data-structures/matrix/matrix.ts +7 -0
  246. package/src/types/data-structures/matrix/navigator.ts +14 -0
  247. package/src/types/data-structures/priority-queue/index.ts +3 -0
  248. package/src/types/data-structures/priority-queue/max-priority-queue.ts +1 -0
  249. package/src/types/data-structures/priority-queue/min-priority-queue.ts +1 -0
  250. package/src/types/data-structures/priority-queue/priority-queue.ts +3 -0
  251. package/src/types/data-structures/queue/deque.ts +5 -0
  252. package/src/types/data-structures/queue/index.ts +2 -0
  253. package/src/types/data-structures/queue/queue.ts +5 -0
  254. package/src/types/data-structures/stack/index.ts +1 -0
  255. package/src/types/data-structures/stack/stack.ts +3 -0
  256. package/src/types/data-structures/tree/index.ts +1 -0
  257. package/src/types/data-structures/tree/tree.ts +1 -0
  258. package/src/types/data-structures/trie/index.ts +1 -0
  259. package/src/types/data-structures/trie/trie.ts +3 -0
  260. package/src/types/index.ts +3 -0
  261. package/src/types/utils/index.ts +2 -0
  262. package/src/types/utils/utils.ts +33 -0
  263. package/src/types/utils/validate-type.ts +35 -0
  264. package/src/utils/index.ts +2 -0
  265. package/src/utils/number.ts +22 -0
  266. package/src/utils/utils.ts +350 -0
  267. package/test/index.test.ts +111 -0
  268. package/tsconfig.base.json +23 -0
  269. package/tsconfig.json +12 -0
  270. package/tsconfig.test.json +8 -0
  271. package/tsconfig.types.json +15 -0
  272. package/tsup.config.js +28 -0
  273. package/tsup.node.config.js +71 -0
@@ -0,0 +1,437 @@
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
+ * // basic DoublyLinkedList creation and push operation
64
+ * // Create a simple DoublyLinkedList with initial values
65
+ * const list = new DoublyLinkedList([1, 2, 3, 4, 5]);
66
+ *
67
+ * // Verify the list maintains insertion order
68
+ * console.log([...list]); // [1, 2, 3, 4, 5];
69
+ *
70
+ * // Check length
71
+ * console.log(list.length); // 5;
72
+ *
73
+ * // Push a new element to the end
74
+ * list.push(6);
75
+ * console.log(list.length); // 6;
76
+ * console.log([...list]); // [1, 2, 3, 4, 5, 6];
77
+ * @example
78
+ * // DoublyLinkedList pop and shift operations
79
+ * const list = new DoublyLinkedList<number>([10, 20, 30, 40, 50]);
80
+ *
81
+ * // Pop removes from the end
82
+ * const last = list.pop();
83
+ * console.log(last); // 50;
84
+ *
85
+ * // Shift removes from the beginning
86
+ * const first = list.shift();
87
+ * console.log(first); // 10;
88
+ *
89
+ * // Verify remaining elements
90
+ * console.log([...list]); // [20, 30, 40];
91
+ * console.log(list.length); // 3;
92
+ * @example
93
+ * // DoublyLinkedList for...of iteration and map operation
94
+ * const list = new DoublyLinkedList<number>([1, 2, 3, 4, 5]);
95
+ *
96
+ * // Iterate through list
97
+ * const doubled = list.map(value => value * 2);
98
+ * console.log(doubled.length); // 5;
99
+ *
100
+ * // Use for...of loop
101
+ * const result: number[] = [];
102
+ * for (const item of list) {
103
+ * result.push(item);
104
+ * }
105
+ * console.log(result); // [1, 2, 3, 4, 5];
106
+ * @example
107
+ * // Browser history
108
+ * const browserHistory = new DoublyLinkedList<string>();
109
+ *
110
+ * browserHistory.push('home page');
111
+ * browserHistory.push('search page');
112
+ * browserHistory.push('details page');
113
+ *
114
+ * console.log(browserHistory.last); // 'details page';
115
+ * console.log(browserHistory.pop()); // 'details page';
116
+ * console.log(browserHistory.last); // 'search page';
117
+ * @example
118
+ * // DoublyLinkedList for LRU cache implementation
119
+ * interface CacheEntry {
120
+ * key: string;
121
+ * value: string;
122
+ * }
123
+ *
124
+ * // Simulate LRU cache using DoublyLinkedList
125
+ * // DoublyLinkedList is perfect because:
126
+ * // - O(1) delete from any position
127
+ * // - O(1) push to end
128
+ * // - Bidirectional traversal for LRU policy
129
+ *
130
+ * const cacheList = new DoublyLinkedList<CacheEntry>();
131
+ * const maxSize = 3;
132
+ *
133
+ * // Add cache entries
134
+ * cacheList.push({ key: 'user:1', value: 'Alice' });
135
+ * cacheList.push({ key: 'user:2', value: 'Bob' });
136
+ * cacheList.push({ key: 'user:3', value: 'Charlie' });
137
+ *
138
+ * // Try to add a new entry when cache is full
139
+ * if (cacheList.length >= maxSize) {
140
+ * // Remove the oldest (first) entry
141
+ * const evicted = cacheList.shift();
142
+ * console.log(evicted?.key); // 'user:1';
143
+ * }
144
+ *
145
+ * // Add new entry
146
+ * cacheList.push({ key: 'user:4', value: 'Diana' });
147
+ *
148
+ * // Verify current cache state
149
+ * console.log(cacheList.length); // 3;
150
+ * const cachedKeys = [...cacheList].map(entry => entry.key);
151
+ * console.log(cachedKeys); // ['user:2', 'user:3', 'user:4'];
152
+ *
153
+ * // Access entry (in real LRU, this would move it to end)
154
+ * const foundEntry = [...cacheList].find(entry => entry.key === 'user:2');
155
+ * console.log(foundEntry?.value); // 'Bob';
156
+ */
157
+ export declare class DoublyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, DoublyLinkedListNode<E>> {
158
+ protected _equals: (a: E, b: E) => boolean;
159
+ /**
160
+ * Create a DoublyLinkedList and optionally bulk-insert elements.
161
+ * @remarks Time O(N), Space O(N)
162
+ * @param [elements] - Iterable of elements or nodes (or raw records if toElementFn is provided).
163
+ * @param [options] - Options such as maxLen and toElementFn.
164
+ * @returns New DoublyLinkedList instance.
165
+ */
166
+ constructor(elements?: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>, options?: DoublyLinkedListOptions<E, R>);
167
+ protected _head: DoublyLinkedListNode<E> | undefined;
168
+ /**
169
+ * Get the head node.
170
+ * @remarks Time O(1), Space O(1)
171
+ * @returns Head node or undefined.
172
+ */
173
+ get head(): DoublyLinkedListNode<E> | undefined;
174
+ protected _tail: DoublyLinkedListNode<E> | undefined;
175
+ /**
176
+ * Get the tail node.
177
+ * @remarks Time O(1), Space O(1)
178
+ * @returns Tail node or undefined.
179
+ */
180
+ get tail(): DoublyLinkedListNode<E> | undefined;
181
+ protected _length: number;
182
+ /**
183
+ * Get the number of elements.
184
+ * @remarks Time O(1), Space O(1)
185
+ * @returns Current length.
186
+ */
187
+ get length(): number;
188
+ /**
189
+ * Get the first element value.
190
+ * @remarks Time O(1), Space O(1)
191
+ * @returns First element or undefined.
192
+ */
193
+ get first(): E | undefined;
194
+ /**
195
+ * Get the last element value.
196
+ * @remarks Time O(1), Space O(1)
197
+ * @returns Last element or undefined.
198
+ */
199
+ get last(): E | undefined;
200
+ /**
201
+ * Create a new list from an array of elements.
202
+ * @remarks Time O(N), Space O(N)
203
+ * @template E
204
+ * @template R
205
+ * @param this - The constructor (subclass) to instantiate.
206
+ * @param data - Array of elements to insert.
207
+ * @returns A new list populated with the array's elements.
208
+ */
209
+ static fromArray<E, R = any>(this: new (elements?: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>, options?: DoublyLinkedListOptions<E, R>) => any, data: E[]): any;
210
+ /**
211
+ * Type guard: check whether the input is a DoublyLinkedListNode.
212
+ * @remarks Time O(1), Space O(1)
213
+ * @param elementNodeOrPredicate - Element, node, or predicate.
214
+ * @returns True if the value is a DoublyLinkedListNode.
215
+ */
216
+ isNode(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): elementNodeOrPredicate is DoublyLinkedListNode<E>;
217
+ /**
218
+ * Append an element/node to the tail.
219
+ * @remarks Time O(1), Space O(1)
220
+ * @param elementOrNode - Element or node to append.
221
+ * @returns True when appended.
222
+ */
223
+ push(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
224
+ /**
225
+ * Remove and return the tail element.
226
+ * @remarks Time O(1), Space O(1)
227
+ * @returns Removed element or undefined.
228
+ */
229
+ pop(): E | undefined;
230
+ /**
231
+ * Remove and return the head element.
232
+ * @remarks Time O(1), Space O(1)
233
+ * @returns Removed element or undefined.
234
+ */
235
+ shift(): E | undefined;
236
+ /**
237
+ * Prepend an element/node to the head.
238
+ * @remarks Time O(1), Space O(1)
239
+ * @param elementOrNode - Element or node to prepend.
240
+ * @returns True when prepended.
241
+ */
242
+ unshift(elementOrNode: E | DoublyLinkedListNode<E>): boolean;
243
+ /**
244
+ * Append a sequence of elements/nodes.
245
+ * @remarks Time O(N), Space O(1)
246
+ * @param elements - Iterable of elements or nodes (or raw records if toElementFn is provided).
247
+ * @returns Array of per-element success flags.
248
+ */
249
+ pushMany(elements: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>): boolean[];
250
+ /**
251
+ * Prepend a sequence of elements/nodes.
252
+ * @remarks Time O(N), Space O(1)
253
+ * @param elements - Iterable of elements or nodes (or raw records if toElementFn is provided).
254
+ * @returns Array of per-element success flags.
255
+ */
256
+ unshiftMany(elements: Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>): boolean[];
257
+ /**
258
+ * Get the element at a given index.
259
+ * @remarks Time O(N), Space O(1)
260
+ * @param index - Zero-based index.
261
+ * @returns Element or undefined.
262
+ */
263
+ at(index: number): E | undefined;
264
+ /**
265
+ * Get the node reference at a given index.
266
+ * @remarks Time O(N), Space O(1)
267
+ * @param index - Zero-based index.
268
+ * @returns Node or undefined.
269
+ */
270
+ getNodeAt(index: number): DoublyLinkedListNode<E> | undefined;
271
+ /**
272
+ * Find a node by value, reference, or predicate.
273
+ * @remarks Time O(N), Space O(1)
274
+ * @param [elementNodeOrPredicate] - Element, node, or predicate to match.
275
+ * @returns Matching node or undefined.
276
+ */
277
+ getNode(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean) | undefined): DoublyLinkedListNode<E> | undefined;
278
+ /**
279
+ * Insert a new element/node at an index, shifting following nodes.
280
+ * @remarks Time O(N), Space O(1)
281
+ * @param index - Zero-based index.
282
+ * @param newElementOrNode - Element or node to insert.
283
+ * @returns True if inserted.
284
+ */
285
+ addAt(index: number, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
286
+ /**
287
+ * Insert a new element/node before an existing one.
288
+ * @remarks Time O(N), Space O(1)
289
+ * @param existingElementOrNode - Existing element or node.
290
+ * @param newElementOrNode - Element or node to insert.
291
+ * @returns True if inserted.
292
+ */
293
+ addBefore(existingElementOrNode: E | DoublyLinkedListNode<E>, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
294
+ /**
295
+ * Insert a new element/node after an existing one.
296
+ * @remarks Time O(N), Space O(1)
297
+ * @param existingElementOrNode - Existing element or node.
298
+ * @param newElementOrNode - Element or node to insert.
299
+ * @returns True if inserted.
300
+ */
301
+ addAfter(existingElementOrNode: E | DoublyLinkedListNode<E>, newElementOrNode: E | DoublyLinkedListNode<E>): boolean;
302
+ /**
303
+ * Set the element value at an index.
304
+ * @remarks Time O(N), Space O(1)
305
+ * @param index - Zero-based index.
306
+ * @param value - New value.
307
+ * @returns True if updated.
308
+ */
309
+ setAt(index: number, value: E): boolean;
310
+ /**
311
+ * Delete the element at an index.
312
+ * @remarks Time O(N), Space O(1)
313
+ * @param index - Zero-based index.
314
+ * @returns Removed element or undefined.
315
+ */
316
+ deleteAt(index: number): E | undefined;
317
+ /**
318
+ * Delete the first match by value/node.
319
+ * @remarks Time O(N), Space O(1)
320
+ * @param [elementOrNode] - Element or node to remove.
321
+ * @returns True if removed.
322
+ */
323
+ delete(elementOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
324
+ /**
325
+ * Check whether the list is empty.
326
+ * @remarks Time O(1), Space O(1)
327
+ * @returns True if length is 0.
328
+ */
329
+ isEmpty(): boolean;
330
+ /**
331
+ * Remove all nodes and reset length.
332
+ * @remarks Time O(N), Space O(1)
333
+ * @returns void
334
+ */
335
+ clear(): void;
336
+ /**
337
+ * Find the first value matching a predicate scanning forward.
338
+ * @remarks Time O(N), Space O(1)
339
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
340
+ * @returns Matched value or undefined.
341
+ */
342
+ search(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
343
+ /**
344
+ * Find the first value matching a predicate scanning backward.
345
+ * @remarks Time O(N), Space O(1)
346
+ * @param elementNodeOrPredicate - Element, node, or predicate to match.
347
+ * @returns Matched value or undefined.
348
+ */
349
+ getBackward(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): E | undefined;
350
+ /**
351
+ * Reverse the list in place.
352
+ * @remarks Time O(N), Space O(1)
353
+ * @returns This list.
354
+ */
355
+ reverse(): this;
356
+ /**
357
+ * Set the equality comparator used to compare values.
358
+ * @remarks Time O(1), Space O(1)
359
+ * @param equals - Equality predicate (a, b) → boolean.
360
+ * @returns This list.
361
+ */
362
+ setEquality(equals: (a: E, b: E) => boolean): this;
363
+ /**
364
+ * Deep clone this list (values are copied by reference).
365
+ * @remarks Time O(N), Space O(N)
366
+ * @returns A new list with the same element sequence.
367
+ */
368
+ clone(): this;
369
+ /**
370
+ * Filter values into a new list of the same class.
371
+ * @remarks Time O(N), Space O(N)
372
+ * @param callback - Predicate (value, index, list) → boolean to keep value.
373
+ * @param [thisArg] - Value for `this` inside the callback.
374
+ * @returns A new list with kept values.
375
+ */
376
+ filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): this;
377
+ /**
378
+ * Map values into a new list of the same class.
379
+ * @remarks Time O(N), Space O(N)
380
+ * @param callback - Mapping function (value, index, list) → newValue.
381
+ * @param [thisArg] - Value for `this` inside the callback.
382
+ * @returns A new list with mapped values.
383
+ */
384
+ mapSame(callback: ElementCallback<E, R, E>, thisArg?: any): this;
385
+ /**
386
+ * Map values into a new list (possibly different element type).
387
+ * @remarks Time O(N), Space O(N)
388
+ * @template EM
389
+ * @template RM
390
+ * @param callback - Mapping function (value, index, list) → newElement.
391
+ * @param [options] - Options for the output list (e.g., maxLen, toElementFn).
392
+ * @param [thisArg] - Value for `this` inside the callback.
393
+ * @returns A new DoublyLinkedList with mapped values.
394
+ */
395
+ map<EM, RM>(callback: ElementCallback<E, R, EM>, options?: DoublyLinkedListOptions<EM, RM>, thisArg?: any): DoublyLinkedList<EM, RM>;
396
+ /**
397
+ * (Protected) Create or return a node for the given input (node or raw element).
398
+ * @remarks Time O(1), Space O(1)
399
+ * @param elementOrNode - Element value or node to normalize.
400
+ * @returns A DoublyLinkedListNode for the provided input.
401
+ */
402
+ protected _ensureNode(elementOrNode: E | DoublyLinkedListNode<E>): DoublyLinkedListNode<E>;
403
+ /**
404
+ * (Protected) Normalize input into a predicate over nodes.
405
+ * @remarks Time O(1), Space O(1)
406
+ * @param elementNodeOrPredicate - Element, node, or node predicate.
407
+ * @returns A predicate function taking a node and returning true/false.
408
+ */
409
+ protected _ensurePredicate(elementNodeOrPredicate: E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)): (node: DoublyLinkedListNode<E>) => boolean;
410
+ /**
411
+ * (Protected) Get the previous node of a given node.
412
+ * @remarks Time O(1), Space O(1)
413
+ * @param node - A node in the list.
414
+ * @returns Previous node or undefined.
415
+ */
416
+ protected _getPrevNode(node: DoublyLinkedListNode<E>): DoublyLinkedListNode<E> | undefined;
417
+ /**
418
+ * (Protected) Create an empty instance of the same concrete class.
419
+ * @remarks Time O(1), Space O(1)
420
+ * @param [options] - Options forwarded to the constructor.
421
+ * @returns An empty like-kind list instance.
422
+ */
423
+ protected _createInstance(options?: LinearBaseOptions<E, R>): this;
424
+ /**
425
+ * (Protected) Create a like-kind instance and seed it from an iterable.
426
+ * @remarks Time O(N), Space O(N)
427
+ * @template EM
428
+ * @template RM
429
+ * @param [elements] - Iterable used to seed the new list.
430
+ * @param [options] - Options forwarded to the constructor.
431
+ * @returns A like-kind DoublyLinkedList instance.
432
+ */
433
+ protected _createLike<EM = E, RM = R>(elements?: Iterable<EM> | Iterable<RM> | Iterable<DoublyLinkedListNode<EM>>, options?: DoublyLinkedListOptions<EM, RM>): DoublyLinkedList<EM, RM>;
434
+ protected _getIterator(): IterableIterator<E>;
435
+ protected _getReverseIterator(): IterableIterator<E>;
436
+ protected _getNodeIterator(): IterableIterator<DoublyLinkedListNode<E>>;
437
+ }
@@ -0,0 +1,3 @@
1
+ export * from './singly-linked-list';
2
+ export * from './doubly-linked-list';
3
+ export * from './skip-linked-list';