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
@@ -23,7 +23,10 @@ exports.DoublyLinkedListNode = DoublyLinkedListNode;
23
23
  */
24
24
  class DoublyLinkedList extends base_1.IterableElementBase {
25
25
  /**
26
- * The constructor initializes the linked list with an empty head, tail, and size.
26
+ * The constructor initializes a linked list with optional elements.
27
+ * @param elements - The `elements` parameter is an optional iterable object that contains the
28
+ * initial elements to be added to the data structure. It defaults to an empty array if no elements
29
+ * are provided.
27
30
  */
28
31
  constructor(elements = []) {
29
32
  super();
@@ -36,21 +39,35 @@ class DoublyLinkedList extends base_1.IterableElementBase {
36
39
  }
37
40
  }
38
41
  }
42
+ /**
43
+ * The `head` function returns the first node of a doubly linked list.
44
+ * @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
45
+ */
39
46
  get head() {
40
47
  return this._head;
41
48
  }
49
+ /**
50
+ * The `tail` function returns the last node of a doubly linked list.
51
+ * @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
52
+ * `undefined`.
53
+ */
42
54
  get tail() {
43
55
  return this._tail;
44
56
  }
57
+ /**
58
+ * The function returns the size of an object.
59
+ * @returns The size of the object, which is a number.
60
+ */
45
61
  get size() {
46
62
  return this._size;
47
63
  }
48
64
  /**
49
- * Time Complexity: O(n), where n is the size of the input array.
65
+ * Time Complexity: O(n)
50
66
  * Space Complexity: O(n)
67
+ * where n is the number of elements in the linked list.
51
68
  */
52
69
  /**
53
- * Time Complexity: O(n), where n is the number of elements in the linked list.
70
+ * Time Complexity: O(n)
54
71
  * Space Complexity: O(1)
55
72
  *
56
73
  * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
@@ -65,7 +82,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
65
82
  * Space Complexity: O(1)
66
83
  */
67
84
  /**
68
- * Time Complexity: O(n), where n is the number of elements in the linked list.
85
+ * Time Complexity: O(n)
69
86
  * Space Complexity: O(1)
70
87
  *
71
88
  * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
@@ -89,11 +106,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
89
106
  * @returns The `fromArray` function returns a DoublyLinkedList object.
90
107
  */
91
108
  static fromArray(data) {
92
- const doublyLinkedList = new DoublyLinkedList();
93
- for (const item of data) {
94
- doublyLinkedList.push(item);
95
- }
96
- return doublyLinkedList;
109
+ return new DoublyLinkedList(data);
97
110
  }
98
111
  /**
99
112
  * Time Complexity: O(1)
@@ -148,7 +161,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
148
161
  return removedNode.value;
149
162
  }
150
163
  /**
151
- * Time Complexity: O(n), where n is the number of elements in the linked list.
164
+ * Time Complexity: O(n)
152
165
  * Space Complexity: O(1)
153
166
  */
154
167
  /**
@@ -175,7 +188,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
175
188
  return removedNode.value;
176
189
  }
177
190
  /**
178
- * Time Complexity: O(n), where n is the number of elements in the linked list.
191
+ * Time Complexity: O(n)
179
192
  * Space Complexity: O(1)
180
193
  */
181
194
  /**
@@ -201,20 +214,20 @@ class DoublyLinkedList extends base_1.IterableElementBase {
201
214
  return true;
202
215
  }
203
216
  /**
204
- * Time Complexity: O(n), where n is the number of elements in the linked list.
217
+ * Time Complexity: O(n)
205
218
  * Space Complexity: O(1)
206
219
  */
207
220
  /**
208
- * Time Complexity: O(n), where n is the number of elements in the linked list.
221
+ * Time Complexity: O(n)
209
222
  * Space Complexity: O(1)
210
223
  *
211
- * The `getAt` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
224
+ * The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
212
225
  * @param {number} index - The index parameter is a number that represents the position of the element we want to
213
226
  * retrieve from the list.
214
227
  * @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
215
228
  * or the linked list is empty, it will return undefined.
216
229
  */
217
- getAt(index) {
230
+ at(index) {
218
231
  if (index < 0 || index >= this.size)
219
232
  return undefined;
220
233
  let current = this.head;
@@ -224,11 +237,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
224
237
  return current.value;
225
238
  }
226
239
  /**
227
- * Time Complexity: O(n), where n is the number of elements in the linked list.
240
+ * Time Complexity: O(n)
228
241
  * Space Complexity: O(1)
229
242
  */
230
243
  /**
231
- * Time Complexity: O(n), where n is the number of elements in the linked list.
244
+ * Time Complexity: O(n)
232
245
  * Space Complexity: O(1)
233
246
  *
234
247
  * The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
@@ -248,11 +261,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
248
261
  return current;
249
262
  }
250
263
  /**
251
- * Time Complexity: O(n), where n is the number of elements in the linked list.
264
+ * Time Complexity: O(n)
252
265
  * Space Complexity: O(1)
253
266
  */
254
267
  /**
255
- * Time Complexity: O(n), where n is the number of elements in the linked list.
268
+ * Time Complexity: O(n)
256
269
  * Space Complexity: O(1)
257
270
  *
258
271
  * The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
@@ -272,11 +285,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
272
285
  return undefined;
273
286
  }
274
287
  /**
275
- * Time Complexity: O(n), where n is the number of elements in the linked list.
288
+ * Time Complexity: O(n)
276
289
  * Space Complexity: O(1)
277
290
  */
278
291
  /**
279
- * Time Complexity: O(n), where n is the number of elements in the linked list.
292
+ * Time Complexity: O(n)
280
293
  * Space Complexity: O(1)
281
294
  *
282
295
  * The `insert` function inserts a value at a specified index in a doubly linked list.
@@ -309,11 +322,12 @@ class DoublyLinkedList extends base_1.IterableElementBase {
309
322
  return true;
310
323
  }
311
324
  /**
312
- * Time Complexity: O(n), where n is the number of elements in the linked list.
325
+ * Time Complexity: O(n)
313
326
  * Space Complexity: O(1)
327
+ * where n is the number of elements in the linked list.
314
328
  */
315
329
  /**
316
- * Time Complexity: O(n), where n is the number of elements in the linked list.
330
+ * Time Complexity: O(n)
317
331
  * Space Complexity: O(1)
318
332
  *
319
333
  * The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
@@ -350,11 +364,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
350
364
  return false;
351
365
  }
352
366
  /**
353
- * Time Complexity: O(n), where n is the number of elements in the linked list.
367
+ * Time Complexity: O(n)
354
368
  * Space Complexity: O(1)
355
369
  */
356
370
  /**
357
- * Time Complexity: O(n), where n is the number of elements in the linked list.
371
+ * Time Complexity: O(n)
358
372
  * Space Complexity: O(1)
359
373
  *
360
374
  * The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
@@ -390,7 +404,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
390
404
  return false;
391
405
  }
392
406
  /**
393
- * Time Complexity: O(n), where n is the number of elements in the linked list.
407
+ * Time Complexity: O(n)
394
408
  * Space Complexity: O(1)
395
409
  *
396
410
  * The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
@@ -419,7 +433,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
419
433
  return true;
420
434
  }
421
435
  /**
422
- * Time Complexity: O(n), where n is the number of elements in the linked list.
436
+ * Time Complexity: O(n)
423
437
  * Space Complexity: O(1)
424
438
  *
425
439
  * The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
@@ -455,7 +469,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
455
469
  return false;
456
470
  }
457
471
  /**
458
- * Time Complexity: O(n), where n is the number of elements in the linked list.
472
+ * Time Complexity: O(1)
459
473
  * Space Complexity: O(1)
460
474
  */
461
475
  /**
@@ -466,7 +480,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
466
480
  return this.size === 0;
467
481
  }
468
482
  /**
469
- * Time Complexity: O(n), where n is the number of elements in the linked list.
483
+ * Time Complexity: O(1)
470
484
  * Space Complexity: O(1)
471
485
  */
472
486
  /**
@@ -478,35 +492,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
478
492
  this._size = 0;
479
493
  }
480
494
  /**
481
- * Time Complexity: O(n), where n is the number of elements in the linked list.
482
- * Space Complexity: O(1)
483
- */
484
- /**
485
- * Time Complexity: O(n), where n is the number of elements in the linked list.
486
- * Space Complexity: O(1)
487
- *
488
- * The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
489
- * @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
490
- * function is used to determine whether a particular value in the linked list satisfies a certain condition.
491
- * @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
492
- * the callback function. If no element satisfies the condition, it returns `undefined`.
493
- */
494
- find(callback) {
495
- let current = this.head;
496
- while (current) {
497
- if (callback(current.value)) {
498
- return current.value;
499
- }
500
- current = current.next;
501
- }
502
- return undefined;
503
- }
504
- /**
505
- * Time Complexity: O(n), where n is the number of elements in the linked list.
495
+ * Time Complexity: O(n)
506
496
  * Space Complexity: O(1)
507
497
  */
508
498
  /**
509
- * Time Complexity: O(n), where n is the number of elements in the linked list.
499
+ * Time Complexity: O(n)
510
500
  * Space Complexity: O(1)
511
501
  *
512
502
  * The function returns the index of the first occurrence of a given value in a linked list.
@@ -528,11 +518,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
528
518
  return -1;
529
519
  }
530
520
  /**
531
- * Time Complexity: O(n), where n is the number of elements in the linked list.
521
+ * Time Complexity: O(n)
532
522
  * Space Complexity: O(n)
533
523
  */
534
524
  /**
535
- * Time Complexity: O(n), where n is the number of elements in the linked list.
525
+ * Time Complexity: O(n)
536
526
  * Space Complexity: O(1)
537
527
  *
538
528
  * The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
@@ -553,11 +543,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
553
543
  return undefined;
554
544
  }
555
545
  /**
556
- * Time Complexity: O(n), where n is the number of elements in the linked list.
546
+ * Time Complexity: O(n)
557
547
  * Space Complexity: O(n)
558
548
  */
559
549
  /**
560
- * Time Complexity: O(n), where n is the number of elements in the linked list.
550
+ * Time Complexity: O(n)
561
551
  * Space Complexity: O(1)
562
552
  *
563
553
  * The `reverse` function reverses the order of the elements in a doubly linked list.
@@ -577,7 +567,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
577
567
  * Space Complexity: O(n)
578
568
  */
579
569
  /**
580
- * Time Complexity: O(n), where n is the number of elements in the linked list.
570
+ * Time Complexity: O(n)
581
571
  * Space Complexity: O(n)
582
572
  *
583
573
  * The `toArray` function converts a linked list into an array.
@@ -593,11 +583,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
593
583
  return array;
594
584
  }
595
585
  /**
596
- * Time Complexity: O(n), where n is the number of elements in the linked list.
586
+ * Time Complexity: O(n)
597
587
  * Space Complexity: O(n)
598
588
  */
599
589
  /**
600
- * Time Complexity: O(n), where n is the number of elements in the linked list.
590
+ * Time Complexity: O(n)
601
591
  * Space Complexity: O(n)
602
592
  *
603
593
  * The `toReversedArray` function converts a doubly linked list into an array in reverse order.
@@ -612,6 +602,22 @@ class DoublyLinkedList extends base_1.IterableElementBase {
612
602
  }
613
603
  return array;
614
604
  }
605
+ /**
606
+ * Time Complexity: O(n)
607
+ * Space Complexity: O(n)
608
+ */
609
+ /**
610
+ * Time Complexity: O(n)
611
+ * Space Complexity: O(n)
612
+ *
613
+ * The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
614
+ * as the original list.
615
+ * @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
616
+ * is a copy of the original list.
617
+ */
618
+ clone() {
619
+ return new DoublyLinkedList(this.values());
620
+ }
615
621
  /**
616
622
  * Time Complexity: O(1)
617
623
  * Space Complexity: O(1)
@@ -704,7 +710,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
704
710
  return this.pop();
705
711
  }
706
712
  /**
707
- * Time Complexity: O(n), where n is the number of elements in the linked list.
713
+ * Time Complexity: O(n)
708
714
  * Space Complexity: O(1)
709
715
  */
710
716
  /**
@@ -719,7 +725,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
719
725
  return this.shift();
720
726
  }
721
727
  /**
722
- * Time Complexity: O(n), where n is the number of elements in the linked list.
728
+ * Time Complexity: O(n)
723
729
  * Space Complexity: O(1)
724
730
  */
725
731
  /**