data-structure-typed 1.49.2 → 1.49.4

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/CHANGELOG.md +1 -1
  2. package/README.md +69 -66
  3. package/README_zh-CN.md +43 -48
  4. package/benchmark/report.html +16 -16
  5. package/benchmark/report.json +187 -187
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +8 -17
  10. package/dist/cjs/data-structures/graph/abstract-graph.js +43 -29
  11. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  12. package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
  13. package/dist/cjs/data-structures/graph/directed-graph.js +6 -2
  14. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -1
  16. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -1
  17. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  18. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
  19. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +49 -49
  20. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  21. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  22. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
  23. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +36 -36
  24. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  25. package/dist/cjs/data-structures/queue/queue.d.ts +33 -33
  26. package/dist/cjs/data-structures/queue/queue.js +40 -40
  27. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  28. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  29. package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
  30. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +8 -17
  31. package/dist/mjs/data-structures/graph/abstract-graph.js +43 -29
  32. package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
  33. package/dist/mjs/data-structures/graph/directed-graph.js +6 -2
  34. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -1
  35. package/dist/mjs/data-structures/graph/undirected-graph.js +1 -1
  36. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
  37. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +47 -47
  38. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
  39. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +36 -36
  40. package/dist/mjs/data-structures/queue/queue.d.ts +33 -33
  41. package/dist/mjs/data-structures/queue/queue.js +39 -39
  42. package/dist/umd/data-structure-typed.js +176 -158
  43. package/dist/umd/data-structure-typed.min.js +2 -2
  44. package/dist/umd/data-structure-typed.min.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/data-structures/binary-tree/binary-tree.ts +1 -1
  47. package/src/data-structures/graph/abstract-graph.ts +56 -27
  48. package/src/data-structures/graph/directed-graph.ts +10 -5
  49. package/src/data-structures/graph/undirected-graph.ts +2 -2
  50. package/src/data-structures/linked-list/doubly-linked-list.ts +53 -53
  51. package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
  52. package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
  53. package/src/data-structures/queue/queue.ts +45 -45
  54. package/test/performance/data-structures/comparison/comparison.test.ts +12 -12
  55. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +16 -27
  56. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -12
  57. package/test/performance/data-structures/queue/deque.test.ts +8 -8
  58. package/test/performance/data-structures/queue/queue.test.ts +5 -5
  59. package/test/performance/data-structures/stack/stack.test.ts +11 -11
  60. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +15 -0
  61. package/test/unit/data-structures/graph/abstract-graph.test.ts +12 -1
  62. package/test/unit/data-structures/graph/directed-graph.test.ts +63 -5
  63. package/test/unit/data-structures/graph/undirected-graph.test.ts +61 -4
  64. package/test/unit/data-structures/hash/hash-map.test.ts +21 -0
  65. package/test/unit/data-structures/heap/heap.test.ts +6 -1
  66. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +27 -0
  67. package/test/utils/big-o.ts +14 -14
@@ -39,6 +39,30 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
39
39
  * Time Complexity: O(n), where n is the size of the input array.
40
40
  * Space Complexity: O(n)
41
41
  */
42
+ /**
43
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
44
+ * Space Complexity: O(1)
45
+ *
46
+ * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
47
+ * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
48
+ */
49
+ get first(): E | undefined;
50
+ /**
51
+ * Time Complexity: O(1)
52
+ * Space Complexity: O(1)
53
+ */
54
+ /**
55
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
56
+ * Space Complexity: O(1)
57
+ *
58
+ * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
59
+ * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
60
+ */
61
+ get last(): E | undefined;
62
+ /**
63
+ * Time Complexity: O(1)
64
+ * Space Complexity: O(1)
65
+ */
42
66
  /**
43
67
  * Time Complexity: O(n), where n is the size of the input array.
44
68
  * Space Complexity: O(n)
@@ -75,7 +99,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
75
99
  */
76
100
  pop(): E | undefined;
77
101
  /**
78
- * Time Complexity: O(1)
102
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
79
103
  * Space Complexity: O(1)
80
104
  */
81
105
  /**
@@ -88,7 +112,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
88
112
  */
89
113
  shift(): E | undefined;
90
114
  /**
91
- * Time Complexity: O(1)
115
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
92
116
  * Space Complexity: O(1)
93
117
  */
94
118
  /**
@@ -198,10 +222,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
198
222
  * existing value or node is not found in the doubly linked list.
199
223
  */
200
224
  addAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
201
- /**
202
- * Time Complexity: O(n), where n is the number of elements in the linked list.
203
- * Space Complexity: O(1)
204
- */
205
225
  /**
206
226
  * Time Complexity: O(n), where n is the number of elements in the linked list.
207
227
  * Space Complexity: O(1)
@@ -213,10 +233,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
213
233
  * bounds.
214
234
  */
215
235
  deleteAt(index: number): boolean;
216
- /**
217
- * Time Complexity: O(n), where n is the number of elements in the linked list.
218
- * Space Complexity: O(1)
219
- */
220
236
  /**
221
237
  * Time Complexity: O(n), where n is the number of elements in the linked list.
222
238
  * Space Complexity: O(1)
@@ -228,11 +244,19 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
228
244
  * deleted from the doubly linked list, and `false` if the value or node was not found in the list.
229
245
  */
230
246
  delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
247
+ /**
248
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
249
+ * Space Complexity: O(1)
250
+ */
231
251
  /**
232
252
  * The function checks if a variable has a size greater than zero and returns a boolean value.
233
253
  * @returns A boolean value is being returned.
234
254
  */
235
255
  isEmpty(): boolean;
256
+ /**
257
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
258
+ * Space Complexity: O(1)
259
+ */
236
260
  /**
237
261
  * The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
238
262
  */
@@ -269,7 +293,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
269
293
  indexOf(value: E): number;
270
294
  /**
271
295
  * Time Complexity: O(n), where n is the number of elements in the linked list.
272
- * Space Complexity: O(1)
296
+ * Space Complexity: O(n)
273
297
  */
274
298
  /**
275
299
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -285,7 +309,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
285
309
  findBackward(callback: (value: E) => boolean): E | undefined;
286
310
  /**
287
311
  * Time Complexity: O(n), where n is the number of elements in the linked list.
288
- * Space Complexity: O(1)
312
+ * Space Complexity: O(n)
289
313
  */
290
314
  /**
291
315
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -295,7 +319,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
295
319
  */
296
320
  reverse(): this;
297
321
  /**
298
- * Time Complexity: O(n), where n is the number of elements in the linked list.
322
+ * Time Complexity: O(n)
299
323
  * Space Complexity: O(n)
300
324
  */
301
325
  /**
@@ -319,8 +343,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
319
343
  */
320
344
  toReversedArray(): E[];
321
345
  /**
322
- * Time Complexity: O(n)
323
- * Space Complexity: O(n)
346
+ * Time Complexity: O(1)
347
+ * Space Complexity: O(1)
324
348
  */
325
349
  /**
326
350
  * Time Complexity: O(n)
@@ -341,8 +365,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
341
365
  */
342
366
  filter(callback: ElementCallback<E, boolean>, thisArg?: any): DoublyLinkedList<E>;
343
367
  /**
344
- * Time Complexity: O(n), where n is the number of elements in the linked list.
345
- * Space Complexity: O(n)
368
+ * Time Complexity: O(1)
369
+ * Space Complexity: O(1)
346
370
  */
347
371
  /**
348
372
  * Time Complexity: O(n)
@@ -388,7 +412,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
388
412
  */
389
413
  pollLast(): E | undefined;
390
414
  /**
391
- * Time Complexity: O(1)
415
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
392
416
  * Space Complexity: O(1)
393
417
  */
394
418
  /**
@@ -401,7 +425,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
401
425
  */
402
426
  pollFirst(): E | undefined;
403
427
  /**
404
- * Time Complexity: O(1)
428
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
405
429
  * Space Complexity: O(1)
406
430
  */
407
431
  /**
@@ -413,30 +437,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
413
437
  * doubly linked list.
414
438
  */
415
439
  addFirst(value: E): void;
416
- /**
417
- * Time Complexity: O(n), where n is the number of elements in the linked list.
418
- * Space Complexity: O(1)
419
- */
420
- /**
421
- * Time Complexity: O(n), where n is the number of elements in the linked list.
422
- * Space Complexity: O(1)
423
- *
424
- * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
425
- * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
426
- */
427
- get first(): E | undefined;
428
- /**
429
- * Time Complexity: O(n), where n is the number of elements in the linked list.
430
- * Space Complexity: O(1)
431
- */
432
- /**
433
- * Time Complexity: O(n), where n is the number of elements in the linked list.
434
- * Space Complexity: O(1)
435
- *
436
- * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
437
- * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
438
- */
439
- get last(): E | undefined;
440
440
  /**
441
441
  * The function returns an iterator that iterates over the values of a linked list.
442
442
  */
@@ -51,6 +51,34 @@ export class DoublyLinkedList extends IterableElementBase {
51
51
  * Time Complexity: O(n), where n is the size of the input array.
52
52
  * Space Complexity: O(n)
53
53
  */
54
+ /**
55
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
56
+ * Space Complexity: O(1)
57
+ *
58
+ * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
59
+ * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
60
+ */
61
+ get first() {
62
+ return this.head?.value;
63
+ }
64
+ /**
65
+ * Time Complexity: O(1)
66
+ * Space Complexity: O(1)
67
+ */
68
+ /**
69
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
70
+ * Space Complexity: O(1)
71
+ *
72
+ * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
73
+ * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
74
+ */
75
+ get last() {
76
+ return this.tail?.value;
77
+ }
78
+ /**
79
+ * Time Complexity: O(1)
80
+ * Space Complexity: O(1)
81
+ */
54
82
  /**
55
83
  * Time Complexity: O(n), where n is the size of the input array.
56
84
  * Space Complexity: O(n)
@@ -120,7 +148,7 @@ export class DoublyLinkedList extends IterableElementBase {
120
148
  return removedNode.value;
121
149
  }
122
150
  /**
123
- * Time Complexity: O(1)
151
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
124
152
  * Space Complexity: O(1)
125
153
  */
126
154
  /**
@@ -147,7 +175,7 @@ export class DoublyLinkedList extends IterableElementBase {
147
175
  return removedNode.value;
148
176
  }
149
177
  /**
150
- * Time Complexity: O(1)
178
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
151
179
  * Space Complexity: O(1)
152
180
  */
153
181
  /**
@@ -361,10 +389,6 @@ export class DoublyLinkedList extends IterableElementBase {
361
389
  }
362
390
  return false;
363
391
  }
364
- /**
365
- * Time Complexity: O(n), where n is the number of elements in the linked list.
366
- * Space Complexity: O(1)
367
- */
368
392
  /**
369
393
  * Time Complexity: O(n), where n is the number of elements in the linked list.
370
394
  * Space Complexity: O(1)
@@ -394,10 +418,6 @@ export class DoublyLinkedList extends IterableElementBase {
394
418
  this._size--;
395
419
  return true;
396
420
  }
397
- /**
398
- * Time Complexity: O(n), where n is the number of elements in the linked list.
399
- * Space Complexity: O(1)
400
- */
401
421
  /**
402
422
  * Time Complexity: O(n), where n is the number of elements in the linked list.
403
423
  * Space Complexity: O(1)
@@ -434,6 +454,10 @@ export class DoublyLinkedList extends IterableElementBase {
434
454
  }
435
455
  return false;
436
456
  }
457
+ /**
458
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
459
+ * Space Complexity: O(1)
460
+ */
437
461
  /**
438
462
  * The function checks if a variable has a size greater than zero and returns a boolean value.
439
463
  * @returns A boolean value is being returned.
@@ -441,6 +465,10 @@ export class DoublyLinkedList extends IterableElementBase {
441
465
  isEmpty() {
442
466
  return this.size === 0;
443
467
  }
468
+ /**
469
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
470
+ * Space Complexity: O(1)
471
+ */
444
472
  /**
445
473
  * The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
446
474
  */
@@ -501,7 +529,7 @@ export class DoublyLinkedList extends IterableElementBase {
501
529
  }
502
530
  /**
503
531
  * Time Complexity: O(n), where n is the number of elements in the linked list.
504
- * Space Complexity: O(1)
532
+ * Space Complexity: O(n)
505
533
  */
506
534
  /**
507
535
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -526,7 +554,7 @@ export class DoublyLinkedList extends IterableElementBase {
526
554
  }
527
555
  /**
528
556
  * Time Complexity: O(n), where n is the number of elements in the linked list.
529
- * Space Complexity: O(1)
557
+ * Space Complexity: O(n)
530
558
  */
531
559
  /**
532
560
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -545,7 +573,7 @@ export class DoublyLinkedList extends IterableElementBase {
545
573
  return this;
546
574
  }
547
575
  /**
548
- * Time Complexity: O(n), where n is the number of elements in the linked list.
576
+ * Time Complexity: O(n)
549
577
  * Space Complexity: O(n)
550
578
  */
551
579
  /**
@@ -585,8 +613,8 @@ export class DoublyLinkedList extends IterableElementBase {
585
613
  return array;
586
614
  }
587
615
  /**
588
- * Time Complexity: O(n)
589
- * Space Complexity: O(n)
616
+ * Time Complexity: O(1)
617
+ * Space Complexity: O(1)
590
618
  */
591
619
  /**
592
620
  * Time Complexity: O(n)
@@ -617,8 +645,8 @@ export class DoublyLinkedList extends IterableElementBase {
617
645
  return filteredList;
618
646
  }
619
647
  /**
620
- * Time Complexity: O(n), where n is the number of elements in the linked list.
621
- * Space Complexity: O(n)
648
+ * Time Complexity: O(1)
649
+ * Space Complexity: O(1)
622
650
  */
623
651
  /**
624
652
  * Time Complexity: O(n)
@@ -676,7 +704,7 @@ export class DoublyLinkedList extends IterableElementBase {
676
704
  return this.pop();
677
705
  }
678
706
  /**
679
- * Time Complexity: O(1)
707
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
680
708
  * Space Complexity: O(1)
681
709
  */
682
710
  /**
@@ -691,7 +719,7 @@ export class DoublyLinkedList extends IterableElementBase {
691
719
  return this.shift();
692
720
  }
693
721
  /**
694
- * Time Complexity: O(1)
722
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
695
723
  * Space Complexity: O(1)
696
724
  */
697
725
  /**
@@ -705,34 +733,6 @@ export class DoublyLinkedList extends IterableElementBase {
705
733
  addFirst(value) {
706
734
  this.unshift(value);
707
735
  }
708
- /**
709
- * Time Complexity: O(n), where n is the number of elements in the linked list.
710
- * Space Complexity: O(1)
711
- */
712
- /**
713
- * Time Complexity: O(n), where n is the number of elements in the linked list.
714
- * Space Complexity: O(1)
715
- *
716
- * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
717
- * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
718
- */
719
- get first() {
720
- return this.head?.value;
721
- }
722
- /**
723
- * Time Complexity: O(n), where n is the number of elements in the linked list.
724
- * Space Complexity: O(1)
725
- */
726
- /**
727
- * Time Complexity: O(n), where n is the number of elements in the linked list.
728
- * Space Complexity: O(1)
729
- *
730
- * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
731
- * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
732
- */
733
- get last() {
734
- return this.tail?.value;
735
- }
736
736
  /**
737
737
  * The function returns an iterator that iterates over the values of a linked list.
738
738
  */
@@ -33,15 +33,13 @@ export declare class SkipList<K, V> {
33
33
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
34
34
  */
35
35
  /**
36
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
36
+ * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
37
37
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
38
38
  *
39
- * The add function adds a new node with a given key and value to a Skip List data structure.
40
- * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
41
- * @param {V} value - The "value" parameter represents the value associated with the key that is being added to the Skip
42
- * List.
39
+ * Get the value of the first element (the smallest element) in the Skip List.
40
+ * @returns The value of the first element, or undefined if the Skip List is empty.
43
41
  */
44
- add(key: K, value: V): void;
42
+ get first(): V | undefined;
45
43
  /**
46
44
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
47
45
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -50,12 +48,10 @@ export declare class SkipList<K, V> {
50
48
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
51
49
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
52
50
  *
53
- * The function `get` retrieves the value associated with a given key from a skip list data structure.
54
- * @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
55
- * @returns The method `get(key: K)` returns the value associated with the given key if it exists in the data structure,
56
- * otherwise it returns `undefined`.
51
+ * Get the value of the last element (the largest element) in the Skip List.
52
+ * @returns The value of the last element, or undefined if the Skip List is empty.
57
53
  */
58
- get(key: K): V | undefined;
54
+ get last(): V | undefined;
59
55
  /**
60
56
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
61
57
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -63,8 +59,13 @@ export declare class SkipList<K, V> {
63
59
  /**
64
60
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
65
61
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
62
+ *
63
+ * The add function adds a new node with a given key and value to a Skip List data structure.
64
+ * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
65
+ * @param {V} value - The "value" parameter represents the value associated with the key that is being added to the Skip
66
+ * List.
66
67
  */
67
- has(key: K): boolean;
68
+ add(key: K, value: V): void;
68
69
  /**
69
70
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
70
71
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -73,24 +74,21 @@ export declare class SkipList<K, V> {
73
74
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
74
75
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
75
76
  *
76
- * The `delete` function removes a node with a specific key from a Skip List data structure.
77
- * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
78
- * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
79
- * skip list, and `false` if the key was not found in the skip list.
77
+ * The function `get` retrieves the value associated with a given key from a skip list data structure.
78
+ * @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
79
+ * @returns The method `get(key: K)` returns the value associated with the given key if it exists in the data structure,
80
+ * otherwise it returns `undefined`.
80
81
  */
81
- delete(key: K): boolean;
82
+ get(key: K): V | undefined;
82
83
  /**
83
84
  * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
84
85
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
85
86
  */
86
87
  /**
87
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
88
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
88
89
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
89
- *
90
- * Get the value of the first element (the smallest element) in the Skip List.
91
- * @returns The value of the first element, or undefined if the Skip List is empty.
92
90
  */
93
- get first(): V | undefined;
91
+ has(key: K): boolean;
94
92
  /**
95
93
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
96
94
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -99,10 +97,12 @@ export declare class SkipList<K, V> {
99
97
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
100
98
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
101
99
  *
102
- * Get the value of the last element (the largest element) in the Skip List.
103
- * @returns The value of the last element, or undefined if the Skip List is empty.
100
+ * The `delete` function removes a node with a specific key from a Skip List data structure.
101
+ * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
102
+ * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
103
+ * skip list, and `false` if the key was not found in the skip list.
104
104
  */
105
- get last(): V | undefined;
105
+ delete(key: K): boolean;
106
106
  /**
107
107
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
108
108
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -45,6 +45,41 @@ export class SkipList {
45
45
  get probability() {
46
46
  return this._probability;
47
47
  }
48
+ /**
49
+ * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
50
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
51
+ */
52
+ /**
53
+ * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
54
+ * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
55
+ *
56
+ * Get the value of the first element (the smallest element) in the Skip List.
57
+ * @returns The value of the first element, or undefined if the Skip List is empty.
58
+ */
59
+ get first() {
60
+ const firstNode = this.head.forward[0];
61
+ return firstNode ? firstNode.value : undefined;
62
+ }
63
+ /**
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.
66
+ */
67
+ /**
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.
70
+ *
71
+ * Get the value of the last element (the largest element) in the Skip List.
72
+ * @returns The value of the last element, or undefined if the Skip List is empty.
73
+ */
74
+ get last() {
75
+ let current = this.head;
76
+ for (let i = this.level - 1; i >= 0; i--) {
77
+ while (current.forward[i]) {
78
+ current = current.forward[i];
79
+ }
80
+ }
81
+ return current.value;
82
+ }
48
83
  /**
49
84
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
50
85
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
@@ -103,7 +138,7 @@ export class SkipList {
103
138
  return undefined;
104
139
  }
105
140
  /**
106
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
141
+ * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
107
142
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
108
143
  */
109
144
  /**
@@ -150,41 +185,6 @@ export class SkipList {
150
185
  }
151
186
  return false;
152
187
  }
153
- /**
154
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
155
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
156
- */
157
- /**
158
- * Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
159
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
160
- *
161
- * Get the value of the first element (the smallest element) in the Skip List.
162
- * @returns The value of the first element, or undefined if the Skip List is empty.
163
- */
164
- get first() {
165
- const firstNode = this.head.forward[0];
166
- return firstNode ? firstNode.value : undefined;
167
- }
168
- /**
169
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
170
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
171
- */
172
- /**
173
- * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
174
- * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
175
- *
176
- * Get the value of the last element (the largest element) in the Skip List.
177
- * @returns The value of the last element, or undefined if the Skip List is empty.
178
- */
179
- get last() {
180
- let current = this.head;
181
- for (let i = this.level - 1; i >= 0; i--) {
182
- while (current.forward[i]) {
183
- current = current.forward[i];
184
- }
185
- }
186
- return current.value;
187
- }
188
188
  /**
189
189
  * Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
190
190
  * Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.