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