data-structure-typed 1.49.1 → 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/README.md +16 -16
- package/README_zh-CN.md +2 -2
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +457 -22
- package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/cjs/data-structures/base/iterable-base.js +21 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +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/hash/hash-map.d.ts +9 -9
- package/dist/cjs/data-structures/hash/hash-map.js +16 -15
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +6 -35
- package/dist/cjs/data-structures/heap/heap.js +10 -42
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +143 -146
- 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 +16 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -42
- package/dist/cjs/data-structures/linked-list/singly-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/deque.d.ts +70 -75
- package/dist/cjs/data-structures/queue/deque.js +100 -110
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +37 -38
- package/dist/cjs/data-structures/queue/queue.js +46 -49
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +2 -3
- package/dist/cjs/data-structures/stack/stack.js +2 -5
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +1 -2
- package/dist/cjs/data-structures/trie/trie.js +2 -5
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/mjs/data-structures/base/iterable-base.js +21 -0
- 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/hash/hash-map.d.ts +9 -9
- package/dist/mjs/data-structures/hash/hash-map.js +16 -15
- package/dist/mjs/data-structures/heap/heap.d.ts +6 -35
- package/dist/mjs/data-structures/heap/heap.js +10 -42
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +99 -105
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +142 -145
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -43
- 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/deque.d.ts +70 -75
- package/dist/mjs/data-structures/queue/deque.js +100 -110
- package/dist/mjs/data-structures/queue/queue.d.ts +37 -38
- package/dist/mjs/data-structures/queue/queue.js +45 -48
- package/dist/mjs/data-structures/stack/stack.d.ts +2 -3
- package/dist/mjs/data-structures/stack/stack.js +2 -5
- package/dist/mjs/data-structures/trie/trie.d.ts +1 -2
- package/dist/mjs/data-structures/trie/trie.js +2 -5
- package/dist/umd/data-structure-typed.js +531 -532
- 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/base/iterable-base.ts +24 -0
- 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/hash/hash-map.ts +27 -28
- package/src/data-structures/heap/heap.ts +19 -57
- package/src/data-structures/linked-list/doubly-linked-list.ts +157 -161
- package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
- package/src/data-structures/linked-list/skip-linked-list.ts +40 -40
- package/src/data-structures/queue/deque.ts +122 -135
- package/src/data-structures/queue/queue.ts +54 -58
- package/src/data-structures/stack/stack.ts +4 -8
- package/src/data-structures/trie/trie.ts +5 -9
- package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
- package/test/performance/data-structures/heap/heap.test.ts +2 -2
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
- 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/hash/hash-map.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +6 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
- package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
- package/test/unit/data-structures/queue/deque.test.ts +5 -5
- package/test/unit/data-structures/queue/queue.test.ts +4 -4
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
|
@@ -84,12 +84,12 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
describe('
|
|
87
|
+
describe('addAfter', () => {
|
|
88
88
|
it('should insert an element after an existing value', () => {
|
|
89
89
|
list.push(1);
|
|
90
90
|
list.push(2);
|
|
91
91
|
list.push(3);
|
|
92
|
-
list.
|
|
92
|
+
list.addAfter(2, 4);
|
|
93
93
|
expect(list.toArray()).toEqual([1, 2, 4, 3]);
|
|
94
94
|
});
|
|
95
95
|
|
|
@@ -97,7 +97,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
97
97
|
list.push(1);
|
|
98
98
|
list.push(2);
|
|
99
99
|
list.push(3);
|
|
100
|
-
const result = list.
|
|
100
|
+
const result = list.addAfter(5, 4);
|
|
101
101
|
expect(result).toBe(false);
|
|
102
102
|
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
103
103
|
});
|
|
@@ -164,7 +164,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
164
164
|
list.push(3);
|
|
165
165
|
list.clear();
|
|
166
166
|
expect(list.toArray()).toEqual([]);
|
|
167
|
-
expect(list.
|
|
167
|
+
expect(list.size).toBe(0);
|
|
168
168
|
expect(list.isEmpty()).toBe(true);
|
|
169
169
|
});
|
|
170
170
|
});
|
|
@@ -223,19 +223,19 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
223
223
|
});
|
|
224
224
|
});
|
|
225
225
|
|
|
226
|
-
describe('
|
|
226
|
+
describe('addBefore', () => {
|
|
227
227
|
it('should insert an element before an existing value', () => {
|
|
228
228
|
list.push(1);
|
|
229
229
|
list.push(2);
|
|
230
230
|
list.push(3);
|
|
231
|
-
list.
|
|
231
|
+
list.addBefore(2, 4);
|
|
232
232
|
expect(list.toArray()).toEqual([1, 4, 2, 3]);
|
|
233
233
|
});
|
|
234
234
|
|
|
235
235
|
it('should insert an element at the beginning', () => {
|
|
236
236
|
list.push(1);
|
|
237
237
|
list.push(2);
|
|
238
|
-
list.
|
|
238
|
+
list.addBefore(1, 3);
|
|
239
239
|
expect(list.toArray()).toEqual([3, 1, 2]);
|
|
240
240
|
});
|
|
241
241
|
|
|
@@ -243,7 +243,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
243
243
|
list.push(1);
|
|
244
244
|
list.push(2);
|
|
245
245
|
list.push(3);
|
|
246
|
-
const result = list.
|
|
246
|
+
const result = list.addBefore(5, 4);
|
|
247
247
|
expect(result).toBe(false);
|
|
248
248
|
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
249
249
|
});
|
|
@@ -251,10 +251,10 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
251
251
|
|
|
252
252
|
describe('getLength', () => {
|
|
253
253
|
it('should return the correct length of the list', () => {
|
|
254
|
-
expect(list.
|
|
254
|
+
expect(list.size).toBe(0);
|
|
255
255
|
list.push(1);
|
|
256
256
|
list.push(2);
|
|
257
|
-
expect(list.
|
|
257
|
+
expect(list.size).toBe(2);
|
|
258
258
|
});
|
|
259
259
|
});
|
|
260
260
|
|
|
@@ -264,21 +264,21 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
264
264
|
list.push(2);
|
|
265
265
|
list.push(3);
|
|
266
266
|
const removed = list.deleteAt(1);
|
|
267
|
-
expect(removed).toBe(
|
|
267
|
+
expect(removed).toBe(true);
|
|
268
268
|
expect(list.toArray()).toEqual([1, 3]);
|
|
269
269
|
});
|
|
270
270
|
|
|
271
271
|
it('should return undefined for an out-of-bounds index', () => {
|
|
272
272
|
list.push(1);
|
|
273
273
|
const removed = list.deleteAt(1);
|
|
274
|
-
expect(removed).
|
|
274
|
+
expect(removed).toBe(false);
|
|
275
275
|
});
|
|
276
276
|
|
|
277
277
|
it('should delete and return the first element', () => {
|
|
278
278
|
list.push(1);
|
|
279
279
|
list.push(2);
|
|
280
280
|
const removed = list.deleteAt(0);
|
|
281
|
-
expect(removed).toBe(
|
|
281
|
+
expect(removed).toBe(true);
|
|
282
282
|
expect(list.toArray()).toEqual([2]);
|
|
283
283
|
});
|
|
284
284
|
|
|
@@ -286,7 +286,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
286
286
|
list.push(1);
|
|
287
287
|
list.push(2);
|
|
288
288
|
const removed = list.deleteAt(1);
|
|
289
|
-
expect(removed).toBe(
|
|
289
|
+
expect(removed).toBe(true);
|
|
290
290
|
expect(list.toArray()).toEqual([1]);
|
|
291
291
|
});
|
|
292
292
|
});
|
|
@@ -313,9 +313,9 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
313
313
|
|
|
314
314
|
describe('insert and toArray', () => {
|
|
315
315
|
it('should insert elements and return array correctly', () => {
|
|
316
|
-
list.
|
|
317
|
-
list.
|
|
318
|
-
list.
|
|
316
|
+
list.addAt(0, 1);
|
|
317
|
+
list.addAt(1, 3);
|
|
318
|
+
list.addAt(1, 2);
|
|
319
319
|
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
320
320
|
});
|
|
321
321
|
});
|
|
@@ -377,7 +377,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
377
377
|
expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
|
|
378
378
|
|
|
379
379
|
const newObj = { keyA: 2.5 }; // Corrected newObj value
|
|
380
|
-
const insertSuccess = objectList.
|
|
380
|
+
const insertSuccess = objectList.addBefore(obj2, newObj);
|
|
381
381
|
expect(insertSuccess).toBe(true);
|
|
382
382
|
|
|
383
383
|
const getNode = objectList.getNode(newObj); // Use newObj instead of obj2
|
|
@@ -404,7 +404,7 @@ describe('SinglyLinkedList', () => {
|
|
|
404
404
|
it('should initialize an empty list', () => {
|
|
405
405
|
expect(list.head).toBe(undefined);
|
|
406
406
|
expect(list.tail).toBe(undefined);
|
|
407
|
-
expect(list.
|
|
407
|
+
expect(list.size).toBe(0);
|
|
408
408
|
});
|
|
409
409
|
|
|
410
410
|
it('should push elements to the end of the list', () => {
|
|
@@ -412,7 +412,7 @@ describe('SinglyLinkedList', () => {
|
|
|
412
412
|
list.push(2);
|
|
413
413
|
expect(list.head!.value).toBe(1);
|
|
414
414
|
expect(list.tail!.value).toBe(2);
|
|
415
|
-
expect(list.
|
|
415
|
+
expect(list.size).toBe(2);
|
|
416
416
|
});
|
|
417
417
|
|
|
418
418
|
it('should pop elements from the end of the list', () => {
|
|
@@ -422,7 +422,7 @@ describe('SinglyLinkedList', () => {
|
|
|
422
422
|
expect(popped).toBe(2);
|
|
423
423
|
expect(list.head!.value).toBe(1);
|
|
424
424
|
expect(list.tail!.value).toBe(1);
|
|
425
|
-
expect(list.
|
|
425
|
+
expect(list.size).toBe(1);
|
|
426
426
|
});
|
|
427
427
|
|
|
428
428
|
it('should reverse the list', () => {
|
|
@@ -66,11 +66,11 @@ describe('SkipList', () => {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
it('getFirst() should return the getFirst element', () => {
|
|
69
|
-
expect(skipList.
|
|
69
|
+
expect(skipList.first).toBe('One');
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
it('getLast() should return the getLast element', () => {
|
|
73
|
-
expect(skipList.
|
|
73
|
+
expect(skipList.last).toBe('Four');
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
it('higher(key) should return the getFirst element greater than the given key', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Deque } from '../../../../src';
|
|
2
|
-
import { isDebugTest } from '../../../config';
|
|
2
|
+
// import { isDebugTest } from '../../../config';
|
|
3
3
|
|
|
4
|
-
const isDebug = isDebugTest;
|
|
4
|
+
// const isDebug = isDebugTest;
|
|
5
5
|
|
|
6
6
|
describe('Deque - Basic Operations', () => {
|
|
7
7
|
let deque: Deque<number>;
|
|
@@ -57,10 +57,10 @@ describe('Deque - Complex Operations', () => {
|
|
|
57
57
|
deque = new Deque<number>();
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
test('
|
|
60
|
+
test('addAt should insert elements at the specified position', () => {
|
|
61
61
|
deque.push(1);
|
|
62
62
|
deque.push(3);
|
|
63
|
-
deque.
|
|
63
|
+
deque.addAt(1, 2);
|
|
64
64
|
expect(deque.toArray()).toEqual([1, 2, 3]);
|
|
65
65
|
});
|
|
66
66
|
|
|
@@ -111,7 +111,7 @@ describe('Deque - Complex Operations', () => {
|
|
|
111
111
|
deque.push(1);
|
|
112
112
|
deque.push(2);
|
|
113
113
|
deque.sort((a, b) => a - b);
|
|
114
|
-
expect(deque
|
|
114
|
+
expect([...deque]).toEqual([1, 2, 3]);
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
test('shrinkToFit should reduce the memory footprint', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LinkedListQueue, Queue } from '../../../../src';
|
|
2
|
-
import { isDebugTest } from '../../../config';
|
|
2
|
+
// import { isDebugTest } from '../../../config';
|
|
3
3
|
|
|
4
|
-
const isDebug = isDebugTest;
|
|
4
|
+
// const isDebug = isDebugTest;
|
|
5
5
|
|
|
6
6
|
describe('Queue', () => {
|
|
7
7
|
let queue: Queue<number>;
|
|
@@ -224,7 +224,7 @@ describe('LinkedListQueue', () => {
|
|
|
224
224
|
queue.enqueue('A');
|
|
225
225
|
queue.enqueue('B');
|
|
226
226
|
expect(queue.peek()).toBe('A');
|
|
227
|
-
expect(queue.
|
|
227
|
+
expect(queue.size).toBe(2);
|
|
228
228
|
});
|
|
229
229
|
|
|
230
230
|
it('should dequeue elements from the front of the queue', () => {
|
|
@@ -233,7 +233,7 @@ describe('LinkedListQueue', () => {
|
|
|
233
233
|
const dequeued = queue.dequeue();
|
|
234
234
|
expect(dequeued).toBe('A');
|
|
235
235
|
expect(queue.peek()).toBe('B');
|
|
236
|
-
expect(queue.
|
|
236
|
+
expect(queue.size).toBe(1);
|
|
237
237
|
});
|
|
238
238
|
|
|
239
239
|
it('should peek at the front of the queue', () => {
|
|
@@ -843,7 +843,7 @@ describe('Trie class', () => {
|
|
|
843
843
|
|
|
844
844
|
test('filter should return words that satisfy the predicate', () => {
|
|
845
845
|
const filteredWords = trie.filter(word => word.startsWith('ba'));
|
|
846
|
-
expect(filteredWords).toEqual(['banana', 'band', 'bandana']);
|
|
846
|
+
expect([...filteredWords]).toEqual(['banana', 'band', 'bandana']);
|
|
847
847
|
});
|
|
848
848
|
|
|
849
849
|
test('map should apply a function to each word', () => {
|