data-structure-typed 1.49.2 → 1.49.4

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.
Files changed (67) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +69 -66
  3. package/README_zh-CN.md +43 -48
  4. package/benchmark/report.html +16 -16
  5. package/benchmark/report.json +187 -187
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +8 -17
  10. package/dist/cjs/data-structures/graph/abstract-graph.js +43 -29
  11. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  12. package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
  13. package/dist/cjs/data-structures/graph/directed-graph.js +6 -2
  14. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -1
  16. package/dist/cjs/data-structures/graph/undirected-graph.js +1 -1
  17. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  18. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
  19. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +49 -49
  20. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  21. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  22. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
  23. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +36 -36
  24. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  25. package/dist/cjs/data-structures/queue/queue.d.ts +33 -33
  26. package/dist/cjs/data-structures/queue/queue.js +40 -40
  27. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  28. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
  29. package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
  30. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +8 -17
  31. package/dist/mjs/data-structures/graph/abstract-graph.js +43 -29
  32. package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
  33. package/dist/mjs/data-structures/graph/directed-graph.js +6 -2
  34. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -1
  35. package/dist/mjs/data-structures/graph/undirected-graph.js +1 -1
  36. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
  37. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +47 -47
  38. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
  39. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +36 -36
  40. package/dist/mjs/data-structures/queue/queue.d.ts +33 -33
  41. package/dist/mjs/data-structures/queue/queue.js +39 -39
  42. package/dist/umd/data-structure-typed.js +176 -158
  43. package/dist/umd/data-structure-typed.min.js +2 -2
  44. package/dist/umd/data-structure-typed.min.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/data-structures/binary-tree/binary-tree.ts +1 -1
  47. package/src/data-structures/graph/abstract-graph.ts +56 -27
  48. package/src/data-structures/graph/directed-graph.ts +10 -5
  49. package/src/data-structures/graph/undirected-graph.ts +2 -2
  50. package/src/data-structures/linked-list/doubly-linked-list.ts +53 -53
  51. package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
  52. package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
  53. package/src/data-structures/queue/queue.ts +45 -45
  54. package/test/performance/data-structures/comparison/comparison.test.ts +12 -12
  55. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +16 -27
  56. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -12
  57. package/test/performance/data-structures/queue/deque.test.ts +8 -8
  58. package/test/performance/data-structures/queue/queue.test.ts +5 -5
  59. package/test/performance/data-structures/stack/stack.test.ts +11 -11
  60. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +15 -0
  61. package/test/unit/data-structures/graph/abstract-graph.test.ts +12 -1
  62. package/test/unit/data-structures/graph/directed-graph.test.ts +63 -5
  63. package/test/unit/data-structures/graph/undirected-graph.test.ts +61 -4
  64. package/test/unit/data-structures/hash/hash-map.test.ts +21 -0
  65. package/test/unit/data-structures/heap/heap.test.ts +6 -1
  66. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +27 -0
  67. package/test/utils/big-o.ts +14 -14
@@ -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(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
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
- get first() {
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
- get last() {
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.
@@ -1 +1 @@
1
- {"version":3,"file":"skip-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/skip-linked-list.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,MAAa,YAAY;IAKvB,YAAY,GAAM,EAAE,KAAQ,EAAE,KAAa;QACzC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF;AAVD,oCAUC;AAED,MAAa,QAAQ;IACnB;;;;;;OAMG;IACH,YAAY,QAAQ,GAAG,EAAE,EAAE,WAAW,GAAG,GAAG;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAO,SAAgB,EAAE,SAAgB,EAAE,QAAQ,CAAC,CAAC;QAClF,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAID,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAID,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;OAGG;IAEH;;;;;;;;OAQG;IACH,GAAG,CAAC,GAAM,EAAE,KAAQ;QAClB,MAAM,OAAO,GAAG,IAAI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G,GAAG,GAAG,EAAE,CAAC;gBACtB,QAAQ,GAAG,OAAO,CAAC;YACrB,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACO,YAAY;QACpB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjE,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlRD,4BAkRC"}
1
+ {"version":3,"file":"skip-linked-list.js","sourceRoot":"","sources":["../../../../src/data-structures/linked-list/skip-linked-list.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,MAAa,YAAY;IAKvB,YAAY,GAAM,EAAE,KAAQ,EAAE,KAAa;QACzC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,OAAO,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;CACF;AAVD,oCAUC;AAED,MAAa,QAAQ;IACnB;;;;;;OAMG;IACH,YAAY,QAAQ,GAAG,EAAE,EAAE,WAAW,GAAG,GAAG;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,YAAY,CAAO,SAAgB,EAAE,SAAgB,EAAE,QAAQ,CAAC,CAAC;QAClF,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAID,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IA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AC,EAAE,CAAC,EAAE,EAAE,CAAC;YACzC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC;gBAC1D,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC/B,CAAC;YACD,IAAI,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE,CAAC;gBACtB,QAAQ,GAAG,OAAO,CAAC;YACrB,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;IAED;;;OAGG;IAEH;;;;;;OAMG;IACO,YAAY;QACpB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,IAAI,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjE,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlRD,4BAkRC"}
@@ -32,6 +32,32 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
32
32
  * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
33
33
  */
34
34
  get size(): number;
35
+ /**
36
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
37
+ * Space Complexity: O(1) - no additional space is used.
38
+ *
39
+ * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
40
+ * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
41
+ * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
42
+ */
43
+ get first(): E | undefined;
44
+ /**
45
+ * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
46
+ * Space Complexity: O(1) - no additional space is used.
47
+ */
48
+ /**
49
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
50
+ * Space Complexity: O(1) - no additional space is used.
51
+ *
52
+ * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
53
+ * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
54
+ * array is empty, it returns `undefined`.
55
+ */
56
+ get last(): E | undefined;
57
+ /**
58
+ * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
59
+ * Space Complexity: O(1) - no additional space is used.
60
+ */
35
61
  /**
36
62
  * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
37
63
  * @public
@@ -42,7 +68,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
42
68
  */
43
69
  static fromArray<E>(elements: E[]): Queue<E>;
44
70
  /**
45
- * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
71
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
46
72
  * Space Complexity: O(1) - no additional space is used.
47
73
  */
48
74
  /**
@@ -55,7 +81,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
55
81
  */
56
82
  push(element: E): boolean;
57
83
  /**
58
- * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
84
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
59
85
  * Space Complexity: O(1) - no additional space is used.
60
86
  */
61
87
  /**
@@ -67,19 +93,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
67
93
  * @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
68
94
  */
69
95
  shift(): E | undefined;
70
- /**
71
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
72
- * Space Complexity: O(1) - no additional space is used.
73
- */
74
- /**
75
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
76
- * Space Complexity: O(1) - no additional space is used.
77
- *
78
- * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
79
- * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
80
- * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
81
- */
82
- get first(): E | undefined;
83
96
  /**
84
97
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
85
98
  * Space Complexity: O(1) - no additional space is used.
@@ -93,19 +106,6 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
93
106
  * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
94
107
  */
95
108
  peek(): E | undefined;
96
- /**
97
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
98
- * Space Complexity: O(1) - no additional space is used.
99
- */
100
- /**
101
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
102
- * Space Complexity: O(1) - no additional space is used.
103
- *
104
- * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
105
- * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
106
- * array is empty, it returns `undefined`.
107
- */
108
- get last(): E | undefined;
109
109
  /**
110
110
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
111
111
  * Space Complexity: O(1) - no additional space is used.
@@ -247,6 +247,11 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
247
247
  * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
248
248
  */
249
249
  export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
250
+ /**
251
+ * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
252
+ * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
253
+ */
254
+ get first(): E | undefined;
250
255
  /**
251
256
  * The enqueue function adds a value to the end of an array.
252
257
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -257,11 +262,6 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
257
262
  * @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
258
263
  */
259
264
  dequeue(): E | undefined;
260
- /**
261
- * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
262
- * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
263
- */
264
- get first(): E | undefined;
265
265
  /**
266
266
  * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
267
267
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
@@ -37,6 +37,36 @@ class Queue extends base_1.IterableElementBase {
37
37
  get size() {
38
38
  return this.nodes.length - this.offset;
39
39
  }
40
+ /**
41
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
42
+ * Space Complexity: O(1) - no additional space is used.
43
+ *
44
+ * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
45
+ * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
46
+ * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
47
+ */
48
+ get first() {
49
+ return this.size > 0 ? this.nodes[this.offset] : undefined;
50
+ }
51
+ /**
52
+ * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
53
+ * Space Complexity: O(1) - no additional space is used.
54
+ */
55
+ /**
56
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
57
+ * Space Complexity: O(1) - no additional space is used.
58
+ *
59
+ * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
60
+ * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
61
+ * array is empty, it returns `undefined`.
62
+ */
63
+ get last() {
64
+ return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
65
+ }
66
+ /**
67
+ * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
68
+ * Space Complexity: O(1) - no additional space is used.
69
+ */
40
70
  /**
41
71
  * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
42
72
  * @public
@@ -49,7 +79,7 @@ class Queue extends base_1.IterableElementBase {
49
79
  return new Queue(elements);
50
80
  }
51
81
  /**
52
- * Time Complexity: O(1) - constant time as it adds an element to the end of the array.
82
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
53
83
  * Space Complexity: O(1) - no additional space is used.
54
84
  */
55
85
  /**
@@ -65,7 +95,7 @@ class Queue extends base_1.IterableElementBase {
65
95
  return true;
66
96
  }
67
97
  /**
68
- * Time Complexity: O(n) - where n is the number of elements in the queue. In the worst case, it may need to shift all elements to update the offset.
98
+ * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
69
99
  * Space Complexity: O(1) - no additional space is used.
70
100
  */
71
101
  /**
@@ -89,21 +119,6 @@ class Queue extends base_1.IterableElementBase {
89
119
  this._offset = 0;
90
120
  return first;
91
121
  }
92
- /**
93
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
94
- * Space Complexity: O(1) - no additional space is used.
95
- */
96
- /**
97
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
98
- * Space Complexity: O(1) - no additional space is used.
99
- *
100
- * The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
101
- * @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
102
- * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
103
- */
104
- get first() {
105
- return this.size > 0 ? this.nodes[this.offset] : undefined;
106
- }
107
122
  /**
108
123
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
109
124
  * Space Complexity: O(1) - no additional space is used.
@@ -119,21 +134,6 @@ class Queue extends base_1.IterableElementBase {
119
134
  peek() {
120
135
  return this.first;
121
136
  }
122
- /**
123
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
124
- * Space Complexity: O(1) - no additional space is used.
125
- */
126
- /**
127
- * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
128
- * Space Complexity: O(1) - no additional space is used.
129
- *
130
- * The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
131
- * @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
132
- * array is empty, it returns `undefined`.
133
- */
134
- get last() {
135
- return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
136
- }
137
137
  /**
138
138
  * Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
139
139
  * Space Complexity: O(1) - no additional space is used.
@@ -315,6 +315,14 @@ exports.Queue = Queue;
315
315
  * 4. Frequent Enqueuing and Dequeuing Operations: If your application involves frequent enqueuing and dequeuing operations and is less concerned with random access, then LinkedListQueue is a good choice.
316
316
  */
317
317
  class LinkedListQueue extends linked_list_1.SinglyLinkedList {
318
+ /**
319
+ * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
320
+ * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
321
+ */
322
+ get first() {
323
+ var _a;
324
+ return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
325
+ }
318
326
  /**
319
327
  * The enqueue function adds a value to the end of an array.
320
328
  * @param {E} value - The value parameter represents the value that you want to add to the queue.
@@ -329,14 +337,6 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
329
337
  dequeue() {
330
338
  return this.shift();
331
339
  }
332
- /**
333
- * The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
334
- * @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
335
- */
336
- get first() {
337
- var _a;
338
- return (_a = this.head) === null || _a === void 0 ? void 0 : _a.value;
339
- }
340
340
  /**
341
341
  * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
342
342
  * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
@@ -1 +1 @@
1
- {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":";;;AAMA,kCAA8C;AAC9C,gDAAkD;AAElD;;;;;;;;GAQG;AACH,MAAa,KAAe,SAAQ,0BAAsB;IACxD;;;;;OAKG;IACH,YAAY,QAAc;QACxB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,QAAQ,IAAI,EAAE,C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IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI,KAAK;;QACP,OAAO,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAhCD,0CAgCC"}
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/data-structures/queue/queue.ts"],"names":[],"mappings":";;;AAMA,kCAA8C;AAC9C,gDAAkD;AAElD;;;;;;;;GAQG;AACH,MAAa,KAAe,SAAQ,0BAAsB;IACxD;;;;;OAKG;IACH,YAAY,QAAc;QACxB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,QAAQ,IAAI,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC;IACnB,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAID,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7D,CAAC;IAED;;;OAGG;IAEH;;;;;;;OAOG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CA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MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;YACtB,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACvD,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;OAGG;IAEM,CAAE,YAAY;QACrB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC;QACb,CAAC;IACH,CAAC;CACF;AA7UD,sBA6UC;AAED;;;;;GAKG;AACH,MAAa,eAAyB,SAAQ,8BAAmB;IAC/D;;;OAGG;IACH,IAAI,KAAK;;QACP,OAAO,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,KAAQ;QACd,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAhCD,0CAgCC"}
@@ -525,7 +525,7 @@ export declare class BinaryTree<K = any, V = any, N extends BinaryTreeNode<K, V,
525
525
  print(beginRoot?: BTNKeyOrNode<K, N>, options?: BinaryTreePrintOptions): void;
526
526
  protected _getIterator(node?: N | null | undefined): IterableIterator<[K, V | undefined]>;
527
527
  protected _displayAux(node: N | null | undefined, options: BinaryTreePrintOptions): NodeDisplayLayout;
528
- protected _defaultOneParamCallback: (node: N) => K;
528
+ protected _defaultOneParamCallback: (node: N | null | undefined) => K | undefined;
529
529
  /**
530
530
  * Swap the data of two nodes in the binary tree.
531
531
  * @param {N} srcNode - The source node to swap.
@@ -1610,7 +1610,7 @@ export class BinaryTree extends IterableEntryBase {
1610
1610
  return [mergedLines, leftWidth + width + rightWidth, Math.max(leftHeight, rightHeight) + 2, leftWidth + Math.floor(width / 2)];
1611
1611
  }
1612
1612
  }
1613
- _defaultOneParamCallback = (node) => node.key;
1613
+ _defaultOneParamCallback = (node) => node ? node.key : undefined;
1614
1614
  /**
1615
1615
  * Swap the data of two nodes in the binary tree.
1616
1616
  * @param {N} srcNode - The source node to swap.
@@ -99,16 +99,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
99
99
  * Time Complexity: O(1) - Constant time for Map operations.
100
100
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
101
101
  */
102
- /**
103
- * Time Complexity: O(1) - Constant time for Map operations.
104
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
105
- *
106
- * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
107
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
108
- * (`VertexKey`).
109
- * @returns The method is returning a boolean value.
110
- */
111
- deleteVertex(vertexOrKey: VO | VertexKey): boolean;
102
+ abstract deleteVertex(vertexOrKey: VO | VertexKey): boolean;
112
103
  /**
113
104
  * Time Complexity: O(K), where K is the number of vertexMap to be removed.
114
105
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -432,11 +423,6 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
432
423
  * type `number`.
433
424
  */
434
425
  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
426
  /**
441
427
  * The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
442
428
  * @returns an array of VO objects, specifically the cut vertexes.
@@ -453,6 +439,11 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
453
439
  * @returns the bridges found using the Tarjan algorithm.
454
440
  */
455
441
  getBridges(): EO[];
442
+ /**
443
+ * O(V+E+C)
444
+ * O(V+C)
445
+ */
446
+ getCycles(isInclude2Cycle?: boolean): VertexKey[][];
456
447
  /**
457
448
  * Time Complexity: O(n)
458
449
  * Space Complexity: O(n)
@@ -493,8 +484,8 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
493
484
  */
494
485
  map<T>(callback: EntryCallback<VertexKey, V | undefined, T>, thisArg?: any): T[];
495
486
  protected _getIterator(): IterableIterator<[VertexKey, V | undefined]>;
496
- protected abstract _addEdgeOnly(edge: EO): boolean;
497
- protected _addVertexOnly(newVertex: VO): boolean;
487
+ protected abstract _addEdge(edge: EO): boolean;
488
+ protected _addVertex(newVertex: VO): boolean;
498
489
  protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
499
490
  protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
500
491
  }
@@ -86,34 +86,17 @@ export class AbstractGraph extends 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) {
97
97
  const potentialKeyType = typeof potentialKey;
98
98
  return potentialKeyType === "string" || potentialKeyType === "number";
99
99
  }
100
- /**
101
- * Time Complexity: O(1) - Constant time for Map operations.
102
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
103
- */
104
- /**
105
- * Time Complexity: O(1) - Constant time for Map operations.
106
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
107
- *
108
- * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
109
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
110
- * (`VertexKey`).
111
- * @returns The method is returning a boolean value.
112
- */
113
- deleteVertex(vertexOrKey) {
114
- const vertexKey = this._getVertexKey(vertexOrKey);
115
- return this._vertexMap.delete(vertexKey);
116
- }
117
100
  /**
118
101
  * Time Complexity: O(K), where K is the number of vertexMap to be removed.
119
102
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -160,7 +143,7 @@ export class AbstractGraph extends IterableEntryBase {
160
143
  */
161
144
  addEdge(srcOrEdge, dest, weight, value) {
162
145
  if (srcOrEdge instanceof AbstractEdge) {
163
- return this._addEdgeOnly(srcOrEdge);
146
+ return this._addEdge(srcOrEdge);
164
147
  }
165
148
  else {
166
149
  if (dest instanceof AbstractVertex || typeof dest === 'string' || typeof dest === 'number') {
@@ -171,7 +154,7 @@ export class AbstractGraph extends IterableEntryBase {
171
154
  if (dest instanceof AbstractVertex)
172
155
  dest = dest.key;
173
156
  const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
174
- return this._addEdgeOnly(newEdge);
157
+ return this._addEdge(newEdge);
175
158
  }
176
159
  else {
177
160
  throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
@@ -996,13 +979,6 @@ export class AbstractGraph extends IterableEntryBase {
996
979
  getLowMap() {
997
980
  return this.tarjan(false, false, false, false).lowMap;
998
981
  }
999
- /**
1000
- * The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
1001
- * @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
1002
- */
1003
- getCycles() {
1004
- return this.tarjan(false, false, false, true).cycles;
1005
- }
1006
982
  /**
1007
983
  * The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
1008
984
  * @returns an array of VO objects, specifically the cut vertexes.
@@ -1025,6 +1001,44 @@ export class AbstractGraph extends IterableEntryBase {
1025
1001
  getBridges() {
1026
1002
  return this.tarjan(false, true, false, false).bridges;
1027
1003
  }
1004
+ /**
1005
+ * O(V+E+C)
1006
+ * O(V+C)
1007
+ */
1008
+ getCycles(isInclude2Cycle = false) {
1009
+ const cycles = [];
1010
+ const visited = new Set();
1011
+ const dfs = (vertex, currentPath, visited) => {
1012
+ if (visited.has(vertex)) {
1013
+ if ((!isInclude2Cycle && currentPath.length > 2 || isInclude2Cycle && currentPath.length >= 2) && currentPath[0] === vertex.key) {
1014
+ cycles.push([...currentPath]);
1015
+ }
1016
+ return;
1017
+ }
1018
+ visited.add(vertex);
1019
+ currentPath.push(vertex.key);
1020
+ for (const neighbor of this.getNeighbors(vertex)) {
1021
+ neighbor && dfs(neighbor, currentPath, visited);
1022
+ }
1023
+ visited.delete(vertex);
1024
+ currentPath.pop();
1025
+ };
1026
+ for (const vertex of this.vertexMap.values()) {
1027
+ dfs(vertex, [], visited);
1028
+ }
1029
+ // Use a set to eliminate duplicate cycles
1030
+ const uniqueCycles = new Map();
1031
+ for (const cycle of cycles) {
1032
+ const sorted = [...cycle].sort().toString();
1033
+ if (uniqueCycles.has(sorted))
1034
+ continue;
1035
+ else {
1036
+ uniqueCycles.set(sorted, cycle);
1037
+ }
1038
+ }
1039
+ // Convert the unique cycles back to an array
1040
+ return [...uniqueCycles].map(cycleString => cycleString[1]);
1041
+ }
1028
1042
  /**
1029
1043
  * Time Complexity: O(n)
1030
1044
  * Space Complexity: O(n)
@@ -1087,7 +1101,7 @@ export class AbstractGraph extends IterableEntryBase {
1087
1101
  yield [vertex.key, vertex.value];
1088
1102
  }
1089
1103
  }
1090
- _addVertexOnly(newVertex) {
1104
+ _addVertex(newVertex) {
1091
1105
  if (this.hasVertex(newVertex)) {
1092
1106
  return false;
1093
1107
  // 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
  }
@@ -209,6 +209,10 @@ export class DirectedGraph extends AbstractGraph {
209
209
  vertexKey = this._getVertexKey(vertexOrKey);
210
210
  }
211
211
  if (vertex) {
212
+ const neighbors = this.getNeighbors(vertex);
213
+ for (const neighbor of neighbors) {
214
+ this._inEdgeMap.delete(neighbor);
215
+ }
212
216
  this._outEdgeMap.delete(vertex);
213
217
  this._inEdgeMap.delete(vertex);
214
218
  }
@@ -528,13 +532,13 @@ export class DirectedGraph extends AbstractGraph {
528
532
  * Time Complexity: O(1)
529
533
  * Space Complexity: O(1)
530
534
  *
531
- * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertexMap exist.
535
+ * The function `_addEdge` adds an edge to a graph if the source and destination vertexMap exist.
532
536
  * @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
533
537
  * needs to be added to the graph.
534
538
  * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
535
539
  * source or destination vertex does not exist in the graph.
536
540
  */
537
- _addEdgeOnly(edge) {
541
+ _addEdge(edge) {
538
542
  if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
539
543
  return false;
540
544
  }
@@ -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
  }
@@ -332,7 +332,7 @@ export class UndirectedGraph extends AbstractGraph {
332
332
  * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
333
333
  * @returns a boolean value.
334
334
  */
335
- _addEdgeOnly(edge) {
335
+ _addEdge(edge) {
336
336
  for (const end of edge.vertexMap) {
337
337
  const endVertex = this._getVertex(end);
338
338
  if (endVertex === undefined)