data-structure-typed 1.47.7 → 1.47.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +98 -17
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/cjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/cjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/cjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/cjs/data-structures/queue/queue.js +13 -13
- package/dist/cjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/cjs/data-structures/stack/stack.js +7 -7
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +6 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +7 -7
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +17 -17
- package/dist/mjs/data-structures/graph/abstract-graph.js +30 -30
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +24 -24
- package/dist/mjs/data-structures/graph/directed-graph.js +28 -28
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +14 -14
- package/dist/mjs/data-structures/graph/undirected-graph.js +18 -18
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +28 -28
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +33 -33
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +21 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +27 -27
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +4 -4
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -13
- package/dist/mjs/data-structures/queue/queue.js +13 -13
- package/dist/mjs/data-structures/stack/stack.d.ts +6 -6
- package/dist/mjs/data-structures/stack/stack.js +7 -7
- package/dist/mjs/types/data-structures/graph/abstract-graph.d.ts +2 -2
- package/dist/umd/data-structure-typed.js +161 -161
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/segment-tree.ts +10 -10
- package/src/data-structures/graph/abstract-graph.ts +46 -46
- package/src/data-structures/graph/directed-graph.ts +40 -40
- package/src/data-structures/graph/undirected-graph.ts +26 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +45 -45
- package/src/data-structures/linked-list/singly-linked-list.ts +38 -38
- package/src/data-structures/linked-list/skip-linked-list.ts +4 -4
- package/src/data-structures/queue/queue.ts +13 -13
- package/src/data-structures/stack/stack.ts +9 -9
- package/src/types/data-structures/graph/abstract-graph.ts +2 -2
- package/test/integration/index.html +102 -33
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +1 -1
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +4 -4
- package/test/unit/data-structures/graph/directed-graph.test.ts +10 -10
- package/test/unit/data-structures/graph/undirected-graph.test.ts +3 -3
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -3
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +2 -2
|
@@ -15,8 +15,8 @@ export class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
19
|
-
* @returns The method is returning the element at the front of the queue, or
|
|
18
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
19
|
+
* @returns The method is returning the element at the front of the queue, or undefined if the queue is empty.
|
|
20
20
|
*/
|
|
21
21
|
dequeue(): E | undefined {
|
|
22
22
|
return this.shift();
|
|
@@ -112,7 +112,7 @@ export class Queue<E = any> {
|
|
|
112
112
|
*
|
|
113
113
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
114
114
|
* necessary to optimize performance.
|
|
115
|
-
* @returns The function `shift()` returns either the first element in the queue or `
|
|
115
|
+
* @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
|
|
116
116
|
*/
|
|
117
117
|
shift(): E | undefined {
|
|
118
118
|
if (this.size === 0) return undefined;
|
|
@@ -138,9 +138,9 @@ export class Queue<E = any> {
|
|
|
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 `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
141
|
+
* The `getFirst` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
142
142
|
* @returns The `getFirst()` 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
|
getFirst(): E | undefined {
|
|
146
146
|
return this.size > 0 ? this.nodes[this.offset] : undefined;
|
|
@@ -155,9 +155,9 @@ export class Queue<E = any> {
|
|
|
155
155
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
156
156
|
* Space Complexity: O(1) - no additional space is used.
|
|
157
157
|
*
|
|
158
|
-
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `
|
|
158
|
+
* The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `undefined`.
|
|
159
159
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
|
|
160
|
-
* the `_offset` index. If the data structure is empty (size is 0), it returns `
|
|
160
|
+
* the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
|
|
161
161
|
*/
|
|
162
162
|
peek(): E | undefined {
|
|
163
163
|
return this.getFirst();
|
|
@@ -172,9 +172,9 @@ export class Queue<E = any> {
|
|
|
172
172
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
173
173
|
* Space Complexity: O(1) - no additional space is used.
|
|
174
174
|
*
|
|
175
|
-
* The `getLast` function returns the last element in an array-like data structure, or
|
|
175
|
+
* The `getLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
176
176
|
* @returns The method `getLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
177
|
-
* array is empty, it returns `
|
|
177
|
+
* array is empty, it returns `undefined`.
|
|
178
178
|
*/
|
|
179
179
|
getLast(): E | undefined {
|
|
180
180
|
return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
|
|
@@ -189,9 +189,9 @@ export class Queue<E = any> {
|
|
|
189
189
|
* Time Complexity: O(1) - constant time as it retrieves the value at the current offset.
|
|
190
190
|
* Space Complexity: O(1) - no additional space is used.
|
|
191
191
|
*
|
|
192
|
-
* The `peekLast` function returns the last element in an array-like data structure, or
|
|
192
|
+
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
193
193
|
* @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
|
|
194
|
-
* array is empty, it returns `
|
|
194
|
+
* array is empty, it returns `undefined`.
|
|
195
195
|
*/
|
|
196
196
|
peekLast(): E | undefined {
|
|
197
197
|
return this.getLast();
|
|
@@ -222,8 +222,8 @@ export class Queue<E = any> {
|
|
|
222
222
|
* Time Complexity: O(n) - same as shift().
|
|
223
223
|
* Space Complexity: O(1) - same as shift().
|
|
224
224
|
*
|
|
225
|
-
* The `dequeue` function removes and returns the first element from a queue, or returns
|
|
226
|
-
* @returns The method is returning a value of type E or
|
|
225
|
+
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
226
|
+
* @returns The method is returning a value of type E or undefined.
|
|
227
227
|
*/
|
|
228
228
|
dequeue(): E | undefined {
|
|
229
229
|
return this.shift();
|
|
@@ -68,11 +68,11 @@ export class Stack<E = any> {
|
|
|
68
68
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
69
69
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
70
70
|
*
|
|
71
|
-
* The `peek` function returns the last element of an array, or
|
|
72
|
-
* @returns The `peek()` function returns the last element of the `_elements` array, or `
|
|
71
|
+
* The `peek` function returns the last element of an array, or undefined if the array is empty.
|
|
72
|
+
* @returns The `peek()` function returns the last element of the `_elements` array, or `undefined` if the array is empty.
|
|
73
73
|
*/
|
|
74
|
-
peek(): E |
|
|
75
|
-
if (this.isEmpty()) return
|
|
74
|
+
peek(): E | undefined {
|
|
75
|
+
if (this.isEmpty()) return undefined;
|
|
76
76
|
|
|
77
77
|
return this.elements[this.elements.length - 1];
|
|
78
78
|
}
|
|
@@ -104,14 +104,14 @@ export class Stack<E = any> {
|
|
|
104
104
|
* Time Complexity: O(1), as it only involves accessing the last element of the array.
|
|
105
105
|
* Space Complexity: O(1), as it does not use any additional space.
|
|
106
106
|
*
|
|
107
|
-
* The `pop` function removes and returns the last element from an array, or returns
|
|
107
|
+
* The `pop` function removes and returns the last element from an array, or returns undefined if the array is empty.
|
|
108
108
|
* @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
|
|
109
|
-
* array is empty, it returns `
|
|
109
|
+
* array is empty, it returns `undefined`.
|
|
110
110
|
*/
|
|
111
|
-
pop(): E |
|
|
112
|
-
if (this.isEmpty()) return
|
|
111
|
+
pop(): E | undefined {
|
|
112
|
+
if (this.isEmpty()) return undefined;
|
|
113
113
|
|
|
114
|
-
return this.elements.pop() ||
|
|
114
|
+
return this.elements.pop() || undefined;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
|
@@ -3,9 +3,9 @@ export type VertexKey = string | number;
|
|
|
3
3
|
export type DijkstraResult<V> = {
|
|
4
4
|
distMap: Map<V, number>;
|
|
5
5
|
distPaths?: Map<V, V[]>;
|
|
6
|
-
preMap: Map<V, V |
|
|
6
|
+
preMap: Map<V, V | undefined>;
|
|
7
7
|
seen: Set<V>;
|
|
8
8
|
paths: V[][];
|
|
9
9
|
minDist: number;
|
|
10
10
|
minPath: V[];
|
|
11
|
-
} |
|
|
11
|
+
} | undefined;
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset='UTF-8'>
|
|
5
5
|
<title>CDN Test</title>
|
|
6
6
|
<!-- <script src="../../dist/umd/data-structure-typed.min.js"></script>-->
|
|
7
|
-
<script src="../../dist/umd/data-structure-typed.js"></script
|
|
8
|
-
|
|
7
|
+
<!-- <script src="../../dist/umd/data-structure-typed.js"></script>-->
|
|
8
|
+
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>
|
|
9
9
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.42.2/dist/umd/data-structure-typed.min.js'></script>-->
|
|
10
10
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.43.3/dist/umd/data-structure-typed.min.js'></script>-->
|
|
11
11
|
<!-- <script src='https://cdn.jsdelivr.net/npm/data-structure-typed@1.44.0/dist/umd/data-structure-typed.min.js'></script>-->
|
|
@@ -215,91 +215,160 @@
|
|
|
215
215
|
} catch (e) {
|
|
216
216
|
console.error(e);
|
|
217
217
|
}
|
|
218
|
-
|
|
218
|
+
|
|
219
219
|
try {
|
|
220
|
-
|
|
220
|
+
const {
|
|
221
221
|
AVLTree,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
222
|
+
BinaryTree,
|
|
223
|
+
BST,
|
|
224
|
+
Deque,
|
|
225
|
+
DoublyLinkedList,
|
|
226
|
+
HashMap,
|
|
227
|
+
Heap,
|
|
228
|
+
MaxPriorityQueue,
|
|
229
|
+
MinHeap,
|
|
230
|
+
MinPriorityQueue,
|
|
231
|
+
Queue,
|
|
232
|
+
RedBlackTree,
|
|
233
|
+
SinglyLinkedList,
|
|
234
|
+
Stack,
|
|
235
|
+
TreeMultimap,
|
|
236
|
+
Trie
|
|
237
237
|
} = dataStructureTyped;
|
|
238
238
|
const orgArr = [6, 1, 2, 7, 5, 3, 4, 9, 8];
|
|
239
239
|
const orgStrArr = ["trie", "trial", "trick", "trip", "tree", "trend", "triangle", "track", "trace", "transmit"];
|
|
240
240
|
const entries = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];
|
|
241
241
|
|
|
242
242
|
const queue = new Queue(orgArr);
|
|
243
|
-
queue.print();
|
|
243
|
+
queue.print(); // [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
244
244
|
|
|
245
245
|
const deque = new Deque(orgArr);
|
|
246
|
-
deque.print();
|
|
246
|
+
deque.print(); // [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
247
247
|
|
|
248
248
|
const sList = new SinglyLinkedList(orgArr);
|
|
249
|
-
sList.print();
|
|
249
|
+
sList.print(); // [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
250
250
|
|
|
251
251
|
const dList = new DoublyLinkedList(orgArr);
|
|
252
|
-
dList.print();
|
|
252
|
+
dList.print(); // [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
253
253
|
|
|
254
254
|
const stack = new Stack(orgArr);
|
|
255
|
-
stack.print();
|
|
255
|
+
stack.print(); // [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
256
256
|
|
|
257
257
|
const minHeap = new MinHeap(orgArr);
|
|
258
|
-
minHeap.print();
|
|
258
|
+
minHeap.print(); // [1, 5, 2, 7, 6, 3, 4, 9, 8]
|
|
259
259
|
|
|
260
260
|
const maxPQ = new MaxPriorityQueue(orgArr);
|
|
261
|
-
maxPQ.print();
|
|
261
|
+
maxPQ.print(); // [9, 8, 4, 7, 5, 2, 3, 1, 6]
|
|
262
262
|
|
|
263
263
|
const biTree = new BinaryTree(entries);
|
|
264
264
|
biTree.print();
|
|
265
|
+
// ___6___
|
|
266
|
+
// / \
|
|
267
|
+
// ___1_ _2_
|
|
268
|
+
// / \ / \
|
|
269
|
+
// _7_ 5 3 4
|
|
270
|
+
// / \
|
|
271
|
+
// 9 8
|
|
265
272
|
|
|
266
273
|
const bst = new BST(entries);
|
|
267
274
|
bst.print();
|
|
275
|
+
// _____5___
|
|
276
|
+
// / \
|
|
277
|
+
// _2_ _7_
|
|
278
|
+
// / \ / \
|
|
279
|
+
// 1 3_ 6 8_
|
|
280
|
+
// \ \
|
|
281
|
+
// 4 9
|
|
282
|
+
|
|
268
283
|
|
|
269
284
|
const rbTree = new RedBlackTree(entries);
|
|
270
285
|
rbTree.print();
|
|
286
|
+
// ___4___
|
|
287
|
+
// / \
|
|
288
|
+
// _2_ _6___
|
|
289
|
+
// / \ / \
|
|
290
|
+
// 1 3 5 _8_
|
|
291
|
+
// / \
|
|
292
|
+
// 7 9
|
|
293
|
+
|
|
271
294
|
|
|
272
295
|
const avl = new AVLTree(entries);
|
|
273
296
|
avl.print();
|
|
297
|
+
// ___4___
|
|
298
|
+
// / \
|
|
299
|
+
// _2_ _6___
|
|
300
|
+
// / \ / \
|
|
301
|
+
// 1 3 5 _8_
|
|
302
|
+
// / \
|
|
303
|
+
// 7 9
|
|
274
304
|
|
|
275
305
|
const treeMulti = new TreeMultimap(entries);
|
|
276
306
|
treeMulti.print();
|
|
307
|
+
// ___4___
|
|
308
|
+
// / \
|
|
309
|
+
// _2_ _6___
|
|
310
|
+
// / \ / \
|
|
311
|
+
// 1 3 5 _8_
|
|
312
|
+
// / \
|
|
313
|
+
// 7 9
|
|
277
314
|
|
|
278
315
|
const hm = new HashMap(entries);
|
|
279
|
-
hm.print()
|
|
316
|
+
hm.print() // [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]]
|
|
317
|
+
|
|
280
318
|
const rbTreeH = new RedBlackTree(hm);
|
|
281
319
|
rbTreeH.print();
|
|
320
|
+
// ___4___
|
|
321
|
+
// / \
|
|
322
|
+
// _2_ _6___
|
|
323
|
+
// / \ / \
|
|
324
|
+
// 1 3 5 _8_
|
|
325
|
+
// / \
|
|
326
|
+
// 7 9
|
|
282
327
|
|
|
283
328
|
const pq = new MinPriorityQueue(orgArr);
|
|
284
|
-
pq.print();
|
|
329
|
+
pq.print(); // [1, 5, 2, 7, 6, 3, 4, 9, 8]
|
|
330
|
+
|
|
285
331
|
const bst1 = new BST(pq);
|
|
286
332
|
bst1.print();
|
|
333
|
+
// _____5___
|
|
334
|
+
// / \
|
|
335
|
+
// _2_ _7_
|
|
336
|
+
// / \ / \
|
|
337
|
+
// 1 3_ 6 8_
|
|
338
|
+
// \ \
|
|
339
|
+
// 4 9
|
|
287
340
|
|
|
288
341
|
const dq1 = new Deque(orgArr);
|
|
289
|
-
dq1.print();
|
|
342
|
+
dq1.print(); // [6, 1, 2, 7, 5, 3, 4, 9, 8]
|
|
290
343
|
const rbTree1 = new RedBlackTree(dq1);
|
|
291
344
|
rbTree1.print();
|
|
345
|
+
// _____5___
|
|
346
|
+
// / \
|
|
347
|
+
// _2___ _7___
|
|
348
|
+
// / \ / \
|
|
349
|
+
// 1 _4 6 _9
|
|
350
|
+
// / /
|
|
351
|
+
// 3 8
|
|
352
|
+
|
|
292
353
|
|
|
293
354
|
const trie2 = new Trie(orgStrArr);
|
|
294
|
-
trie2.print();
|
|
355
|
+
trie2.print(); // ['trie', 'trial', 'triangle', 'trick', 'trip', 'tree', 'trend', 'track', 'trace', 'transmit']
|
|
295
356
|
const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
|
|
296
|
-
heap2.print();
|
|
357
|
+
heap2.print(); // ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
|
|
297
358
|
const dq2 = new Deque(heap2);
|
|
298
|
-
dq2.print();
|
|
359
|
+
dq2.print(); // ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
|
|
299
360
|
const entries2 = dq2.map((el, i) => [i, el]);
|
|
300
361
|
const avl2 = new AVLTree(entries2);
|
|
301
362
|
avl2.print();
|
|
302
|
-
|
|
363
|
+
// ___3_______
|
|
364
|
+
// / \
|
|
365
|
+
// _1_ ___7_
|
|
366
|
+
// / \ / \
|
|
367
|
+
// 0 2 _5_ 8_
|
|
368
|
+
// / \ \
|
|
369
|
+
// 4 6 9
|
|
370
|
+
|
|
371
|
+
} catch (e) {
|
|
303
372
|
console.error(e);
|
|
304
373
|
}
|
|
305
374
|
</script>
|
|
@@ -57,7 +57,7 @@ suite
|
|
|
57
57
|
})
|
|
58
58
|
.add(`${LINEAR.toLocaleString()} insertBefore`, () => {
|
|
59
59
|
const doublyList = new DoublyLinkedList<number>();
|
|
60
|
-
let midNode: DoublyLinkedListNode |
|
|
60
|
+
let midNode: DoublyLinkedListNode | undefined;
|
|
61
61
|
const midIndex = Math.floor(LINEAR / 2);
|
|
62
62
|
for (let i = 0; i < LINEAR; i++) {
|
|
63
63
|
doublyList.push(i);
|
|
@@ -19,7 +19,7 @@ suite
|
|
|
19
19
|
})
|
|
20
20
|
.add(`${TEN_THOUSAND.toLocaleString()} insertBefore`, () => {
|
|
21
21
|
const singlyList = new SinglyLinkedList<number>();
|
|
22
|
-
let midSinglyNode: SinglyLinkedListNode |
|
|
22
|
+
let midSinglyNode: SinglyLinkedListNode | undefined;
|
|
23
23
|
const midIndex = Math.floor(TEN_THOUSAND / 2);
|
|
24
24
|
for (let i = 0; i < TEN_THOUSAND; i++) {
|
|
25
25
|
singlyList.push(i);
|
|
@@ -37,7 +37,7 @@ describe('SegmentTree', () => {
|
|
|
37
37
|
it('should handle an empty input array', () => {
|
|
38
38
|
// Check behavior when dealing with an empty input array
|
|
39
39
|
const emptySegmentTree = new SegmentTree([]);
|
|
40
|
-
expect(emptySegmentTree.root).toBe(
|
|
40
|
+
expect(emptySegmentTree.root).toBe(undefined);
|
|
41
41
|
expect(emptySegmentTree.querySumByRange(0, 2)).toBe(0); // Sum of an empty array should be 0
|
|
42
42
|
});
|
|
43
43
|
|
|
@@ -36,11 +36,11 @@ class MyGraph<
|
|
|
36
36
|
return new MyEdge(srcOrV1, destOrV2, weight, value) as EO;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
deleteEdge(edge: EO): EO |
|
|
39
|
+
deleteEdge(edge: EO): EO | undefined {
|
|
40
40
|
return edge;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
getEdge(srcOrKey: VertexKey, destOrKey: VertexKey): EO |
|
|
43
|
+
getEdge(srcOrKey: VertexKey, destOrKey: VertexKey): EO | undefined {
|
|
44
44
|
return new MyEdge(srcOrKey, destOrKey) as EO;
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -62,8 +62,8 @@ class MyGraph<
|
|
|
62
62
|
return [new MyVertex(a, 'b') as VO];
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
getEndsOfEdge(edge: EO): [VO, VO] |
|
|
66
|
-
return edge ?
|
|
65
|
+
getEndsOfEdge(edge: EO): [VO, VO] | undefined {
|
|
66
|
+
return edge ? undefined : undefined;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
protected _addEdgeOnly(edge: EO): boolean {
|
|
@@ -196,7 +196,7 @@ describe('Inherit from DirectedGraph and perform operations', () => {
|
|
|
196
196
|
expect(edge1).toBeInstanceOf(MyEdge);
|
|
197
197
|
expect(edge1.src).toBe(1);
|
|
198
198
|
expect(edge1).toEqual(edge2);
|
|
199
|
-
expect(edge3).
|
|
199
|
+
expect(edge3).toBe(undefined);
|
|
200
200
|
}
|
|
201
201
|
});
|
|
202
202
|
|
|
@@ -217,7 +217,7 @@ describe('Inherit from DirectedGraph and perform operations', () => {
|
|
|
217
217
|
removedEdge && expect(removedEdge.value).toBe('edge-data1-2');
|
|
218
218
|
removedEdge && expect(removedEdge.src).toBe(1);
|
|
219
219
|
}
|
|
220
|
-
expect(edgeAfterRemoval).
|
|
220
|
+
expect(edgeAfterRemoval).toBe(undefined);
|
|
221
221
|
});
|
|
222
222
|
|
|
223
223
|
it('Topological sort', () => {
|
|
@@ -303,7 +303,7 @@ describe('Inherit from DirectedGraph and perform operations test2.', () => {
|
|
|
303
303
|
|
|
304
304
|
myGraph.addEdge(new MyEdge(7, 3, 73, 'edge-data7-3'));
|
|
305
305
|
const topologicalSorted = myGraph.topologicalSort();
|
|
306
|
-
expect(topologicalSorted).
|
|
306
|
+
expect(topologicalSorted).toBe(undefined);
|
|
307
307
|
|
|
308
308
|
const minPath1to7 = myGraph.getMinPathBetween(1, 7);
|
|
309
309
|
|
|
@@ -378,11 +378,11 @@ describe('Inherit from DirectedGraph and perform operations test2.', () => {
|
|
|
378
378
|
|
|
379
379
|
expect(predecessor).toBeInstanceOf(Array);
|
|
380
380
|
expect(predecessor.length).toBe(9);
|
|
381
|
-
expect(predecessor[0]).toEqual([vertex2,
|
|
382
|
-
expect(predecessor[1]).toEqual([
|
|
383
|
-
expect(predecessor[5]).toEqual([
|
|
384
|
-
expect(predecessor[7]).toEqual([
|
|
385
|
-
expect(predecessor[8]).toEqual([vertex7, vertex7, vertex7, vertex7, vertex7,
|
|
381
|
+
expect(predecessor[0]).toEqual([vertex2, undefined, vertex2, undefined, vertex3, undefined, vertex4, undefined, undefined]);
|
|
382
|
+
expect(predecessor[1]).toEqual([undefined, vertex1, undefined, vertex1, vertex3, undefined, vertex4, undefined, vertex1]);
|
|
383
|
+
expect(predecessor[5]).toEqual([undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined]);
|
|
384
|
+
expect(predecessor[7]).toEqual([undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined]);
|
|
385
|
+
expect(predecessor[8]).toEqual([vertex7, vertex7, vertex7, vertex7, vertex7, undefined, undefined, undefined, vertex7]);
|
|
386
386
|
}
|
|
387
387
|
|
|
388
388
|
const dijkstraRes12tt = myGraph.dijkstra(1, 2, true, true);
|
|
@@ -436,7 +436,7 @@ describe('Inherit from DirectedGraph and perform operations test2.', () => {
|
|
|
436
436
|
expect(paths[8][1]).toBe(vertex9);
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
-
const dijkstraRes1ntt = myGraph.dijkstra(1,
|
|
439
|
+
const dijkstraRes1ntt = myGraph.dijkstra(1, undefined, true, true);
|
|
440
440
|
|
|
441
441
|
expect(dijkstraRes1ntt).toBeTruthy();
|
|
442
442
|
if (dijkstraRes1ntt) {
|
|
@@ -499,7 +499,7 @@ describe('Inherit from DirectedGraph and perform operations test2.', () => {
|
|
|
499
499
|
expect(paths[8][1]).toBe(vertex9);
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
-
const dijkstraWithoutHeapRes1ntt = myGraph.dijkstraWithoutHeap(1,
|
|
502
|
+
const dijkstraWithoutHeapRes1ntt = myGraph.dijkstraWithoutHeap(1, undefined, true, true);
|
|
503
503
|
expect(dijkstraWithoutHeapRes1ntt).toBeTruthy();
|
|
504
504
|
if (dijkstraWithoutHeapRes1ntt) {
|
|
505
505
|
const { distMap, minDist, minPath, paths } = dijkstraWithoutHeapRes1ntt;
|
|
@@ -10,11 +10,11 @@ describe('UndirectedGraph Operation Test', () => {
|
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
it('should edge cases', () => {
|
|
13
|
-
expect(graph.deleteEdge(new UndirectedEdge('c', 'd'))).toBe(
|
|
14
|
-
expect(graph.deleteEdgeBetween('c', 'd')).toBe(
|
|
13
|
+
expect(graph.deleteEdge(new UndirectedEdge('c', 'd'))).toBe(undefined);
|
|
14
|
+
expect(graph.deleteEdgeBetween('c', 'd')).toBe(undefined);
|
|
15
15
|
expect(graph.degreeOf('c')).toBe(0);
|
|
16
16
|
expect(graph.edgesOf('c').length).toBe(0);
|
|
17
|
-
expect(graph.getEndsOfEdge(new UndirectedEdge('c', 'd'))).toBe(
|
|
17
|
+
expect(graph.getEndsOfEdge(new UndirectedEdge('c', 'd'))).toBe(undefined);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
it('should add vertices', () => {
|
|
@@ -17,8 +17,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('should out of bound index', () => {
|
|
20
|
-
expect(list.getNodeAt(-1)).toBe(
|
|
21
|
-
expect(list.getNodeAt(5)).toBe(
|
|
20
|
+
expect(list.getNodeAt(-1)).toBe(undefined);
|
|
21
|
+
expect(list.getNodeAt(5)).toBe(undefined);
|
|
22
22
|
expect(list.insertAt(5, 6)).toBe(true);
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -37,16 +37,16 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
37
37
|
expect(list.tail?.value).toBe(4);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
it('should find
|
|
41
|
-
expect(list.find(value => value === 6)).toBe(
|
|
40
|
+
it('should find undefined', () => {
|
|
41
|
+
expect(list.find(value => value === 6)).toBe(undefined);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
it('should indexOf -1', () => {
|
|
45
45
|
expect(list.indexOf(6)).toBe(-1);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
it('should findBackward
|
|
49
|
-
expect(list.findBackward(value => value === 0)).toBe(
|
|
48
|
+
it('should findBackward undefined', () => {
|
|
49
|
+
expect(list.findBackward(value => value === 0)).toBe(undefined);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it('should insertAfter tail', () => {
|
|
@@ -69,8 +69,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
69
69
|
|
|
70
70
|
it('should initialize an empty list', () => {
|
|
71
71
|
expect(list.length).toBe(0);
|
|
72
|
-
expect(list.head).
|
|
73
|
-
expect(list.tail).
|
|
72
|
+
expect(list.head).toBe(undefined);
|
|
73
|
+
expect(list.tail).toBe(undefined);
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
it('should push elements to the list', () => {
|
|
@@ -134,8 +134,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
134
134
|
// Deleting from the end
|
|
135
135
|
list.deleteAt(0);
|
|
136
136
|
expect(list.length).toBe(0);
|
|
137
|
-
expect(list.head).
|
|
138
|
-
expect(list.tail).
|
|
137
|
+
expect(list.head).toBe(undefined);
|
|
138
|
+
expect(list.tail).toBe(undefined);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
it('should delete elements by value', () => {
|
|
@@ -154,8 +154,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
154
154
|
|
|
155
155
|
list.delete(3);
|
|
156
156
|
expect(list.length).toBe(0);
|
|
157
|
-
expect(list.head).
|
|
158
|
-
expect(list.tail).
|
|
157
|
+
expect(list.head).toBe(undefined);
|
|
158
|
+
expect(list.tail).toBe(undefined);
|
|
159
159
|
});
|
|
160
160
|
|
|
161
161
|
it('should reverse the linked list', () => {
|
|
@@ -259,8 +259,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
259
259
|
list.clear();
|
|
260
260
|
|
|
261
261
|
expect(list.length).toBe(0);
|
|
262
|
-
expect(list.head).toBe(
|
|
263
|
-
expect(list.tail).toBe(
|
|
262
|
+
expect(list.head).toBe(undefined);
|
|
263
|
+
expect(list.tail).toBe(undefined);
|
|
264
264
|
});
|
|
265
265
|
|
|
266
266
|
it('should create a reversed array of values', () => {
|
|
@@ -333,7 +333,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
333
333
|
list.push(1);
|
|
334
334
|
list.push(3);
|
|
335
335
|
const result = list.find(data => data % 2 === 0);
|
|
336
|
-
expect(result).
|
|
336
|
+
expect(result).toBe(undefined);
|
|
337
337
|
});
|
|
338
338
|
});
|
|
339
339
|
|
|
@@ -402,8 +402,8 @@ describe('SinglyLinkedList', () => {
|
|
|
402
402
|
});
|
|
403
403
|
|
|
404
404
|
it('should initialize an empty list', () => {
|
|
405
|
-
expect(list.head).
|
|
406
|
-
expect(list.tail).
|
|
405
|
+
expect(list.head).toBe(undefined);
|
|
406
|
+
expect(list.tail).toBe(undefined);
|
|
407
407
|
expect(list.length).toBe(0);
|
|
408
408
|
});
|
|
409
409
|
|
|
@@ -154,7 +154,7 @@ describe('Deque', () => {
|
|
|
154
154
|
expect(deque.getAt(2)).toBe(3);
|
|
155
155
|
});
|
|
156
156
|
|
|
157
|
-
it('should return
|
|
157
|
+
it('should return undefined for out-of-bounds index', () => {
|
|
158
158
|
// expect(deque.getAt(0)).toThrowError('Index out of bounds.');
|
|
159
159
|
// expect(deque.getAt(1)).toThrow('Index out of bounds');
|
|
160
160
|
// expect(deque.getAt(-1)).toThrow('Index out of bounds');
|
|
@@ -35,9 +35,9 @@ describe('Stack', () => {
|
|
|
35
35
|
expect(stack.size).toBe(2);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
it('should return
|
|
38
|
+
it('should return undefined when popping from an empty stack', () => {
|
|
39
39
|
const poppedElement = stack.pop();
|
|
40
|
-
expect(poppedElement).
|
|
40
|
+
expect(poppedElement).toBe(undefined);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
it('should convert the stack to an array', () => {
|