min-heap-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.
@@ -432,11 +432,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
432
432
  * type `number`.
433
433
  */
434
434
  getLowMap(): Map<VO, number>;
435
- /**
436
- * The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
437
- * @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
438
- */
439
- getCycles(): Map<number, VO[]>;
440
435
  /**
441
436
  * The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
442
437
  * @returns an array of VO objects, specifically the cut vertexes.
@@ -453,6 +448,11 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
453
448
  * @returns the bridges found using the Tarjan algorithm.
454
449
  */
455
450
  getBridges(): EO[];
451
+ /**
452
+ * O(V+E+C)
453
+ * O(V+C)
454
+ */
455
+ getCycles(isInclude2Cycle?: boolean): VertexKey[][];
456
456
  /**
457
457
  * Time Complexity: O(n)
458
458
  * Space Complexity: O(n)
@@ -493,8 +493,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
493
493
  */
494
494
  map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: any): T[];
495
495
  protected _getIterator(): IterableIterator<[VertexKey, V | undefined]>;
496
- protected abstract _addEdgeOnly(edge: EO): boolean;
497
- protected _addVertexOnly(newVertex: VO): boolean;
496
+ protected abstract _addEdge(edge: EO): boolean;
497
+ protected _addVertex(newVertex: VO): boolean;
498
498
  protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
499
499
  protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
500
500
  }
@@ -86,11 +86,11 @@ class AbstractGraph extends base_1.IterableEntryBase {
86
86
  */
87
87
  addVertex(keyOrVertex, value) {
88
88
  if (keyOrVertex instanceof AbstractVertex) {
89
- return this._addVertexOnly(keyOrVertex);
89
+ return this._addVertex(keyOrVertex);
90
90
  }
91
91
  else {
92
92
  const newVertex = this.createVertex(keyOrVertex, value);
93
- return this._addVertexOnly(newVertex);
93
+ return this._addVertex(newVertex);
94
94
  }
95
95
  }
96
96
  isVertexKey(potentialKey) {
@@ -160,7 +160,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
160
160
  */
161
161
  addEdge(srcOrEdge, dest, weight, value) {
162
162
  if (srcOrEdge instanceof AbstractEdge) {
163
- return this._addEdgeOnly(srcOrEdge);
163
+ return this._addEdge(srcOrEdge);
164
164
  }
165
165
  else {
166
166
  if (dest instanceof AbstractVertex || typeof dest === 'string' || typeof dest === 'number') {
@@ -171,7 +171,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
171
171
  if (dest instanceof AbstractVertex)
172
172
  dest = dest.key;
173
173
  const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
174
- return this._addEdgeOnly(newEdge);
174
+ return this._addEdge(newEdge);
175
175
  }
176
176
  else {
177
177
  throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
@@ -1001,13 +1001,6 @@ class AbstractGraph extends base_1.IterableEntryBase {
1001
1001
  getLowMap() {
1002
1002
  return this.tarjan(false, false, false, false).lowMap;
1003
1003
  }
1004
- /**
1005
- * The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
1006
- * @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
1007
- */
1008
- getCycles() {
1009
- return this.tarjan(false, false, false, true).cycles;
1010
- }
1011
1004
  /**
1012
1005
  * The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
1013
1006
  * @returns an array of VO objects, specifically the cut vertexes.
@@ -1030,6 +1023,44 @@ class AbstractGraph extends base_1.IterableEntryBase {
1030
1023
  getBridges() {
1031
1024
  return this.tarjan(false, true, false, false).bridges;
1032
1025
  }
1026
+ /**
1027
+ * O(V+E+C)
1028
+ * O(V+C)
1029
+ */
1030
+ getCycles(isInclude2Cycle = false) {
1031
+ const cycles = [];
1032
+ const visited = new Set();
1033
+ const dfs = (vertex, currentPath, visited) => {
1034
+ if (visited.has(vertex)) {
1035
+ if ((!isInclude2Cycle && currentPath.length > 2 || isInclude2Cycle && currentPath.length >= 2) && currentPath[0] === vertex.key) {
1036
+ cycles.push([...currentPath]);
1037
+ }
1038
+ return;
1039
+ }
1040
+ visited.add(vertex);
1041
+ currentPath.push(vertex.key);
1042
+ for (const neighbor of this.getNeighbors(vertex)) {
1043
+ neighbor && dfs(neighbor, currentPath, visited);
1044
+ }
1045
+ visited.delete(vertex);
1046
+ currentPath.pop();
1047
+ };
1048
+ for (const vertex of this.vertexMap.values()) {
1049
+ dfs(vertex, [], visited);
1050
+ }
1051
+ // Use a set to eliminate duplicate cycles
1052
+ const uniqueCycles = new Map();
1053
+ for (const cycle of cycles) {
1054
+ const sorted = [...cycle].sort().toString();
1055
+ if (uniqueCycles.has(sorted))
1056
+ continue;
1057
+ else {
1058
+ uniqueCycles.set(sorted, cycle);
1059
+ }
1060
+ }
1061
+ // Convert the unique cycles back to an array
1062
+ return [...uniqueCycles].map(cycleString => cycleString[1]);
1063
+ }
1033
1064
  /**
1034
1065
  * Time Complexity: O(n)
1035
1066
  * Space Complexity: O(n)
@@ -1092,7 +1123,7 @@ class AbstractGraph extends base_1.IterableEntryBase {
1092
1123
  yield [vertex.key, vertex.value];
1093
1124
  }
1094
1125
  }
1095
- _addVertexOnly(newVertex) {
1126
+ _addVertex(newVertex) {
1096
1127
  if (this.hasVertex(newVertex)) {
1097
1128
  return false;
1098
1129
  // throw (new Error('Duplicated vertex key is not allowed'));
@@ -335,11 +335,11 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
335
335
  * Time Complexity: O(1)
336
336
  * Space Complexity: O(1)
337
337
  *
338
- * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertexMap exist.
338
+ * The function `_addEdge` adds an edge to a graph if the source and destination vertexMap exist.
339
339
  * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
340
340
  * needs to be added to the graph.
341
341
  * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
342
342
  * source or destination vertex does not exist in the graph.
343
343
  */
344
- protected _addEdgeOnly(edge: EO): boolean;
344
+ protected _addEdge(edge: EO): boolean;
345
345
  }
@@ -531,13 +531,13 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
531
531
  * Time Complexity: O(1)
532
532
  * Space Complexity: O(1)
533
533
  *
534
- * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertexMap exist.
534
+ * The function `_addEdge` adds an edge to a graph if the source and destination vertexMap exist.
535
535
  * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
536
536
  * needs to be added to the graph.
537
537
  * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
538
538
  * source or destination vertex does not exist in the graph.
539
539
  */
540
- _addEdgeOnly(edge) {
540
+ _addEdge(edge) {
541
541
  if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
542
542
  return false;
543
543
  }
@@ -205,5 +205,5 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
205
205
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
206
206
  * @returns a boolean value.
207
207
  */
208
- protected _addEdgeOnly(edge: EO): boolean;
208
+ protected _addEdge(edge: EO): boolean;
209
209
  }
@@ -337,7 +337,7 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
337
337
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
338
338
  * @returns a boolean value.
339
339
  */
340
- _addEdgeOnly(edge) {
340
+ _addEdge(edge) {
341
341
  for (const end of edge.vertexMap) {
342
342
  const endVertex = this._getVertex(end);
343
343
  if (endVertex === undefined)
@@ -39,6 +39,30 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
39
39
  * Time Complexity: O(n), where n is the size of the input array.
40
40
  * Space Complexity: O(n)
41
41
  */
42
+ /**
43
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
44
+ * Space Complexity: O(1)
45
+ *
46
+ * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
47
+ * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
48
+ */
49
+ get first(): E | undefined;
50
+ /**
51
+ * Time Complexity: O(1)
52
+ * Space Complexity: O(1)
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 last` function returns the last node in a doubly linked list, or undefined if the list is empty.
59
+ * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
60
+ */
61
+ get last(): E | undefined;
62
+ /**
63
+ * Time Complexity: O(1)
64
+ * Space Complexity: O(1)
65
+ */
42
66
  /**
43
67
  * Time Complexity: O(n), where n is the size of the input array.
44
68
  * Space Complexity: O(n)
@@ -75,7 +99,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
75
99
  */
76
100
  pop(): E | undefined;
77
101
  /**
78
- * Time Complexity: O(1)
102
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
79
103
  * Space Complexity: O(1)
80
104
  */
81
105
  /**
@@ -88,7 +112,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
88
112
  */
89
113
  shift(): E | undefined;
90
114
  /**
91
- * Time Complexity: O(1)
115
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
92
116
  * Space Complexity: O(1)
93
117
  */
94
118
  /**
@@ -198,10 +222,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
198
222
  * existing value or node is not found in the doubly linked list.
199
223
  */
200
224
  addAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
201
- /**
202
- * Time Complexity: O(n), where n is the number of elements in the linked list.
203
- * Space Complexity: O(1)
204
- */
205
225
  /**
206
226
  * Time Complexity: O(n), where n is the number of elements in the linked list.
207
227
  * Space Complexity: O(1)
@@ -213,10 +233,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
213
233
  * bounds.
214
234
  */
215
235
  deleteAt(index: number): boolean;
216
- /**
217
- * Time Complexity: O(n), where n is the number of elements in the linked list.
218
- * Space Complexity: O(1)
219
- */
220
236
  /**
221
237
  * Time Complexity: O(n), where n is the number of elements in the linked list.
222
238
  * Space Complexity: O(1)
@@ -228,11 +244,19 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
228
244
  * deleted from the doubly linked list, and `false` if the value or node was not found in the list.
229
245
  */
230
246
  delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
247
+ /**
248
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
249
+ * Space Complexity: O(1)
250
+ */
231
251
  /**
232
252
  * The function checks if a variable has a size greater than zero and returns a boolean value.
233
253
  * @returns A boolean value is being returned.
234
254
  */
235
255
  isEmpty(): boolean;
256
+ /**
257
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
258
+ * Space Complexity: O(1)
259
+ */
236
260
  /**
237
261
  * The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
238
262
  */
@@ -269,7 +293,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
269
293
  indexOf(value: E): number;
270
294
  /**
271
295
  * Time Complexity: O(n), where n is the number of elements in the linked list.
272
- * Space Complexity: O(1)
296
+ * Space Complexity: O(n)
273
297
  */
274
298
  /**
275
299
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -285,7 +309,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
285
309
  findBackward(callback: (value: E) => boolean): E | undefined;
286
310
  /**
287
311
  * Time Complexity: O(n), where n is the number of elements in the linked list.
288
- * Space Complexity: O(1)
312
+ * Space Complexity: O(n)
289
313
  */
290
314
  /**
291
315
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -295,7 +319,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
295
319
  */
296
320
  reverse(): this;
297
321
  /**
298
- * Time Complexity: O(n), where n is the number of elements in the linked list.
322
+ * Time Complexity: O(n)
299
323
  * Space Complexity: O(n)
300
324
  */
301
325
  /**
@@ -319,8 +343,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
319
343
  */
320
344
  toReversedArray(): E[];
321
345
  /**
322
- * Time Complexity: O(n)
323
- * Space Complexity: O(n)
346
+ * Time Complexity: O(1)
347
+ * Space Complexity: O(1)
324
348
  */
325
349
  /**
326
350
  * Time Complexity: O(n)
@@ -341,8 +365,8 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
341
365
  */
342
366
  filter(callback: ElementCallback<E, boolean>, thisArg?: any): DoublyLinkedList<E>;
343
367
  /**
344
- * Time Complexity: O(n), where n is the number of elements in the linked list.
345
- * Space Complexity: O(n)
368
+ * Time Complexity: O(1)
369
+ * Space Complexity: O(1)
346
370
  */
347
371
  /**
348
372
  * Time Complexity: O(n)
@@ -388,7 +412,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
388
412
  */
389
413
  pollLast(): E | undefined;
390
414
  /**
391
- * Time Complexity: O(1)
415
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
392
416
  * Space Complexity: O(1)
393
417
  */
394
418
  /**
@@ -401,7 +425,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
401
425
  */
402
426
  pollFirst(): E | undefined;
403
427
  /**
404
- * Time Complexity: O(1)
428
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
405
429
  * Space Complexity: O(1)
406
430
  */
407
431
  /**
@@ -413,30 +437,6 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
413
437
  * doubly linked list.
414
438
  */
415
439
  addFirst(value: E): void;
416
- /**
417
- * Time Complexity: O(n), where n is the number of elements in the linked list.
418
- * Space Complexity: O(1)
419
- */
420
- /**
421
- * Time Complexity: O(n), where n is the number of elements in the linked list.
422
- * Space Complexity: O(1)
423
- *
424
- * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
425
- * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
426
- */
427
- get first(): E | undefined;
428
- /**
429
- * Time Complexity: O(n), where n is the number of elements in the linked list.
430
- * Space Complexity: O(1)
431
- */
432
- /**
433
- * Time Complexity: O(n), where n is the number of elements in the linked list.
434
- * Space Complexity: O(1)
435
- *
436
- * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
437
- * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
438
- */
439
- get last(): E | undefined;
440
440
  /**
441
441
  * The function returns an iterator that iterates over the values of a linked list.
442
442
  */
@@ -49,6 +49,36 @@ class DoublyLinkedList extends base_1.IterableElementBase {
49
49
  * Time Complexity: O(n), where n is the size of the input array.
50
50
  * Space Complexity: O(n)
51
51
  */
52
+ /**
53
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
54
+ * Space Complexity: O(1)
55
+ *
56
+ * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
57
+ * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
58
+ */
59
+ get first() {
60
+ var _a;
61
+ return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
62
+ }
63
+ /**
64
+ * Time Complexity: O(1)
65
+ * Space Complexity: O(1)
66
+ */
67
+ /**
68
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
69
+ * Space Complexity: O(1)
70
+ *
71
+ * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
72
+ * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
73
+ */
74
+ get last() {
75
+ var _a;
76
+ return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.value;
77
+ }
78
+ /**
79
+ * Time Complexity: O(1)
80
+ * Space Complexity: O(1)
81
+ */
52
82
  /**
53
83
  * Time Complexity: O(n), where n is the size of the input array.
54
84
  * Space Complexity: O(n)
@@ -118,7 +148,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
118
148
  return removedNode.value;
119
149
  }
120
150
  /**
121
- * Time Complexity: O(1)
151
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
122
152
  * Space Complexity: O(1)
123
153
  */
124
154
  /**
@@ -145,7 +175,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
145
175
  return removedNode.value;
146
176
  }
147
177
  /**
148
- * Time Complexity: O(1)
178
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
149
179
  * Space Complexity: O(1)
150
180
  */
151
181
  /**
@@ -359,10 +389,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
359
389
  }
360
390
  return false;
361
391
  }
362
- /**
363
- * Time Complexity: O(n), where n is the number of elements in the linked list.
364
- * Space Complexity: O(1)
365
- */
366
392
  /**
367
393
  * Time Complexity: O(n), where n is the number of elements in the linked list.
368
394
  * Space Complexity: O(1)
@@ -392,10 +418,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
392
418
  this._size--;
393
419
  return true;
394
420
  }
395
- /**
396
- * Time Complexity: O(n), where n is the number of elements in the linked list.
397
- * Space Complexity: O(1)
398
- */
399
421
  /**
400
422
  * Time Complexity: O(n), where n is the number of elements in the linked list.
401
423
  * Space Complexity: O(1)
@@ -432,6 +454,10 @@ class DoublyLinkedList extends base_1.IterableElementBase {
432
454
  }
433
455
  return false;
434
456
  }
457
+ /**
458
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
459
+ * Space Complexity: O(1)
460
+ */
435
461
  /**
436
462
  * The function checks if a variable has a size greater than zero and returns a boolean value.
437
463
  * @returns A boolean value is being returned.
@@ -439,6 +465,10 @@ class DoublyLinkedList extends base_1.IterableElementBase {
439
465
  isEmpty() {
440
466
  return this.size === 0;
441
467
  }
468
+ /**
469
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
470
+ * Space Complexity: O(1)
471
+ */
442
472
  /**
443
473
  * The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
444
474
  */
@@ -499,7 +529,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
499
529
  }
500
530
  /**
501
531
  * Time Complexity: O(n), where n is the number of elements in the linked list.
502
- * Space Complexity: O(1)
532
+ * Space Complexity: O(n)
503
533
  */
504
534
  /**
505
535
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -524,7 +554,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
524
554
  }
525
555
  /**
526
556
  * Time Complexity: O(n), where n is the number of elements in the linked list.
527
- * Space Complexity: O(1)
557
+ * Space Complexity: O(n)
528
558
  */
529
559
  /**
530
560
  * Time Complexity: O(n), where n is the number of elements in the linked list.
@@ -543,7 +573,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
543
573
  return this;
544
574
  }
545
575
  /**
546
- * Time Complexity: O(n), where n is the number of elements in the linked list.
576
+ * Time Complexity: O(n)
547
577
  * Space Complexity: O(n)
548
578
  */
549
579
  /**
@@ -583,8 +613,8 @@ class DoublyLinkedList extends base_1.IterableElementBase {
583
613
  return array;
584
614
  }
585
615
  /**
586
- * Time Complexity: O(n)
587
- * Space Complexity: O(n)
616
+ * Time Complexity: O(1)
617
+ * Space Complexity: O(1)
588
618
  */
589
619
  /**
590
620
  * Time Complexity: O(n)
@@ -615,8 +645,8 @@ class DoublyLinkedList extends base_1.IterableElementBase {
615
645
  return filteredList;
616
646
  }
617
647
  /**
618
- * Time Complexity: O(n), where n is the number of elements in the linked list.
619
- * Space Complexity: O(n)
648
+ * Time Complexity: O(1)
649
+ * Space Complexity: O(1)
620
650
  */
621
651
  /**
622
652
  * Time Complexity: O(n)
@@ -674,7 +704,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
674
704
  return this.pop();
675
705
  }
676
706
  /**
677
- * Time Complexity: O(1)
707
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
678
708
  * Space Complexity: O(1)
679
709
  */
680
710
  /**
@@ -689,7 +719,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
689
719
  return this.shift();
690
720
  }
691
721
  /**
692
- * Time Complexity: O(1)
722
+ * Time Complexity: O(n), where n is the number of elements in the linked list.
693
723
  * Space Complexity: O(1)
694
724
  */
695
725
  /**
@@ -703,36 +733,6 @@ class DoublyLinkedList extends base_1.IterableElementBase {
703
733
  addFirst(value) {
704
734
  this.unshift(value);
705
735
  }
706
- /**
707
- * Time Complexity: O(n), where n is the number of elements in the linked list.
708
- * Space Complexity: O(1)
709
- */
710
- /**
711
- * Time Complexity: O(n), where n is the number of elements in the linked list.
712
- * Space Complexity: O(1)
713
- *
714
- * The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
715
- * @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
716
- */
717
- get first() {
718
- var _a;
719
- return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
720
- }
721
- /**
722
- * Time Complexity: O(n), where n is the number of elements in the linked list.
723
- * Space Complexity: O(1)
724
- */
725
- /**
726
- * Time Complexity: O(n), where n is the number of elements in the linked list.
727
- * Space Complexity: O(1)
728
- *
729
- * The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
730
- * @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
731
- */
732
- get last() {
733
- var _a;
734
- return (_a = this.tail) === null || _a === void 0 ? void 0 : _a.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(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
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
- * The add function adds a new node with a given key and value to a Skip List data structure.
40
- * @param {K} key - The key parameter represents the key of the node that needs to be added to the skip list.
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
- add(key: K, value: V): void;
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
- * The function `get` retrieves the value associated with a given key from a skip list data structure.
54
- * @param {K} key - The `key` parameter is the key of the element that we want to retrieve from the data structure.
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(key: K): V | undefined;
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
- has(key: K): boolean;
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 `delete` function removes a node with a specific key from a Skip List data structure.
77
- * @param {K} key - The key parameter represents the key of the node that needs to be removed from the skip list.
78
- * @returns The `delete` method returns a boolean value. It returns `true` if the key was successfully removed from the
79
- * skip list, and `false` if the key was not found in the skip list.
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
- delete(key: K): boolean;
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(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
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
- get first(): V | undefined;
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
- * Get the value of the last element (the largest element) in the Skip List.
103
- * @returns The value of the last element, or undefined if the Skip List is empty.
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
- get last(): V | undefined;
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.