data-structure-typed 0.8.18 → 1.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 (272) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +690 -2
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -18
  8. package/dist/data-structures/binary-tree/avl-tree.js +110 -37
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +40 -2
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +44 -2
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -138
  12. package/dist/data-structures/binary-tree/binary-tree.js +27 -979
  13. package/dist/data-structures/binary-tree/bst.d.ts +118 -28
  14. package/dist/data-structures/binary-tree/bst.js +162 -124
  15. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  16. package/dist/data-structures/binary-tree/index.js +1 -0
  17. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  18. package/dist/data-structures/binary-tree/rb-tree.js +40 -2
  19. package/dist/data-structures/binary-tree/segment-tree.d.ts +63 -13
  20. package/dist/data-structures/binary-tree/segment-tree.js +80 -17
  21. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -10
  22. package/dist/data-structures/binary-tree/tree-multiset.js +682 -9
  23. package/dist/data-structures/graph/abstract-graph.d.ts +270 -64
  24. package/dist/data-structures/graph/abstract-graph.js +365 -92
  25. package/dist/data-structures/graph/directed-graph.d.ts +175 -26
  26. package/dist/data-structures/graph/directed-graph.js +249 -95
  27. package/dist/data-structures/graph/index.d.ts +1 -0
  28. package/dist/data-structures/graph/index.js +1 -0
  29. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  30. package/dist/data-structures/graph/map-graph.js +111 -0
  31. package/dist/data-structures/graph/undirected-graph.d.ts +111 -8
  32. package/dist/data-structures/graph/undirected-graph.js +154 -44
  33. package/dist/data-structures/hash/coordinate-map.d.ts +39 -2
  34. package/dist/data-structures/hash/coordinate-map.js +44 -3
  35. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  36. package/dist/data-structures/hash/coordinate-set.js +34 -0
  37. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  38. package/dist/data-structures/hash/hash-table.js +4 -0
  39. package/dist/data-structures/hash/index.d.ts +5 -0
  40. package/dist/data-structures/hash/index.js +5 -0
  41. package/dist/data-structures/hash/pair.d.ts +2 -1
  42. package/dist/data-structures/hash/pair.js +4 -0
  43. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  44. package/dist/data-structures/hash/tree-map.js +4 -0
  45. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-set.js +4 -0
  47. package/dist/data-structures/heap/heap.d.ts +62 -51
  48. package/dist/data-structures/heap/heap.js +106 -63
  49. package/dist/data-structures/heap/max-heap.d.ts +13 -4
  50. package/dist/data-structures/heap/max-heap.js +10 -2
  51. package/dist/data-structures/heap/min-heap.d.ts +14 -4
  52. package/dist/data-structures/heap/min-heap.js +11 -2
  53. package/dist/data-structures/index.d.ts +1 -0
  54. package/dist/data-structures/index.js +1 -0
  55. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -57
  56. package/dist/data-structures/linked-list/doubly-linked-list.js +461 -194
  57. package/dist/data-structures/linked-list/index.d.ts +1 -0
  58. package/dist/data-structures/linked-list/index.js +1 -0
  59. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -319
  60. package/dist/data-structures/linked-list/singly-linked-list.js +338 -557
  61. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  62. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  63. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  64. package/dist/data-structures/matrix/matrix.js +14 -0
  65. package/dist/data-structures/matrix/matrix2d.d.ts +87 -4
  66. package/dist/data-structures/matrix/matrix2d.js +91 -8
  67. package/dist/data-structures/matrix/navigator.d.ts +37 -16
  68. package/dist/data-structures/matrix/navigator.js +28 -0
  69. package/dist/data-structures/matrix/vector2d.d.ts +156 -29
  70. package/dist/data-structures/matrix/vector2d.js +184 -55
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -1
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +28 -4
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -1
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +29 -4
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +166 -22
  76. package/dist/data-structures/priority-queue/priority-queue.js +219 -75
  77. package/dist/data-structures/queue/deque.d.ts +141 -13
  78. package/dist/data-structures/queue/deque.js +151 -7
  79. package/dist/data-structures/queue/queue.d.ts +68 -42
  80. package/dist/data-structures/queue/queue.js +95 -51
  81. package/dist/data-structures/stack/stack.d.ts +30 -36
  82. package/dist/data-structures/stack/stack.js +31 -37
  83. package/dist/data-structures/tree/index.d.ts +1 -0
  84. package/dist/data-structures/tree/index.js +17 -0
  85. package/dist/data-structures/tree/tree.d.ts +14 -0
  86. package/dist/{types/utils.js → data-structures/tree/tree.js} +26 -19
  87. package/dist/data-structures/trie/trie.d.ts +39 -6
  88. package/dist/data-structures/trie/trie.js +81 -12
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.js +3 -0
  91. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  92. package/dist/interfaces/abstract-binary-tree.js +2 -0
  93. package/dist/interfaces/abstract-graph.d.ts +17 -0
  94. package/dist/interfaces/abstract-graph.js +2 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/avl-tree.js +2 -0
  97. package/dist/interfaces/binary-tree.d.ts +6 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/bst.d.ts +17 -0
  100. package/dist/interfaces/bst.js +2 -0
  101. package/dist/interfaces/directed-graph.d.ts +12 -0
  102. package/dist/interfaces/directed-graph.js +2 -0
  103. package/dist/interfaces/doubly-linked-list.js +2 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +15 -0
  106. package/dist/interfaces/index.js +31 -0
  107. package/dist/interfaces/navigator.js +2 -0
  108. package/dist/interfaces/priority-queue.js +2 -0
  109. package/dist/interfaces/rb-tree.d.ts +8 -0
  110. package/dist/interfaces/rb-tree.js +2 -0
  111. package/dist/interfaces/segment-tree.js +2 -0
  112. package/dist/interfaces/singly-linked-list.js +2 -0
  113. package/dist/interfaces/tree-multiset.d.ts +7 -0
  114. package/dist/interfaces/tree-multiset.js +2 -0
  115. package/dist/interfaces/undirected-graph.d.ts +5 -0
  116. package/dist/interfaces/undirected-graph.js +2 -0
  117. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  118. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  119. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  120. package/dist/types/data-structures/abstract-graph.js +2 -0
  121. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  122. package/dist/types/data-structures/avl-tree.js +2 -0
  123. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  124. package/dist/types/data-structures/binary-tree.js +2 -0
  125. package/dist/types/data-structures/bst.d.ts +13 -0
  126. package/dist/types/data-structures/bst.js +9 -0
  127. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  128. package/dist/types/data-structures/directed-graph.js +9 -0
  129. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  130. package/dist/types/data-structures/heap.d.ts +3 -0
  131. package/dist/types/data-structures/heap.js +2 -0
  132. package/dist/types/data-structures/index.d.ts +13 -7
  133. package/dist/types/data-structures/index.js +31 -0
  134. package/dist/types/data-structures/map-graph.d.ts +1 -0
  135. package/dist/types/data-structures/map-graph.js +2 -0
  136. package/dist/types/data-structures/navigator.d.ts +14 -0
  137. package/dist/types/data-structures/navigator.js +2 -0
  138. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  139. package/dist/types/data-structures/priority-queue.js +2 -0
  140. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  141. package/dist/types/data-structures/rb-tree.js +8 -0
  142. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  143. package/dist/types/data-structures/segment-tree.js +2 -0
  144. package/dist/types/data-structures/singly-linked-list.js +2 -0
  145. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  146. package/dist/types/data-structures/tree-multiset.js +2 -0
  147. package/dist/types/helpers.d.ts +1 -0
  148. package/dist/types/helpers.js +2 -0
  149. package/dist/types/index.d.ts +2 -0
  150. package/dist/types/index.js +2 -0
  151. package/dist/types/utils/index.d.ts +2 -0
  152. package/dist/types/utils/index.js +18 -0
  153. package/dist/types/utils/utils.d.ts +7 -0
  154. package/dist/types/utils/utils.js +2 -0
  155. package/dist/types/utils/validate-type.d.ts +19 -0
  156. package/dist/types/utils/validate-type.js +2 -0
  157. package/dist/utils/index.js +17 -0
  158. package/dist/utils/utils.d.ts +19 -0
  159. package/dist/{data-structures/trampoline.js → utils/utils.js} +26 -12
  160. package/package.json +106 -55
  161. package/.idea/data-structure-typed.iml +0 -12
  162. package/.idea/modules.xml +0 -8
  163. package/.idea/vcs.xml +0 -6
  164. package/dist/data-structures/trampoline.d.ts +0 -25
  165. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  167. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  169. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  170. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  171. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  172. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  173. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  174. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  175. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  176. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  177. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  178. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  179. package/dist/types/data-structures/graph/index.d.ts +0 -3
  180. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  181. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  182. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  185. package/dist/types/data-structures/heap/index.d.ts +0 -3
  186. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  187. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  188. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  189. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  190. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  191. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  192. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  193. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  194. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  195. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  196. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  199. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  200. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  201. package/dist/types/data-structures/queue/index.d.ts +0 -1
  202. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  203. package/dist/types/data-structures/stack/index.d.ts +0 -1
  204. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  205. package/dist/types/data-structures/trampoline.d.ts +0 -25
  206. package/dist/types/data-structures/trie/index.d.ts +0 -1
  207. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/types/utils.d.ts +0 -46
  210. package/dist/utils.d.ts +0 -122
  211. package/dist/utils.js +0 -569
  212. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  213. package/src/data-structures/binary-tree/avl-tree.ts +0 -232
  214. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  215. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  216. package/src/data-structures/binary-tree/binary-tree.ts +0 -1088
  217. package/src/data-structures/binary-tree/bst.ts +0 -404
  218. package/src/data-structures/binary-tree/index.ts +0 -11
  219. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  220. package/src/data-structures/binary-tree/segment-tree.ts +0 -164
  221. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  222. package/src/data-structures/binary-tree/tree-multiset.ts +0 -21
  223. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  224. package/src/data-structures/graph/abstract-graph.ts +0 -789
  225. package/src/data-structures/graph/directed-graph.ts +0 -322
  226. package/src/data-structures/graph/index.ts +0 -3
  227. package/src/data-structures/graph/undirected-graph.ts +0 -154
  228. package/src/data-structures/hash/coordinate-map.ts +0 -24
  229. package/src/data-structures/hash/coordinate-set.ts +0 -20
  230. package/src/data-structures/hash/hash-table.ts +0 -1
  231. package/src/data-structures/hash/index.ts +0 -1
  232. package/src/data-structures/heap/heap.ts +0 -136
  233. package/src/data-structures/heap/index.ts +0 -3
  234. package/src/data-structures/heap/max-heap.ts +0 -22
  235. package/src/data-structures/heap/min-heap.ts +0 -24
  236. package/src/data-structures/index.ts +0 -11
  237. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -258
  238. package/src/data-structures/linked-list/index.ts +0 -2
  239. package/src/data-structures/linked-list/singly-linked-list.ts +0 -750
  240. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  241. package/src/data-structures/matrix/index.ts +0 -4
  242. package/src/data-structures/matrix/matrix.ts +0 -13
  243. package/src/data-structures/matrix/matrix2d.ts +0 -125
  244. package/src/data-structures/matrix/navigator.ts +0 -99
  245. package/src/data-structures/matrix/vector2d.ts +0 -189
  246. package/src/data-structures/priority-queue/index.ts +0 -3
  247. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -12
  248. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -12
  249. package/src/data-structures/priority-queue/priority-queue.ts +0 -208
  250. package/src/data-structures/queue/deque.ts +0 -139
  251. package/src/data-structures/queue/index.ts +0 -2
  252. package/src/data-structures/queue/queue.ts +0 -123
  253. package/src/data-structures/stack/index.ts +0 -1
  254. package/src/data-structures/stack/stack.ts +0 -104
  255. package/src/data-structures/trampoline.ts +0 -91
  256. package/src/data-structures/trie/index.ts +0 -1
  257. package/src/data-structures/trie/trie.ts +0 -153
  258. package/src/index.ts +0 -1
  259. package/src/types/index.ts +0 -1
  260. package/src/types/patches/index.d.ts +0 -0
  261. package/src/types/utils.ts +0 -158
  262. package/src/utils.ts +0 -605
  263. package/tsconfig.json +0 -53
  264. /package/dist/{types/data-structures/hash/hash-table.d.ts → interfaces/doubly-linked-list.d.ts} +0 -0
  265. /package/dist/{types/data-structures/hash/pair.d.ts → interfaces/heap.d.ts} +0 -0
  266. /package/dist/{types/data-structures/hash/tree-map.d.ts → interfaces/navigator.d.ts} +0 -0
  267. /package/dist/{types/data-structures/hash/tree-set.d.ts → interfaces/priority-queue.d.ts} +0 -0
  268. /package/dist/{types/data-structures/linked-list/skip-linked-list.d.ts → interfaces/segment-tree.d.ts} +0 -0
  269. /package/{src/data-structures/hash/pair.ts → dist/interfaces/singly-linked-list.d.ts} +0 -0
  270. /package/{src/data-structures/hash/tree-map.ts → dist/types/data-structures/doubly-linked-list.d.ts} +0 -0
  271. /package/{src/data-structures/hash/tree-set.ts → dist/types/data-structures/singly-linked-list.d.ts} +0 -0
  272. /package/dist/{types/types → utils}/index.d.ts +0 -0
@@ -1,2 +1,3 @@
1
1
  export * from './singly-linked-list';
2
2
  export * from './doubly-linked-list';
3
+ export * from './skip-linked-list';
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./singly-linked-list"), exports);
18
18
  __exportStar(require("./doubly-linked-list"), exports);
19
+ __exportStar(require("./skip-linked-list"), exports);
@@ -1,358 +1,156 @@
1
- /** Type used for filter and find methods, returning a boolean */
2
- type TTestFunction<NodeData> = (data: NodeData, index: number, list: SinglyLinkedList<NodeData>) => boolean;
3
- /** Type used for map and forEach methods, returning anything */
4
- type TMapFunction<NodeData> = (data: any, index: number, list: SinglyLinkedList<NodeData>) => any;
5
1
  /**
6
- * The class which represents one link or node in a linked list
7
- * ```ts
8
- * const node = new SinglyLinkedListNode(1, null, null, null);
9
- * ```
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
10
7
  */
11
- export declare class SinglyLinkedListNode<NodeData = any> {
12
- /** Data stored on the node */
13
- val: NodeData;
14
- /** The previous node in the list */
15
- prev: SinglyLinkedListNode<NodeData> | null;
16
- /** The next link in the list */
17
- next: SinglyLinkedListNode<NodeData> | null;
18
- /** The list this node belongs to */
19
- list: SinglyLinkedList<NodeData> | null;
20
- constructor(
21
- /** Data stored on the node */
22
- val: NodeData,
23
- /** The previous node in the list */
24
- prev: SinglyLinkedListNode<NodeData> | null,
25
- /** The next link in the list */
26
- next: SinglyLinkedListNode<NodeData> | null,
27
- /** The list this node belongs to */
28
- list: SinglyLinkedList<NodeData> | null);
29
- /**
30
- * Alias to .val
31
- * ```ts
32
- * new LinkedList(1, 2, 3).head.value; // 1
33
- * ```
34
- */
35
- get value(): NodeData;
36
- /**
37
- * Get the index of this node
38
- * ```ts
39
- * new LinkedList(1, 2, 3).head.index; // 0
40
- * ```
41
- */
42
- get index(): number | undefined;
43
- /**
44
- * Insert a new node before this one
45
- * ```ts
46
- * new LinkedList(2, 3).head.insertBefore(1); // 1 <=> 2 <=> 3
47
- * ```
48
- * @param val Data to save in the node
49
- */
50
- insertBefore(val: NodeData): SinglyLinkedList<NodeData>;
51
- /**
52
- * Insert new val after this node
53
- * ```ts
54
- * new LinkedList(1, 2).tail.insertAfter(3); // 1 <=> 2 <=> 3
55
- * ```
56
- * @param val Data to be saved in the node
57
- */
58
- insertAfter(val: NodeData): SinglyLinkedList<NodeData>;
59
- /**
60
- * Remove this node
61
- * ```ts
62
- * new LinkedList(1, 2, 3, 4).tail.remove(); // 1 <=> 2 <=> 3
63
- * ```
64
- */
65
- remove(): SinglyLinkedListNode<NodeData>;
8
+ export declare class SinglyLinkedListNode<T = number> {
9
+ /**
10
+ * The constructor function initializes an instance of a class with a given value and sets the next property to null.
11
+ * @param {T} val - The "val" parameter is of type T, which means it can be any data type. It represents the value that
12
+ * will be stored in the node of a linked list.
13
+ */
14
+ constructor(val: T);
15
+ private _val;
16
+ get val(): T;
17
+ set val(value: T);
18
+ private _next;
19
+ get next(): SinglyLinkedListNode<T> | null;
20
+ set next(value: SinglyLinkedListNode<T> | null);
66
21
  }
67
- /**
68
- * A doubly linked list
69
- * ```ts
70
- * const list = new LinkedList(1, 2, 3);
71
- * const listFromArray = LinkedList.from([1, 2, 3]);
72
- * ```
73
- */
74
- export declare class SinglyLinkedList<NodeData = any> {
75
- /**
76
- * The length of the list
77
- */
22
+ export declare class SinglyLinkedList<T = any> {
23
+ /**
24
+ * The constructor initializes the linked list with an empty head, tail, and length.
25
+ */
26
+ constructor();
27
+ private _head;
28
+ get head(): SinglyLinkedListNode<T> | null;
29
+ set head(value: SinglyLinkedListNode<T> | null);
30
+ private _tail;
31
+ get tail(): SinglyLinkedListNode<T> | null;
32
+ set tail(value: SinglyLinkedListNode<T> | null);
33
+ private _length;
78
34
  get length(): number;
79
35
  /**
80
- * Convert any iterable to a new linked list
81
- * ```javascript
82
- * const array = [1, 2, 3];
83
- * const list = LinkedList.from(array);
84
- * ```
85
- * @param iterable Any iterable datatype like Array or Map
86
- */
87
- static from<T>(iterable: Iterable<T>): SinglyLinkedList<T>;
88
- /** The head of the list, the first node */
89
- head: SinglyLinkedListNode<NodeData> | null;
90
- /** The tail of the list, the last node */
91
- tail: SinglyLinkedListNode<NodeData> | null;
92
- /** Internal size reference */
93
- private size;
94
- constructor(...args: NodeData[]);
95
- /**
96
- * Get the node val at a specified index, zero based
97
- * ```ts
98
- * new LinkedList(1, 2, 3).get(0); // 1
99
- * ```
100
- * @param index to retrieve val at
101
- */
102
- get(index: number): NodeData | undefined;
103
- /**
104
- * Get the node at index, zero based
105
- * ```ts
106
- * new LinkedList(1, 2, 3).getNode(0);
107
- * // { prev: null, val: 1, next: SinglyLinkedListNode }
108
- * ```
109
- */
110
- getNode(index: number): SinglyLinkedListNode<NodeData> | undefined;
111
- /**
112
- * Return the first node and its index in the list that
113
- * satisfies the testing function
114
- * ```ts
115
- * new LinkedList(1, 2, 3).findNodeIndex(val => val === 1);
116
- * // { node: SinglyLinkedListNode, index: 0 }
117
- * ```
118
- * @param f A function to be applied to the val of each node
119
- */
120
- findNodeIndex(f: TTestFunction<NodeData>): ({
121
- node: SinglyLinkedListNode<NodeData>;
122
- index: number;
123
- }) | undefined;
124
- /**
125
- * Returns the first node in the list that
126
- * satisfies the provided testing function. Otherwise undefined is returned.
127
- * ```ts
128
- * new LinkedList(1, 2, 3).findNode(val => val === 1);
129
- * // { prev: null, val: 1, next: SinglyLinkedListNode }
130
- * ```
131
- * @param f Function to test val against
132
- */
133
- findNode(f: TTestFunction<NodeData>): SinglyLinkedListNode<NodeData> | undefined;
134
- /**
135
- * Returns the value of the first element in the list that
136
- * satisfies the provided testing function. Otherwise undefined is returned.
137
- * ```ts
138
- * new LinkedList(1, 2, 3).find(val => val === 1); // 1
139
- * ```
140
- * @param f Function to test val against
141
- */
142
- find(f: TTestFunction<NodeData>): NodeData | undefined;
143
- /**
144
- * Returns the index of the first node in the list that
145
- * satisfies the provided testing function. Ohterwise -1 is returned.
146
- * ```ts
147
- * new LinkedList(1, 2, 3).findIndex(val => val === 3); // 2
148
- * ```
149
- * @param f Function to test val against
150
- */
151
- findIndex(f: TTestFunction<NodeData>): number;
152
- /**
153
- * Append one or any number of nodes to the end of the list.
154
- * This modifies the list in place and returns the list itself
155
- * to make this method chainable.
156
- * ```ts
157
- * new LinkedList(1).append(2).append(3, 4); // 1 <=> 2 <=> 3 <=> 4
158
- * ```
159
- * @param args Data to be stored in the node, takes any number of arguments
160
- */
161
- append(...args: NodeData[]): SinglyLinkedList<NodeData>;
162
- /**
163
- * Synonym for append
164
- * ```ts
165
- * new LinkedList(1).push(2).push(3, 4); // 1 <=> 2 <=> 3 <=> 4
166
- * ```
167
- * @param args Data to be stored, takes any number of arguments
168
- */
169
- push(...args: NodeData[]): number;
170
- /**
171
- * Prepend any number of val arguments to the list. The
172
- * argument list is prepended as a block to reduce confusion:
173
- * ```javascript
174
- * new LinkedList(3, 4).prepend(0, 1, 2); // [0, 1, 2, 3, 4]
175
- * ```
176
- * @param args Data to be stored in the node, accepts any number of arguments
177
- */
178
- prepend(...args: NodeData[]): SinglyLinkedList<NodeData>;
179
- /**
180
- * Insert a new node at a given index position. If index is
181
- * out of bounds, the node is appended, if index is negative
182
- * or 0, it will be prepended.
183
- * ```ts
184
- * new LinkedList(1, 3).insertAt(1, 2); // 1 <=> 2 <=> 3
185
- * ```
186
- * @param index The index to insert the new node at
187
- * @param val Data to be stored on the new node
188
- */
189
- insertAt(index: number, val: NodeData): SinglyLinkedList<NodeData>;
190
- /**
191
- * Remove the specified node from the list and return the removed
192
- * node afterwards.
193
- * ```ts
194
- * const list = new LinkedList(1, 2, 3);
195
- * list.removeNode(list.tail); // { prev: null, val: 3, next: null, list: null }
196
- * ```
197
- * @param node The node to be removed
198
- */
199
- removeNode(node: SinglyLinkedListNode<NodeData>): SinglyLinkedListNode<NodeData>;
200
- /**
201
- * Remove the node at the specified index
202
- * ```ts
203
- * new LinkedList(1, 2, 3).removeAt(2); // { prev: null, val: 3, next: null, list: null }
204
- * ```
205
- * @param index Index at which to remove
36
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
37
+ * array.
38
+ * @param {T[]} data - The `data` parameter is an array of elements of type `T`.
39
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
206
40
  */
207
- removeAt(index: number): SinglyLinkedListNode<NodeData> | undefined;
41
+ static fromArray<T>(data: T[]): SinglyLinkedList<T>;
42
+ getLength(): number;
208
43
  /**
209
- * Insert a new node before the reference node
210
- * ```ts
211
- * const list = new LinkedList(1, 3);
212
- * list.insertBefore(list.tail, 2); // 1 <=> 2 <=> 3
213
- * ```
214
- * @param referenceNode The node reference
215
- * @param val Data to save in the node
44
+ * The `push` function adds a new node with the given data to the end of a singly linked list.
45
+ * @param {T} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
46
+ * any type (T) as specified in the generic type declaration of the class or function.
216
47
  */
217
- insertBefore(referenceNode: SinglyLinkedListNode<NodeData>, val: NodeData): SinglyLinkedList<NodeData>;
48
+ push(data: T): void;
218
49
  /**
219
- * Sorts the linked list using the provided compare function
220
- * @param compare A function used to compare the val of two nodes. It should return
221
- * a boolean. True will insert a before b, false will insert b before a.
222
- * (a, b) => a < b or (1, 2) => 1 < 2 === true, 2 will be inserted after 1,
223
- * the sort order will be ascending.
50
+ * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
51
+ * pointers accordingly.
52
+ * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
53
+ * the linked list is empty, it returns `null`.
224
54
  */
225
- sort(compare: (a: NodeData, b: NodeData) => boolean): SinglyLinkedList<NodeData>;
55
+ pop(): T | undefined;
226
56
  /**
227
- * Insert a new node after this one
228
- * ```ts
229
- * const list = new LinkedList(2, 3);
230
- * list.insertAfter(list.head, 1); // 1 <=> 2 <=> 3
231
- * ```
232
- * @param referenceNode The reference node
233
- * @param val Data to be saved in the node
57
+ * The `shift()` function removes and returns the value of the first node in a linked list.
58
+ * @returns The value of the node that is being removed from the beginning of the linked list.
234
59
  */
235
- insertAfter(referenceNode: SinglyLinkedListNode<NodeData>, val: NodeData): SinglyLinkedList<NodeData>;
60
+ shift(): T | undefined;
236
61
  /**
237
- * Remove the first node from the list and return the val of the removed node
238
- * or undefined
239
- * ```ts
240
- * new LinkedList(1, 2, 3).shift(); // 1
241
- * ```
62
+ * The unshift function adds a new node with the given value to the beginning of a singly linked list.
63
+ * @param {T} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
64
+ * linked list.
242
65
  */
243
- shift(): NodeData | undefined;
66
+ unshift(val: T): void;
244
67
  /**
245
- * Remove the last node from the list and return the val of the removed node
246
- * or undefined if the list was empty
247
- * ```ts
248
- * new LinkedList(1, 2, 3).pop(); // 3
249
- * ```
68
+ * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
69
+ * @param {number} index - The index parameter is a number that represents the position of the element we want to
70
+ * retrieve from the list.
71
+ * @returns The method `getAt(index: number): T | null` returns the value at the specified index in the linked list, or
72
+ * `null` if the index is out of bounds.
250
73
  */
251
- pop(): NodeData | undefined;
74
+ getAt(index: number): T | null;
252
75
  /**
253
- * Merge the current list with another. Both lists will be
254
- * equal after merging.
255
- * ```ts
256
- * const list = new LinkedList(1, 2);
257
- * const otherList = new LinkedList(3);
258
- * list.merge(otherList);
259
- * (list === otherList); // true
260
- * ```
261
- * @param list The list to be merged
76
+ * The function `getNodeAt` returns the node at a given index in a singly linked list.
77
+ * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
78
+ * retrieve from the linked list. It indicates the zero-based index of the node we want to access.
79
+ * @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<T>` object if the node at the
80
+ * specified index exists, or `null` if the index is out of bounds.
262
81
  */
263
- merge(list: SinglyLinkedList<NodeData>): void;
82
+ getNodeAt(index: number): SinglyLinkedListNode<T> | null;
264
83
  /**
265
- * Removes all nodes from a list
266
- *
267
- * ```ts
268
- * list.clear();
269
- * ```
84
+ * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
85
+ * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
86
+ * data structure. It is of type number.
87
+ * @returns The method `deleteAt` returns the value of the node that was deleted, or `null` if the index is out of
88
+ * bounds.
270
89
  */
271
- clear(): this;
90
+ deleteAt(index: number): T | undefined;
91
+ delete(valueOrNode: T): boolean;
92
+ delete(valueOrNode: SinglyLinkedListNode<T>): boolean;
272
93
  /**
273
- * The slice() method returns a shallow copy of a
274
- * portion of a list into a new list object selected
275
- * from start to end (end not included).
276
- * The original list will not be modified.
277
- * ```ts
278
- * const list = new LinkedList(1, 2, 3, 4, 5);
279
- * const newList = list.slice(0, 3); // 1 <=> 2 <=> 3
280
- * ```
281
- * @param start Start index
282
- * @param end End index, optional
94
+ * The `insertAt` function inserts a value at a specified index in a singly linked list.
95
+ * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
96
+ * linked list. It is of type number.
97
+ * @param {T} val - The `val` parameter represents the value that you want to insert into the linked list at the
98
+ * specified index.
99
+ * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
100
+ * if the index is out of bounds.
283
101
  */
284
- slice(start: number, end?: number): SinglyLinkedList<NodeData | {}>;
102
+ insertAt(index: number, val: T): boolean;
285
103
  /**
286
- * The reverse() function reverses the list in place and returns the list
287
- * itself.
288
- * ```ts
289
- * new LinkedList(1, 2, 3).reverse(); // 3 <=> 2 <=> 1
290
- * ```
104
+ * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
105
+ * whether it is empty or not.
106
+ * @returns A boolean value indicating whether the length of the object is equal to 0.
291
107
  */
292
- reverse(): SinglyLinkedList<NodeData>;
108
+ isEmpty(): boolean;
293
109
  /**
294
- * The forEach() method executes a provided function once for each list node.
295
- * ```ts
296
- * new LinkedList(1, 2, 3).forEach(val => log(val)); // 1 2 3
297
- * ```
298
- * @param f Function to execute for each element, taking up to three arguments.
299
- * @param reverse Indicates if the list should be walked in reverse order, default is false
110
+ * The `clear` function resets the linked list by setting the head, tail, and length to null and 0 respectively.
300
111
  */
301
- forEach(f: TMapFunction<NodeData>, reverse?: boolean): void;
112
+ clear(): void;
302
113
  /**
303
- * The map() method creates a new list with the results of
304
- * calling a provided function on every node in the calling list.
305
- * ```ts
306
- * new LinkedList(1, 2, 3).map(val => val + 10); // 11 <=> 12 <=> 13
307
- * ```
308
- * @param f Function that produces an node of the new list, taking up to three arguments
309
- * @param reverse Indicates if the list should be mapped in reverse order, default is false
114
+ * The `toArray` function converts a linked list into an array.
115
+ * @returns The `toArray()` method is returning an array of type `T[]`.
310
116
  */
311
- map(f: TMapFunction<NodeData>, reverse?: boolean): SinglyLinkedList<NodeData | {}>;
117
+ toArray(): T[];
312
118
  /**
313
- * The filter() method creates a new list with all nodes
314
- * that pass the test implemented by the provided function.
315
- * ```ts
316
- * new LinkedList(1, 2, 3, 4, 5).filter(val => val < 4); // 1 <=> 2 <=> 3
317
- * ```
318
- * @param f Function to test each node val in the list. Return true to keep the node
319
- * @param reverse Indicates if the list should be filtered in reverse order, default is false
119
+ * The `reverse` function reverses the order of the nodes in a singly linked list.
120
+ * @returns The reverse() method does not return anything. It has a return type of void.
320
121
  */
321
- filter(f: TTestFunction<NodeData>, reverse?: boolean): SinglyLinkedList<NodeData | {}>;
122
+ reverse(): void;
322
123
  /**
323
- * Reduce over each node in the list
324
- * ```ts
325
- * new LinkedList(1, 2, 3).reduce(n => n += 1, 0); // 3
326
- * ```
327
- * @param f A reducer function
328
- * @param start An initial value
329
- * @returns The final state of the accumulator
124
+ * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
125
+ * @param callback - A function that takes a value of type T as its parameter and returns a boolean value. This
126
+ * function is used to determine whether a particular value in the linked list satisfies a certain condition.
127
+ * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
128
+ * the callback function. If no element satisfies the condition, it returns `null`.
330
129
  */
331
- reduce(f: (accumulator: any, currentNode: NodeData, index: number, list: SinglyLinkedList<NodeData>) => any, start?: any, reverse?: boolean): any;
130
+ find(callback: (val: T) => boolean): T | null;
332
131
  /**
333
- * Convert the linked list to an array
334
- * ```ts
335
- * new LinkedList(1, 2, 3).toArray(); // [1, 2, 3]
336
- * ```
132
+ * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
133
+ * @param {T} value - The value parameter is the value that you want to find the index of in the linked list.
134
+ * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
135
+ * value is not found, it returns -1.
337
136
  */
338
- toArray(): NodeData[];
137
+ indexOf(value: T): number;
339
138
  /**
340
- * Convert a linked list to string
341
- * ```ts
342
- * new LinkedList('one', 'two', 'three').toString(' <=> ') === 'one <=> two <=> three';
343
- * ```
344
- * @param separator Optional string to be placed in between val nodes, default is one space
139
+ * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
140
+ * null.
141
+ * @param {T} value - The value parameter is the value that we want to search for in the linked list.
142
+ * @returns a `SinglyLinkedListNode<T>` if a node with the specified value is found in the linked list. If no node with
143
+ * the specified value is found, the function returns `null`.
345
144
  */
346
- toString(separator?: string): string;
145
+ findNode(value: T): SinglyLinkedListNode<T> | null;
146
+ insertBefore(existingValue: T, newValue: T): boolean;
147
+ insertBefore(existingValue: SinglyLinkedListNode<T>, newValue: T): boolean;
148
+ insertAfter(existingValueOrNode: T, newValue: T): boolean;
149
+ insertAfter(existingValueOrNode: SinglyLinkedListNode<T>, newValue: T): boolean;
347
150
  /**
348
- * The iterator implementation
349
- * ```ts
350
- * const list = new LinkedList(1, 2, 3);
351
- * for (const val of list) { log(val); } // 1 2 3
352
- * ```
151
+ * The function counts the number of occurrences of a given value in a linked list.
152
+ * @param {T} value - The value parameter is the value that you want to count the occurrences of in the linked list.
153
+ * @returns The count of occurrences of the given value in the linked list.
353
154
  */
354
- [Symbol.iterator](): IterableIterator<NodeData>;
355
- /** Private helper function to reduce duplication of pop() and shift() methods */
356
- private removeFromAnyEnd;
155
+ countOccurrences(value: T): number;
357
156
  }
358
- export {};