data-structure-typed 1.47.7 → 1.47.8
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 +98 -17
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/cjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/cjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- 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 +21 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/cjs/data-structures/queue/queue.js +13 -13
- package/dist/cjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/cjs/data-structures/stack/stack.js +7 -7
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/mjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/mjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/mjs/data-structures/queue/queue.js +13 -13
- package/dist/mjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/mjs/data-structures/stack/stack.js +7 -7
- package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/umd/data-structure-typed.js +161 -161
- 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/binary-tree/segment-tree.ts +10 -10
- package/src/data-structures/graph/abstract-graph.ts +46 -46
- package/src/data-structures/graph/directed-graph.ts +40 -40
- package/src/data-structures/graph/undirected-graph.ts +26 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
- package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
- package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
- package/src/data-structures/queue/queue.ts +13 -13
- package/src/data-structures/stack/stack.ts +9 -9
- package/src/types/data-structures/graph/abstract-graph.ts +2 -2
- package/test/integration/index.html +102 -33
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +10 -10
- package/test/unit/data-structures/graph/undirected-graph.test.ts +3 -3
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -3
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export declare class SinglyLinkedListNode<E = any> {
|
|
9
9
|
value: E;
|
|
10
|
-
next: SinglyLinkedListNode<E> |
|
|
10
|
+
next: SinglyLinkedListNode<E> | undefined;
|
|
11
11
|
/**
|
|
12
|
-
* The constructor function initializes an instance of a class with a given value and sets the next property to
|
|
12
|
+
* The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
|
|
13
13
|
* @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
|
|
14
14
|
* will be stored in the node of a linked list.
|
|
15
15
|
*/
|
|
@@ -20,10 +20,10 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
20
20
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
21
21
|
*/
|
|
22
22
|
constructor(elements?: Iterable<E>);
|
|
23
|
-
protected _head: SinglyLinkedListNode<E> |
|
|
24
|
-
get head(): SinglyLinkedListNode<E> |
|
|
25
|
-
protected _tail: SinglyLinkedListNode<E> |
|
|
26
|
-
get tail(): SinglyLinkedListNode<E> |
|
|
23
|
+
protected _head: SinglyLinkedListNode<E> | undefined;
|
|
24
|
+
get head(): SinglyLinkedListNode<E> | undefined;
|
|
25
|
+
protected _tail: SinglyLinkedListNode<E> | undefined;
|
|
26
|
+
get tail(): SinglyLinkedListNode<E> | undefined;
|
|
27
27
|
protected _length: number;
|
|
28
28
|
get length(): number;
|
|
29
29
|
/**
|
|
@@ -77,7 +77,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
77
77
|
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
78
78
|
* pointers accordingly.
|
|
79
79
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
80
|
-
* the linked list is empty, it returns `
|
|
80
|
+
* the linked list is empty, it returns `undefined`.
|
|
81
81
|
*/
|
|
82
82
|
pop(): E | undefined;
|
|
83
83
|
/**
|
|
@@ -91,7 +91,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
91
91
|
* The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
92
92
|
* pointers accordingly.
|
|
93
93
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
94
|
-
* the linked list is empty, it returns `
|
|
94
|
+
* the linked list is empty, it returns `undefined`.
|
|
95
95
|
*/
|
|
96
96
|
popLast(): E | undefined;
|
|
97
97
|
/**
|
|
@@ -152,11 +152,11 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
152
152
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
153
153
|
* Space Complexity: O(1) - Constant space.
|
|
154
154
|
*
|
|
155
|
-
* The function `getAt` returns the value at a specified index in a linked list, or
|
|
155
|
+
* The function `getAt` returns the value at a specified index in a linked list, or undefined if the index is out of range.
|
|
156
156
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
157
157
|
* retrieve from the list.
|
|
158
|
-
* @returns The method `getAt(index: number): E |
|
|
159
|
-
* `
|
|
158
|
+
* @returns The method `getAt(index: number): E | undefined` returns the value at the specified index in the linked list, or
|
|
159
|
+
* `undefined` if the index is out of bounds.
|
|
160
160
|
*/
|
|
161
161
|
getAt(index: number): E | undefined;
|
|
162
162
|
/**
|
|
@@ -171,9 +171,9 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
171
171
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
172
172
|
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
|
|
173
173
|
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<E>` object if the node at the
|
|
174
|
-
* specified index exists, or `
|
|
174
|
+
* specified index exists, or `undefined` if the index is out of bounds.
|
|
175
175
|
*/
|
|
176
|
-
getNodeAt(index: number): SinglyLinkedListNode<E> |
|
|
176
|
+
getNodeAt(index: number): SinglyLinkedListNode<E> | undefined;
|
|
177
177
|
/**
|
|
178
178
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
179
179
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -185,7 +185,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
185
185
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
186
186
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
187
187
|
* data structure. It is of type number.
|
|
188
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `
|
|
188
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
189
189
|
* bounds.
|
|
190
190
|
*/
|
|
191
191
|
deleteAt(index: number): E | undefined;
|
|
@@ -203,7 +203,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
203
203
|
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
|
|
204
204
|
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
|
|
205
205
|
*/
|
|
206
|
-
delete(valueOrNode: E | SinglyLinkedListNode<E> |
|
|
206
|
+
delete(valueOrNode: E | SinglyLinkedListNode<E> | undefined | undefined): boolean;
|
|
207
207
|
/**
|
|
208
208
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
209
209
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -228,7 +228,7 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
228
228
|
*/
|
|
229
229
|
isEmpty(): boolean;
|
|
230
230
|
/**
|
|
231
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to
|
|
231
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
232
232
|
*/
|
|
233
233
|
clear(): void;
|
|
234
234
|
/**
|
|
@@ -267,9 +267,9 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
267
267
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
268
268
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
269
269
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
270
|
-
* the callback function. If no element satisfies the condition, it returns `
|
|
270
|
+
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
271
271
|
*/
|
|
272
|
-
find(callback: (value: E) => boolean): E |
|
|
272
|
+
find(callback: (value: E) => boolean): E | undefined;
|
|
273
273
|
/**
|
|
274
274
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
275
275
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -293,12 +293,12 @@ export declare class SinglyLinkedList<E = any> {
|
|
|
293
293
|
* Space Complexity: O(1) - Constant space.
|
|
294
294
|
*
|
|
295
295
|
* The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
|
|
296
|
-
*
|
|
296
|
+
* undefined.
|
|
297
297
|
* @param {E} value - The value parameter is the value that we want to search for in the linked list.
|
|
298
298
|
* @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
|
|
299
|
-
* the specified value is found, the function returns `
|
|
299
|
+
* the specified value is found, the function returns `undefined`.
|
|
300
300
|
*/
|
|
301
|
-
getNode(value: E): SinglyLinkedListNode<E> |
|
|
301
|
+
getNode(value: E): SinglyLinkedListNode<E> | undefined;
|
|
302
302
|
/**
|
|
303
303
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
304
304
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -9,13 +9,13 @@ export class SinglyLinkedListNode {
|
|
|
9
9
|
value;
|
|
10
10
|
next;
|
|
11
11
|
/**
|
|
12
|
-
* The constructor function initializes an instance of a class with a given value and sets the next property to
|
|
12
|
+
* The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
|
|
13
13
|
* @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
|
|
14
14
|
* will be stored in the node of a linked list.
|
|
15
15
|
*/
|
|
16
16
|
constructor(value) {
|
|
17
17
|
this.value = value;
|
|
18
|
-
this.next =
|
|
18
|
+
this.next = undefined;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
export class SinglyLinkedList {
|
|
@@ -23,8 +23,8 @@ export class SinglyLinkedList {
|
|
|
23
23
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
24
24
|
*/
|
|
25
25
|
constructor(elements) {
|
|
26
|
-
this._head =
|
|
27
|
-
this._tail =
|
|
26
|
+
this._head = undefined;
|
|
27
|
+
this._tail = undefined;
|
|
28
28
|
this._length = 0;
|
|
29
29
|
if (elements) {
|
|
30
30
|
for (const el of elements)
|
|
@@ -113,15 +113,15 @@ export class SinglyLinkedList {
|
|
|
113
113
|
* The `pop()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
114
114
|
* pointers accordingly.
|
|
115
115
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
116
|
-
* the linked list is empty, it returns `
|
|
116
|
+
* the linked list is empty, it returns `undefined`.
|
|
117
117
|
*/
|
|
118
118
|
pop() {
|
|
119
119
|
if (!this.head)
|
|
120
120
|
return undefined;
|
|
121
121
|
if (this.head === this.tail) {
|
|
122
122
|
const value = this.head.value;
|
|
123
|
-
this._head =
|
|
124
|
-
this._tail =
|
|
123
|
+
this._head = undefined;
|
|
124
|
+
this._tail = undefined;
|
|
125
125
|
this._length--;
|
|
126
126
|
return value;
|
|
127
127
|
}
|
|
@@ -130,7 +130,7 @@ export class SinglyLinkedList {
|
|
|
130
130
|
current = current.next;
|
|
131
131
|
}
|
|
132
132
|
const value = this.tail.value;
|
|
133
|
-
current.next =
|
|
133
|
+
current.next = undefined;
|
|
134
134
|
this._tail = current;
|
|
135
135
|
this._length--;
|
|
136
136
|
return value;
|
|
@@ -146,7 +146,7 @@ export class SinglyLinkedList {
|
|
|
146
146
|
* The `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
147
147
|
* pointers accordingly.
|
|
148
148
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
149
|
-
* the linked list is empty, it returns `
|
|
149
|
+
* the linked list is empty, it returns `undefined`.
|
|
150
150
|
*/
|
|
151
151
|
popLast() {
|
|
152
152
|
return this.pop();
|
|
@@ -231,11 +231,11 @@ export class SinglyLinkedList {
|
|
|
231
231
|
* 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
232
|
* Space Complexity: O(1) - Constant space.
|
|
233
233
|
*
|
|
234
|
-
* The function `getAt` returns the value at a specified index in a linked list, or
|
|
234
|
+
* The function `getAt` returns the value at a specified index in a linked list, or undefined if the index is out of range.
|
|
235
235
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
236
236
|
* retrieve from the list.
|
|
237
|
-
* @returns The method `getAt(index: number): E |
|
|
238
|
-
* `
|
|
237
|
+
* @returns The method `getAt(index: number): E | undefined` returns the value at the specified index in the linked list, or
|
|
238
|
+
* `undefined` if the index is out of bounds.
|
|
239
239
|
*/
|
|
240
240
|
getAt(index) {
|
|
241
241
|
if (index < 0 || index >= this.length)
|
|
@@ -258,7 +258,7 @@ export class SinglyLinkedList {
|
|
|
258
258
|
* @param {number} index - The `index` parameter is a number that represents the position of the node we want to
|
|
259
259
|
* retrieve from the linked list. It indicates the zero-based index of the node we want to access.
|
|
260
260
|
* @returns The method `getNodeAt(index: number)` returns a `SinglyLinkedListNode<E>` object if the node at the
|
|
261
|
-
* specified index exists, or `
|
|
261
|
+
* specified index exists, or `undefined` if the index is out of bounds.
|
|
262
262
|
*/
|
|
263
263
|
getNodeAt(index) {
|
|
264
264
|
let current = this.head;
|
|
@@ -278,7 +278,7 @@ export class SinglyLinkedList {
|
|
|
278
278
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
279
279
|
* @param {number} index - The index parameter represents the position of the element that needs to be deleted in the
|
|
280
280
|
* data structure. It is of type number.
|
|
281
|
-
* @returns The method `deleteAt` returns the value of the node that was deleted, or `
|
|
281
|
+
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
282
282
|
* bounds.
|
|
283
283
|
*/
|
|
284
284
|
deleteAt(index) {
|
|
@@ -318,13 +318,13 @@ export class SinglyLinkedList {
|
|
|
318
318
|
else {
|
|
319
319
|
value = valueOrNode;
|
|
320
320
|
}
|
|
321
|
-
let current = this.head, prev =
|
|
321
|
+
let current = this.head, prev = undefined;
|
|
322
322
|
while (current) {
|
|
323
323
|
if (current.value === value) {
|
|
324
|
-
if (prev ===
|
|
324
|
+
if (prev === undefined) {
|
|
325
325
|
this._head = current.next;
|
|
326
326
|
if (current === this.tail) {
|
|
327
|
-
this._tail =
|
|
327
|
+
this._tail = undefined;
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
330
|
else {
|
|
@@ -384,11 +384,11 @@ export class SinglyLinkedList {
|
|
|
384
384
|
return this.length === 0;
|
|
385
385
|
}
|
|
386
386
|
/**
|
|
387
|
-
* The `clear` function resets the linked list by setting the head, tail, and length to
|
|
387
|
+
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
388
388
|
*/
|
|
389
389
|
clear() {
|
|
390
|
-
this._head =
|
|
391
|
-
this._tail =
|
|
390
|
+
this._head = undefined;
|
|
391
|
+
this._tail = undefined;
|
|
392
392
|
this._length = 0;
|
|
393
393
|
}
|
|
394
394
|
/**
|
|
@@ -425,9 +425,9 @@ export class SinglyLinkedList {
|
|
|
425
425
|
reverse() {
|
|
426
426
|
if (!this.head || this.head === this.tail)
|
|
427
427
|
return;
|
|
428
|
-
let prev =
|
|
428
|
+
let prev = undefined;
|
|
429
429
|
let current = this.head;
|
|
430
|
-
let next =
|
|
430
|
+
let next = undefined;
|
|
431
431
|
while (current) {
|
|
432
432
|
next = current.next;
|
|
433
433
|
current.next = prev;
|
|
@@ -448,7 +448,7 @@ export class SinglyLinkedList {
|
|
|
448
448
|
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
449
449
|
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
450
450
|
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
451
|
-
* the callback function. If no element satisfies the condition, it returns `
|
|
451
|
+
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
452
452
|
*/
|
|
453
453
|
find(callback) {
|
|
454
454
|
let current = this.head;
|
|
@@ -458,7 +458,7 @@ export class SinglyLinkedList {
|
|
|
458
458
|
}
|
|
459
459
|
current = current.next;
|
|
460
460
|
}
|
|
461
|
-
return
|
|
461
|
+
return undefined;
|
|
462
462
|
}
|
|
463
463
|
/**
|
|
464
464
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
@@ -494,10 +494,10 @@ export class SinglyLinkedList {
|
|
|
494
494
|
* Space Complexity: O(1) - Constant space.
|
|
495
495
|
*
|
|
496
496
|
* The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
|
|
497
|
-
*
|
|
497
|
+
* undefined.
|
|
498
498
|
* @param {E} value - The value parameter is the value that we want to search for in the linked list.
|
|
499
499
|
* @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
|
|
500
|
-
* the specified value is found, the function returns `
|
|
500
|
+
* the specified value is found, the function returns `undefined`.
|
|
501
501
|
*/
|
|
502
502
|
getNode(value) {
|
|
503
503
|
let current = this.head;
|
|
@@ -507,7 +507,7 @@ export class SinglyLinkedList {
|
|
|
507
507
|
}
|
|
508
508
|
current = current.next;
|
|
509
509
|
}
|
|
510
|
-
return
|
|
510
|
+
return undefined;
|
|
511
511
|
}
|
|
512
512
|
/**
|
|
513
513
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
@@ -24,7 +24,7 @@ export class SkipList {
|
|
|
24
24
|
* level in the skip list. It is used to determine the height of each node in the skip list.
|
|
25
25
|
*/
|
|
26
26
|
constructor(maxLevel = 16, probability = 0.5) {
|
|
27
|
-
this._head = new SkipListNode(
|
|
27
|
+
this._head = new SkipListNode(undefined, undefined, maxLevel);
|
|
28
28
|
this._level = 0;
|
|
29
29
|
this._maxLevel = maxLevel;
|
|
30
30
|
this._probability = probability;
|
|
@@ -72,7 +72,7 @@ export class SkipList {
|
|
|
72
72
|
newNode.forward[i] = update[i].forward[i];
|
|
73
73
|
update[i].forward[i] = newNode;
|
|
74
74
|
}
|
|
75
|
-
if (newNode.forward[0]
|
|
75
|
+
if (!newNode.forward[0]) {
|
|
76
76
|
this._level = Math.max(this.level, newNode.forward.length);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -143,7 +143,7 @@ export class SkipList {
|
|
|
143
143
|
}
|
|
144
144
|
update[i].forward[i] = current.forward[i];
|
|
145
145
|
}
|
|
146
|
-
while (this.level > 0 && this.head.forward[this.level - 1]
|
|
146
|
+
while (this.level > 0 && !this.head.forward[this.level - 1]) {
|
|
147
147
|
this._level--;
|
|
148
148
|
}
|
|
149
149
|
return true;
|
|
@@ -221,7 +221,7 @@ export class SkipList {
|
|
|
221
221
|
*/
|
|
222
222
|
lower(key) {
|
|
223
223
|
let current = this.head;
|
|
224
|
-
let lastLess =
|
|
224
|
+
let lastLess = undefined;
|
|
225
225
|
for (let i = this.level - 1; i >= 0; i--) {
|
|
226
226
|
while (current.forward[i] && current.forward[i].key < key) {
|
|
227
227
|
current = current.forward[i];
|
|
@@ -11,8 +11,8 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
|
11
11
|
*/
|
|
12
12
|
enqueue(value: E): void;
|
|
13
13
|
/**
|
|
14
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
15
|
-
* @returns The method is returning the element at the front of the queue, or
|
|
14
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
15
|
+
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
16
16
|
*/
|
|
17
17
|
dequeue(): E | undefined;
|
|
18
18
|
/**
|
|
@@ -75,7 +75,7 @@ export declare class Queue<E = any> {
|
|
|
75
75
|
*
|
|
76
76
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
77
77
|
* necessary to optimize performance.
|
|
78
|
-
* @returns The function `shift()` returns either the first element in the queue or `
|
|
78
|
+
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
79
79
|
*/
|
|
80
80
|
shift(): E | undefined;
|
|
81
81
|
/**
|
|
@@ -86,9 +86,9 @@ export declare class Queue<E = any> {
|
|
|
86
86
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
87
87
|
* Space Complexity: O(1) - no additional space is used.
|
|
88
88
|
*
|
|
89
|
-
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
89
|
+
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
90
90
|
* @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
91
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
91
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
92
92
|
*/
|
|
93
93
|
getFirst(): E | undefined;
|
|
94
94
|
/**
|
|
@@ -99,9 +99,9 @@ export declare class Queue<E = any> {
|
|
|
99
99
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
100
100
|
* Space Complexity: O(1) - no additional space is used.
|
|
101
101
|
*
|
|
102
|
-
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
102
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
103
103
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
104
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
104
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
105
105
|
*/
|
|
106
106
|
peek(): E | undefined;
|
|
107
107
|
/**
|
|
@@ -112,9 +112,9 @@ export declare class Queue<E = any> {
|
|
|
112
112
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
113
113
|
* Space Complexity: O(1) - no additional space is used.
|
|
114
114
|
*
|
|
115
|
-
* The `getLast` function returns the last element in an array-like data structure, or
|
|
115
|
+
* The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
116
116
|
* @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
117
|
-
* array is empty, it returns `
|
|
117
|
+
* array is empty, it returns `undefined`.
|
|
118
118
|
*/
|
|
119
119
|
getLast(): E | undefined;
|
|
120
120
|
/**
|
|
@@ -125,9 +125,9 @@ export declare class Queue<E = any> {
|
|
|
125
125
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
126
126
|
* Space Complexity: O(1) - no additional space is used.
|
|
127
127
|
*
|
|
128
|
-
* The `peekLast` function returns the last element in an array-like data structure, or
|
|
128
|
+
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
129
129
|
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
130
|
-
* array is empty, it returns `
|
|
130
|
+
* array is empty, it returns `undefined`.
|
|
131
131
|
*/
|
|
132
132
|
peekLast(): E | undefined;
|
|
133
133
|
/**
|
|
@@ -150,8 +150,8 @@ export declare class Queue<E = any> {
|
|
|
150
150
|
* Time Complexity: O(n) - same as shift().
|
|
151
151
|
* Space Complexity: O(1) - same as shift().
|
|
152
152
|
*
|
|
153
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
154
|
-
* @returns The method is returning a value of type E or
|
|
153
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
154
|
+
* @returns The method is returning a value of type E or undefined.
|
|
155
155
|
*/
|
|
156
156
|
dequeue(): E | undefined;
|
|
157
157
|
/**
|
|
@@ -13,8 +13,8 @@ export class LinkedListQueue extends SinglyLinkedList {
|
|
|
13
13
|
this.push(value);
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
17
|
-
* @returns The method is returning the element at the front of the queue, or
|
|
16
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
17
|
+
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
18
18
|
*/
|
|
19
19
|
dequeue() {
|
|
20
20
|
return this.shift();
|
|
@@ -97,7 +97,7 @@ export class Queue {
|
|
|
97
97
|
*
|
|
98
98
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
99
99
|
* necessary to optimize performance.
|
|
100
|
-
* @returns The function `shift()` returns either the first element in the queue or `
|
|
100
|
+
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
101
101
|
*/
|
|
102
102
|
shift() {
|
|
103
103
|
if (this.size === 0)
|
|
@@ -120,9 +120,9 @@ export class Queue {
|
|
|
120
120
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
121
121
|
* Space Complexity: O(1) - no additional space is used.
|
|
122
122
|
*
|
|
123
|
-
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
123
|
+
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
124
124
|
* @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
125
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
125
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
126
126
|
*/
|
|
127
127
|
getFirst() {
|
|
128
128
|
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
@@ -135,9 +135,9 @@ export class Queue {
|
|
|
135
135
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
136
136
|
* Space Complexity: O(1) - no additional space is used.
|
|
137
137
|
*
|
|
138
|
-
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
138
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
139
139
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
140
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
140
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
141
141
|
*/
|
|
142
142
|
peek() {
|
|
143
143
|
return this.getFirst();
|
|
@@ -150,9 +150,9 @@ export class Queue {
|
|
|
150
150
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
151
151
|
* Space Complexity: O(1) - no additional space is used.
|
|
152
152
|
*
|
|
153
|
-
* The `getLast` function returns the last element in an array-like data structure, or
|
|
153
|
+
* The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
154
154
|
* @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
155
|
-
* array is empty, it returns `
|
|
155
|
+
* array is empty, it returns `undefined`.
|
|
156
156
|
*/
|
|
157
157
|
getLast() {
|
|
158
158
|
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
@@ -165,9 +165,9 @@ export class Queue {
|
|
|
165
165
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
166
166
|
* Space Complexity: O(1) - no additional space is used.
|
|
167
167
|
*
|
|
168
|
-
* The `peekLast` function returns the last element in an array-like data structure, or
|
|
168
|
+
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
169
169
|
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
170
|
-
* array is empty, it returns `
|
|
170
|
+
* array is empty, it returns `undefined`.
|
|
171
171
|
*/
|
|
172
172
|
peekLast() {
|
|
173
173
|
return this.getLast();
|
|
@@ -194,8 +194,8 @@ export class Queue {
|
|
|
194
194
|
* Time Complexity: O(n) - same as shift().
|
|
195
195
|
* Space Complexity: O(1) - same as shift().
|
|
196
196
|
*
|
|
197
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
198
|
-
* @returns The method is returning a value of type E or
|
|
197
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
198
|
+
* @returns The method is returning a value of type E or undefined.
|
|
199
199
|
*/
|
|
200
200
|
dequeue() {
|
|
201
201
|
return this.shift();
|
|
@@ -45,10 +45,10 @@ export declare class Stack<E = any> {
|
|
|
45
45
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
46
46
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
47
47
|
*
|
|
48
|
-
* The `peek` function returns the last element of an array, or
|
|
49
|
-
* @returns The `peek()` function returns the last element of the `_elements` array, or `
|
|
48
|
+
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
49
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
50
50
|
*/
|
|
51
|
-
peek(): E |
|
|
51
|
+
peek(): E | undefined;
|
|
52
52
|
/**
|
|
53
53
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
54
54
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
@@ -70,11 +70,11 @@ export declare class Stack<E = any> {
|
|
|
70
70
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
71
71
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
72
72
|
*
|
|
73
|
-
* The `pop` function removes and returns the last element from an array, or returns
|
|
73
|
+
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
74
74
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
75
|
-
* array is empty, it returns `
|
|
75
|
+
* array is empty, it returns `undefined`.
|
|
76
76
|
*/
|
|
77
|
-
pop(): E |
|
|
77
|
+
pop(): E | undefined;
|
|
78
78
|
/**
|
|
79
79
|
* Time Complexity: O(n)
|
|
80
80
|
* Space Complexity: O(n)
|
|
@@ -60,12 +60,12 @@ export class Stack {
|
|
|
60
60
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
61
61
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
62
62
|
*
|
|
63
|
-
* The `peek` function returns the last element of an array, or
|
|
64
|
-
* @returns The `peek()` function returns the last element of the `_elements` array, or `
|
|
63
|
+
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
64
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
65
65
|
*/
|
|
66
66
|
peek() {
|
|
67
67
|
if (this.isEmpty())
|
|
68
|
-
return
|
|
68
|
+
return undefined;
|
|
69
69
|
return this.elements[this.elements.length - 1];
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
@@ -92,14 +92,14 @@ export class Stack {
|
|
|
92
92
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
93
93
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
94
94
|
*
|
|
95
|
-
* The `pop` function removes and returns the last element from an array, or returns
|
|
95
|
+
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
96
96
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
97
|
-
* array is empty, it returns `
|
|
97
|
+
* array is empty, it returns `undefined`.
|
|
98
98
|
*/
|
|
99
99
|
pop() {
|
|
100
100
|
if (this.isEmpty())
|
|
101
|
-
return
|
|
102
|
-
return this.elements.pop() ||
|
|
101
|
+
return undefined;
|
|
102
|
+
return this.elements.pop() || undefined;
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
105
|
* Time Complexity: O(n)
|
|
@@ -2,9 +2,9 @@ export type VertexKey = string | number;
|
|
|
2
2
|
export type DijkstraResult<V> = {
|
|
3
3
|
distMap: Map<V, number>;
|
|
4
4
|
distPaths?: Map<V, V[]>;
|
|
5
|
-
preMap: Map<V, V |
|
|
5
|
+
preMap: Map<V, V | undefined>;
|
|
6
6
|
seen: Set<V>;
|
|
7
7
|
paths: V[][];
|
|
8
8
|
minDist: number;
|
|
9
9
|
minPath: V[];
|
|
10
|
-
} |
|
|
10
|
+
} | undefined;
|