data-structure-typed 1.49.2 → 1.49.3
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/CHANGELOG.md +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +7 -7
- package/dist/cjs/data-structures/graph/abstract-graph.js +43 -12
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +49 -49
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +36 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +33 -33
- package/dist/cjs/data-structures/queue/queue.js +40 -40
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +7 -7
- package/dist/mjs/data-structures/graph/abstract-graph.js +43 -12
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/directed-graph.js +2 -2
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +47 -47
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +36 -36
- package/dist/mjs/data-structures/queue/queue.d.ts +33 -33
- package/dist/mjs/data-structures/queue/queue.js +39 -39
- package/dist/umd/data-structure-typed.js +171 -140
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/graph/abstract-graph.ts +55 -14
- package/src/data-structures/graph/directed-graph.ts +3 -2
- package/src/data-structures/graph/undirected-graph.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +53 -53
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
- package/src/data-structures/queue/queue.ts +45 -45
- package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +48 -3
- package/test/unit/data-structures/graph/undirected-graph.test.ts +48 -4
- package/test/unit/data-structures/heap/heap.test.ts +6 -1
|
@@ -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(
|
|
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(
|
|
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(
|
|
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(
|
|
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)
|
|
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(
|
|
589
|
-
* Space Complexity: O(
|
|
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(
|
|
621
|
-
* Space Complexity: O(
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
*
|
|
40
|
-
* @
|
|
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
|
-
|
|
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
|
-
*
|
|
54
|
-
* @
|
|
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(
|
|
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
|
-
|
|
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 `
|
|
77
|
-
* @param {K} key - The key parameter
|
|
78
|
-
* @returns The `
|
|
79
|
-
*
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
-
*
|
|
103
|
-
* @
|
|
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
|
-
|
|
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(
|
|
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.
|
|
@@ -32,6 +32,32 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
32
32
|
* @returns {number} The size of the array, which is the difference between the length of the array and the offset.
|
|
33
33
|
*/
|
|
34
34
|
get size(): number;
|
|
35
|
+
/**
|
|
36
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
37
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
38
|
+
*
|
|
39
|
+
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
40
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
41
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
42
|
+
*/
|
|
43
|
+
get first(): E | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Time Complexity: O(1) - constant time as it adds an element to the end of the array.
|
|
46
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
47
|
+
*/
|
|
48
|
+
/**
|
|
49
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
50
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
51
|
+
*
|
|
52
|
+
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
53
|
+
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
54
|
+
* array is empty, it returns `undefined`.
|
|
55
|
+
*/
|
|
56
|
+
get last(): E | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
|
|
59
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
60
|
+
*/
|
|
35
61
|
/**
|
|
36
62
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
37
63
|
* @public
|
|
@@ -42,7 +68,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
42
68
|
*/
|
|
43
69
|
static fromArray<E>(elements: E[]): Queue<E>;
|
|
44
70
|
/**
|
|
45
|
-
* Time Complexity: O(1) - constant time as it
|
|
71
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
46
72
|
* Space Complexity: O(1) - no additional space is used.
|
|
47
73
|
*/
|
|
48
74
|
/**
|
|
@@ -55,7 +81,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
55
81
|
*/
|
|
56
82
|
push(element: E): boolean;
|
|
57
83
|
/**
|
|
58
|
-
* Time Complexity: O(
|
|
84
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
59
85
|
* Space Complexity: O(1) - no additional space is used.
|
|
60
86
|
*/
|
|
61
87
|
/**
|
|
@@ -67,19 +93,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
67
93
|
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
68
94
|
*/
|
|
69
95
|
shift(): E | undefined;
|
|
70
|
-
/**
|
|
71
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
72
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
73
|
-
*/
|
|
74
|
-
/**
|
|
75
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
76
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
77
|
-
*
|
|
78
|
-
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
79
|
-
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
80
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
81
|
-
*/
|
|
82
|
-
get first(): E | undefined;
|
|
83
96
|
/**
|
|
84
97
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
85
98
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -93,19 +106,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
93
106
|
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
94
107
|
*/
|
|
95
108
|
peek(): E | undefined;
|
|
96
|
-
/**
|
|
97
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
98
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
99
|
-
*/
|
|
100
|
-
/**
|
|
101
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
102
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
103
|
-
*
|
|
104
|
-
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
105
|
-
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
106
|
-
* array is empty, it returns `undefined`.
|
|
107
|
-
*/
|
|
108
|
-
get last(): E | undefined;
|
|
109
109
|
/**
|
|
110
110
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
111
111
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -247,6 +247,11 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
247
247
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
248
248
|
*/
|
|
249
249
|
export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
250
|
+
/**
|
|
251
|
+
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
252
|
+
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
253
|
+
*/
|
|
254
|
+
get first(): E | undefined;
|
|
250
255
|
/**
|
|
251
256
|
* The enqueue function adds a value to the end of an array.
|
|
252
257
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -257,11 +262,6 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
|
257
262
|
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
258
263
|
*/
|
|
259
264
|
dequeue(): E | undefined;
|
|
260
|
-
/**
|
|
261
|
-
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
262
|
-
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
263
|
-
*/
|
|
264
|
-
get first(): E | undefined;
|
|
265
265
|
/**
|
|
266
266
|
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
267
267
|
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
@@ -36,6 +36,36 @@ export class Queue extends IterableElementBase {
|
|
|
36
36
|
get size() {
|
|
37
37
|
return this.nodes.length - this.offset;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
41
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
42
|
+
*
|
|
43
|
+
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
44
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
45
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
46
|
+
*/
|
|
47
|
+
get first() {
|
|
48
|
+
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Time Complexity: O(1) - constant time as it adds an element to the end of the array.
|
|
52
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
56
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
57
|
+
*
|
|
58
|
+
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
59
|
+
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
60
|
+
* array is empty, it returns `undefined`.
|
|
61
|
+
*/
|
|
62
|
+
get last() {
|
|
63
|
+
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
|
|
67
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
68
|
+
*/
|
|
39
69
|
/**
|
|
40
70
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
41
71
|
* @public
|
|
@@ -48,7 +78,7 @@ export class Queue extends IterableElementBase {
|
|
|
48
78
|
return new Queue(elements);
|
|
49
79
|
}
|
|
50
80
|
/**
|
|
51
|
-
* Time Complexity: O(1) - constant time as it
|
|
81
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
52
82
|
* Space Complexity: O(1) - no additional space is used.
|
|
53
83
|
*/
|
|
54
84
|
/**
|
|
@@ -64,7 +94,7 @@ export class Queue extends IterableElementBase {
|
|
|
64
94
|
return true;
|
|
65
95
|
}
|
|
66
96
|
/**
|
|
67
|
-
* Time Complexity: O(
|
|
97
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
68
98
|
* Space Complexity: O(1) - no additional space is used.
|
|
69
99
|
*/
|
|
70
100
|
/**
|
|
@@ -88,21 +118,6 @@ export class Queue extends IterableElementBase {
|
|
|
88
118
|
this._offset = 0;
|
|
89
119
|
return first;
|
|
90
120
|
}
|
|
91
|
-
/**
|
|
92
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
93
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
94
|
-
*/
|
|
95
|
-
/**
|
|
96
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
97
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
98
|
-
*
|
|
99
|
-
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
100
|
-
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
101
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
102
|
-
*/
|
|
103
|
-
get first() {
|
|
104
|
-
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
105
|
-
}
|
|
106
121
|
/**
|
|
107
122
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
108
123
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -118,21 +133,6 @@ export class Queue extends IterableElementBase {
|
|
|
118
133
|
peek() {
|
|
119
134
|
return this.first;
|
|
120
135
|
}
|
|
121
|
-
/**
|
|
122
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
123
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
124
|
-
*/
|
|
125
|
-
/**
|
|
126
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
127
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
128
|
-
*
|
|
129
|
-
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
130
|
-
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
131
|
-
* array is empty, it returns `undefined`.
|
|
132
|
-
*/
|
|
133
|
-
get last() {
|
|
134
|
-
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
135
|
-
}
|
|
136
136
|
/**
|
|
137
137
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
138
138
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -313,6 +313,13 @@ export class Queue extends IterableElementBase {
|
|
|
313
313
|
* 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
|
|
314
314
|
*/
|
|
315
315
|
export class LinkedListQueue extends SinglyLinkedList {
|
|
316
|
+
/**
|
|
317
|
+
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
318
|
+
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
319
|
+
*/
|
|
320
|
+
get first() {
|
|
321
|
+
return this.head?.value;
|
|
322
|
+
}
|
|
316
323
|
/**
|
|
317
324
|
* The enqueue function adds a value to the end of an array.
|
|
318
325
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -327,13 +334,6 @@ export class LinkedListQueue extends SinglyLinkedList {
|
|
|
327
334
|
dequeue() {
|
|
328
335
|
return this.shift();
|
|
329
336
|
}
|
|
330
|
-
/**
|
|
331
|
-
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
332
|
-
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
333
|
-
*/
|
|
334
|
-
get first() {
|
|
335
|
-
return this.head?.value;
|
|
336
|
-
}
|
|
337
337
|
/**
|
|
338
338
|
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
339
339
|
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|