min-heap-typed 1.50.0 → 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.
- package/dist/data-structures/base/iterable-base.d.ts +114 -9
- package/dist/data-structures/base/iterable-base.js +143 -7
- package/dist/data-structures/binary-tree/avl-tree.d.ts +43 -46
- package/dist/data-structures/binary-tree/avl-tree.js +68 -71
- package/dist/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/data-structures/binary-tree/bst.d.ts +54 -74
- package/dist/data-structures/binary-tree/bst.js +30 -71
- package/dist/data-structures/binary-tree/rb-tree.d.ts +78 -60
- package/dist/data-structures/binary-tree/rb-tree.js +84 -89
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +37 -56
- package/dist/data-structures/binary-tree/tree-multimap.js +64 -85
- package/dist/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/data-structures/graph/abstract-graph.js +3 -0
- package/dist/data-structures/graph/directed-graph.d.ts +14 -0
- package/dist/data-structures/graph/directed-graph.js +26 -0
- package/dist/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/data-structures/graph/map-graph.js +14 -0
- package/dist/data-structures/graph/undirected-graph.d.ts +16 -0
- package/dist/data-structures/graph/undirected-graph.js +25 -0
- package/dist/data-structures/hash/hash-map.d.ts +121 -15
- package/dist/data-structures/hash/hash-map.js +160 -25
- package/dist/data-structures/heap/heap.d.ts +66 -6
- package/dist/data-structures/heap/heap.js +66 -6
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
- package/dist/data-structures/linked-list/doubly-linked-list.js +70 -64
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +128 -103
- package/dist/data-structures/linked-list/singly-linked-list.js +130 -112
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/data-structures/matrix/matrix.js +50 -11
- package/dist/data-structures/queue/deque.d.ts +49 -19
- package/dist/data-structures/queue/deque.js +101 -47
- package/dist/data-structures/queue/queue.d.ts +39 -5
- package/dist/data-structures/queue/queue.js +47 -5
- package/dist/data-structures/stack/stack.d.ts +16 -0
- package/dist/data-structures/stack/stack.js +22 -0
- package/dist/data-structures/trie/trie.d.ts +38 -1
- package/dist/data-structures/trie/trie.js +41 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/types/utils/utils.d.ts +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/iterable-base.ts +172 -19
- package/src/data-structures/binary-tree/avl-tree.ts +97 -97
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +89 -131
- package/src/data-structures/binary-tree/rb-tree.ts +127 -155
- package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
- package/src/data-structures/graph/abstract-graph.ts +4 -0
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +28 -0
- package/src/data-structures/hash/hash-map.ts +175 -34
- package/src/data-structures/heap/heap.ts +66 -6
- package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
- package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- package/src/data-structures/queue/deque.ts +108 -49
- package/src/data-structures/queue/queue.ts +51 -5
- package/src/data-structures/stack/stack.ts +24 -0
- package/src/data-structures/trie/trie.ts +45 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
|
@@ -33,7 +33,10 @@ export class DoublyLinkedListNode<E = any> {
|
|
|
33
33
|
*/
|
|
34
34
|
export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
35
35
|
/**
|
|
36
|
-
* The constructor initializes
|
|
36
|
+
* The constructor initializes a linked list with optional elements.
|
|
37
|
+
* @param elements - The `elements` parameter is an optional iterable object that contains the
|
|
38
|
+
* initial elements to be added to the data structure. It defaults to an empty array if no elements
|
|
39
|
+
* are provided.
|
|
37
40
|
*/
|
|
38
41
|
constructor(elements: Iterable<E> = []) {
|
|
39
42
|
super();
|
|
@@ -49,29 +52,43 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
49
52
|
|
|
50
53
|
protected _head: DoublyLinkedListNode<E> | undefined;
|
|
51
54
|
|
|
55
|
+
/**
|
|
56
|
+
* The `head` function returns the first node of a doubly linked list.
|
|
57
|
+
* @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
|
|
58
|
+
*/
|
|
52
59
|
get head(): DoublyLinkedListNode<E> | undefined {
|
|
53
60
|
return this._head;
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
protected _tail: DoublyLinkedListNode<E> | undefined;
|
|
57
64
|
|
|
65
|
+
/**
|
|
66
|
+
* The `tail` function returns the last node of a doubly linked list.
|
|
67
|
+
* @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
|
|
68
|
+
* `undefined`.
|
|
69
|
+
*/
|
|
58
70
|
get tail(): DoublyLinkedListNode<E> | undefined {
|
|
59
71
|
return this._tail;
|
|
60
72
|
}
|
|
61
73
|
|
|
62
74
|
protected _size: number;
|
|
63
75
|
|
|
76
|
+
/**
|
|
77
|
+
* The function returns the size of an object.
|
|
78
|
+
* @returns The size of the object, which is a number.
|
|
79
|
+
*/
|
|
64
80
|
get size(): number {
|
|
65
81
|
return this._size;
|
|
66
82
|
}
|
|
67
83
|
|
|
68
84
|
/**
|
|
69
|
-
* Time Complexity: O(n)
|
|
85
|
+
* Time Complexity: O(n)
|
|
70
86
|
* Space Complexity: O(n)
|
|
87
|
+
* where n is the number of elements in the linked list.
|
|
71
88
|
*/
|
|
72
89
|
|
|
73
90
|
/**
|
|
74
|
-
* Time Complexity: O(n)
|
|
91
|
+
* Time Complexity: O(n)
|
|
75
92
|
* Space Complexity: O(1)
|
|
76
93
|
*
|
|
77
94
|
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -87,7 +104,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
87
104
|
*/
|
|
88
105
|
|
|
89
106
|
/**
|
|
90
|
-
* Time Complexity: O(n)
|
|
107
|
+
* Time Complexity: O(n)
|
|
91
108
|
* Space Complexity: O(1)
|
|
92
109
|
*
|
|
93
110
|
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -112,11 +129,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
112
129
|
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
113
130
|
*/
|
|
114
131
|
static fromArray<E>(data: E[]) {
|
|
115
|
-
|
|
116
|
-
for (const item of data) {
|
|
117
|
-
doublyLinkedList.push(item);
|
|
118
|
-
}
|
|
119
|
-
return doublyLinkedList;
|
|
132
|
+
return new DoublyLinkedList<E>(data);
|
|
120
133
|
}
|
|
121
134
|
|
|
122
135
|
/**
|
|
@@ -173,7 +186,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
173
186
|
}
|
|
174
187
|
|
|
175
188
|
/**
|
|
176
|
-
* Time Complexity: O(n)
|
|
189
|
+
* Time Complexity: O(n)
|
|
177
190
|
* Space Complexity: O(1)
|
|
178
191
|
*/
|
|
179
192
|
|
|
@@ -200,7 +213,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
200
213
|
}
|
|
201
214
|
|
|
202
215
|
/**
|
|
203
|
-
* Time Complexity: O(n)
|
|
216
|
+
* Time Complexity: O(n)
|
|
204
217
|
* Space Complexity: O(1)
|
|
205
218
|
*/
|
|
206
219
|
|
|
@@ -227,21 +240,21 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
227
240
|
}
|
|
228
241
|
|
|
229
242
|
/**
|
|
230
|
-
* Time Complexity: O(n)
|
|
243
|
+
* Time Complexity: O(n)
|
|
231
244
|
* Space Complexity: O(1)
|
|
232
245
|
*/
|
|
233
246
|
|
|
234
247
|
/**
|
|
235
|
-
* Time Complexity: O(n)
|
|
248
|
+
* Time Complexity: O(n)
|
|
236
249
|
* Space Complexity: O(1)
|
|
237
250
|
*
|
|
238
|
-
* The `
|
|
251
|
+
* The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
|
|
239
252
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
240
253
|
* retrieve from the list.
|
|
241
254
|
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
242
255
|
* or the linked list is empty, it will return undefined.
|
|
243
256
|
*/
|
|
244
|
-
|
|
257
|
+
at(index: number): E | undefined {
|
|
245
258
|
if (index < 0 || index >= this.size) return undefined;
|
|
246
259
|
let current = this.head;
|
|
247
260
|
for (let i = 0; i < index; i++) {
|
|
@@ -251,12 +264,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
251
264
|
}
|
|
252
265
|
|
|
253
266
|
/**
|
|
254
|
-
* Time Complexity: O(n)
|
|
267
|
+
* Time Complexity: O(n)
|
|
255
268
|
* Space Complexity: O(1)
|
|
256
269
|
*/
|
|
257
270
|
|
|
258
271
|
/**
|
|
259
|
-
* Time Complexity: O(n)
|
|
272
|
+
* Time Complexity: O(n)
|
|
260
273
|
* Space Complexity: O(1)
|
|
261
274
|
*
|
|
262
275
|
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
|
|
@@ -276,12 +289,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
276
289
|
}
|
|
277
290
|
|
|
278
291
|
/**
|
|
279
|
-
* Time Complexity: O(n)
|
|
292
|
+
* Time Complexity: O(n)
|
|
280
293
|
* Space Complexity: O(1)
|
|
281
294
|
*/
|
|
282
295
|
|
|
283
296
|
/**
|
|
284
|
-
* Time Complexity: O(n)
|
|
297
|
+
* Time Complexity: O(n)
|
|
285
298
|
* Space Complexity: O(1)
|
|
286
299
|
*
|
|
287
300
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
@@ -304,12 +317,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
304
317
|
}
|
|
305
318
|
|
|
306
319
|
/**
|
|
307
|
-
* Time Complexity: O(n)
|
|
320
|
+
* Time Complexity: O(n)
|
|
308
321
|
* Space Complexity: O(1)
|
|
309
322
|
*/
|
|
310
323
|
|
|
311
324
|
/**
|
|
312
|
-
* Time Complexity: O(n)
|
|
325
|
+
* Time Complexity: O(n)
|
|
313
326
|
* Space Complexity: O(1)
|
|
314
327
|
*
|
|
315
328
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
@@ -343,12 +356,13 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
343
356
|
}
|
|
344
357
|
|
|
345
358
|
/**
|
|
346
|
-
* Time Complexity: O(n)
|
|
359
|
+
* Time Complexity: O(n)
|
|
347
360
|
* Space Complexity: O(1)
|
|
361
|
+
* where n is the number of elements in the linked list.
|
|
348
362
|
*/
|
|
349
363
|
|
|
350
364
|
/**
|
|
351
|
-
* Time Complexity: O(n)
|
|
365
|
+
* Time Complexity: O(n)
|
|
352
366
|
* Space Complexity: O(1)
|
|
353
367
|
*
|
|
354
368
|
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
@@ -388,12 +402,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
388
402
|
}
|
|
389
403
|
|
|
390
404
|
/**
|
|
391
|
-
* Time Complexity: O(n)
|
|
405
|
+
* Time Complexity: O(n)
|
|
392
406
|
* Space Complexity: O(1)
|
|
393
407
|
*/
|
|
394
408
|
|
|
395
409
|
/**
|
|
396
|
-
* Time Complexity: O(n)
|
|
410
|
+
* Time Complexity: O(n)
|
|
397
411
|
* Space Complexity: O(1)
|
|
398
412
|
*
|
|
399
413
|
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
@@ -432,7 +446,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
432
446
|
}
|
|
433
447
|
|
|
434
448
|
/**
|
|
435
|
-
* Time Complexity: O(n)
|
|
449
|
+
* Time Complexity: O(n)
|
|
436
450
|
* Space Complexity: O(1)
|
|
437
451
|
*
|
|
438
452
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
@@ -462,7 +476,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
462
476
|
}
|
|
463
477
|
|
|
464
478
|
/**
|
|
465
|
-
* Time Complexity: O(n)
|
|
479
|
+
* Time Complexity: O(n)
|
|
466
480
|
* Space Complexity: O(1)
|
|
467
481
|
*
|
|
468
482
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -498,7 +512,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
498
512
|
}
|
|
499
513
|
|
|
500
514
|
/**
|
|
501
|
-
* Time Complexity: O(
|
|
515
|
+
* Time Complexity: O(1)
|
|
502
516
|
* Space Complexity: O(1)
|
|
503
517
|
*/
|
|
504
518
|
|
|
@@ -511,7 +525,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
511
525
|
}
|
|
512
526
|
|
|
513
527
|
/**
|
|
514
|
-
* Time Complexity: O(
|
|
528
|
+
* Time Complexity: O(1)
|
|
515
529
|
* Space Complexity: O(1)
|
|
516
530
|
*/
|
|
517
531
|
|
|
@@ -525,38 +539,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
525
539
|
}
|
|
526
540
|
|
|
527
541
|
/**
|
|
528
|
-
* Time Complexity: O(n)
|
|
529
|
-
* Space Complexity: O(1)
|
|
530
|
-
*/
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
534
|
-
* Space Complexity: O(1)
|
|
535
|
-
*
|
|
536
|
-
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
537
|
-
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
538
|
-
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
539
|
-
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
540
|
-
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
541
|
-
*/
|
|
542
|
-
find(callback: (value: E) => boolean): E | undefined {
|
|
543
|
-
let current = this.head;
|
|
544
|
-
while (current) {
|
|
545
|
-
if (callback(current.value)) {
|
|
546
|
-
return current.value;
|
|
547
|
-
}
|
|
548
|
-
current = current.next;
|
|
549
|
-
}
|
|
550
|
-
return undefined;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
542
|
+
* Time Complexity: O(n)
|
|
555
543
|
* Space Complexity: O(1)
|
|
556
544
|
*/
|
|
557
545
|
|
|
558
546
|
/**
|
|
559
|
-
* Time Complexity: O(n)
|
|
547
|
+
* Time Complexity: O(n)
|
|
560
548
|
* Space Complexity: O(1)
|
|
561
549
|
*
|
|
562
550
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
@@ -579,12 +567,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
579
567
|
}
|
|
580
568
|
|
|
581
569
|
/**
|
|
582
|
-
* Time Complexity: O(n)
|
|
570
|
+
* Time Complexity: O(n)
|
|
583
571
|
* Space Complexity: O(n)
|
|
584
572
|
*/
|
|
585
573
|
|
|
586
574
|
/**
|
|
587
|
-
* Time Complexity: O(n)
|
|
575
|
+
* Time Complexity: O(n)
|
|
588
576
|
* Space Complexity: O(1)
|
|
589
577
|
*
|
|
590
578
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
@@ -606,12 +594,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
606
594
|
}
|
|
607
595
|
|
|
608
596
|
/**
|
|
609
|
-
* Time Complexity: O(n)
|
|
597
|
+
* Time Complexity: O(n)
|
|
610
598
|
* Space Complexity: O(n)
|
|
611
599
|
*/
|
|
612
600
|
|
|
613
601
|
/**
|
|
614
|
-
* Time Complexity: O(n)
|
|
602
|
+
* Time Complexity: O(n)
|
|
615
603
|
* Space Complexity: O(1)
|
|
616
604
|
*
|
|
617
605
|
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
@@ -633,7 +621,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
633
621
|
*/
|
|
634
622
|
|
|
635
623
|
/**
|
|
636
|
-
* Time Complexity: O(n)
|
|
624
|
+
* Time Complexity: O(n)
|
|
637
625
|
* Space Complexity: O(n)
|
|
638
626
|
*
|
|
639
627
|
* The `toArray` function converts a linked list into an array.
|
|
@@ -650,12 +638,12 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
650
638
|
}
|
|
651
639
|
|
|
652
640
|
/**
|
|
653
|
-
* Time Complexity: O(n)
|
|
641
|
+
* Time Complexity: O(n)
|
|
654
642
|
* Space Complexity: O(n)
|
|
655
643
|
*/
|
|
656
644
|
|
|
657
645
|
/**
|
|
658
|
-
* Time Complexity: O(n)
|
|
646
|
+
* Time Complexity: O(n)
|
|
659
647
|
* Space Complexity: O(n)
|
|
660
648
|
*
|
|
661
649
|
* The `toReversedArray` function converts a doubly linked list into an array in reverse order.
|
|
@@ -671,6 +659,24 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
671
659
|
return array;
|
|
672
660
|
}
|
|
673
661
|
|
|
662
|
+
/**
|
|
663
|
+
* Time Complexity: O(n)
|
|
664
|
+
* Space Complexity: O(n)
|
|
665
|
+
*/
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Time Complexity: O(n)
|
|
669
|
+
* Space Complexity: O(n)
|
|
670
|
+
*
|
|
671
|
+
* The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
|
|
672
|
+
* as the original list.
|
|
673
|
+
* @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
|
|
674
|
+
* is a copy of the original list.
|
|
675
|
+
*/
|
|
676
|
+
clone(): DoublyLinkedList<E> {
|
|
677
|
+
return new DoublyLinkedList(this.values());
|
|
678
|
+
}
|
|
679
|
+
|
|
674
680
|
/**
|
|
675
681
|
* Time Complexity: O(1)
|
|
676
682
|
* Space Complexity: O(1)
|
|
@@ -772,7 +778,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
772
778
|
}
|
|
773
779
|
|
|
774
780
|
/**
|
|
775
|
-
* Time Complexity: O(n)
|
|
781
|
+
* Time Complexity: O(n)
|
|
776
782
|
* Space Complexity: O(1)
|
|
777
783
|
*/
|
|
778
784
|
|
|
@@ -789,7 +795,7 @@ export class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
789
795
|
}
|
|
790
796
|
|
|
791
797
|
/**
|
|
792
|
-
* Time Complexity: O(n)
|
|
798
|
+
* Time Complexity: O(n)
|
|
793
799
|
* Space Complexity: O(1)
|
|
794
800
|
*/
|
|
795
801
|
|