data-structure-typed 1.49.1 → 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/README.md +16 -16
- package/README_zh-CN.md +2 -2
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +457 -22
- package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/cjs/data-structures/base/iterable-base.js +21 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +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/hash/hash-map.d.ts +9 -9
- package/dist/cjs/data-structures/hash/hash-map.js +16 -15
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +6 -35
- package/dist/cjs/data-structures/heap/heap.js +10 -42
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +143 -146
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -42
- package/dist/cjs/data-structures/linked-list/singly-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/deque.d.ts +70 -75
- package/dist/cjs/data-structures/queue/deque.js +100 -110
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +37 -38
- package/dist/cjs/data-structures/queue/queue.js +46 -49
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +2 -3
- package/dist/cjs/data-structures/stack/stack.js +2 -5
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +1 -2
- package/dist/cjs/data-structures/trie/trie.js +2 -5
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/mjs/data-structures/base/iterable-base.js +21 -0
- 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/hash/hash-map.d.ts +9 -9
- package/dist/mjs/data-structures/hash/hash-map.js +16 -15
- package/dist/mjs/data-structures/heap/heap.d.ts +6 -35
- package/dist/mjs/data-structures/heap/heap.js +10 -42
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +142 -145
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -43
- 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/deque.d.ts +70 -75
- package/dist/mjs/data-structures/queue/deque.js +100 -110
- package/dist/mjs/data-structures/queue/queue.d.ts +37 -38
- package/dist/mjs/data-structures/queue/queue.js +45 -48
- package/dist/mjs/data-structures/stack/stack.d.ts +2 -3
- package/dist/mjs/data-structures/stack/stack.js +2 -5
- package/dist/mjs/data-structures/trie/trie.d.ts +1 -2
- package/dist/mjs/data-structures/trie/trie.js +2 -5
- package/dist/umd/data-structure-typed.js +531 -532
- 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/base/iterable-base.ts +24 -0
- 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/hash/hash-map.ts +27 -28
- package/src/data-structures/heap/heap.ts +19 -57
- package/src/data-structures/linked-list/doubly-linked-list.ts +157 -161
- package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
- package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
- package/src/data-structures/queue/deque.ts +122 -135
- package/src/data-structures/queue/queue.ts +54 -58
- package/src/data-structures/stack/stack.ts +4 -8
- package/src/data-structures/trie/trie.ts +5 -9
- package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
- package/test/performance/data-structures/heap/heap.test.ts +2 -2
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
- 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/hash/hash-map.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +6 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
- package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
- package/test/unit/data-structures/queue/deque.test.ts +5 -5
- package/test/unit/data-structures/queue/queue.test.ts +4 -4
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
|
@@ -26,8 +26,8 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
26
26
|
get head(): SinglyLinkedListNode<E> | undefined;
|
|
27
27
|
protected _tail: SinglyLinkedListNode<E> | undefined;
|
|
28
28
|
get tail(): SinglyLinkedListNode<E> | undefined;
|
|
29
|
-
protected
|
|
30
|
-
get
|
|
29
|
+
protected _size: number;
|
|
30
|
+
get size(): number;
|
|
31
31
|
/**
|
|
32
32
|
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
|
|
33
33
|
* Space Complexity: O(n) - Linear space, as it creates a new node for each element in the array.
|
|
@@ -54,7 +54,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
54
54
|
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
55
55
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
56
56
|
*/
|
|
57
|
-
push(value: E):
|
|
57
|
+
push(value: E): boolean;
|
|
58
58
|
/**
|
|
59
59
|
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
|
|
60
60
|
* Space Complexity: O(1) - Constant space, as it only creates a new node.
|
|
@@ -67,7 +67,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
67
67
|
* @param {E} value - The "value" parameter represents the value that you want to add to the linked list. It can be of
|
|
68
68
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
69
69
|
*/
|
|
70
|
-
addLast(value: E):
|
|
70
|
+
addLast(value: E): boolean;
|
|
71
71
|
/**
|
|
72
72
|
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
73
73
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -132,7 +132,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
132
132
|
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
133
133
|
* linked list.
|
|
134
134
|
*/
|
|
135
|
-
unshift(value: E):
|
|
135
|
+
unshift(value: E): boolean;
|
|
136
136
|
/**
|
|
137
137
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
138
138
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -145,7 +145,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
145
145
|
* @param {E} value - The parameter "value" represents the value of the new node that will be added to the beginning of the
|
|
146
146
|
* linked list.
|
|
147
147
|
*/
|
|
148
|
-
addFirst(value: E):
|
|
148
|
+
addFirst(value: E): boolean;
|
|
149
149
|
/**
|
|
150
150
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
151
151
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -190,7 +190,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
190
190
|
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
191
191
|
* bounds.
|
|
192
192
|
*/
|
|
193
|
-
deleteAt(index: number):
|
|
193
|
+
deleteAt(index: number): boolean;
|
|
194
194
|
/**
|
|
195
195
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
196
196
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -205,7 +205,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
205
205
|
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
|
|
206
206
|
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
|
|
207
207
|
*/
|
|
208
|
-
delete(valueOrNode: E | SinglyLinkedListNode<E> | undefined
|
|
208
|
+
delete(valueOrNode: E | SinglyLinkedListNode<E> | undefined): boolean;
|
|
209
209
|
/**
|
|
210
210
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
211
211
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -214,7 +214,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
214
214
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
215
215
|
* Space Complexity: O(1) - Constant space.
|
|
216
216
|
*
|
|
217
|
-
* The `
|
|
217
|
+
* The `addAt` function inserts a value at a specified index in a singly linked list.
|
|
218
218
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
219
219
|
* linked list. It is of type number.
|
|
220
220
|
* @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
|
|
@@ -222,7 +222,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
222
222
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
223
223
|
* if the index is out of bounds.
|
|
224
224
|
*/
|
|
225
|
-
|
|
225
|
+
addAt(index: number, value: E): boolean;
|
|
226
226
|
/**
|
|
227
227
|
* The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
|
|
228
228
|
* whether it is empty or not.
|
|
@@ -256,7 +256,7 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
256
256
|
* The `reverse` function reverses the order of the nodes in a singly linked list.
|
|
257
257
|
* @returns The reverse() method does not return anything. It has a return type of void.
|
|
258
258
|
*/
|
|
259
|
-
reverse():
|
|
259
|
+
reverse(): this;
|
|
260
260
|
/**
|
|
261
261
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
262
262
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -309,14 +309,14 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
309
309
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
310
310
|
* Space Complexity: O(1) - Constant space.
|
|
311
311
|
*
|
|
312
|
-
* The `
|
|
312
|
+
* The `addBefore` function inserts a new value before an existing value in a singly linked list.
|
|
313
313
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
|
|
314
314
|
* new value before. It can be either the value itself or a node containing the value in the linked list.
|
|
315
315
|
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
|
|
316
|
-
* @returns The method `
|
|
316
|
+
* @returns The method `addBefore` returns a boolean value. It returns `true` if the new value was successfully
|
|
317
317
|
* inserted before the existing value, and `false` otherwise.
|
|
318
318
|
*/
|
|
319
|
-
|
|
319
|
+
addBefore(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
320
320
|
/**
|
|
321
321
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
322
322
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -325,14 +325,14 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
325
325
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
326
326
|
* Space Complexity: O(1) - Constant space.
|
|
327
327
|
*
|
|
328
|
-
* The `
|
|
328
|
+
* The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
|
|
329
329
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
|
|
330
330
|
* the new value will be inserted. It can be either the value of the existing node or the existing node itself.
|
|
331
331
|
* @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
|
|
332
332
|
* @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
|
|
333
333
|
* existing value or node, and false if the existing value or node was not found in the linked list.
|
|
334
334
|
*/
|
|
335
|
-
|
|
335
|
+
addAfter(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
|
|
336
336
|
/**
|
|
337
337
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
338
338
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -387,10 +387,5 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
387
387
|
* of applying the provided `callback` function to each element in the original list.
|
|
388
388
|
*/
|
|
389
389
|
map<T>(callback: ElementCallback<E, T>, thisArg?: any): SinglyLinkedList<T>;
|
|
390
|
-
/**
|
|
391
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
392
|
-
* Space Complexity: O(n)
|
|
393
|
-
*/
|
|
394
|
-
print(): void;
|
|
395
390
|
protected _getIterator(): IterableIterator<E>;
|
|
396
391
|
}
|
|
@@ -22,7 +22,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
22
22
|
super();
|
|
23
23
|
this._head = undefined;
|
|
24
24
|
this._tail = undefined;
|
|
25
|
-
this.
|
|
25
|
+
this._size = 0;
|
|
26
26
|
if (elements) {
|
|
27
27
|
for (const el of elements)
|
|
28
28
|
this.push(el);
|
|
@@ -34,8 +34,8 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
34
34
|
get tail() {
|
|
35
35
|
return this._tail;
|
|
36
36
|
}
|
|
37
|
-
get
|
|
38
|
-
return this.
|
|
37
|
+
get size() {
|
|
38
|
+
return this._size;
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
|
|
@@ -79,7 +79,8 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
79
79
|
this.tail.next = newNode;
|
|
80
80
|
this._tail = newNode;
|
|
81
81
|
}
|
|
82
|
-
this.
|
|
82
|
+
this._size++;
|
|
83
|
+
return true;
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
86
|
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
|
|
@@ -94,7 +95,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
94
95
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
95
96
|
*/
|
|
96
97
|
addLast(value) {
|
|
97
|
-
this.push(value);
|
|
98
|
+
return this.push(value);
|
|
98
99
|
}
|
|
99
100
|
/**
|
|
100
101
|
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
@@ -116,7 +117,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
116
117
|
const value = this.head.value;
|
|
117
118
|
this._head = undefined;
|
|
118
119
|
this._tail = undefined;
|
|
119
|
-
this.
|
|
120
|
+
this._size--;
|
|
120
121
|
return value;
|
|
121
122
|
}
|
|
122
123
|
let current = this.head;
|
|
@@ -126,7 +127,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
126
127
|
const value = this.tail.value;
|
|
127
128
|
current.next = undefined;
|
|
128
129
|
this._tail = current;
|
|
129
|
-
this.
|
|
130
|
+
this._size--;
|
|
130
131
|
return value;
|
|
131
132
|
}
|
|
132
133
|
/**
|
|
@@ -161,7 +162,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
161
162
|
return undefined;
|
|
162
163
|
const removedNode = this.head;
|
|
163
164
|
this._head = this.head.next;
|
|
164
|
-
this.
|
|
165
|
+
this._size--;
|
|
165
166
|
return removedNode.value;
|
|
166
167
|
}
|
|
167
168
|
/**
|
|
@@ -200,7 +201,8 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
200
201
|
newNode.next = this.head;
|
|
201
202
|
this._head = newNode;
|
|
202
203
|
}
|
|
203
|
-
this.
|
|
204
|
+
this._size++;
|
|
205
|
+
return true;
|
|
204
206
|
}
|
|
205
207
|
/**
|
|
206
208
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
@@ -215,7 +217,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
215
217
|
* linked list.
|
|
216
218
|
*/
|
|
217
219
|
addFirst(value) {
|
|
218
|
-
this.unshift(value);
|
|
220
|
+
return this.unshift(value);
|
|
219
221
|
}
|
|
220
222
|
/**
|
|
221
223
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
@@ -232,7 +234,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
232
234
|
* `undefined` if the index is out of bounds.
|
|
233
235
|
*/
|
|
234
236
|
getAt(index) {
|
|
235
|
-
if (index < 0 || index >= this.
|
|
237
|
+
if (index < 0 || index >= this.size)
|
|
236
238
|
return undefined;
|
|
237
239
|
let current = this.head;
|
|
238
240
|
for (let i = 0; i < index; i++) {
|
|
@@ -276,17 +278,21 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
276
278
|
* bounds.
|
|
277
279
|
*/
|
|
278
280
|
deleteAt(index) {
|
|
279
|
-
if (index < 0 || index >= this.
|
|
280
|
-
return
|
|
281
|
-
if (index === 0)
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
281
|
+
if (index < 0 || index >= this.size)
|
|
282
|
+
return false;
|
|
283
|
+
if (index === 0) {
|
|
284
|
+
this.shift();
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
if (index === this.size - 1) {
|
|
288
|
+
this.pop();
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
285
291
|
const prevNode = this.getNodeAt(index - 1);
|
|
286
292
|
const removedNode = prevNode.next;
|
|
287
293
|
prevNode.next = removedNode.next;
|
|
288
|
-
this.
|
|
289
|
-
return
|
|
294
|
+
this._size--;
|
|
295
|
+
return true;
|
|
290
296
|
}
|
|
291
297
|
/**
|
|
292
298
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
@@ -327,7 +333,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
327
333
|
this._tail = prev;
|
|
328
334
|
}
|
|
329
335
|
}
|
|
330
|
-
this.
|
|
336
|
+
this._size--;
|
|
331
337
|
return true;
|
|
332
338
|
}
|
|
333
339
|
prev = current;
|
|
@@ -343,7 +349,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
343
349
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
344
350
|
* Space Complexity: O(1) - Constant space.
|
|
345
351
|
*
|
|
346
|
-
* The `
|
|
352
|
+
* The `addAt` function inserts a value at a specified index in a singly linked list.
|
|
347
353
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
348
354
|
* linked list. It is of type number.
|
|
349
355
|
* @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
|
|
@@ -351,14 +357,14 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
351
357
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
352
358
|
* if the index is out of bounds.
|
|
353
359
|
*/
|
|
354
|
-
|
|
355
|
-
if (index < 0 || index > this.
|
|
360
|
+
addAt(index, value) {
|
|
361
|
+
if (index < 0 || index > this.size)
|
|
356
362
|
return false;
|
|
357
363
|
if (index === 0) {
|
|
358
364
|
this.unshift(value);
|
|
359
365
|
return true;
|
|
360
366
|
}
|
|
361
|
-
if (index === this.
|
|
367
|
+
if (index === this.size) {
|
|
362
368
|
this.push(value);
|
|
363
369
|
return true;
|
|
364
370
|
}
|
|
@@ -366,7 +372,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
366
372
|
const prevNode = this.getNodeAt(index - 1);
|
|
367
373
|
newNode.next = prevNode.next;
|
|
368
374
|
prevNode.next = newNode;
|
|
369
|
-
this.
|
|
375
|
+
this._size++;
|
|
370
376
|
return true;
|
|
371
377
|
}
|
|
372
378
|
/**
|
|
@@ -375,7 +381,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
375
381
|
* @returns A boolean value indicating whether the length of the object is equal to 0.
|
|
376
382
|
*/
|
|
377
383
|
isEmpty() {
|
|
378
|
-
return this.
|
|
384
|
+
return this.size === 0;
|
|
379
385
|
}
|
|
380
386
|
/**
|
|
381
387
|
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
@@ -383,7 +389,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
383
389
|
clear() {
|
|
384
390
|
this._head = undefined;
|
|
385
391
|
this._tail = undefined;
|
|
386
|
-
this.
|
|
392
|
+
this._size = 0;
|
|
387
393
|
}
|
|
388
394
|
/**
|
|
389
395
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
|
|
@@ -418,7 +424,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
418
424
|
*/
|
|
419
425
|
reverse() {
|
|
420
426
|
if (!this.head || this.head === this.tail)
|
|
421
|
-
return;
|
|
427
|
+
return this;
|
|
422
428
|
let prev = undefined;
|
|
423
429
|
let current = this.head;
|
|
424
430
|
let next = undefined;
|
|
@@ -429,6 +435,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
429
435
|
current = next;
|
|
430
436
|
}
|
|
431
437
|
[this._head, this._tail] = [this.tail, this.head];
|
|
438
|
+
return this;
|
|
432
439
|
}
|
|
433
440
|
/**
|
|
434
441
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
@@ -511,14 +518,14 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
511
518
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
512
519
|
* Space Complexity: O(1) - Constant space.
|
|
513
520
|
*
|
|
514
|
-
* The `
|
|
521
|
+
* The `addBefore` function inserts a new value before an existing value in a singly linked list.
|
|
515
522
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
|
|
516
523
|
* new value before. It can be either the value itself or a node containing the value in the linked list.
|
|
517
524
|
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
|
|
518
|
-
* @returns The method `
|
|
525
|
+
* @returns The method `addBefore` returns a boolean value. It returns `true` if the new value was successfully
|
|
519
526
|
* inserted before the existing value, and `false` otherwise.
|
|
520
527
|
*/
|
|
521
|
-
|
|
528
|
+
addBefore(existingValueOrNode, newValue) {
|
|
522
529
|
if (!this.head)
|
|
523
530
|
return false;
|
|
524
531
|
let existingValue;
|
|
@@ -538,7 +545,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
538
545
|
const newNode = new SinglyLinkedListNode(newValue);
|
|
539
546
|
newNode.next = current.next;
|
|
540
547
|
current.next = newNode;
|
|
541
|
-
this.
|
|
548
|
+
this._size++;
|
|
542
549
|
return true;
|
|
543
550
|
}
|
|
544
551
|
current = current.next;
|
|
@@ -553,14 +560,14 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
553
560
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
554
561
|
* Space Complexity: O(1) - Constant space.
|
|
555
562
|
*
|
|
556
|
-
* The `
|
|
563
|
+
* The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
|
|
557
564
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
|
|
558
565
|
* the new value will be inserted. It can be either the value of the existing node or the existing node itself.
|
|
559
566
|
* @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
|
|
560
567
|
* @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
|
|
561
568
|
* existing value or node, and false if the existing value or node was not found in the linked list.
|
|
562
569
|
*/
|
|
563
|
-
|
|
570
|
+
addAfter(existingValueOrNode, newValue) {
|
|
564
571
|
let existingNode;
|
|
565
572
|
if (existingValueOrNode instanceof SinglyLinkedListNode) {
|
|
566
573
|
existingNode = existingValueOrNode;
|
|
@@ -575,7 +582,7 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
575
582
|
if (existingNode === this.tail) {
|
|
576
583
|
this._tail = newNode;
|
|
577
584
|
}
|
|
578
|
-
this.
|
|
585
|
+
this._size++;
|
|
579
586
|
return true;
|
|
580
587
|
}
|
|
581
588
|
return false;
|
|
@@ -662,13 +669,6 @@ class SinglyLinkedList extends base_1.IterableElementBase {
|
|
|
662
669
|
}
|
|
663
670
|
return mappedList;
|
|
664
671
|
}
|
|
665
|
-
/**
|
|
666
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
667
|
-
* Space Complexity: O(n)
|
|
668
|
-
*/
|
|
669
|
-
print() {
|
|
670
|
-
console.log([...this]);
|
|
671
|
-
}
|
|
672
672
|
*_getIterator() {
|
|
673
673
|
let current = this.head;
|
|
674
674
|
while (current) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C,MAAa,oBAAoB;IAI/B;;;;OAIG;IACH,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;CACF;AAbD,oDAaC;AAED,MAAa,gBAA0B,SAAQ,0BAAsB;IACnE;;OAEG;IACH,YAAY,QAAsB;QAChC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;QACjB,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,MAAM,EAAE,IAAI,QAAQ;gBACvB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAID,IAAI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AO,CAAC,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AA3tBD,4CA2tBC"}
|
|
1
|
+
{"version":3,"file":"singly-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/singly-linked-list.ts"],"names":[],"mappings":";;;AAQA,kCAA8C;AAE9C,MAAa,oBAAoB;IAI/B;;;;OAIG;IACH,YAAY,KAAQ;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;IACxB,CAAC;CACF;AAbD,oDAaC;AAED,MAAa,gBAA0B,SAAQ,0BAAsB;IACnE;;OAEG;IACH,YAAY,QAAsB;QAChC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACf,IAAI,QAAQ,EAAE,CAAC;YACb,KAAK,MAAM,EAAE,IAAI,QAAQ;gBACvB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IAEH;;;;;;;;OAQG;IACH,MAAM,CAAC,SAAS,CAAI,IAAS;QAC3B,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAK,CAAC;QACnD,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED;;;OAGG;IAEH;;;;;;;OAOG;IACH,IAAI,CAAC,KAAQ;Q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AI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC;gBACjD,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7B,CAAC;YACD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;IAGD;;;OAGG;IACH;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAI,QAA+B,EAAE,OAAa;QACnD,MAAM,UAAU,GAAG,IAAI,gBAAgB,EAAK,CAAC;QAC7C,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,OAAO,IAAI,IAAI,EAAE,CAAC;YAC3B,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YAC9D,KAAK,EAAE,CAAC;QACV,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAEQ,CAAE,YAAY;QACrB,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QAExB,OAAO,OAAO,EAAE,CAAC;YACf,MAAM,OAAO,CAAC,KAAK,CAAC;YACpB,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AA3tBD,4CA2tBC"}
|
|
@@ -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.
|
|
@@ -42,6 +42,41 @@ class SkipList {
|
|
|
42
42
|
get probability() {
|
|
43
43
|
return this._probability;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
47
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
51
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
52
|
+
*
|
|
53
|
+
* Get the value of the first element (the smallest element) in the Skip List.
|
|
54
|
+
* @returns The value of the first element, or undefined if the Skip List is empty.
|
|
55
|
+
*/
|
|
56
|
+
get first() {
|
|
57
|
+
const firstNode = this.head.forward[0];
|
|
58
|
+
return firstNode ? firstNode.value : undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
62
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
63
|
+
*/
|
|
64
|
+
/**
|
|
65
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
66
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
67
|
+
*
|
|
68
|
+
* Get the value of the last element (the largest element) in the Skip List.
|
|
69
|
+
* @returns The value of the last element, or undefined if the Skip List is empty.
|
|
70
|
+
*/
|
|
71
|
+
get last() {
|
|
72
|
+
let current = this.head;
|
|
73
|
+
for (let i = this.level - 1; i >= 0; i--) {
|
|
74
|
+
while (current.forward[i]) {
|
|
75
|
+
current = current.forward[i];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return current.value;
|
|
79
|
+
}
|
|
45
80
|
/**
|
|
46
81
|
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
47
82
|
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
@@ -100,7 +135,7 @@ class SkipList {
|
|
|
100
135
|
return undefined;
|
|
101
136
|
}
|
|
102
137
|
/**
|
|
103
|
-
* Time Complexity: O(
|
|
138
|
+
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
104
139
|
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
105
140
|
*/
|
|
106
141
|
/**
|
|
@@ -147,41 +182,6 @@ class SkipList {
|
|
|
147
182
|
}
|
|
148
183
|
return false;
|
|
149
184
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
152
|
-
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
153
|
-
*/
|
|
154
|
-
/**
|
|
155
|
-
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
156
|
-
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
157
|
-
*
|
|
158
|
-
* Get the value of the first element (the smallest element) in the Skip List.
|
|
159
|
-
* @returns The value of the first element, or undefined if the Skip List is empty.
|
|
160
|
-
*/
|
|
161
|
-
getFirst() {
|
|
162
|
-
const firstNode = this.head.forward[0];
|
|
163
|
-
return firstNode ? firstNode.value : undefined;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
167
|
-
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
168
|
-
*/
|
|
169
|
-
/**
|
|
170
|
-
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
171
|
-
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
172
|
-
*
|
|
173
|
-
* Get the value of the last element (the largest element) in the Skip List.
|
|
174
|
-
* @returns The value of the last element, or undefined if the Skip List is empty.
|
|
175
|
-
*/
|
|
176
|
-
getLast() {
|
|
177
|
-
let current = this.head;
|
|
178
|
-
for (let i = this.level - 1; i >= 0; i--) {
|
|
179
|
-
while (current.forward[i]) {
|
|
180
|
-
current = current.forward[i];
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return current.value;
|
|
184
|
-
}
|
|
185
185
|
/**
|
|
186
186
|
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
187
187
|
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|