data-structure-typed 1.47.7 → 1.47.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +98 -17
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +22 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +71 -30
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/cjs/data-structures/graph/directed-graph.js +29 -29
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/cjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/cjs/data-structures/queue/queue.js +13 -13
- package/dist/cjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/cjs/data-structures/stack/stack.js +7 -7
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +22 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +71 -30
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/mjs/data-structures/graph/directed-graph.js +29 -29
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/mjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/mjs/data-structures/queue/queue.js +13 -13
- package/dist/mjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/mjs/data-structures/stack/stack.js +7 -7
- package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/umd/data-structure-typed.js +203 -162
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/segment-tree.ts +10 -10
- package/src/data-structures/graph/abstract-graph.ts +92 -46
- package/src/data-structures/graph/directed-graph.ts +41 -41
- package/src/data-structures/graph/undirected-graph.ts +26 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
- package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
- package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
- package/src/data-structures/queue/queue.ts +13 -13
- package/src/data-structures/stack/stack.ts +9 -9
- package/src/types/data-structures/graph/abstract-graph.ts +2 -2
- package/test/integration/index.html +102 -33
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +51 -10
- package/test/unit/data-structures/graph/undirected-graph.test.ts +3 -3
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -3
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
|
@@ -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,
|
|
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,K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SAAS,CAAC;IAC/C,CAAC;IAED;;;OAGG;IAEH;;;;;;;OAOG;IACH,KAAK,CAAC,GAAM;QACV,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,IAAI,QAAQ,GAAG,SAAS,CAAC;QAEzB,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE;YACxC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE;gBACzD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;aAC9B;YACD,IAAI,OAAO,CAAC,GAAG,GAAG,GAAG,EAAE;gBACrB,QAAQ,GAAG,OAAO,CAAC;aACpB;SACF;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;YAChE,KAAK,EAAE,CAAC;SACT;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAlRD,4BAkRC"}
|
|
@@ -11,8 +11,8 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
|
11
11
|
*/
|
|
12
12
|
enqueue(value: E): void;
|
|
13
13
|
/**
|
|
14
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
15
|
-
* @returns The method is returning the element at the front of the queue, or
|
|
14
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
15
|
+
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
16
16
|
*/
|
|
17
17
|
dequeue(): E | undefined;
|
|
18
18
|
/**
|
|
@@ -75,7 +75,7 @@ export declare class Queue<E = any> {
|
|
|
75
75
|
*
|
|
76
76
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
77
77
|
* necessary to optimize performance.
|
|
78
|
-
* @returns The function `shift()` returns either the first element in the queue or `
|
|
78
|
+
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
79
79
|
*/
|
|
80
80
|
shift(): E | undefined;
|
|
81
81
|
/**
|
|
@@ -86,9 +86,9 @@ export declare class Queue<E = any> {
|
|
|
86
86
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
87
87
|
* Space Complexity: O(1) - no additional space is used.
|
|
88
88
|
*
|
|
89
|
-
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
89
|
+
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
90
90
|
* @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
91
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
91
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
92
92
|
*/
|
|
93
93
|
getFirst(): E | undefined;
|
|
94
94
|
/**
|
|
@@ -99,9 +99,9 @@ export declare class Queue<E = any> {
|
|
|
99
99
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
100
100
|
* Space Complexity: O(1) - no additional space is used.
|
|
101
101
|
*
|
|
102
|
-
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
102
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
103
103
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
104
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
104
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
105
105
|
*/
|
|
106
106
|
peek(): E | undefined;
|
|
107
107
|
/**
|
|
@@ -112,9 +112,9 @@ export declare class Queue<E = any> {
|
|
|
112
112
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
113
113
|
* Space Complexity: O(1) - no additional space is used.
|
|
114
114
|
*
|
|
115
|
-
* The `getLast` function returns the last element in an array-like data structure, or
|
|
115
|
+
* The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
116
116
|
* @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
117
|
-
* array is empty, it returns `
|
|
117
|
+
* array is empty, it returns `undefined`.
|
|
118
118
|
*/
|
|
119
119
|
getLast(): E | undefined;
|
|
120
120
|
/**
|
|
@@ -125,9 +125,9 @@ export declare class Queue<E = any> {
|
|
|
125
125
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
126
126
|
* Space Complexity: O(1) - no additional space is used.
|
|
127
127
|
*
|
|
128
|
-
* The `peekLast` function returns the last element in an array-like data structure, or
|
|
128
|
+
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
129
129
|
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
130
|
-
* array is empty, it returns `
|
|
130
|
+
* array is empty, it returns `undefined`.
|
|
131
131
|
*/
|
|
132
132
|
peekLast(): E | undefined;
|
|
133
133
|
/**
|
|
@@ -150,8 +150,8 @@ export declare class Queue<E = any> {
|
|
|
150
150
|
* Time Complexity: O(n) - same as shift().
|
|
151
151
|
* Space Complexity: O(1) - same as shift().
|
|
152
152
|
*
|
|
153
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
154
|
-
* @returns The method is returning a value of type E or
|
|
153
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
154
|
+
* @returns The method is returning a value of type E or undefined.
|
|
155
155
|
*/
|
|
156
156
|
dequeue(): E | undefined;
|
|
157
157
|
/**
|
|
@@ -16,8 +16,8 @@ class LinkedListQueue extends linked_list_1.SinglyLinkedList {
|
|
|
16
16
|
this.push(value);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
20
|
-
* @returns The method is returning the element at the front of the queue, or
|
|
19
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
20
|
+
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
21
21
|
*/
|
|
22
22
|
dequeue() {
|
|
23
23
|
return this.shift();
|
|
@@ -100,7 +100,7 @@ class Queue {
|
|
|
100
100
|
*
|
|
101
101
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
102
102
|
* necessary to optimize performance.
|
|
103
|
-
* @returns The function `shift()` returns either the first element in the queue or `
|
|
103
|
+
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
104
104
|
*/
|
|
105
105
|
shift() {
|
|
106
106
|
if (this.size === 0)
|
|
@@ -123,9 +123,9 @@ class Queue {
|
|
|
123
123
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
124
124
|
* Space Complexity: O(1) - no additional space is used.
|
|
125
125
|
*
|
|
126
|
-
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
126
|
+
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
127
127
|
* @returns The `getFirst()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
128
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
128
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
129
129
|
*/
|
|
130
130
|
getFirst() {
|
|
131
131
|
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
@@ -138,9 +138,9 @@ class Queue {
|
|
|
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.
|
|
140
140
|
*
|
|
141
|
-
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
141
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
142
142
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
143
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
143
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
144
144
|
*/
|
|
145
145
|
peek() {
|
|
146
146
|
return this.getFirst();
|
|
@@ -153,9 +153,9 @@ class Queue {
|
|
|
153
153
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
154
154
|
* Space Complexity: O(1) - no additional space is used.
|
|
155
155
|
*
|
|
156
|
-
* The `getLast` function returns the last element in an array-like data structure, or
|
|
156
|
+
* The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
157
157
|
* @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
158
|
-
* array is empty, it returns `
|
|
158
|
+
* array is empty, it returns `undefined`.
|
|
159
159
|
*/
|
|
160
160
|
getLast() {
|
|
161
161
|
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
@@ -168,9 +168,9 @@ class Queue {
|
|
|
168
168
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
169
169
|
* Space Complexity: O(1) - no additional space is used.
|
|
170
170
|
*
|
|
171
|
-
* The `peekLast` function returns the last element in an array-like data structure, or
|
|
171
|
+
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
172
172
|
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
173
|
-
* array is empty, it returns `
|
|
173
|
+
* array is empty, it returns `undefined`.
|
|
174
174
|
*/
|
|
175
175
|
peekLast() {
|
|
176
176
|
return this.getLast();
|
|
@@ -197,8 +197,8 @@ class Queue {
|
|
|
197
197
|
* Time Complexity: O(n) - same as shift().
|
|
198
198
|
* Space Complexity: O(1) - same as shift().
|
|
199
199
|
*
|
|
200
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
201
|
-
* @returns The method is returning a value of type E or
|
|
200
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
201
|
+
* @returns The method is returning a value of type E or undefined.
|
|
202
202
|
*/
|
|
203
203
|
dequeue() {
|
|
204
204
|
return this.shift();
|
|
@@ -45,10 +45,10 @@ export declare class Stack<E = any> {
|
|
|
45
45
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
46
46
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
47
47
|
*
|
|
48
|
-
* The `peek` function returns the last element of an array, or
|
|
49
|
-
* @returns The `peek()` function returns the last element of the `_elements` array, or `
|
|
48
|
+
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
49
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
50
50
|
*/
|
|
51
|
-
peek(): E |
|
|
51
|
+
peek(): E | undefined;
|
|
52
52
|
/**
|
|
53
53
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
54
54
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
@@ -70,11 +70,11 @@ export declare class Stack<E = any> {
|
|
|
70
70
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
71
71
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
72
72
|
*
|
|
73
|
-
* The `pop` function removes and returns the last element from an array, or returns
|
|
73
|
+
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
74
74
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
75
|
-
* array is empty, it returns `
|
|
75
|
+
* array is empty, it returns `undefined`.
|
|
76
76
|
*/
|
|
77
|
-
pop(): E |
|
|
77
|
+
pop(): E | undefined;
|
|
78
78
|
/**
|
|
79
79
|
* Time Complexity: O(n)
|
|
80
80
|
* Space Complexity: O(n)
|
|
@@ -62,12 +62,12 @@ class Stack {
|
|
|
62
62
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
63
63
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
64
64
|
*
|
|
65
|
-
* The `peek` function returns the last element of an array, or
|
|
66
|
-
* @returns The `peek()` function returns the last element of the `_elements` array, or `
|
|
65
|
+
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
66
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
67
67
|
*/
|
|
68
68
|
peek() {
|
|
69
69
|
if (this.isEmpty())
|
|
70
|
-
return
|
|
70
|
+
return undefined;
|
|
71
71
|
return this.elements[this.elements.length - 1];
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
@@ -94,14 +94,14 @@ class Stack {
|
|
|
94
94
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
95
95
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
96
96
|
*
|
|
97
|
-
* The `pop` function removes and returns the last element from an array, or returns
|
|
97
|
+
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
98
98
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
99
|
-
* array is empty, it returns `
|
|
99
|
+
* array is empty, it returns `undefined`.
|
|
100
100
|
*/
|
|
101
101
|
pop() {
|
|
102
102
|
if (this.isEmpty())
|
|
103
|
-
return
|
|
104
|
-
return this.elements.pop() ||
|
|
103
|
+
return undefined;
|
|
104
|
+
return this.elements.pop() || undefined;
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* Time Complexity: O(n)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/data-structures/stack/stack.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,KAAK;IAChB;;;;;OAKG;IACH,YAAY,QAAsB;QAChC,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CAAC,CAAC;IACzB,CAAC;CACF;AAjND,sBAiNC"}
|
|
@@ -2,9 +2,9 @@ export type VertexKey = string | number;
|
|
|
2
2
|
export type DijkstraResult<V> = {
|
|
3
3
|
distMap: Map<V, number>;
|
|
4
4
|
distPaths?: Map<V, V[]>;
|
|
5
|
-
preMap: Map<V, V |
|
|
5
|
+
preMap: Map<V, V | undefined>;
|
|
6
6
|
seen: Set<V>;
|
|
7
7
|
paths: V[][];
|
|
8
8
|
minDist: number;
|
|
9
9
|
minPath: V[];
|
|
10
|
-
} |
|
|
10
|
+
} | undefined;
|
|
@@ -9,11 +9,11 @@ import type { SegmentTreeNodeVal } from '../../types';
|
|
|
9
9
|
export declare class SegmentTreeNode {
|
|
10
10
|
start: number;
|
|
11
11
|
end: number;
|
|
12
|
-
value: SegmentTreeNodeVal |
|
|
12
|
+
value: SegmentTreeNodeVal | undefined;
|
|
13
13
|
sum: number;
|
|
14
|
-
left: SegmentTreeNode |
|
|
15
|
-
right: SegmentTreeNode |
|
|
16
|
-
constructor(start: number, end: number, sum: number, value?: SegmentTreeNodeVal |
|
|
14
|
+
left: SegmentTreeNode | undefined;
|
|
15
|
+
right: SegmentTreeNode | undefined;
|
|
16
|
+
constructor(start: number, end: number, sum: number, value?: SegmentTreeNodeVal | undefined);
|
|
17
17
|
}
|
|
18
18
|
export declare class SegmentTree {
|
|
19
19
|
/**
|
|
@@ -32,8 +32,8 @@ export declare class SegmentTree {
|
|
|
32
32
|
get start(): number;
|
|
33
33
|
protected _end: number;
|
|
34
34
|
get end(): number;
|
|
35
|
-
protected _root: SegmentTreeNode |
|
|
36
|
-
get root(): SegmentTreeNode |
|
|
35
|
+
protected _root: SegmentTreeNode | undefined;
|
|
36
|
+
get root(): SegmentTreeNode | undefined;
|
|
37
37
|
/**
|
|
38
38
|
* The build function creates a segment tree by recursively dividing the given range into smaller segments and assigning
|
|
39
39
|
* the sum of values to each segment.
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
export class SegmentTreeNode {
|
|
9
9
|
start = 0;
|
|
10
10
|
end = 0;
|
|
11
|
-
value =
|
|
11
|
+
value = undefined;
|
|
12
12
|
sum = 0;
|
|
13
|
-
left =
|
|
14
|
-
right =
|
|
13
|
+
left = undefined;
|
|
14
|
+
right = undefined;
|
|
15
15
|
constructor(start, end, sum, value) {
|
|
16
16
|
this.start = start;
|
|
17
17
|
this.end = end;
|
|
18
18
|
this.sum = sum;
|
|
19
|
-
this.value = value ||
|
|
19
|
+
this.value = value || undefined;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
export class SegmentTree {
|
|
@@ -39,7 +39,7 @@ export class SegmentTree {
|
|
|
39
39
|
this._root = this.build(start, end);
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
|
-
this._root =
|
|
42
|
+
this._root = undefined;
|
|
43
43
|
this._values = [];
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -94,7 +94,7 @@ export class SegmentTree {
|
|
|
94
94
|
* @returns The function does not return anything.
|
|
95
95
|
*/
|
|
96
96
|
updateNode(index, sum, value) {
|
|
97
|
-
const root = this.root ||
|
|
97
|
+
const root = this.root || undefined;
|
|
98
98
|
if (!root) {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
@@ -130,7 +130,7 @@ export class SegmentTree {
|
|
|
130
130
|
* @returns The function `querySumByRange` returns a number.
|
|
131
131
|
*/
|
|
132
132
|
querySumByRange(indexA, indexB) {
|
|
133
|
-
const root = this.root ||
|
|
133
|
+
const root = this.root || undefined;
|
|
134
134
|
if (!root) {
|
|
135
135
|
return 0;
|
|
136
136
|
}
|
|
@@ -47,13 +47,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
47
47
|
* @param value
|
|
48
48
|
*/
|
|
49
49
|
abstract createEdge(srcOrV1: VertexKey, destOrV2: VertexKey, weight?: number, value?: E): EO;
|
|
50
|
-
abstract deleteEdge(edge: EO): EO |
|
|
51
|
-
abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO |
|
|
50
|
+
abstract deleteEdge(edge: EO): EO | undefined;
|
|
51
|
+
abstract getEdge(srcOrKey: VO | VertexKey, destOrKey: VO | VertexKey): EO | undefined;
|
|
52
52
|
abstract degreeOf(vertexOrKey: VO | VertexKey): number;
|
|
53
53
|
abstract edgeSet(): EO[];
|
|
54
54
|
abstract edgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
55
55
|
abstract getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
56
|
-
abstract getEndsOfEdge(edge: EO): [VO, VO] |
|
|
56
|
+
abstract getEndsOfEdge(edge: EO): [VO, VO] | undefined;
|
|
57
57
|
/**
|
|
58
58
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
59
59
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -62,13 +62,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
62
62
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
63
63
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
64
64
|
*
|
|
65
|
-
* The function "getVertex" returns the vertex with the specified ID or
|
|
65
|
+
* The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
|
|
66
66
|
* @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
|
|
67
67
|
* the `_vertices` map.
|
|
68
68
|
* @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertices`
|
|
69
|
-
* map. If the vertex does not exist, it returns `
|
|
69
|
+
* map. If the vertex does not exist, it returns `undefined`.
|
|
70
70
|
*/
|
|
71
|
-
getVertex(vertexKey: VertexKey): VO |
|
|
71
|
+
getVertex(vertexKey: VertexKey): VO | undefined;
|
|
72
72
|
/**
|
|
73
73
|
* Time Complexity: O(1) - Constant time for Map lookup.
|
|
74
74
|
* Space Complexity: O(1) - Constant space, as it creates only a few variables.
|
|
@@ -201,7 +201,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
201
201
|
* vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
|
|
202
202
|
* minimum number of
|
|
203
203
|
*/
|
|
204
|
-
getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number |
|
|
204
|
+
getMinCostBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean): number | undefined;
|
|
205
205
|
/**
|
|
206
206
|
* Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
207
207
|
* Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
|
|
@@ -223,9 +223,9 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
223
223
|
* followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
|
|
224
224
|
* so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
|
|
225
225
|
* @returns The function `getMinPathBetween` returns an array of vertices (`VO[]`) representing the minimum path between
|
|
226
|
-
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `
|
|
226
|
+
* two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `undefined`.
|
|
227
227
|
*/
|
|
228
|
-
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] |
|
|
228
|
+
getMinPathBetween(v1: VO | VertexKey, v2: VO | VertexKey, isWeight?: boolean, isDFS?: boolean): VO[] | undefined;
|
|
229
229
|
/**
|
|
230
230
|
* Dijkstra algorithm time: O(VE) space: O(VO + EO)
|
|
231
231
|
* /
|
|
@@ -242,9 +242,9 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
242
242
|
* a graph without using a heap data structure.
|
|
243
243
|
* @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
|
|
244
244
|
* vertex object or a vertex ID.
|
|
245
|
-
* @param {VO | VertexKey |
|
|
245
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
|
|
246
246
|
* parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
|
|
247
|
-
* identifier. If no destination is provided, the value is set to `
|
|
247
|
+
* identifier. If no destination is provided, the value is set to `undefined`.
|
|
248
248
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
249
249
|
* distance from the source vertex to the destination vertex should be calculated and returned in the result. If
|
|
250
250
|
* `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
|
|
@@ -253,7 +253,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
253
253
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
254
254
|
* @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
|
|
255
255
|
*/
|
|
256
|
-
dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey |
|
|
256
|
+
dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
|
|
257
257
|
/**
|
|
258
258
|
* Dijkstra algorithm time: O(logVE) space: O(VO + EO)
|
|
259
259
|
*
|
|
@@ -276,7 +276,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
276
276
|
* optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
|
|
277
277
|
* @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
|
|
278
278
|
* start. It can be either a vertex object or a vertex ID.
|
|
279
|
-
* @param {VO | VertexKey |
|
|
279
|
+
* @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
|
|
280
280
|
* vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
|
|
281
281
|
* will calculate the shortest paths to all other vertices from the source vertex.
|
|
282
282
|
* @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
|
|
@@ -287,7 +287,7 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
287
287
|
* shortest paths from the source vertex to all other vertices in the graph. If `genPaths
|
|
288
288
|
* @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
|
|
289
289
|
*/
|
|
290
|
-
dijkstra(src: VO | VertexKey, dest?: VO | VertexKey |
|
|
290
|
+
dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | undefined, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<VO>;
|
|
291
291
|
/**
|
|
292
292
|
* Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
|
|
293
293
|
* Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
|
|
@@ -353,12 +353,12 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
353
353
|
* graph.
|
|
354
354
|
* @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
|
|
355
355
|
* property is a 2D array of numbers representing the shortest path costs between vertices in a graph. The
|
|
356
|
-
* `predecessor` property is a 2D array of vertices (or `
|
|
356
|
+
* `predecessor` property is a 2D array of vertices (or `undefined`) representing the predecessor vertices in the shortest
|
|
357
357
|
* path between vertices in the
|
|
358
358
|
*/
|
|
359
359
|
floydWarshall(): {
|
|
360
360
|
costs: number[][];
|
|
361
|
-
predecessor: (VO |
|
|
361
|
+
predecessor: (VO | undefined)[][];
|
|
362
362
|
};
|
|
363
363
|
/**
|
|
364
364
|
* Time Complexity: O(V + E) - Linear time (Tarjan's algorithm).
|
|
@@ -443,8 +443,13 @@ export declare abstract class AbstractGraph<V = any, E = any, VO extends Abstrac
|
|
|
443
443
|
* @returns the bridges found using the Tarjan algorithm.
|
|
444
444
|
*/
|
|
445
445
|
getBridges(): EO[];
|
|
446
|
+
[Symbol.iterator](): Iterator<[VertexKey, V | undefined]>;
|
|
447
|
+
forEach(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => void): void;
|
|
448
|
+
filter(predicate: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => boolean): [VertexKey, V | undefined][];
|
|
449
|
+
map<T>(callback: (entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T): T[];
|
|
450
|
+
reduce<T>(callback: (accumulator: T, entry: [VertexKey, V | undefined], index: number, map: Map<VertexKey, VO>) => T, initialValue: T): T;
|
|
446
451
|
protected abstract _addEdgeOnly(edge: EO): boolean;
|
|
447
452
|
protected _addVertexOnly(newVertex: VO): boolean;
|
|
448
|
-
protected _getVertex(vertexOrKey: VertexKey | VO): VO |
|
|
453
|
+
protected _getVertex(vertexOrKey: VertexKey | VO): VO | undefined;
|
|
449
454
|
protected _getVertexKey(vertexOrKey: VO | VertexKey): VertexKey;
|
|
450
455
|
}
|