min-heap-typed 1.50.1 → 1.50.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 (67) hide show
  1. package/dist/data-structures/base/iterable-base.d.ts +114 -9
  2. package/dist/data-structures/base/iterable-base.js +143 -7
  3. package/dist/data-structures/binary-tree/avl-tree.d.ts +43 -46
  4. package/dist/data-structures/binary-tree/avl-tree.js +68 -71
  5. package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
  6. package/dist/data-structures/binary-tree/binary-tree.js +484 -376
  7. package/dist/data-structures/binary-tree/bst.d.ts +54 -74
  8. package/dist/data-structures/binary-tree/bst.js +30 -71
  9. package/dist/data-structures/binary-tree/rb-tree.d.ts +78 -60
  10. package/dist/data-structures/binary-tree/rb-tree.js +84 -89
  11. package/dist/data-structures/binary-tree/tree-multimap.d.ts +37 -56
  12. package/dist/data-structures/binary-tree/tree-multimap.js +64 -85
  13. package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
  14. package/dist/data-structures/graph/abstract-graph.js +3 -0
  15. package/dist/data-structures/graph/directed-graph.d.ts +14 -0
  16. package/dist/data-structures/graph/directed-graph.js +26 -0
  17. package/dist/data-structures/graph/map-graph.d.ts +8 -0
  18. package/dist/data-structures/graph/map-graph.js +14 -0
  19. package/dist/data-structures/graph/undirected-graph.d.ts +16 -0
  20. package/dist/data-structures/graph/undirected-graph.js +25 -0
  21. package/dist/data-structures/hash/hash-map.d.ts +121 -15
  22. package/dist/data-structures/hash/hash-map.js +160 -25
  23. package/dist/data-structures/heap/heap.d.ts +66 -6
  24. package/dist/data-structures/heap/heap.js +66 -6
  25. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
  26. package/dist/data-structures/linked-list/doubly-linked-list.js +70 -64
  27. package/dist/data-structures/linked-list/singly-linked-list.d.ts +128 -103
  28. package/dist/data-structures/linked-list/singly-linked-list.js +130 -112
  29. package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  30. package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
  31. package/dist/data-structures/matrix/matrix.d.ts +35 -4
  32. package/dist/data-structures/matrix/matrix.js +50 -11
  33. package/dist/data-structures/queue/deque.d.ts +49 -19
  34. package/dist/data-structures/queue/deque.js +101 -47
  35. package/dist/data-structures/queue/queue.d.ts +39 -5
  36. package/dist/data-structures/queue/queue.js +47 -5
  37. package/dist/data-structures/stack/stack.d.ts +16 -0
  38. package/dist/data-structures/stack/stack.js +22 -0
  39. package/dist/data-structures/trie/trie.d.ts +38 -1
  40. package/dist/data-structures/trie/trie.js +41 -0
  41. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  42. package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
  43. package/dist/types/utils/utils.d.ts +1 -0
  44. package/package.json +2 -2
  45. package/src/data-structures/base/iterable-base.ts +172 -19
  46. package/src/data-structures/binary-tree/avl-tree.ts +97 -97
  47. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  48. package/src/data-structures/binary-tree/bst.ts +89 -131
  49. package/src/data-structures/binary-tree/rb-tree.ts +127 -155
  50. package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
  51. package/src/data-structures/graph/abstract-graph.ts +4 -0
  52. package/src/data-structures/graph/directed-graph.ts +30 -0
  53. package/src/data-structures/graph/map-graph.ts +15 -0
  54. package/src/data-structures/graph/undirected-graph.ts +28 -0
  55. package/src/data-structures/hash/hash-map.ts +175 -34
  56. package/src/data-structures/heap/heap.ts +66 -6
  57. package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
  58. package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
  59. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  60. package/src/data-structures/matrix/matrix.ts +52 -12
  61. package/src/data-structures/queue/deque.ts +108 -49
  62. package/src/data-structures/queue/queue.ts +51 -5
  63. package/src/data-structures/stack/stack.ts +24 -0
  64. package/src/data-structures/trie/trie.ts +45 -1
  65. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  66. package/src/types/data-structures/hash/hash-map.ts +4 -3
  67. package/src/types/utils/utils.ts +2 -0
@@ -16,7 +16,10 @@ class SinglyLinkedListNode {
16
16
  exports.SinglyLinkedListNode = SinglyLinkedListNode;
17
17
  class SinglyLinkedList extends base_1.IterableElementBase {
18
18
  /**
19
- * The constructor initializes the linked list with an empty head, tail, and length.
19
+ * The constructor initializes a new instance of a class with an optional iterable of elements.
20
+ * @param elements - The `elements` parameter is an optional iterable object that contains the
21
+ * initial elements to be added to the instance of the class. If no `elements` are provided, an empty
22
+ * array will be used as the default value.
20
23
  */
21
24
  constructor(elements = []) {
22
25
  super();
@@ -26,22 +29,36 @@ class SinglyLinkedList extends base_1.IterableElementBase {
26
29
  this.push(el);
27
30
  }
28
31
  }
32
+ /**
33
+ * The `head` function returns the first node of a singly linked list.
34
+ * @returns The method is returning either a SinglyLinkedListNode object or undefined.
35
+ */
29
36
  get head() {
30
37
  return this._head;
31
38
  }
39
+ /**
40
+ * The `tail` function returns the last node of a singly linked list.
41
+ * @returns The method is returning either a SinglyLinkedListNode object or undefined.
42
+ */
32
43
  get tail() {
33
44
  return this._tail;
34
45
  }
46
+ /**
47
+ * The function returns the size of an object.
48
+ * @returns The size of the object, which is a number.
49
+ */
35
50
  get size() {
36
51
  return this._size;
37
52
  }
38
53
  /**
39
- * Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
40
- * Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
54
+ * Time Complexity: O(n)
55
+ * Space Complexity: O(n)
56
+ * Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
57
+ * Linear space, as it creates a new node for each element in the array.
41
58
  */
42
59
  /**
43
- * Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
44
- * Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
60
+ * Time Complexity: O(n)
61
+ * Space Complexity: O(n)
45
62
  *
46
63
  * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
47
64
  * array.
@@ -56,12 +73,14 @@ class SinglyLinkedList extends base_1.IterableElementBase {
56
73
  return singlyLinkedList;
57
74
  }
58
75
  /**
59
- * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
60
- * Space Complexity: O(1) - Constant space, as it only creates a new node.
76
+ * Time Complexity: O(1)
77
+ * Space Complexity: O(1)
78
+ * Constant time, as it involves basic pointer adjustments.
79
+ * Constant space, as it only creates a new node.
61
80
  */
62
81
  /**
63
- * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
64
- * Space Complexity: O(1) - Constant space, as it only creates a new node.
82
+ * Time Complexity: O(1)
83
+ * Space Complexity: O(1)
65
84
  *
66
85
  * The `push` function adds a new node with the given value to the end of a singly linked list.
67
86
  * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
@@ -81,12 +100,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
81
100
  return true;
82
101
  }
83
102
  /**
84
- * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
85
- * Space Complexity: O(1) - Constant space, as it only creates a new node.
103
+ * Time Complexity: O(1)
104
+ * Space Complexity: O(1)
86
105
  */
87
106
  /**
88
- * Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
89
- * Space Complexity: O(1) - Constant space, as it only creates a new node.
107
+ * Time Complexity: O(1)
108
+ * Space Complexity: O(1)
90
109
  *
91
110
  * The `push` function adds a new node with the given value to the end of a singly linked list.
92
111
  * @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
@@ -96,12 +115,13 @@ class SinglyLinkedList extends base_1.IterableElementBase {
96
115
  return this.push(value);
97
116
  }
98
117
  /**
99
- * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
100
- * Space Complexity: O(1) - Constant space.
118
+ * Time Complexity: O(n)
119
+ * Space Complexity: O(1)
120
+ * Linear time in the worst case, as it may need to traverse the list to find the last element.
101
121
  */
102
122
  /**
103
- * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
104
- * Space Complexity: O(1) - Constant space.
123
+ * Time Complexity: O(n)
124
+ * Space Complexity: O(1)
105
125
  *
106
126
  * The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
107
127
  * pointers accordingly.
@@ -129,12 +149,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
129
149
  return value;
130
150
  }
131
151
  /**
132
- * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
133
- * Space Complexity: O(1) - Constant space.
152
+ * Time Complexity: O(n)
153
+ * Space Complexity: O(1)
134
154
  */
135
155
  /**
136
- * Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
137
- * Space Complexity: O(1) - Constant space.
156
+ * Time Complexity: O(n)
157
+ * Space Complexity: O(1)
138
158
  *
139
159
  * The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
140
160
  * pointers accordingly.
@@ -145,12 +165,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
145
165
  return this.pop();
146
166
  }
147
167
  /**
148
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
149
- * Space Complexity: O(1) - Constant space.
168
+ * Time Complexity: O(1)
169
+ * Space Complexity: O(1)
150
170
  */
151
171
  /**
152
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
153
- * Space Complexity: O(1) - Constant space.
172
+ * Time Complexity: O(1)
173
+ * Space Complexity: O(1)
154
174
  *
155
175
  * The `shift()` function removes and returns the value of the first node in a linked list.
156
176
  * @returns The value of the node that is being removed from the beginning of the linked list.
@@ -164,12 +184,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
164
184
  return removedNode.value;
165
185
  }
166
186
  /**
167
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
168
- * Space Complexity: O(1) - Constant space.
187
+ * Time Complexity: O(1)
188
+ * Space Complexity: O(1)
169
189
  */
170
190
  /**
171
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
172
- * Space Complexity: O(1) - Constant space.
191
+ * Time Complexity: O(1)
192
+ * Space Complexity: O(1)
173
193
  *
174
194
  * The `pollFirst()` function removes and returns the value of the first node in a linked list.
175
195
  * @returns The value of the node that is being removed from the beginning of the linked list.
@@ -178,12 +198,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
178
198
  return this.shift();
179
199
  }
180
200
  /**
181
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
182
- * Space Complexity: O(1) - Constant space.
201
+ * Time Complexity: O(1)
202
+ * Space Complexity: O(1)
183
203
  */
184
204
  /**
185
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
186
- * Space Complexity: O(1) - Constant space.
205
+ * Time Complexity: O(1)
206
+ * Space Complexity: O(1)
187
207
  *
188
208
  * The unshift function adds a new node with the given value to the beginning of a singly linked list.
189
209
  * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
@@ -203,12 +223,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
203
223
  return true;
204
224
  }
205
225
  /**
206
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
207
- * Space Complexity: O(1) - Constant space.
226
+ * Time Complexity: O(1)
227
+ * Space Complexity: O(1)
208
228
  */
209
229
  /**
210
- * Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
211
- * Space Complexity: O(1) - Constant space.
230
+ * Time Complexity: O(1)
231
+ * Space Complexity: O(1)
212
232
  *
213
233
  * The addFirst function adds a new node with the given value to the beginning of a singly linked list.
214
234
  * @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
@@ -218,20 +238,21 @@ class SinglyLinkedList extends base_1.IterableElementBase {
218
238
  return this.unshift(value);
219
239
  }
220
240
  /**
221
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
222
- * Space Complexity: O(1) - Constant space.
241
+ * Time Complexity: O(n)
242
+ * Space Complexity: O(1)
243
+ * Linear time, where n is the index, as it may need to traverse the list to find the desired node.
223
244
  */
224
245
  /**
225
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
226
- * Space Complexity: O(1) - Constant space.
246
+ * Time Complexity: O(n)
247
+ * Space Complexity: O(1)
227
248
  *
228
- * The function `getAt` returns the value at a specified index in a linked list, or undefined if the index is out of range.
249
+ * The function `at` returns the value at a specified index in a linked list, or undefined if the index is out of range.
229
250
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
230
251
  * retrieve from the list.
231
- * @returns The method `getAt(index: number): E | undefined` returns the value at the specified index in the linked list, or
252
+ * @returns The method `at(index: number): E | undefined` returns the value at the specified index in the linked list, or
232
253
  * `undefined` if the index is out of bounds.
233
254
  */
234
- getAt(index) {
255
+ at(index) {
235
256
  if (index < 0 || index >= this.size)
236
257
  return undefined;
237
258
  let current = this.head;
@@ -241,12 +262,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
241
262
  return current.value;
242
263
  }
243
264
  /**
244
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
245
- * Space Complexity: O(1) - Constant space.
265
+ * Time Complexity: O(n)
266
+ * Space Complexity: O(1)
246
267
  */
247
268
  /**
248
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
249
- * Space Complexity: O(1) - Constant space.
269
+ * Time Complexity: O(n)
270
+ * Space Complexity: O(1)
250
271
  *
251
272
  * The function `getNodeAt` returns the node at a given index in a singly linked list.
252
273
  * @param {number} index - The `index` parameter is a number that represents the position of the node we want to
@@ -262,12 +283,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
262
283
  return current;
263
284
  }
264
285
  /**
265
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
266
- * Space Complexity: O(1) - Constant space.
286
+ * Time Complexity: O(n)
287
+ * Space Complexity: O(1)
267
288
  */
268
289
  /**
269
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
270
- * Space Complexity: O(1) - Constant space.
290
+ * Time Complexity: O(n)
291
+ * Space Complexity: O(1)
271
292
  *
272
293
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
273
294
  * @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
@@ -293,12 +314,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
293
314
  return true;
294
315
  }
295
316
  /**
296
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
297
- * Space Complexity: O(1) - Constant space.
317
+ * Time Complexity: O(n)
318
+ * Space Complexity: O(1)
298
319
  */
299
320
  /**
300
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
301
- * Space Complexity: O(1) - Constant space.
321
+ * Time Complexity: O(n)
322
+ * Space Complexity: O(1)
302
323
  *
303
324
  * The delete function removes a node with a specific value from a singly linked list.
304
325
  * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
@@ -340,12 +361,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
340
361
  return false;
341
362
  }
342
363
  /**
343
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
344
- * Space Complexity: O(1) - Constant space.
364
+ * Time Complexity: O(n)
365
+ * Space Complexity: O(1)
345
366
  */
346
367
  /**
347
- * Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
348
- * Space Complexity: O(1) - Constant space.
368
+ * Time Complexity: O(n)
369
+ * Space Complexity: O(1)
349
370
  *
350
371
  * The `addAt` function inserts a value at a specified index in a singly linked list.
351
372
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
@@ -390,12 +411,14 @@ class SinglyLinkedList extends base_1.IterableElementBase {
390
411
  this._size = 0;
391
412
  }
392
413
  /**
393
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
394
- * Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
414
+ * Time Complexity: O(n)
415
+ * Space Complexity: O(n)
416
+ * Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
417
+ * Linear space, as it creates an array with the same length as the list.
395
418
  */
396
419
  /**
397
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
398
- * Space Complexity: O(n) - Linear space, as it creates an array with the same length as the list.
420
+ * Time Complexity: O(n)
421
+ * Space Complexity: O(n)
399
422
  *
400
423
  * The `toArray` function converts a linked list into an array.
401
424
  * @returns The `toArray()` method is returning an array of type `E[]`.
@@ -410,12 +433,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
410
433
  return array;
411
434
  }
412
435
  /**
413
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
414
- * Space Complexity: O(1) - Constant space.
436
+ * Time Complexity: O(n)
437
+ * Space Complexity: O(1)
415
438
  */
416
439
  /**
417
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
418
- * Space Complexity: O(1) - Constant space.
440
+ * Time Complexity: O(n)
441
+ * Space Complexity: O(1)
419
442
  *
420
443
  * The `reverse` function reverses the order of the nodes in a singly linked list.
421
444
  * @returns The reverse() method does not return anything. It has a return type of void.
@@ -436,36 +459,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
436
459
  return this;
437
460
  }
438
461
  /**
439
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
440
- * Space Complexity: O(1) - Constant space.
441
- */
442
- /**
443
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
444
- * Space Complexity: O(1) - Constant space.
445
- *
446
- * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
447
- * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
448
- * function is used to determine whether a particular value in the linked list satisfies a certain condition.
449
- * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
450
- * the callback function. If no element satisfies the condition, it returns `undefined`.
451
- */
452
- find(callback) {
453
- let current = this.head;
454
- while (current) {
455
- if (callback(current.value)) {
456
- return current.value;
457
- }
458
- current = current.next;
459
- }
460
- return undefined;
461
- }
462
- /**
463
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
464
- * Space Complexity: O(1) - Constant space.
462
+ * Time Complexity: O(n)
463
+ * Space Complexity: O(1)
465
464
  */
466
465
  /**
467
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
468
- * Space Complexity: O(1) - Constant space.
466
+ * Time Complexity: O(n)
467
+ * Space Complexity: O(1)
469
468
  *
470
469
  * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
471
470
  * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
@@ -485,12 +484,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
485
484
  return -1;
486
485
  }
487
486
  /**
488
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
489
- * Space Complexity: O(1) - Constant space.
487
+ * Time Complexity: O(n)
488
+ * Space Complexity: O(1)
490
489
  */
491
490
  /**
492
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
493
- * Space Complexity: O(1) - Constant space.
491
+ * Time Complexity: O(n)
492
+ * Space Complexity: O(1)
494
493
  *
495
494
  * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
496
495
  * undefined.
@@ -509,12 +508,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
509
508
  return undefined;
510
509
  }
511
510
  /**
512
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
513
- * Space Complexity: O(1) - Constant space.
511
+ * Time Complexity: O(n)
512
+ * Space Complexity: O(1)
514
513
  */
515
514
  /**
516
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
517
- * Space Complexity: O(1) - Constant space.
515
+ * Time Complexity: O(n)
516
+ * Space Complexity: O(1)
518
517
  *
519
518
  * The `addBefore` function inserts a new value before an existing value in a singly linked list.
520
519
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
@@ -551,12 +550,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
551
550
  return false;
552
551
  }
553
552
  /**
554
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
555
- * Space Complexity: O(1) - Constant space.
553
+ * Time Complexity: O(n)
554
+ * Space Complexity: O(1)
556
555
  */
557
556
  /**
558
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
559
- * Space Complexity: O(1) - Constant space.
557
+ * Time Complexity: O(n)
558
+ * Space Complexity: O(1)
560
559
  *
561
560
  * The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
562
561
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
@@ -586,12 +585,12 @@ class SinglyLinkedList extends base_1.IterableElementBase {
586
585
  return false;
587
586
  }
588
587
  /**
589
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
590
- * Space Complexity: O(1) - Constant space.
588
+ * Time Complexity: O(n)
589
+ * Space Complexity: O(1)
591
590
  */
592
591
  /**
593
- * Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
594
- * Space Complexity: O(1) - Constant space.
592
+ * Time Complexity: O(n)
593
+ * Space Complexity: O(1)
595
594
  *
596
595
  * The function counts the number of occurrences of a given value in a linked list.
597
596
  * @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
@@ -608,6 +607,22 @@ class SinglyLinkedList extends base_1.IterableElementBase {
608
607
  }
609
608
  return count;
610
609
  }
610
+ /**
611
+ * Time Complexity: O(n)
612
+ * Space Complexity: O(n)
613
+ */
614
+ /**
615
+ * Time Complexity: O(n)
616
+ * Space Complexity: O(n)
617
+ *
618
+ * The `clone` function returns a new instance of the `SinglyLinkedList` class with the same values
619
+ * as the original list.
620
+ * @returns The `clone()` method is returning a new instance of the `SinglyLinkedList` class, which
621
+ * is a clone of the original list.
622
+ */
623
+ clone() {
624
+ return new SinglyLinkedList(this.values());
625
+ }
611
626
  /**
612
627
  * Time Complexity: O(n)
613
628
  * Space Complexity: O(n)
@@ -667,6 +682,9 @@ class SinglyLinkedList extends base_1.IterableElementBase {
667
682
  }
668
683
  return mappedList;
669
684
  }
685
+ /**
686
+ * The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
687
+ */
670
688
  *_getIterator() {
671
689
  let current = this.head;
672
690
  while (current) {
@@ -13,46 +13,70 @@ export declare class SkipListNode<K, V> {
13
13
  constructor(key: K, value: V, level: number);
14
14
  }
15
15
  export declare class SkipList<K, V> {
16
+ /**
17
+ * The constructor function initializes a SkipLinkedList object with optional options and elements.
18
+ * @param elements - The `elements` parameter is an iterable containing key-value pairs `[K, V]`. It
19
+ * is used to initialize the SkipLinkedList with the given key-value pairs. If no elements are
20
+ * provided, the SkipLinkedList will be empty.
21
+ * @param {SkipLinkedListOptions} [options] - The `options` parameter is an optional object that can
22
+ * contain two properties:
23
+ */
16
24
  constructor(elements?: Iterable<[K, V]>, options?: SkipLinkedListOptions);
17
25
  protected _head: SkipListNode<K, V>;
26
+ /**
27
+ * The function returns the head node of a SkipList.
28
+ * @returns The method is returning a SkipListNode object with generic key type K and value type V.
29
+ */
18
30
  get head(): SkipListNode<K, V>;
19
31
  protected _level: number;
32
+ /**
33
+ * The function returns the value of the private variable _level.
34
+ * @returns The level property of the object.
35
+ */
20
36
  get level(): number;
21
37
  protected _maxLevel: number;
38
+ /**
39
+ * The function returns the maximum level.
40
+ * @returns The value of the variable `_maxLevel` is being returned.
41
+ */
22
42
  get maxLevel(): number;
23
43
  protected _probability: number;
44
+ /**
45
+ * The function returns the probability value.
46
+ * @returns The probability value stored in the private variable `_probability` is being returned.
47
+ */
24
48
  get probability(): number;
25
49
  /**
26
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
27
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
50
+ * Time Complexity: O(log n)
51
+ * Space Complexity: O(1)
28
52
  */
29
53
  /**
30
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
31
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
54
+ * Time Complexity: O(1)
55
+ * Space Complexity: O(1)
32
56
  *
33
57
  * Get the value of the first element (the smallest element) in the Skip List.
34
58
  * @returns The value of the first element, or undefined if the Skip List is empty.
35
59
  */
36
60
  get first(): V | undefined;
37
61
  /**
38
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
39
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
62
+ * Time Complexity: O(log n)
63
+ * Space Complexity: O(1)
40
64
  */
41
65
  /**
42
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
43
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
66
+ * Time Complexity: O(log n)
67
+ * Space Complexity: O(1)
44
68
  *
45
69
  * Get the value of the last element (the largest element) in the Skip List.
46
70
  * @returns The value of the last element, or undefined if the Skip List is empty.
47
71
  */
48
72
  get last(): V | undefined;
49
73
  /**
50
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
51
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
74
+ * Time Complexity: O(log n)
75
+ * Space Complexity: O(1)
52
76
  */
53
77
  /**
54
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
55
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
78
+ * Time Complexity: O(log n)
79
+ * Space Complexity: O(1)
56
80
  *
57
81
  * The add function adds a new node with a given key and value to a Skip List data structure.
58
82
  * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
@@ -61,12 +85,12 @@ export declare class SkipList<K, V> {
61
85
  */
62
86
  add(key: K, value: V): void;
63
87
  /**
64
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
65
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
88
+ * Time Complexity: O(log n)
89
+ * Space Complexity: O(1)
66
90
  */
67
91
  /**
68
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
69
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
92
+ * Time Complexity: O(log n)
93
+ * Space Complexity: O(1)
70
94
  *
71
95
  * The function `get` retrieves the value associated with a given key from a skip list data structure.
72
96
  * @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
@@ -75,21 +99,23 @@ export declare class SkipList<K, V> {
75
99
  */
76
100
  get(key: K): V | undefined;
77
101
  /**
78
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
79
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
102
+ * Time Complexity: O(log n)
103
+ * Space Complexity: O(1)
80
104
  */
81
105
  /**
82
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
83
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
106
+ * The function checks if a key exists in a data structure.
107
+ * @param {K} key - The parameter "key" is of type K, which represents the type of the key being
108
+ * checked.
109
+ * @returns a boolean value.
84
110
  */
85
111
  has(key: K): boolean;
86
112
  /**
87
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
88
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
113
+ * Time Complexity: O(log n)
114
+ * Space Complexity: O(1)
89
115
  */
90
116
  /**
91
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
92
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
117
+ * Time Complexity: O(log n)
118
+ * Space Complexity: O(1)
93
119
  *
94
120
  * The `delete` function removes a node with a specific key from a Skip List data structure.
95
121
  * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
@@ -98,12 +124,12 @@ export declare class SkipList<K, V> {
98
124
  */
99
125
  delete(key: K): boolean;
100
126
  /**
101
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
102
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
127
+ * Time Complexity: O(log n)
128
+ * Space Complexity: O(1)
103
129
  */
104
130
  /**
105
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
106
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
131
+ * Time Complexity: O(log n)
132
+ * Space Complexity: O(1)
107
133
  *
108
134
  * Get the value of the first element in the Skip List that is greater than the given key.
109
135
  * @param key - the given key.
@@ -111,12 +137,12 @@ export declare class SkipList<K, V> {
111
137
  */
112
138
  higher(key: K): V | undefined;
113
139
  /**
114
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
115
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
140
+ * Time Complexity: O(log n)
141
+ * Space Complexity: O(1)
116
142
  */
117
143
  /**
118
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
119
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
144
+ * Time Complexity: O(log n)
145
+ * Space Complexity: O(1)
120
146
  *
121
147
  * Get the value of the last element in the Skip List that is less than the given key.
122
148
  * @param key - the given key.
@@ -124,12 +150,13 @@ export declare class SkipList<K, V> {
124
150
  */
125
151
  lower(key: K): V | undefined;
126
152
  /**
127
- * Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
128
- * Space Complexity: O(1) - constant space.
153
+ * Time Complexity: O(maxLevel)
154
+ * Space Complexity: O(1)
155
+ * where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
129
156
  */
130
157
  /**
131
- * Time Complexity: O(maxLevel) - where maxLevel is the maximum level of the SkipList, as it may iterate up to maxLevel times in the worst case.
132
- * Space Complexity: O(1) - constant space.
158
+ * Time Complexity: O(maxLevel)
159
+ * Space Complexity: O(1)
133
160
  *
134
161
  * The function "_randomLevel" generates a random level based on a given probability and maximum level.
135
162
  * @returns the level, which is a number.