data-structure-typed 1.39.0 → 1.39.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 (100) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
  3. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +96 -32
  4. package/dist/cjs/data-structures/binary-tree/binary-tree.js +46 -8
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  6. package/dist/cjs/data-structures/binary-tree/bst.d.ts +6 -6
  7. package/dist/cjs/data-structures/binary-tree/bst.js +2 -2
  8. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
  10. package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
  11. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -1
  12. package/dist/cjs/data-structures/graph/abstract-graph.js +1 -1
  13. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  14. package/dist/cjs/data-structures/graph/map-graph.d.ts +1 -1
  15. package/dist/cjs/data-structures/graph/map-graph.js +1 -1
  16. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  17. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -28
  18. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +59 -49
  19. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  20. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +75 -7
  21. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +110 -9
  22. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  23. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +1 -2
  24. package/dist/cjs/data-structures/matrix/matrix2d.js +3 -7
  25. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  26. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -1
  27. package/dist/cjs/data-structures/matrix/vector2d.js +0 -1
  28. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  29. package/dist/cjs/data-structures/queue/deque.d.ts +20 -20
  30. package/dist/cjs/data-structures/queue/deque.js +22 -22
  31. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  32. package/dist/cjs/data-structures/queue/queue.d.ts +3 -3
  33. package/dist/cjs/data-structures/queue/queue.js +3 -3
  34. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  35. package/dist/cjs/interfaces/binary-tree.d.ts +2 -2
  36. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
  37. package/dist/cjs/types/helpers.d.ts +1 -4
  38. package/dist/cjs/types/helpers.js.map +1 -1
  39. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +2 -2
  40. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +96 -32
  41. package/dist/mjs/data-structures/binary-tree/binary-tree.js +46 -8
  42. package/dist/mjs/data-structures/binary-tree/bst.d.ts +6 -6
  43. package/dist/mjs/data-structures/binary-tree/bst.js +2 -2
  44. package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +2 -2
  45. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
  46. package/dist/mjs/data-structures/graph/abstract-graph.js +1 -1
  47. package/dist/mjs/data-structures/graph/map-graph.d.ts +1 -1
  48. package/dist/mjs/data-structures/graph/map-graph.js +1 -1
  49. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -28
  50. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +59 -49
  51. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +75 -7
  52. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +110 -9
  53. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +1 -2
  54. package/dist/mjs/data-structures/matrix/matrix2d.js +3 -7
  55. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -1
  56. package/dist/mjs/data-structures/matrix/vector2d.js +0 -1
  57. package/dist/mjs/data-structures/queue/deque.d.ts +20 -20
  58. package/dist/mjs/data-structures/queue/deque.js +22 -22
  59. package/dist/mjs/data-structures/queue/queue.d.ts +3 -3
  60. package/dist/mjs/data-structures/queue/queue.js +3 -3
  61. package/dist/mjs/interfaces/binary-tree.d.ts +2 -2
  62. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +0 -2
  63. package/dist/mjs/types/helpers.d.ts +1 -4
  64. package/dist/umd/data-structure-typed.min.js +1 -1
  65. package/dist/umd/data-structure-typed.min.js.map +1 -1
  66. package/package.json +5 -5
  67. package/src/data-structures/binary-tree/avl-tree.ts +2 -2
  68. package/src/data-structures/binary-tree/binary-tree.ts +76 -90
  69. package/src/data-structures/binary-tree/bst.ts +9 -16
  70. package/src/data-structures/binary-tree/tree-multiset.ts +2 -2
  71. package/src/data-structures/graph/abstract-graph.ts +1 -1
  72. package/src/data-structures/graph/map-graph.ts +2 -2
  73. package/src/data-structures/linked-list/doubly-linked-list.ts +62 -56
  74. package/src/data-structures/linked-list/singly-linked-list.ts +118 -13
  75. package/src/data-structures/matrix/matrix2d.ts +1 -3
  76. package/src/data-structures/matrix/vector2d.ts +0 -2
  77. package/src/data-structures/queue/deque.ts +22 -22
  78. package/src/data-structures/queue/queue.ts +3 -3
  79. package/src/interfaces/binary-tree.ts +2 -2
  80. package/src/types/data-structures/binary-tree/binary-tree.ts +0 -4
  81. package/src/types/helpers.ts +1 -7
  82. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +141 -1
  83. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +289 -47
  84. package/test/unit/data-structures/binary-tree/bst.test.ts +391 -1
  85. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +73 -7
  86. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +241 -186
  87. package/test/unit/data-structures/graph/directed-graph.test.ts +34 -4
  88. package/test/unit/data-structures/graph/map-graph.test.ts +82 -1
  89. package/test/unit/data-structures/graph/undirected-graph.test.ts +82 -0
  90. package/test/unit/data-structures/hash/coordinate-map.test.ts +20 -0
  91. package/test/unit/data-structures/hash/coordinate-set.test.ts +25 -0
  92. package/test/unit/data-structures/hash/hash-table.test.ts +3 -1
  93. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +69 -6
  94. package/test/unit/data-structures/linked-list/linked-list.test.ts +2 -2
  95. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +59 -12
  96. package/test/unit/data-structures/matrix/matrix2d.test.ts +207 -0
  97. package/test/unit/data-structures/matrix/navigator.test.ts +166 -1
  98. package/test/unit/data-structures/matrix/vector2d.test.ts +171 -0
  99. package/test/unit/data-structures/queue/deque.test.ts +283 -20
  100. package/test/unit/data-structures/queue/queue.test.ts +10 -8
@@ -209,7 +209,7 @@ class BST extends binary_tree_1.BinaryTree {
209
209
  * callback.
210
210
  * @param {ReturnType<C> | N} identifier - The `nodeProperty` parameter is used to specify the
211
211
  * property of the binary tree node that you want to search for. It can be either a specific key
212
- * value (`BinaryTreeNodeKey`) or a custom callback function (`MapCallback<N>`) that determines
212
+ * value (`BinaryTreeNodeKey`) or a custom callback function (`OneParamCallback<N>`) that determines
213
213
  * whether a node matches the desired property.
214
214
  * @param callback - The `callback` parameter is a function that is used to determine whether a node
215
215
  * matches the desired property. It takes a node as input and returns a boolean value indicating
@@ -340,7 +340,7 @@ class BST extends binary_tree_1.BinaryTree {
340
340
  * (`BinaryTreeNodeKey`), or `null` to
341
341
  * @param iterationType - The `iterationType` parameter determines whether the traversal should be
342
342
  * done recursively or iteratively. It can have two possible values:
343
- * @returns The function `lesserOrGreaterTraverse` returns an array of `MapCallbackReturn<N>`.
343
+ * @returns The function `lesserOrGreaterTraverse` returns an array of `ReturnType<OneParamCallback<N>>`.
344
344
  */
345
345
  lesserOrGreaterTraverse(callback = this._defaultCallbackByKey, lesserOrGreater = types_1.CP.lt, targetNode = this.root, iterationType = this.iterationType) {
346
346
  if (typeof targetNode === 'number')
@@ -6,7 +6,7 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import type { BinaryTreeNodeKey, TreeMultisetNodeNested, TreeMultisetOptions } from '../../types';
9
- import { BinaryTreeDeletedResult, IterationType, MapCallback } from '../../types';
9
+ import { BinaryTreeDeletedResult, IterationType, OneParamCallback } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  import { AVLTree, AVLTreeNode } from './avl-tree';
12
12
  export declare class TreeMultisetNode<V = any, N extends TreeMultisetNode<V, N> = TreeMultisetNodeNested<V>> extends AVLTreeNode<V, N> {
@@ -105,7 +105,7 @@ export declare class TreeMultiset<V = any, N extends TreeMultisetNode<V, N> = Tr
105
105
  * decremented by 1 and
106
106
  * @returns The method `delete` returns an array of `BinaryTreeDeletedResult<N>` objects.
107
107
  */
108
- delete<C extends MapCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
108
+ delete<C extends OneParamCallback<N>>(identifier: ReturnType<C>, callback?: C, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
109
109
  /**
110
110
  * The clear() function clears the contents of a data structure and sets the count to zero.
111
111
  */
@@ -103,7 +103,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any> = Abst
103
103
  * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
104
104
  * were removed.
105
105
  */
106
- removeAllVertices(vertices: V[] | VertexKey[]): boolean;
106
+ removeManyVertices(vertices: V[] | VertexKey[]): boolean;
107
107
  /**
108
108
  * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
109
109
  * @param {VertexKey | V} v1 - The parameter v1 can be either a VertexKey or a V. A VertexKey represents the unique
@@ -136,7 +136,7 @@ class AbstractGraph {
136
136
  * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertices
137
137
  * were removed.
138
138
  */
139
- removeAllVertices(vertices) {
139
+ removeManyVertices(vertices) {
140
140
  const removed = [];
141
141
  for (const v of vertices) {
142
142
  removed.push(this.deleteVertex(v));
@@ -62,7 +62,7 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
62
62
  * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
63
63
  * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
64
64
  */
65
- createVertex(key: VertexKey, val?: V['val'], lat?: number, long?: number): V;
65
+ createVertex(key: VertexKey, lat?: number, long?: number, val?: V['val']): V;
66
66
  /**
67
67
  * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
68
68
  * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
@@ -92,7 +92,7 @@ class MapGraph extends directed_graph_1.DirectedGraph {
92
92
  * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
93
93
  * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
94
94
  */
95
- createVertex(key, val, lat = this.origin[0], long = this.origin[1]) {
95
+ createVertex(key, lat = this.origin[0], long = this.origin[1], val) {
96
96
  return new MapVertex(key, lat, long, val);
97
97
  }
98
98
  /**
@@ -60,11 +60,11 @@ export declare class DoublyLinkedList<E = any> {
60
60
  */
61
61
  pop(): E | undefined;
62
62
  /**
63
- * The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
63
+ * The `popLast()` function removes and returns the value of the last node in a doubly linked list.
64
64
  * @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
65
65
  * list is empty, it returns null.
66
66
  */
67
- pollLast(): E | undefined;
67
+ popLast(): E | undefined;
68
68
  /**
69
69
  * The `shift()` function removes and returns the value of the first node in a doubly linked list.
70
70
  * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
@@ -72,11 +72,11 @@ export declare class DoublyLinkedList<E = any> {
72
72
  */
73
73
  shift(): E | undefined;
74
74
  /**
75
- * The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
75
+ * The `popFirst()` function removes and returns the value of the first node in a doubly linked list.
76
76
  * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
77
77
  * list.
78
78
  */
79
- pollFirst(): E | undefined;
79
+ popFirst(): E | undefined;
80
80
  /**
81
81
  * The unshift function adds a new node with the given value to the beginning of a doubly linked list.
82
82
  * @param {E} val - The `val` parameter represents the value of the new node that will be added to the beginning of the
@@ -90,15 +90,15 @@ export declare class DoublyLinkedList<E = any> {
90
90
  */
91
91
  addFirst(val: E): void;
92
92
  /**
93
- * The `peekFirst` function returns the first node in a doubly linked list, or null if the list is empty.
94
- * @returns The method `peekFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
93
+ * The `getFirst` function returns the first node in a doubly linked list, or null if the list is empty.
94
+ * @returns The method `getFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
95
95
  */
96
- peekFirst(): E | undefined;
96
+ getFirst(): E | undefined;
97
97
  /**
98
- * The `peekLast` function returns the last node in a doubly linked list, or null if the list is empty.
99
- * @returns The method `peekLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
98
+ * The `getLast` function returns the last node in a doubly linked list, or null if the list is empty.
99
+ * @returns The method `getLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
100
100
  */
101
- peekLast(): E | undefined;
101
+ getLast(): E | undefined;
102
102
  /**
103
103
  * The `getAt` function returns the value at a specified index in a linked list, or null if the index is out of bounds.
104
104
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
@@ -123,7 +123,7 @@ export declare class DoublyLinkedList<E = any> {
123
123
  * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
124
124
  * is found in the linked list. If no such node is found, it returns `null`.
125
125
  */
126
- findNode(val: E | null): DoublyLinkedListNode<E> | null;
126
+ getNode(val: E | null): DoublyLinkedListNode<E> | null;
127
127
  /**
128
128
  * The `insert` function inserts a value at a specified index in a doubly linked list.
129
129
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
@@ -134,6 +134,17 @@ export declare class DoublyLinkedList<E = any> {
134
134
  * if the index is out of bounds.
135
135
  */
136
136
  insertAt(index: number, val: E): boolean;
137
+ /**
138
+ * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
139
+ * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
140
+ * before which the new value will be inserted. It can be either the value of the existing node or the existing node
141
+ * itself.
142
+ * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
143
+ * list.
144
+ * @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
145
+ * insertion fails.
146
+ */
147
+ insertBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
137
148
  /**
138
149
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
139
150
  * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
@@ -142,8 +153,14 @@ export declare class DoublyLinkedList<E = any> {
142
153
  * bounds.
143
154
  */
144
155
  deleteAt(index: number): E | undefined;
145
- delete(valOrNode: E): boolean;
146
- delete(valOrNode: DoublyLinkedListNode<E>): boolean;
156
+ /**
157
+ * The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
158
+ * @param {E | DoublyLinkedListNode<E>} valOrNode - The `valOrNode` parameter can accept either a value of type `E` or
159
+ * a `DoublyLinkedListNode<E>` object.
160
+ * @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
161
+ * deleted from the doubly linked list, and `false` if the value or node was not found in the list.
162
+ */
163
+ delete(valOrNode: E | DoublyLinkedListNode<E> | null): boolean;
147
164
  /**
148
165
  * The `toArray` function converts a linked list into an array.
149
166
  * @returns The `toArray()` method is returning an array of type `E[]`.
@@ -175,19 +192,19 @@ export declare class DoublyLinkedList<E = any> {
175
192
  */
176
193
  indexOf(val: E): number;
177
194
  /**
178
- * The `findLast` function iterates through a linked list from the last node to the first node and returns the last
195
+ * The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
179
196
  * value that satisfies the given callback function, or null if no value satisfies the callback.
180
197
  * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
181
198
  * function is used to determine whether a given value satisfies a certain condition.
182
- * @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
199
+ * @returns The method `findBackward` returns the last value in the linked list that satisfies the condition specified by
183
200
  * the callback function. If no value satisfies the condition, it returns `null`.
184
201
  */
185
- findLast(callback: (val: E) => boolean): E | null;
202
+ findBackward(callback: (val: E) => boolean): E | null;
186
203
  /**
187
- * The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
188
- * @returns The `toArrayReverse()` function returns an array of type `E[]`.
204
+ * The `toArrayBackward` function converts a doubly linked list into an array in reverse order.
205
+ * @returns The `toArrayBackward()` function returns an array of type `E[]`.
189
206
  */
190
- toArrayReverse(): E[];
207
+ toArrayBackward(): E[];
191
208
  /**
192
209
  * The `reverse` function reverses the order of the elements in a doubly linked list.
193
210
  */
@@ -227,17 +244,18 @@ export declare class DoublyLinkedList<E = any> {
227
244
  * elements in the linked list.
228
245
  */
229
246
  reduce<U>(callback: (accumulator: U, val: E) => U, initialValue: U): U;
230
- insertAfter(existingValueOrNode: E, newValue: E): boolean;
231
- insertAfter(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
232
247
  /**
233
- * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
248
+ * The `insertAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
234
249
  * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
235
- * before which the new value will be inserted. It can be either the value of the existing node or the existing node
250
+ * after which the new value will be inserted. It can be either the value of the existing node or the existing node
236
251
  * itself.
237
- * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
238
- * list.
239
- * @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
240
- * insertion fails.
252
+ * @param {E} newValue - The value that you want to insert into the doubly linked list.
253
+ * @returns The method returns a boolean value. It returns true if the insertion is successful, and false if the
254
+ * existing value or node is not found in the doubly linked list.
241
255
  */
242
- insertBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
256
+ insertAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
257
+ /**
258
+ * The function returns an iterator that iterates over the values of a linked list.
259
+ */
260
+ [Symbol.iterator](): Generator<E, void, unknown>;
243
261
  }
@@ -130,11 +130,11 @@ class DoublyLinkedList {
130
130
  return removedNode.val;
131
131
  }
132
132
  /**
133
- * The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
133
+ * The `popLast()` function removes and returns the value of the last node in a doubly linked list.
134
134
  * @returns The method is returning the value of the removed node (removedNode.val) if the list is not empty. If the
135
135
  * list is empty, it returns null.
136
136
  */
137
- pollLast() {
137
+ popLast() {
138
138
  return this.pop();
139
139
  }
140
140
  /**
@@ -158,11 +158,11 @@ class DoublyLinkedList {
158
158
  return removedNode.val;
159
159
  }
160
160
  /**
161
- * The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
161
+ * The `popFirst()` function removes and returns the value of the first node in a doubly linked list.
162
162
  * @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
163
163
  * list.
164
164
  */
165
- pollFirst() {
165
+ popFirst() {
166
166
  return this.shift();
167
167
  }
168
168
  /**
@@ -192,17 +192,17 @@ class DoublyLinkedList {
192
192
  this.unshift(val);
193
193
  }
194
194
  /**
195
- * The `peekFirst` function returns the first node in a doubly linked list, or null if the list is empty.
196
- * @returns The method `peekFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
195
+ * The `getFirst` function returns the first node in a doubly linked list, or null if the list is empty.
196
+ * @returns The method `getFirst()` returns the first node of the doubly linked list, or `null` if the list is empty.
197
197
  */
198
- peekFirst() {
198
+ getFirst() {
199
199
  return this.head?.val;
200
200
  }
201
201
  /**
202
- * The `peekLast` function returns the last node in a doubly linked list, or null if the list is empty.
203
- * @returns The method `peekLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
202
+ * The `getLast` function returns the last node in a doubly linked list, or null if the list is empty.
203
+ * @returns The method `getLast()` returns the last node of the doubly linked list, or `null` if the list is empty.
204
204
  */
205
- peekLast() {
205
+ getLast() {
206
206
  return this.tail?.val;
207
207
  }
208
208
  /**
@@ -245,7 +245,7 @@ class DoublyLinkedList {
245
245
  * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
246
246
  * is found in the linked list. If no such node is found, it returns `null`.
247
247
  */
248
- findNode(val) {
248
+ getNode(val) {
249
249
  let current = this.head;
250
250
  while (current) {
251
251
  if (current.val === val) {
@@ -285,6 +285,40 @@ class DoublyLinkedList {
285
285
  this._length++;
286
286
  return true;
287
287
  }
288
+ /**
289
+ * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
290
+ * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
291
+ * before which the new value will be inserted. It can be either the value of the existing node or the existing node
292
+ * itself.
293
+ * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
294
+ * list.
295
+ * @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
296
+ * insertion fails.
297
+ */
298
+ insertBefore(existingValueOrNode, newValue) {
299
+ let existingNode;
300
+ if (existingValueOrNode instanceof DoublyLinkedListNode) {
301
+ existingNode = existingValueOrNode;
302
+ }
303
+ else {
304
+ existingNode = this.getNode(existingValueOrNode);
305
+ }
306
+ if (existingNode) {
307
+ const newNode = new DoublyLinkedListNode(newValue);
308
+ newNode.prev = existingNode.prev;
309
+ if (existingNode.prev) {
310
+ existingNode.prev.next = newNode;
311
+ }
312
+ newNode.next = existingNode;
313
+ existingNode.prev = newNode;
314
+ if (existingNode === this.head) {
315
+ this.head = newNode;
316
+ }
317
+ this._length++;
318
+ return true;
319
+ }
320
+ return false;
321
+ }
288
322
  /**
289
323
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
290
324
  * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
@@ -320,7 +354,7 @@ class DoublyLinkedList {
320
354
  node = valOrNode;
321
355
  }
322
356
  else {
323
- node = this.findNode(valOrNode);
357
+ node = this.getNode(valOrNode);
324
358
  }
325
359
  if (node) {
326
360
  if (node === this.head) {
@@ -405,14 +439,14 @@ class DoublyLinkedList {
405
439
  return -1;
406
440
  }
407
441
  /**
408
- * The `findLast` function iterates through a linked list from the last node to the first node and returns the last
442
+ * The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
409
443
  * value that satisfies the given callback function, or null if no value satisfies the callback.
410
444
  * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
411
445
  * function is used to determine whether a given value satisfies a certain condition.
412
- * @returns The method `findLast` returns the last value in the linked list that satisfies the condition specified by
446
+ * @returns The method `findBackward` returns the last value in the linked list that satisfies the condition specified by
413
447
  * the callback function. If no value satisfies the condition, it returns `null`.
414
448
  */
415
- findLast(callback) {
449
+ findBackward(callback) {
416
450
  let current = this.tail;
417
451
  while (current) {
418
452
  if (callback(current.val)) {
@@ -423,10 +457,10 @@ class DoublyLinkedList {
423
457
  return null;
424
458
  }
425
459
  /**
426
- * The `toArrayReverse` function converts a doubly linked list into an array in reverse order.
427
- * @returns The `toArrayReverse()` function returns an array of type `E[]`.
460
+ * The `toArrayBackward` function converts a doubly linked list into an array in reverse order.
461
+ * @returns The `toArrayBackward()` function returns an array of type `E[]`.
428
462
  */
429
- toArrayReverse() {
463
+ toArrayBackward() {
430
464
  const array = [];
431
465
  let current = this.tail;
432
466
  while (current) {
@@ -531,7 +565,7 @@ class DoublyLinkedList {
531
565
  existingNode = existingValueOrNode;
532
566
  }
533
567
  else {
534
- existingNode = this.findNode(existingValueOrNode);
568
+ existingNode = this.getNode(existingValueOrNode);
535
569
  }
536
570
  if (existingNode) {
537
571
  const newNode = new DoublyLinkedListNode(newValue);
@@ -550,38 +584,14 @@ class DoublyLinkedList {
550
584
  return false;
551
585
  }
552
586
  /**
553
- * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
554
- * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
555
- * before which the new value will be inserted. It can be either the value of the existing node or the existing node
556
- * itself.
557
- * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
558
- * list.
559
- * @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
560
- * insertion fails.
587
+ * The function returns an iterator that iterates over the values of a linked list.
561
588
  */
562
- insertBefore(existingValueOrNode, newValue) {
563
- let existingNode;
564
- if (existingValueOrNode instanceof DoublyLinkedListNode) {
565
- existingNode = existingValueOrNode;
566
- }
567
- else {
568
- existingNode = this.findNode(existingValueOrNode);
569
- }
570
- if (existingNode) {
571
- const newNode = new DoublyLinkedListNode(newValue);
572
- newNode.prev = existingNode.prev;
573
- if (existingNode.prev) {
574
- existingNode.prev.next = newNode;
575
- }
576
- newNode.next = existingNode;
577
- existingNode.prev = newNode;
578
- if (existingNode === this.head) {
579
- this.head = newNode;
580
- }
581
- this._length++;
582
- return true;
589
+ *[Symbol.iterator]() {
590
+ let current = this.head;
591
+ while (current) {
592
+ yield current.val;
593
+ current = current.next;
583
594
  }
584
- return false;
585
595
  }
586
596
  }
587
597
  exports.DoublyLinkedList = DoublyLinkedList;
@@ -39,13 +39,18 @@ export declare class SinglyLinkedList<E = any> {
39
39
  * @returns The `fromArray` function returns a `SinglyLinkedList` object.
40
40
  */
41
41
  static fromArray<E>(data: E[]): SinglyLinkedList<E>;
42
- getLength(): number;
43
42
  /**
44
- * The `push` function adds a new node with the given data to the end of a singly linked list.
45
- * @param {E} data - The "data" parameter represents the value that you want to add to the linked list. It can be of
43
+ * The `push` function adds a new node with the given val to the end of a singly linked list.
44
+ * @param {E} val - The "val" parameter represents the value that you want to add to the linked list. It can be of
46
45
  * any type (E) as specified in the generic type declaration of the class or function.
47
46
  */
48
- push(data: E): void;
47
+ push(val: E): void;
48
+ /**
49
+ * The `push` function adds a new node with the given val to the end of a singly linked list.
50
+ * @param {E} val - The "val" parameter represents the value that you want to add to the linked list. It can be of
51
+ * any type (E) as specified in the generic type declaration of the class or function.
52
+ */
53
+ addLast(val: E): void;
49
54
  /**
50
55
  * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
51
56
  * pointers accordingly.
@@ -53,17 +58,35 @@ export declare class SinglyLinkedList<E = any> {
53
58
  * the linked list is empty, it returns `null`.
54
59
  */
55
60
  pop(): E | undefined;
61
+ /**
62
+ * The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
63
+ * pointers accordingly.
64
+ * @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
65
+ * the linked list is empty, it returns `null`.
66
+ */
67
+ popLast(): E | undefined;
56
68
  /**
57
69
  * The `shift()` function removes and returns the value of the first node in a linked list.
58
70
  * @returns The value of the node that is being removed from the beginning of the linked list.
59
71
  */
60
72
  shift(): E | undefined;
73
+ /**
74
+ * The `popFirst()` function removes and returns the value of the first node in a linked list.
75
+ * @returns The value of the node that is being removed from the beginning of the linked list.
76
+ */
77
+ popFirst(): E | undefined;
61
78
  /**
62
79
  * The unshift function adds a new node with the given value to the beginning of a singly linked list.
63
80
  * @param {E} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
64
81
  * linked list.
65
82
  */
66
83
  unshift(val: E): void;
84
+ /**
85
+ * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
86
+ * @param {E} val - The parameter "val" represents the value of the new node that will be added to the beginning of the
87
+ * linked list.
88
+ */
89
+ addFirst(val: E): void;
67
90
  /**
68
91
  * The function `getAt` returns the value at a specified index in a linked list, or null if the index is out of range.
69
92
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
@@ -148,7 +171,7 @@ export declare class SinglyLinkedList<E = any> {
148
171
  * @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
149
172
  * the specified value is found, the function returns `null`.
150
173
  */
151
- findNode(value: E): SinglyLinkedListNode<E> | null;
174
+ getNode(value: E): SinglyLinkedListNode<E> | null;
152
175
  /**
153
176
  * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
154
177
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
@@ -158,13 +181,58 @@ export declare class SinglyLinkedList<E = any> {
158
181
  * inserted before the existing value, and `false` otherwise.
159
182
  */
160
183
  insertBefore(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
161
- insertAfter(existingValueOrNode: E, newValue: E): boolean;
162
- insertAfter(existingValueOrNode: SinglyLinkedListNode<E>, newValue: E): boolean;
184
+ /**
185
+ * The `insertAfter` function inserts a new node with a given value after an existing node in a singly linked list.
186
+ * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
187
+ * the new value will be inserted. It can be either the value of the existing node or the existing node itself.
188
+ * @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
189
+ * @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
190
+ * existing value or node, and false if the existing value or node was not found in the linked list.
191
+ */
192
+ insertAfter(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
163
193
  /**
164
194
  * The function counts the number of occurrences of a given value in a linked list.
165
195
  * @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
166
196
  * @returns The count of occurrences of the given value in the linked list.
167
197
  */
168
198
  countOccurrences(value: E): number;
199
+ /**
200
+ * The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
201
+ * @param callback - The callback parameter is a function that takes two arguments: val and index. The val argument
202
+ * represents the value of the current node in the linked list, and the index argument represents the index of the
203
+ * current node in the linked list.
204
+ */
205
+ forEach(callback: (val: E, index: number) => void): void;
206
+ /**
207
+ * The `map` function takes a callback function and applies it to each element in the SinglyLinkedList, returning a new
208
+ * SinglyLinkedList with the transformed values.
209
+ * @param callback - The callback parameter is a function that takes a value of type E (the type of values stored in
210
+ * the original SinglyLinkedList) and returns a value of type U (the type of values that will be stored in the mapped
211
+ * SinglyLinkedList).
212
+ * @returns The `map` function is returning a new instance of `SinglyLinkedList<U>` that contains the mapped values.
213
+ */
214
+ map<U>(callback: (val: E) => U): SinglyLinkedList<U>;
215
+ /**
216
+ * The `filter` function iterates through a SinglyLinkedList and returns a new SinglyLinkedList containing only the
217
+ * elements that satisfy the given callback function.
218
+ * @param callback - The `callback` parameter is a function that takes a value of type `E` and returns a boolean value.
219
+ * It is used to determine whether a value should be included in the filtered list or not.
220
+ * @returns The filtered list, which is an instance of the SinglyLinkedList class.
221
+ */
222
+ filter(callback: (val: E) => boolean): SinglyLinkedList<E>;
223
+ /**
224
+ * The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
225
+ * single value.
226
+ * @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `val`. It is
227
+ * used to perform a specific operation on each element of the linked list.
228
+ * @param {U} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
229
+ * point for the reduction operation.
230
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
231
+ * elements in the linked list.
232
+ */
233
+ reduce<U>(callback: (accumulator: U, val: E) => U, initialValue: U): U;
234
+ /**
235
+ * The function returns an iterator that iterates over the values of a linked list.
236
+ */
169
237
  [Symbol.iterator](): Generator<E, void, unknown>;
170
238
  }