linked-list-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 +2152 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/esm/index.mjs +2143 -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/linked-list-typed.js +2146 -0
  87. package/dist/umd/linked-list-typed.js.map +1 -0
  88. package/dist/umd/linked-list-typed.min.js +9 -0
  89. package/dist/umd/linked-list-typed.min.js.map +1 -0
  90. package/package.json +25 -5
  91. package/src/data-structures/binary-tree/avl-tree-counter.ts +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,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./singly-linked-list"), exports);
18
- __exportStar(require("./doubly-linked-list"), exports);
19
- __exportStar(require("./skip-linked-list"), exports);
@@ -1,451 +0,0 @@
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 { ElementCallback, SinglyLinkedListOptions } from '../../types';
9
- import { LinearLinkedBase, LinkedListNode } from '../base/linear-base';
10
- /**
11
- * Node of a singly linked list; stores value and the next link.
12
- * @remarks Time O(1), Space O(1)
13
- * @template E
14
- */
15
- export declare class SinglyLinkedListNode<E = any> extends LinkedListNode<E> {
16
- /**
17
- * Create a list 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: SinglyLinkedListNode<E> | undefined;
24
- /**
25
- * Get the next node.
26
- * @remarks Time O(1), Space O(1)
27
- * @returns Next node or undefined.
28
- */
29
- get next(): SinglyLinkedListNode<E> | undefined;
30
- /**
31
- * Set the next node.
32
- * @remarks Time O(1), Space O(1)
33
- * @param value - Next node or undefined.
34
- * @returns void
35
- */
36
- set next(value: SinglyLinkedListNode<E> | undefined);
37
- }
38
- /**
39
- * Singly linked list with O(1) push/pop-like ends operations and linear scans.
40
- * @remarks Time O(1), Space O(1)
41
- * @template E
42
- * @template R
43
- * 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.
44
- * 2. Bidirectional Traversal: Unlike doubly linked lists, singly linked lists can be easily traversed forwards but not backwards.
45
- * 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.
46
- * 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.
47
- * 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).
48
- * @example
49
- * // implementation of a basic text editor
50
- * class TextEditor {
51
- * private content: SinglyLinkedList<string>;
52
- * private cursorIndex: number;
53
- * private undoStack: Stack<{ operation: string; data?: any }>;
54
- *
55
- * constructor() {
56
- * this.content = new SinglyLinkedList<string>();
57
- * this.cursorIndex = 0; // Cursor starts at the beginning
58
- * this.undoStack = new Stack<{ operation: string; data?: any }>(); // Stack to keep track of operations for undo
59
- * }
60
- *
61
- * insert(char: string) {
62
- * this.content.addAt(this.cursorIndex, char);
63
- * this.cursorIndex++;
64
- * this.undoStack.push({ operation: 'insert', data: { index: this.cursorIndex - 1 } });
65
- * }
66
- *
67
- * delete() {
68
- * if (this.cursorIndex === 0) return; // Nothing to delete
69
- * const deleted = this.content.deleteAt(this.cursorIndex - 1);
70
- * this.cursorIndex--;
71
- * this.undoStack.push({ operation: 'delete', data: { index: this.cursorIndex, char: deleted } });
72
- * }
73
- *
74
- * moveCursor(index: number) {
75
- * this.cursorIndex = Math.max(0, Math.min(index, this.content.length));
76
- * }
77
- *
78
- * undo() {
79
- * if (this.undoStack.size === 0) return; // No operations to undo
80
- * const lastAction = this.undoStack.pop();
81
- *
82
- * if (lastAction!.operation === 'insert') {
83
- * this.content.deleteAt(lastAction!.data.index);
84
- * this.cursorIndex = lastAction!.data.index;
85
- * } else if (lastAction!.operation === 'delete') {
86
- * this.content.addAt(lastAction!.data.index, lastAction!.data.char);
87
- * this.cursorIndex = lastAction!.data.index + 1;
88
- * }
89
- * }
90
- *
91
- * getText(): string {
92
- * return [...this.content].join('');
93
- * }
94
- * }
95
- *
96
- * // Example Usage
97
- * const editor = new TextEditor();
98
- * editor.insert('H');
99
- * editor.insert('e');
100
- * editor.insert('l');
101
- * editor.insert('l');
102
- * editor.insert('o');
103
- * console.log(editor.getText()); // 'Hello' // Output: "Hello"
104
- *
105
- * editor.delete();
106
- * console.log(editor.getText()); // 'Hell' // Output: "Hell"
107
- *
108
- * editor.undo();
109
- * console.log(editor.getText()); // 'Hello' // Output: "Hello"
110
- *
111
- * editor.moveCursor(1);
112
- * editor.insert('a');
113
- * console.log(editor.getText()); // 'Haello'
114
- */
115
- export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, SinglyLinkedListNode<E>> {
116
- protected _equals: (a: E, b: E) => boolean;
117
- /**
118
- * Create a SinglyLinkedList and optionally bulk-insert elements.
119
- * @remarks Time O(N), Space O(N)
120
- * @param [elements] - Iterable of elements or nodes (or raw records if toElementFn is provided).
121
- * @param [options] - Options such as maxLen and toElementFn.
122
- * @returns New SinglyLinkedList instance.
123
- */
124
- constructor(elements?: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>, options?: SinglyLinkedListOptions<E, R>);
125
- protected _head: SinglyLinkedListNode<E> | undefined;
126
- /**
127
- * Get the head node.
128
- * @remarks Time O(1), Space O(1)
129
- * @returns Head node or undefined.
130
- */
131
- get head(): SinglyLinkedListNode<E> | undefined;
132
- protected _tail: SinglyLinkedListNode<E> | undefined;
133
- /**
134
- * Get the tail node.
135
- * @remarks Time O(1), Space O(1)
136
- * @returns Tail node or undefined.
137
- */
138
- get tail(): SinglyLinkedListNode<E> | undefined;
139
- protected _length: number;
140
- /**
141
- * Get the number of elements.
142
- * @remarks Time O(1), Space O(1)
143
- * @returns Current length.
144
- */
145
- get length(): number;
146
- /**
147
- * Get the first element value.
148
- * @remarks Time O(1), Space O(1)
149
- * @returns First element or undefined.
150
- */
151
- get first(): E | undefined;
152
- /**
153
- * Get the last element value.
154
- * @remarks Time O(1), Space O(1)
155
- * @returns Last element or undefined.
156
- */
157
- get last(): E | undefined;
158
- /**
159
- * Create a new list from an iterable of elements.
160
- * @remarks Time O(N), Space O(N)
161
- * @template E
162
- * @template R
163
- * @template S
164
- * @param this - The constructor (subclass) to instantiate.
165
- * @param data - Iterable of elements to insert.
166
- * @param [options] - Options forwarded to the constructor.
167
- * @returns A new list populated with the iterable's elements.
168
- */
169
- static from<E, R = any, S extends SinglyLinkedList<E, R> = SinglyLinkedList<E, R>>(this: new (elements?: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>, options?: SinglyLinkedListOptions<E, R>) => S, data: Iterable<E>, options?: SinglyLinkedListOptions<E, R>): S;
170
- /**
171
- * Append an element/node to the tail.
172
- * @remarks Time O(1), Space O(1)
173
- * @param elementOrNode - Element or node to append.
174
- * @returns True when appended.
175
- */
176
- push(elementOrNode: E | SinglyLinkedListNode<E>): boolean;
177
- /**
178
- * Remove and return the tail element.
179
- * @remarks Time O(N), Space O(1)
180
- * @returns Removed element or undefined.
181
- */
182
- pop(): E | undefined;
183
- /**
184
- * Remove and return the head element.
185
- * @remarks Time O(1), Space O(1)
186
- * @returns Removed element or undefined.
187
- */
188
- shift(): E | undefined;
189
- /**
190
- * Prepend an element/node to the head.
191
- * @remarks Time O(1), Space O(1)
192
- * @param elementOrNode - Element or node to prepend.
193
- * @returns True when prepended.
194
- */
195
- unshift(elementOrNode: E | SinglyLinkedListNode<E>): boolean;
196
- /**
197
- * Append a sequence of elements/nodes.
198
- * @remarks Time O(N), Space O(1)
199
- * @param elements - Iterable of elements or nodes (or raw records if toElementFn is provided).
200
- * @returns Array of per-element success flags.
201
- */
202
- pushMany(elements: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>): boolean[];
203
- /**
204
- * Prepend a sequence of elements/nodes.
205
- * @remarks Time O(N), Space O(1)
206
- * @param elements - Iterable of elements or nodes (or raw records if toElementFn is provided).
207
- * @returns Array of per-element success flags.
208
- */
209
- unshiftMany(elements: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>): boolean[];
210
- /**
211
- * Find the first value matching a predicate (by node).
212
- * @remarks Time O(N), Space O(1)
213
- * @param elementNodeOrPredicate - Element, node, or node predicate to match.
214
- * @returns Matched value or undefined.
215
- */
216
- search(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): E | undefined;
217
- /**
218
- * Get the element at a given index.
219
- * @remarks Time O(N), Space O(1)
220
- * @param index - Zero-based index.
221
- * @returns Element or undefined.
222
- */
223
- at(index: number): E | undefined;
224
- /**
225
- * Type guard: check whether the input is a SinglyLinkedListNode.
226
- * @remarks Time O(1), Space O(1)
227
- * @param elementNodeOrPredicate - Element, node, or predicate.
228
- * @returns True if the value is a SinglyLinkedListNode.
229
- */
230
- isNode(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): elementNodeOrPredicate is SinglyLinkedListNode<E>;
231
- /**
232
- * Get the node reference at a given index.
233
- * @remarks Time O(N), Space O(1)
234
- * @param index - Zero-based index.
235
- * @returns Node or undefined.
236
- */
237
- getNodeAt(index: number): SinglyLinkedListNode<E> | undefined;
238
- /**
239
- * Delete the element at an index.
240
- * @remarks Time O(N), Space O(1)
241
- * @param index - Zero-based index.
242
- * @returns Removed element or undefined.
243
- */
244
- deleteAt(index: number): E | undefined;
245
- /**
246
- * Delete the first match by value/node.
247
- * @remarks Time O(N), Space O(1)
248
- * @param [elementOrNode] - Element or node to remove; if omitted/undefined, nothing happens.
249
- * @returns True if removed.
250
- */
251
- delete(elementOrNode: E | SinglyLinkedListNode<E> | undefined): boolean;
252
- /**
253
- * Insert a new element/node at an index, shifting following nodes.
254
- * @remarks Time O(N), Space O(1)
255
- * @param index - Zero-based index.
256
- * @param newElementOrNode - Element or node to insert.
257
- * @returns True if inserted.
258
- */
259
- addAt(index: number, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
260
- /**
261
- * Set the element value at an index.
262
- * @remarks Time O(N), Space O(1)
263
- * @param index - Zero-based index.
264
- * @param value - New value.
265
- * @returns True if updated.
266
- */
267
- setAt(index: number, value: E): boolean;
268
- /**
269
- * Check whether the list is empty.
270
- * @remarks Time O(1), Space O(1)
271
- * @returns True if length is 0.
272
- */
273
- isEmpty(): boolean;
274
- /**
275
- * Remove all nodes and reset length.
276
- * @remarks Time O(N), Space O(1)
277
- * @returns void
278
- */
279
- clear(): void;
280
- /**
281
- * Reverse the list in place.
282
- * @remarks Time O(N), Space O(1)
283
- * @returns This list.
284
- */
285
- reverse(): this;
286
- /**
287
- * Find a node by value, reference, or predicate.
288
- * @remarks Time O(N), Space O(1)
289
- * @param [elementNodeOrPredicate] - Element, node, or node predicate to match.
290
- * @returns Matching node or undefined.
291
- */
292
- getNode(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean) | undefined): SinglyLinkedListNode<E> | undefined;
293
- /**
294
- * Insert a new element/node before an existing one.
295
- * @remarks Time O(N), Space O(1)
296
- * @param existingElementOrNode - Existing element or node.
297
- * @param newElementOrNode - Element or node to insert.
298
- * @returns True if inserted.
299
- */
300
- addBefore(existingElementOrNode: E | SinglyLinkedListNode<E>, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
301
- /**
302
- * Insert a new element/node after an existing one.
303
- * @remarks Time O(N), Space O(1)
304
- * @param existingElementOrNode - Existing element or node.
305
- * @param newElementOrNode - Element or node to insert.
306
- * @returns True if inserted.
307
- */
308
- addAfter(existingElementOrNode: E | SinglyLinkedListNode<E>, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
309
- /**
310
- * Remove and/or insert elements at a position (array-like behavior).
311
- * @remarks Time O(N + M), Space O(M)
312
- * @param start - Start index (clamped to [0, length]).
313
- * @param [deleteCount] - Number of elements to remove (default 0).
314
- * @param [items] - Elements to insert after `start`.
315
- * @returns A new list containing the removed elements (typed as `this`).
316
- */
317
- splice(start: number, deleteCount?: number, ...items: E[]): this;
318
- /**
319
- * Count how many nodes match a value/node/predicate.
320
- * @remarks Time O(N), Space O(1)
321
- * @param elementOrNode - Element, node, or node predicate to match.
322
- * @returns Number of matches in the list.
323
- */
324
- countOccurrences(elementOrNode: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): number;
325
- /**
326
- * Set the equality comparator used to compare values.
327
- * @remarks Time O(1), Space O(1)
328
- * @param equals - Equality predicate (a, b) → boolean.
329
- * @returns This list.
330
- */
331
- setEquality(equals: (a: E, b: E) => boolean): this;
332
- /**
333
- * Delete the first node whose value matches a predicate.
334
- * @remarks Time O(N), Space O(1)
335
- * @param predicate - Predicate (value, index, list) → boolean to decide deletion.
336
- * @returns True if a node was removed.
337
- */
338
- deleteWhere(predicate: (value: E, index: number, list: this) => boolean): boolean;
339
- /**
340
- * Deep clone this list (values are copied by reference).
341
- * @remarks Time O(N), Space O(N)
342
- * @returns A new list with the same element sequence.
343
- */
344
- clone(): this;
345
- /**
346
- * Filter values into a new list of the same class.
347
- * @remarks Time O(N), Space O(N)
348
- * @param callback - Predicate (value, index, list) → boolean to keep value.
349
- * @param [thisArg] - Value for `this` inside the callback.
350
- * @returns A new list with kept values.
351
- */
352
- filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): this;
353
- /**
354
- * Map values into a new list of the same class.
355
- * @remarks Time O(N), Space O(N)
356
- * @param callback - Mapping function (value, index, list) → newValue.
357
- * @param [thisArg] - Value for `this` inside the callback.
358
- * @returns A new list with mapped values.
359
- */
360
- mapSame(callback: ElementCallback<E, R, E>, thisArg?: any): this;
361
- /**
362
- * Map values into a new list (possibly different element type).
363
- * @remarks Time O(N), Space O(N)
364
- * @template EM
365
- * @template RM
366
- * @param callback - Mapping function (value, index, list) → newElement.
367
- * @param [options] - Options for the output list (e.g., maxLen, toElementFn).
368
- * @param [thisArg] - Value for `this` inside the callback.
369
- * @returns A new SinglyLinkedList with mapped values.
370
- */
371
- map<EM, RM = any>(callback: ElementCallback<E, R, EM>, options?: SinglyLinkedListOptions<EM, RM>, thisArg?: any): SinglyLinkedList<EM, RM>;
372
- /**
373
- * (Protected) Create a node from a value.
374
- * @remarks Time O(1), Space O(1)
375
- * @param value - Value to wrap in a node.
376
- * @returns A new SinglyLinkedListNode instance.
377
- */
378
- protected _createNode(value: E): SinglyLinkedListNode<E>;
379
- /**
380
- * (Protected) Check if input is a node predicate function.
381
- * @remarks Time O(1), Space O(1)
382
- * @param elementNodeOrPredicate - Element, node, or node predicate.
383
- * @returns True if input is a predicate function.
384
- */
385
- protected _isPredicate(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): elementNodeOrPredicate is (node: SinglyLinkedListNode<E>) => boolean;
386
- /**
387
- * (Protected) Normalize input into a node instance.
388
- * @remarks Time O(1), Space O(1)
389
- * @param elementOrNode - Element or node.
390
- * @returns A SinglyLinkedListNode for the provided input.
391
- */
392
- protected _ensureNode(elementOrNode: E | SinglyLinkedListNode<E>): SinglyLinkedListNode<E>;
393
- /**
394
- * (Protected) Normalize input into a node predicate.
395
- * @remarks Time O(1), Space O(1)
396
- * @param elementNodeOrPredicate - Element, node, or predicate.
397
- * @returns A predicate taking a node and returning true/false.
398
- */
399
- protected _ensurePredicate(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): (node: SinglyLinkedListNode<E>) => boolean;
400
- /**
401
- * (Protected) Get the previous node of a given node.
402
- * @remarks Time O(N), Space O(1)
403
- * @param node - A node in the list.
404
- * @returns Previous node or undefined.
405
- */
406
- protected _getPrevNode(node: SinglyLinkedListNode<E>): SinglyLinkedListNode<E> | undefined;
407
- /**
408
- * (Protected) Iterate values from head to tail.
409
- * @remarks Time O(N), Space O(1)
410
- * @returns Iterator of values (E).
411
- */
412
- protected _getIterator(): IterableIterator<E>;
413
- /**
414
- * (Protected) Iterate values from tail to head.
415
- * @remarks Time O(N), Space O(N)
416
- * @returns Iterator of values (E).
417
- */
418
- protected _getReverseIterator(): IterableIterator<E>;
419
- /**
420
- * (Protected) Iterate nodes from head to tail.
421
- * @remarks Time O(N), Space O(1)
422
- * @returns Iterator of nodes.
423
- */
424
- protected _getNodeIterator(): IterableIterator<SinglyLinkedListNode<E>>;
425
- /**
426
- * (Protected) Create an empty instance of the same concrete class.
427
- * @remarks Time O(1), Space O(1)
428
- * @param [options] - Options forwarded to the constructor.
429
- * @returns An empty like-kind list instance.
430
- */
431
- protected _createInstance(options?: SinglyLinkedListOptions<E, R>): this;
432
- /**
433
- * (Protected) Create a like-kind instance and seed it from an iterable.
434
- * @remarks Time O(N), Space O(N)
435
- * @template EM
436
- * @template RM
437
- * @param [elements] - Iterable used to seed the new list.
438
- * @param [options] - Options forwarded to the constructor.
439
- * @returns A like-kind SinglyLinkedList instance.
440
- */
441
- protected _createLike<EM, RM>(elements?: Iterable<EM> | Iterable<RM> | Iterable<SinglyLinkedListNode<EM>>, options?: SinglyLinkedListOptions<EM, RM>): SinglyLinkedList<EM, RM>;
442
- /**
443
- * (Protected) Spawn an empty like-kind list instance.
444
- * @remarks Time O(1), Space O(1)
445
- * @template EM
446
- * @template RM
447
- * @param [options] - Options forwarded to the constructor.
448
- * @returns An empty like-kind SinglyLinkedList instance.
449
- */
450
- protected _spawnLike<EM, RM>(options?: SinglyLinkedListOptions<EM, RM>): SinglyLinkedList<EM, RM>;
451
- }