data-structure-typed 1.49.2 → 1.49.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +7 -7
- package/dist/cjs/data-structures/graph/abstract-graph.js +43 -12
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js +2 -2
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +49 -49
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +36 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +33 -33
- package/dist/cjs/data-structures/queue/queue.js +40 -40
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +7 -7
- package/dist/mjs/data-structures/graph/abstract-graph.js +43 -12
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +2 -2
- package/dist/mjs/data-structures/graph/directed-graph.js +2 -2
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/undirected-graph.js +1 -1
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +43 -43
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +47 -47
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +25 -25
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +36 -36
- package/dist/mjs/data-structures/queue/queue.d.ts +33 -33
- package/dist/mjs/data-structures/queue/queue.js +39 -39
- package/dist/umd/data-structure-typed.js +171 -140
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/graph/abstract-graph.ts +55 -14
- package/src/data-structures/graph/directed-graph.ts +3 -2
- package/src/data-structures/graph/undirected-graph.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +53 -53
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
- package/src/data-structures/queue/queue.ts +45 -45
- package/test/unit/data-structures/graph/abstract-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/directed-graph.test.ts +48 -3
- package/test/unit/data-structures/graph/undirected-graph.test.ts +48 -4
- package/test/unit/data-structures/heap/heap.test.ts +6 -1
|
@@ -2150,6 +2150,36 @@ var dataStructureTyped = (() => {
|
|
|
2150
2150
|
* Time Complexity: O(n), where n is the size of the input array.
|
|
2151
2151
|
* Space Complexity: O(n)
|
|
2152
2152
|
*/
|
|
2153
|
+
/**
|
|
2154
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2155
|
+
* Space Complexity: O(1)
|
|
2156
|
+
*
|
|
2157
|
+
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
2158
|
+
* @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
2159
|
+
*/
|
|
2160
|
+
get first() {
|
|
2161
|
+
var _a;
|
|
2162
|
+
return (_a = this.head) == null ? void 0 : _a.value;
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* Time Complexity: O(1)
|
|
2166
|
+
* Space Complexity: O(1)
|
|
2167
|
+
*/
|
|
2168
|
+
/**
|
|
2169
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2170
|
+
* Space Complexity: O(1)
|
|
2171
|
+
*
|
|
2172
|
+
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
2173
|
+
* @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
2174
|
+
*/
|
|
2175
|
+
get last() {
|
|
2176
|
+
var _a;
|
|
2177
|
+
return (_a = this.tail) == null ? void 0 : _a.value;
|
|
2178
|
+
}
|
|
2179
|
+
/**
|
|
2180
|
+
* Time Complexity: O(1)
|
|
2181
|
+
* Space Complexity: O(1)
|
|
2182
|
+
*/
|
|
2153
2183
|
/**
|
|
2154
2184
|
* Time Complexity: O(n), where n is the size of the input array.
|
|
2155
2185
|
* Space Complexity: O(n)
|
|
@@ -2217,7 +2247,7 @@ var dataStructureTyped = (() => {
|
|
|
2217
2247
|
return removedNode.value;
|
|
2218
2248
|
}
|
|
2219
2249
|
/**
|
|
2220
|
-
* Time Complexity: O(
|
|
2250
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2221
2251
|
* Space Complexity: O(1)
|
|
2222
2252
|
*/
|
|
2223
2253
|
/**
|
|
@@ -2243,7 +2273,7 @@ var dataStructureTyped = (() => {
|
|
|
2243
2273
|
return removedNode.value;
|
|
2244
2274
|
}
|
|
2245
2275
|
/**
|
|
2246
|
-
* Time Complexity: O(
|
|
2276
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2247
2277
|
* Space Complexity: O(1)
|
|
2248
2278
|
*/
|
|
2249
2279
|
/**
|
|
@@ -2454,10 +2484,6 @@ var dataStructureTyped = (() => {
|
|
|
2454
2484
|
}
|
|
2455
2485
|
return false;
|
|
2456
2486
|
}
|
|
2457
|
-
/**
|
|
2458
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2459
|
-
* Space Complexity: O(1)
|
|
2460
|
-
*/
|
|
2461
2487
|
/**
|
|
2462
2488
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2463
2489
|
* Space Complexity: O(1)
|
|
@@ -2487,10 +2513,6 @@ var dataStructureTyped = (() => {
|
|
|
2487
2513
|
this._size--;
|
|
2488
2514
|
return true;
|
|
2489
2515
|
}
|
|
2490
|
-
/**
|
|
2491
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2492
|
-
* Space Complexity: O(1)
|
|
2493
|
-
*/
|
|
2494
2516
|
/**
|
|
2495
2517
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2496
2518
|
* Space Complexity: O(1)
|
|
@@ -2524,6 +2546,10 @@ var dataStructureTyped = (() => {
|
|
|
2524
2546
|
}
|
|
2525
2547
|
return false;
|
|
2526
2548
|
}
|
|
2549
|
+
/**
|
|
2550
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2551
|
+
* Space Complexity: O(1)
|
|
2552
|
+
*/
|
|
2527
2553
|
/**
|
|
2528
2554
|
* The function checks if a variable has a size greater than zero and returns a boolean value.
|
|
2529
2555
|
* @returns A boolean value is being returned.
|
|
@@ -2531,6 +2557,10 @@ var dataStructureTyped = (() => {
|
|
|
2531
2557
|
isEmpty() {
|
|
2532
2558
|
return this.size === 0;
|
|
2533
2559
|
}
|
|
2560
|
+
/**
|
|
2561
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2562
|
+
* Space Complexity: O(1)
|
|
2563
|
+
*/
|
|
2534
2564
|
/**
|
|
2535
2565
|
* The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
|
|
2536
2566
|
*/
|
|
@@ -2591,7 +2621,7 @@ var dataStructureTyped = (() => {
|
|
|
2591
2621
|
}
|
|
2592
2622
|
/**
|
|
2593
2623
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2594
|
-
* Space Complexity: O(
|
|
2624
|
+
* Space Complexity: O(n)
|
|
2595
2625
|
*/
|
|
2596
2626
|
/**
|
|
2597
2627
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -2616,7 +2646,7 @@ var dataStructureTyped = (() => {
|
|
|
2616
2646
|
}
|
|
2617
2647
|
/**
|
|
2618
2648
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2619
|
-
* Space Complexity: O(
|
|
2649
|
+
* Space Complexity: O(n)
|
|
2620
2650
|
*/
|
|
2621
2651
|
/**
|
|
2622
2652
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
@@ -2635,7 +2665,7 @@ var dataStructureTyped = (() => {
|
|
|
2635
2665
|
return this;
|
|
2636
2666
|
}
|
|
2637
2667
|
/**
|
|
2638
|
-
* Time Complexity: O(n)
|
|
2668
|
+
* Time Complexity: O(n)
|
|
2639
2669
|
* Space Complexity: O(n)
|
|
2640
2670
|
*/
|
|
2641
2671
|
/**
|
|
@@ -2675,8 +2705,8 @@ var dataStructureTyped = (() => {
|
|
|
2675
2705
|
return array;
|
|
2676
2706
|
}
|
|
2677
2707
|
/**
|
|
2678
|
-
* Time Complexity: O(
|
|
2679
|
-
* Space Complexity: O(
|
|
2708
|
+
* Time Complexity: O(1)
|
|
2709
|
+
* Space Complexity: O(1)
|
|
2680
2710
|
*/
|
|
2681
2711
|
/**
|
|
2682
2712
|
* Time Complexity: O(n)
|
|
@@ -2707,8 +2737,8 @@ var dataStructureTyped = (() => {
|
|
|
2707
2737
|
return filteredList;
|
|
2708
2738
|
}
|
|
2709
2739
|
/**
|
|
2710
|
-
* Time Complexity: O(
|
|
2711
|
-
* Space Complexity: O(
|
|
2740
|
+
* Time Complexity: O(1)
|
|
2741
|
+
* Space Complexity: O(1)
|
|
2712
2742
|
*/
|
|
2713
2743
|
/**
|
|
2714
2744
|
* Time Complexity: O(n)
|
|
@@ -2766,7 +2796,7 @@ var dataStructureTyped = (() => {
|
|
|
2766
2796
|
return this.pop();
|
|
2767
2797
|
}
|
|
2768
2798
|
/**
|
|
2769
|
-
* Time Complexity: O(
|
|
2799
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2770
2800
|
* Space Complexity: O(1)
|
|
2771
2801
|
*/
|
|
2772
2802
|
/**
|
|
@@ -2781,7 +2811,7 @@ var dataStructureTyped = (() => {
|
|
|
2781
2811
|
return this.shift();
|
|
2782
2812
|
}
|
|
2783
2813
|
/**
|
|
2784
|
-
* Time Complexity: O(
|
|
2814
|
+
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2785
2815
|
* Space Complexity: O(1)
|
|
2786
2816
|
*/
|
|
2787
2817
|
/**
|
|
@@ -2795,36 +2825,6 @@ var dataStructureTyped = (() => {
|
|
|
2795
2825
|
addFirst(value) {
|
|
2796
2826
|
this.unshift(value);
|
|
2797
2827
|
}
|
|
2798
|
-
/**
|
|
2799
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2800
|
-
* Space Complexity: O(1)
|
|
2801
|
-
*/
|
|
2802
|
-
/**
|
|
2803
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2804
|
-
* Space Complexity: O(1)
|
|
2805
|
-
*
|
|
2806
|
-
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
2807
|
-
* @returns The method `get first()` returns the first node of the doubly linked list, or `undefined` if the list is empty.
|
|
2808
|
-
*/
|
|
2809
|
-
get first() {
|
|
2810
|
-
var _a;
|
|
2811
|
-
return (_a = this.head) == null ? void 0 : _a.value;
|
|
2812
|
-
}
|
|
2813
|
-
/**
|
|
2814
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2815
|
-
* Space Complexity: O(1)
|
|
2816
|
-
*/
|
|
2817
|
-
/**
|
|
2818
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
2819
|
-
* Space Complexity: O(1)
|
|
2820
|
-
*
|
|
2821
|
-
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
2822
|
-
* @returns The method `get last()` returns the last node of the doubly linked list, or `undefined` if the list is empty.
|
|
2823
|
-
*/
|
|
2824
|
-
get last() {
|
|
2825
|
-
var _a;
|
|
2826
|
-
return (_a = this.tail) == null ? void 0 : _a.value;
|
|
2827
|
-
}
|
|
2828
2828
|
/**
|
|
2829
2829
|
* The function returns an iterator that iterates over the values of a linked list.
|
|
2830
2830
|
*/
|
|
@@ -2878,6 +2878,41 @@ var dataStructureTyped = (() => {
|
|
|
2878
2878
|
get probability() {
|
|
2879
2879
|
return this._probability;
|
|
2880
2880
|
}
|
|
2881
|
+
/**
|
|
2882
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
2883
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
2884
|
+
*/
|
|
2885
|
+
/**
|
|
2886
|
+
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
2887
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
2888
|
+
*
|
|
2889
|
+
* Get the value of the first element (the smallest element) in the Skip List.
|
|
2890
|
+
* @returns The value of the first element, or undefined if the Skip List is empty.
|
|
2891
|
+
*/
|
|
2892
|
+
get first() {
|
|
2893
|
+
const firstNode = this.head.forward[0];
|
|
2894
|
+
return firstNode ? firstNode.value : void 0;
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
2898
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
2899
|
+
*/
|
|
2900
|
+
/**
|
|
2901
|
+
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
2902
|
+
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
2903
|
+
*
|
|
2904
|
+
* Get the value of the last element (the largest element) in the Skip List.
|
|
2905
|
+
* @returns The value of the last element, or undefined if the Skip List is empty.
|
|
2906
|
+
*/
|
|
2907
|
+
get last() {
|
|
2908
|
+
let current = this.head;
|
|
2909
|
+
for (let i = this.level - 1; i >= 0; i--) {
|
|
2910
|
+
while (current.forward[i]) {
|
|
2911
|
+
current = current.forward[i];
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
return current.value;
|
|
2915
|
+
}
|
|
2881
2916
|
/**
|
|
2882
2917
|
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
2883
2918
|
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
@@ -2936,7 +2971,7 @@ var dataStructureTyped = (() => {
|
|
|
2936
2971
|
return void 0;
|
|
2937
2972
|
}
|
|
2938
2973
|
/**
|
|
2939
|
-
* Time Complexity: O(
|
|
2974
|
+
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
2940
2975
|
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
2941
2976
|
*/
|
|
2942
2977
|
/**
|
|
@@ -2983,41 +3018,6 @@ var dataStructureTyped = (() => {
|
|
|
2983
3018
|
}
|
|
2984
3019
|
return false;
|
|
2985
3020
|
}
|
|
2986
|
-
/**
|
|
2987
|
-
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
2988
|
-
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
2989
|
-
*/
|
|
2990
|
-
/**
|
|
2991
|
-
* Time Complexity: O(1) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
2992
|
-
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
2993
|
-
*
|
|
2994
|
-
* Get the value of the first element (the smallest element) in the Skip List.
|
|
2995
|
-
* @returns The value of the first element, or undefined if the Skip List is empty.
|
|
2996
|
-
*/
|
|
2997
|
-
get first() {
|
|
2998
|
-
const firstNode = this.head.forward[0];
|
|
2999
|
-
return firstNode ? firstNode.value : void 0;
|
|
3000
|
-
}
|
|
3001
|
-
/**
|
|
3002
|
-
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
3003
|
-
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
3004
|
-
*/
|
|
3005
|
-
/**
|
|
3006
|
-
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
3007
|
-
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
3008
|
-
*
|
|
3009
|
-
* Get the value of the last element (the largest element) in the Skip List.
|
|
3010
|
-
* @returns The value of the last element, or undefined if the Skip List is empty.
|
|
3011
|
-
*/
|
|
3012
|
-
get last() {
|
|
3013
|
-
let current = this.head;
|
|
3014
|
-
for (let i = this.level - 1; i >= 0; i--) {
|
|
3015
|
-
while (current.forward[i]) {
|
|
3016
|
-
current = current.forward[i];
|
|
3017
|
-
}
|
|
3018
|
-
}
|
|
3019
|
-
return current.value;
|
|
3020
|
-
}
|
|
3021
3021
|
/**
|
|
3022
3022
|
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
3023
3023
|
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
@@ -3315,6 +3315,36 @@ var dataStructureTyped = (() => {
|
|
|
3315
3315
|
get size() {
|
|
3316
3316
|
return this.nodes.length - this.offset;
|
|
3317
3317
|
}
|
|
3318
|
+
/**
|
|
3319
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3320
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
3321
|
+
*
|
|
3322
|
+
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
3323
|
+
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
3324
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
3325
|
+
*/
|
|
3326
|
+
get first() {
|
|
3327
|
+
return this.size > 0 ? this.nodes[this.offset] : void 0;
|
|
3328
|
+
}
|
|
3329
|
+
/**
|
|
3330
|
+
* Time Complexity: O(1) - constant time as it adds an element to the end of the array.
|
|
3331
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
3332
|
+
*/
|
|
3333
|
+
/**
|
|
3334
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3335
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
3336
|
+
*
|
|
3337
|
+
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
3338
|
+
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
3339
|
+
* array is empty, it returns `undefined`.
|
|
3340
|
+
*/
|
|
3341
|
+
get last() {
|
|
3342
|
+
return this.size > 0 ? this.nodes[this.nodes.length - 1] : void 0;
|
|
3343
|
+
}
|
|
3344
|
+
/**
|
|
3345
|
+
* 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.
|
|
3346
|
+
* Space Complexity: O(1) - no additional space is used.
|
|
3347
|
+
*/
|
|
3318
3348
|
/**
|
|
3319
3349
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
3320
3350
|
* @public
|
|
@@ -3327,7 +3357,7 @@ var dataStructureTyped = (() => {
|
|
|
3327
3357
|
return new _Queue(elements);
|
|
3328
3358
|
}
|
|
3329
3359
|
/**
|
|
3330
|
-
* Time Complexity: O(1) - constant time as it
|
|
3360
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3331
3361
|
* Space Complexity: O(1) - no additional space is used.
|
|
3332
3362
|
*/
|
|
3333
3363
|
/**
|
|
@@ -3343,7 +3373,7 @@ var dataStructureTyped = (() => {
|
|
|
3343
3373
|
return true;
|
|
3344
3374
|
}
|
|
3345
3375
|
/**
|
|
3346
|
-
* Time Complexity: O(
|
|
3376
|
+
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3347
3377
|
* Space Complexity: O(1) - no additional space is used.
|
|
3348
3378
|
*/
|
|
3349
3379
|
/**
|
|
@@ -3365,21 +3395,6 @@ var dataStructureTyped = (() => {
|
|
|
3365
3395
|
this._offset = 0;
|
|
3366
3396
|
return first;
|
|
3367
3397
|
}
|
|
3368
|
-
/**
|
|
3369
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3370
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
3371
|
-
*/
|
|
3372
|
-
/**
|
|
3373
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3374
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
3375
|
-
*
|
|
3376
|
-
* The `first` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
3377
|
-
* @returns The `get first()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
3378
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
3379
|
-
*/
|
|
3380
|
-
get first() {
|
|
3381
|
-
return this.size > 0 ? this.nodes[this.offset] : void 0;
|
|
3382
|
-
}
|
|
3383
3398
|
/**
|
|
3384
3399
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3385
3400
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -3395,21 +3410,6 @@ var dataStructureTyped = (() => {
|
|
|
3395
3410
|
peek() {
|
|
3396
3411
|
return this.first;
|
|
3397
3412
|
}
|
|
3398
|
-
/**
|
|
3399
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3400
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
3401
|
-
*/
|
|
3402
|
-
/**
|
|
3403
|
-
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3404
|
-
* Space Complexity: O(1) - no additional space is used.
|
|
3405
|
-
*
|
|
3406
|
-
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
3407
|
-
* @returns The method `get last()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
3408
|
-
* array is empty, it returns `undefined`.
|
|
3409
|
-
*/
|
|
3410
|
-
get last() {
|
|
3411
|
-
return this.size > 0 ? this.nodes[this.nodes.length - 1] : void 0;
|
|
3412
|
-
}
|
|
3413
3413
|
/**
|
|
3414
3414
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
3415
3415
|
* Space Complexity: O(1) - no additional space is used.
|
|
@@ -3584,6 +3584,14 @@ var dataStructureTyped = (() => {
|
|
|
3584
3584
|
}
|
|
3585
3585
|
};
|
|
3586
3586
|
var LinkedListQueue = class extends SinglyLinkedList {
|
|
3587
|
+
/**
|
|
3588
|
+
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
3589
|
+
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
3590
|
+
*/
|
|
3591
|
+
get first() {
|
|
3592
|
+
var _a;
|
|
3593
|
+
return (_a = this.head) == null ? void 0 : _a.value;
|
|
3594
|
+
}
|
|
3587
3595
|
/**
|
|
3588
3596
|
* The enqueue function adds a value to the end of an array.
|
|
3589
3597
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -3598,14 +3606,6 @@ var dataStructureTyped = (() => {
|
|
|
3598
3606
|
dequeue() {
|
|
3599
3607
|
return this.shift();
|
|
3600
3608
|
}
|
|
3601
|
-
/**
|
|
3602
|
-
* The `get first` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
3603
|
-
* @returns The `get first()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
3604
|
-
*/
|
|
3605
|
-
get first() {
|
|
3606
|
-
var _a;
|
|
3607
|
-
return (_a = this.head) == null ? void 0 : _a.value;
|
|
3608
|
-
}
|
|
3609
3609
|
/**
|
|
3610
3610
|
* The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
|
|
3611
3611
|
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
@@ -5242,10 +5242,10 @@ var dataStructureTyped = (() => {
|
|
|
5242
5242
|
*/
|
|
5243
5243
|
addVertex(keyOrVertex, value) {
|
|
5244
5244
|
if (keyOrVertex instanceof AbstractVertex) {
|
|
5245
|
-
return this.
|
|
5245
|
+
return this._addVertex(keyOrVertex);
|
|
5246
5246
|
} else {
|
|
5247
5247
|
const newVertex = this.createVertex(keyOrVertex, value);
|
|
5248
|
-
return this.
|
|
5248
|
+
return this._addVertex(newVertex);
|
|
5249
5249
|
}
|
|
5250
5250
|
}
|
|
5251
5251
|
isVertexKey(potentialKey) {
|
|
@@ -5315,7 +5315,7 @@ var dataStructureTyped = (() => {
|
|
|
5315
5315
|
*/
|
|
5316
5316
|
addEdge(srcOrEdge, dest, weight, value) {
|
|
5317
5317
|
if (srcOrEdge instanceof AbstractEdge) {
|
|
5318
|
-
return this.
|
|
5318
|
+
return this._addEdge(srcOrEdge);
|
|
5319
5319
|
} else {
|
|
5320
5320
|
if (dest instanceof AbstractVertex || typeof dest === "string" || typeof dest === "number") {
|
|
5321
5321
|
if (!(this.hasVertex(srcOrEdge) && this.hasVertex(dest)))
|
|
@@ -5325,7 +5325,7 @@ var dataStructureTyped = (() => {
|
|
|
5325
5325
|
if (dest instanceof AbstractVertex)
|
|
5326
5326
|
dest = dest.key;
|
|
5327
5327
|
const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
|
|
5328
|
-
return this.
|
|
5328
|
+
return this._addEdge(newEdge);
|
|
5329
5329
|
} else {
|
|
5330
5330
|
throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge");
|
|
5331
5331
|
}
|
|
@@ -6131,13 +6131,6 @@ var dataStructureTyped = (() => {
|
|
|
6131
6131
|
getLowMap() {
|
|
6132
6132
|
return this.tarjan(false, false, false, false).lowMap;
|
|
6133
6133
|
}
|
|
6134
|
-
/**
|
|
6135
|
-
* The function `getCycles` returns a map of cycles found using the Tarjan algorithm.
|
|
6136
|
-
* @returns The function `getCycles()` is returning a `Map<number, VO[]>`.
|
|
6137
|
-
*/
|
|
6138
|
-
getCycles() {
|
|
6139
|
-
return this.tarjan(false, false, false, true).cycles;
|
|
6140
|
-
}
|
|
6141
6134
|
/**
|
|
6142
6135
|
* The function "getCutVertexes" returns an array of cut vertexes using the Tarjan algorithm.
|
|
6143
6136
|
* @returns an array of VO objects, specifically the cut vertexes.
|
|
@@ -6160,6 +6153,44 @@ var dataStructureTyped = (() => {
|
|
|
6160
6153
|
getBridges() {
|
|
6161
6154
|
return this.tarjan(false, true, false, false).bridges;
|
|
6162
6155
|
}
|
|
6156
|
+
/**
|
|
6157
|
+
* O(V+E+C)
|
|
6158
|
+
* O(V+C)
|
|
6159
|
+
*/
|
|
6160
|
+
getCycles(isInclude2Cycle = false) {
|
|
6161
|
+
const cycles = [];
|
|
6162
|
+
const visited = /* @__PURE__ */ new Set();
|
|
6163
|
+
const dfs = (vertex, currentPath, visited2) => {
|
|
6164
|
+
if (visited2.has(vertex)) {
|
|
6165
|
+
if ((!isInclude2Cycle && currentPath.length > 2 || isInclude2Cycle && currentPath.length >= 2) && currentPath[0] === vertex.key) {
|
|
6166
|
+
cycles.push([...currentPath]);
|
|
6167
|
+
}
|
|
6168
|
+
return;
|
|
6169
|
+
}
|
|
6170
|
+
visited2.add(vertex);
|
|
6171
|
+
currentPath.push(vertex.key);
|
|
6172
|
+
for (const neighbor of this.getNeighbors(vertex)) {
|
|
6173
|
+
neighbor && dfs(neighbor, currentPath, visited2);
|
|
6174
|
+
}
|
|
6175
|
+
visited2.delete(vertex);
|
|
6176
|
+
currentPath.pop();
|
|
6177
|
+
};
|
|
6178
|
+
for (const vertex of this.vertexMap.values()) {
|
|
6179
|
+
dfs(vertex, [], visited);
|
|
6180
|
+
}
|
|
6181
|
+
const uniqueCycles = /* @__PURE__ */ new Map();
|
|
6182
|
+
for (const cycle of cycles) {
|
|
6183
|
+
const sorted = [...cycle].sort().toString();
|
|
6184
|
+
if (uniqueCycles.has(sorted))
|
|
6185
|
+
continue;
|
|
6186
|
+
else {
|
|
6187
|
+
uniqueCycles.set(sorted, cycle);
|
|
6188
|
+
}
|
|
6189
|
+
}
|
|
6190
|
+
return [...uniqueCycles].map(
|
|
6191
|
+
(cycleString) => cycleString[1]
|
|
6192
|
+
);
|
|
6193
|
+
}
|
|
6163
6194
|
/**
|
|
6164
6195
|
* Time Complexity: O(n)
|
|
6165
6196
|
* Space Complexity: O(n)
|
|
@@ -6222,7 +6253,7 @@ var dataStructureTyped = (() => {
|
|
|
6222
6253
|
yield [vertex.key, vertex.value];
|
|
6223
6254
|
}
|
|
6224
6255
|
}
|
|
6225
|
-
|
|
6256
|
+
_addVertex(newVertex) {
|
|
6226
6257
|
if (this.hasVertex(newVertex)) {
|
|
6227
6258
|
return false;
|
|
6228
6259
|
}
|
|
@@ -6759,13 +6790,13 @@ var dataStructureTyped = (() => {
|
|
|
6759
6790
|
* Time Complexity: O(1)
|
|
6760
6791
|
* Space Complexity: O(1)
|
|
6761
6792
|
*
|
|
6762
|
-
* The function `
|
|
6793
|
+
* The function `_addEdge` adds an edge to a graph if the source and destination vertexMap exist.
|
|
6763
6794
|
* @param {EO} edge - The parameter `edge` is of type `EO`, which represents an edge in a graph. It is the edge that
|
|
6764
6795
|
* needs to be added to the graph.
|
|
6765
6796
|
* @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
|
|
6766
6797
|
* source or destination vertex does not exist in the graph.
|
|
6767
6798
|
*/
|
|
6768
|
-
|
|
6799
|
+
_addEdge(edge) {
|
|
6769
6800
|
if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
|
|
6770
6801
|
return false;
|
|
6771
6802
|
}
|
|
@@ -7119,7 +7150,7 @@ var dataStructureTyped = (() => {
|
|
|
7119
7150
|
* @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
|
|
7120
7151
|
* @returns a boolean value.
|
|
7121
7152
|
*/
|
|
7122
|
-
|
|
7153
|
+
_addEdge(edge) {
|
|
7123
7154
|
for (const end of edge.vertexMap) {
|
|
7124
7155
|
const endVertex = this._getVertex(end);
|
|
7125
7156
|
if (endVertex === void 0)
|