data-structure-typed 1.45.0 → 1.45.2
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/.eslintrc.js +6 -6
- package/CHANGELOG.md +1 -1
- package/COMMANDS.md +6 -1
- package/README.md +18 -15
- package/benchmark/report.html +18 -15
- package/benchmark/report.json +157 -116
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +58 -58
- package/dist/cjs/data-structures/hash/hash-map.js +73 -73
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +21 -12
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
- package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
- package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +58 -58
- package/dist/mjs/data-structures/hash/hash-map.js +76 -76
- package/dist/mjs/data-structures/heap/heap.js +21 -12
- package/dist/umd/data-structure-typed.js +83 -83
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +7 -7
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -3
- package/src/data-structures/binary-tree/binary-tree.ts +39 -31
- package/src/data-structures/binary-tree/bst.ts +12 -8
- package/src/data-structures/binary-tree/rb-tree.ts +17 -6
- package/src/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/data-structures/binary-tree/tree-multimap.ts +12 -9
- package/src/data-structures/graph/abstract-graph.ts +46 -31
- package/src/data-structures/graph/directed-graph.ts +10 -5
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +9 -9
- package/src/data-structures/hash/hash-map.ts +103 -103
- package/src/data-structures/hash/hash-table.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +2 -1
- package/src/data-structures/hash/tree-set.ts +2 -1
- package/src/data-structures/heap/heap.ts +30 -17
- package/src/data-structures/heap/max-heap.ts +3 -3
- package/src/data-structures/heap/min-heap.ts +3 -3
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/matrix/matrix.ts +2 -2
- package/src/data-structures/matrix/matrix2d.ts +1 -1
- package/src/data-structures/matrix/navigator.ts +3 -3
- package/src/data-structures/matrix/vector2d.ts +2 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +3 -3
- package/src/data-structures/priority-queue/min-priority-queue.ts +3 -3
- package/src/data-structures/priority-queue/priority-queue.ts +3 -3
- package/src/data-structures/queue/deque.ts +5 -4
- package/src/data-structures/queue/queue.ts +2 -2
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +1 -1
- package/src/interfaces/binary-tree.ts +2 -2
- package/src/interfaces/graph.ts +1 -1
- package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +2 -2
- package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/tree-multimap.ts +2 -2
- package/src/types/data-structures/hash/hash-map.ts +6 -6
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +18 -4
- package/src/utils/utils.ts +6 -6
- package/test/integration/all-in-one.ts +1 -1
- package/test/integration/avl-tree.test.ts +1 -1
- package/test/integration/bst.test.ts +19 -19
- package/test/integration/heap.test.js +1 -1
- package/test/integration/index.html +7 -7
- package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/binary-tree.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/bst.test.ts +4 -4
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +9 -9
- package/test/performance/data-structures/comparation.test.ts +142 -0
- package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/performance/data-structures/hash/hash-map.test.ts +8 -8
- package/test/performance/data-structures/heap/heap.test.ts +5 -5
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +7 -7
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -4
- package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +7 -5
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +8 -8
- package/test/performance/data-structures/queue/deque.test.ts +6 -6
- package/test/performance/data-structures/queue/queue.test.ts +7 -7
- package/test/performance/data-structures/stack/stack.test.ts +8 -8
- package/test/performance/data-structures/trie/trie.test.ts +4 -4
- package/test/performance/reportor.ts +48 -20
- package/test/performance/types/reportor.ts +1 -1
- package/test/types/utils/json2html.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +12 -12
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -76
- package/test/unit/data-structures/binary-tree/bst.test.ts +44 -40
- package/test/unit/data-structures/binary-tree/overall.test.ts +17 -17
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +9 -9
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +35 -35
- package/test/unit/data-structures/graph/abstract-graph.test.ts +7 -7
- package/test/unit/data-structures/graph/directed-graph.test.ts +34 -14
- package/test/unit/data-structures/graph/map-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/overall.test.ts +1 -1
- package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
- package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
- package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
- package/test/unit/data-structures/hash/hash-map.test.ts +10 -12
- package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +73 -23
- package/test/unit/data-structures/heap/max-heap.test.ts +2 -2
- package/test/unit/data-structures/heap/min-heap.test.ts +2 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +5 -5
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +5 -5
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/matrix/matrix.test.ts +5 -5
- package/test/unit/data-structures/matrix/matrix2d.test.ts +3 -3
- package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
- package/test/unit/data-structures/matrix/vector2d.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +7 -7
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +19 -19
- package/test/unit/data-structures/queue/deque.test.ts +3 -3
- package/test/unit/data-structures/queue/queue.test.ts +3 -3
- package/test/unit/data-structures/stack/stack.test.ts +1 -1
- package/test/unit/data-structures/tree/tree.test.ts +1 -1
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
- package/test/utils/array.ts +1 -1
- package/test/utils/big-o.ts +4 -4
- package/test/utils/index.ts +1 -0
- package/test/utils/json2html.ts +7 -3
- package/test/utils/performanc.ts +7 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {HashMap} from '../../../../src';
|
|
2
|
-
import {getRandomInt, getRandomIntArray} from
|
|
3
|
-
|
|
1
|
+
import { HashMap } from '../../../../src';
|
|
2
|
+
import { getRandomInt, getRandomIntArray } from '../../../utils';
|
|
4
3
|
|
|
5
4
|
describe('HashMap', () => {
|
|
6
5
|
let hashMap: HashMap<string, number>;
|
|
@@ -66,7 +65,6 @@ describe('HashMap', () => {
|
|
|
66
65
|
// expect(entries).toContainEqual(['three', 3]);
|
|
67
66
|
});
|
|
68
67
|
|
|
69
|
-
|
|
70
68
|
it('should resize the table when load factor is exceeded', () => {
|
|
71
69
|
// Set a small initial capacity for testing resizing
|
|
72
70
|
hashMap = new HashMap<string, number>();
|
|
@@ -84,7 +82,6 @@ describe('HashMap', () => {
|
|
|
84
82
|
});
|
|
85
83
|
|
|
86
84
|
it('should allow using a custom hash function', () => {
|
|
87
|
-
|
|
88
85
|
hashMap = new HashMap<string, number>();
|
|
89
86
|
|
|
90
87
|
hashMap.set('one', 1);
|
|
@@ -115,14 +112,14 @@ describe('HashMap', () => {
|
|
|
115
112
|
});
|
|
116
113
|
|
|
117
114
|
it('should handle object keys correctly', () => {
|
|
118
|
-
const keyObj = {id: 1};
|
|
115
|
+
const keyObj = { id: 1 };
|
|
119
116
|
hashMap.set(keyObj, 'objectValue');
|
|
120
117
|
expect(hashMap.get(keyObj)).toBe('objectValue');
|
|
121
118
|
});
|
|
122
119
|
|
|
123
120
|
it('should handle number keys correctly', () => {
|
|
124
|
-
hashMap.set(999, {a: '999Value'});
|
|
125
|
-
expect(hashMap.get(999)).toEqual({a: '999Value'});
|
|
121
|
+
hashMap.set(999, { a: '999Value' });
|
|
122
|
+
expect(hashMap.get(999)).toEqual({ a: '999Value' });
|
|
126
123
|
});
|
|
127
124
|
|
|
128
125
|
it('should update the value for an existing key', () => {
|
|
@@ -156,7 +153,10 @@ describe('HashMap', () => {
|
|
|
156
153
|
for (const value of hashMap) {
|
|
157
154
|
values.push(value);
|
|
158
155
|
}
|
|
159
|
-
expect(values).toEqual([
|
|
156
|
+
expect(values).toEqual([
|
|
157
|
+
['key1', 'value1'],
|
|
158
|
+
['key2', 'value2']
|
|
159
|
+
]);
|
|
160
160
|
});
|
|
161
161
|
|
|
162
162
|
// test('should delete element at specific index', () => {
|
|
@@ -212,7 +212,6 @@ describe('HashMap', () => {
|
|
|
212
212
|
hashMap.set('key2', 'value2');
|
|
213
213
|
const iterator = hashMap.reverseBegin;
|
|
214
214
|
expect(iterator.next().current).toEqual(['key1', 'value1']);
|
|
215
|
-
|
|
216
215
|
});
|
|
217
216
|
|
|
218
217
|
test('should return the last element', () => {
|
|
@@ -230,5 +229,4 @@ describe('HashMap', () => {
|
|
|
230
229
|
hashMap.set('key2', 'value2');
|
|
231
230
|
expect(hashMap.getAt(1)).toEqual(['key2', 'value2']);
|
|
232
231
|
});
|
|
233
|
-
})
|
|
234
|
-
|
|
232
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {FibonacciHeap, MaxHeap, MinHeap} from '../../../../src';
|
|
2
|
-
import {logBigOMetricsWrap} from '../../../utils';
|
|
1
|
+
import { FibonacciHeap, MaxHeap, MinHeap } from '../../../../src';
|
|
2
|
+
import { logBigOMetricsWrap } from '../../../utils';
|
|
3
3
|
|
|
4
4
|
describe('Heap Operation Test', () => {
|
|
5
5
|
it('should numeric heap work well', function () {
|
|
@@ -22,34 +22,46 @@ describe('Heap Operation Test', () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it('should object heap work well', function () {
|
|
25
|
-
const minHeap = new MinHeap<{ a: string; key: number }>({comparator: (a, b) => a.key - b.key});
|
|
26
|
-
minHeap.add({key: 1, a: 'a1'});
|
|
27
|
-
minHeap.add({key: 6, a: 'a6'});
|
|
28
|
-
minHeap.add({key: 2, a: 'a2'});
|
|
29
|
-
minHeap.add({key: 0, a: 'a0'});
|
|
30
|
-
|
|
31
|
-
expect(minHeap.peek()).toEqual({a: 'a0', key: 0});
|
|
32
|
-
expect(minHeap.toArray().map(item => ({a: item.a}))).toEqual([
|
|
25
|
+
const minHeap = new MinHeap<{ a: string; key: number }>({ comparator: (a, b) => a.key - b.key });
|
|
26
|
+
minHeap.add({ key: 1, a: 'a1' });
|
|
27
|
+
minHeap.add({ key: 6, a: 'a6' });
|
|
28
|
+
minHeap.add({ key: 2, a: 'a2' });
|
|
29
|
+
minHeap.add({ key: 0, a: 'a0' });
|
|
30
|
+
|
|
31
|
+
expect(minHeap.peek()).toEqual({ a: 'a0', key: 0 });
|
|
32
|
+
expect(minHeap.toArray().map(item => ({ a: item.a }))).toEqual([
|
|
33
|
+
{ a: 'a0' },
|
|
34
|
+
{ a: 'a1' },
|
|
35
|
+
{ a: 'a2' },
|
|
36
|
+
{ a: 'a6' }
|
|
37
|
+
]);
|
|
33
38
|
let i = 0;
|
|
34
|
-
const expectPolled = [{a: 'a0'}, {a: 'a1'}, {a: 'a2'}, {a: 'a6'}];
|
|
39
|
+
const expectPolled = [{ a: 'a0' }, { a: 'a1' }, { a: 'a2' }, { a: 'a6' }];
|
|
35
40
|
while (minHeap.size > 0) {
|
|
36
|
-
expect({a: minHeap.poll()?.a}).toEqual(expectPolled[i]);
|
|
41
|
+
expect({ a: minHeap.poll()?.a }).toEqual(expectPolled[i]);
|
|
37
42
|
i++;
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
const maxHeap = new MaxHeap<{ key: number; a: string }>({comparator: (a, b) => b.key - a.key});
|
|
41
|
-
maxHeap.add({key: 1, a: 'a1'});
|
|
42
|
-
maxHeap.add({key: 6, a: 'a6'});
|
|
43
|
-
maxHeap.add({key: 5, a: 'a5'});
|
|
44
|
-
maxHeap.add({key: 2, a: 'a2'});
|
|
45
|
-
maxHeap.add({key: 0, a: 'a0'});
|
|
46
|
-
maxHeap.add({key: 9, a: 'a9'});
|
|
47
|
-
expect(maxHeap.peek()).toEqual({a: 'a9', key: 9});
|
|
48
|
-
expect(maxHeap.toArray().map(item => ({a: item.a}))).toEqual([
|
|
49
|
-
|
|
45
|
+
const maxHeap = new MaxHeap<{ key: number; a: string }>({ comparator: (a, b) => b.key - a.key });
|
|
46
|
+
maxHeap.add({ key: 1, a: 'a1' });
|
|
47
|
+
maxHeap.add({ key: 6, a: 'a6' });
|
|
48
|
+
maxHeap.add({ key: 5, a: 'a5' });
|
|
49
|
+
maxHeap.add({ key: 2, a: 'a2' });
|
|
50
|
+
maxHeap.add({ key: 0, a: 'a0' });
|
|
51
|
+
maxHeap.add({ key: 9, a: 'a9' });
|
|
52
|
+
expect(maxHeap.peek()).toEqual({ a: 'a9', key: 9 });
|
|
53
|
+
expect(maxHeap.toArray().map(item => ({ a: item.a }))).toEqual([
|
|
54
|
+
{ a: 'a9' },
|
|
55
|
+
{ a: 'a2' },
|
|
56
|
+
{ a: 'a6' },
|
|
57
|
+
{ a: 'a1' },
|
|
58
|
+
{ a: 'a0' },
|
|
59
|
+
{ a: 'a5' }
|
|
60
|
+
]);
|
|
61
|
+
const maxExpectPolled = [{ a: 'a9' }, { a: 'a6' }, { a: 'a5' }, { a: 'a2' }, { a: 'a1' }, { a: 'a0' }];
|
|
50
62
|
let maxI = 0;
|
|
51
63
|
while (maxHeap.size > 0) {
|
|
52
|
-
expect({a: maxHeap.poll()?.a}).toEqual(maxExpectPolled[maxI]);
|
|
64
|
+
expect({ a: maxHeap.poll()?.a }).toEqual(maxExpectPolled[maxI]);
|
|
53
65
|
maxI++;
|
|
54
66
|
}
|
|
55
67
|
});
|
|
@@ -245,3 +257,41 @@ describe('FibonacciHeap Stress Test', () => {
|
|
|
245
257
|
);
|
|
246
258
|
});
|
|
247
259
|
});
|
|
260
|
+
|
|
261
|
+
// describe('Competitor performance compare', () => {
|
|
262
|
+
// const minHeap = new MinHeap<number>();
|
|
263
|
+
// const cHeap = new CHeap<number>();
|
|
264
|
+
// const cPQ = new PriorityQueue<number>(undefined, (a, b) => a - b);
|
|
265
|
+
// const n = 10000;
|
|
266
|
+
//
|
|
267
|
+
// it('should add performance well', () => {
|
|
268
|
+
// const heapCost = calcRunTime(() => {
|
|
269
|
+
// for (let i = 0; i < n; i++) {
|
|
270
|
+
// minHeap.add(i);
|
|
271
|
+
// }
|
|
272
|
+
// })
|
|
273
|
+
//
|
|
274
|
+
// console.log(`heapCost: ${heapCost}`)
|
|
275
|
+
// });
|
|
276
|
+
//
|
|
277
|
+
// it('should add performance well', () => {
|
|
278
|
+
//
|
|
279
|
+
// const cHeapCost = calcRunTime(() => {
|
|
280
|
+
// for (let i = 0; i < n; i++) {
|
|
281
|
+
// cHeap.push(i);
|
|
282
|
+
// }
|
|
283
|
+
// })
|
|
284
|
+
//
|
|
285
|
+
// console.log(`cHeapCost: ${cHeapCost}`)
|
|
286
|
+
// });
|
|
287
|
+
//
|
|
288
|
+
// it('should add performance well', () => {
|
|
289
|
+
//
|
|
290
|
+
// const cPQCost = calcRunTime(() => {
|
|
291
|
+
// for (let i = 0; i < n; i++) {
|
|
292
|
+
// cPQ.push(i);
|
|
293
|
+
// }
|
|
294
|
+
// })
|
|
295
|
+
// console.log(`cPQCost: ${cPQCost}`)
|
|
296
|
+
// });
|
|
297
|
+
// });
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {Comparator, MaxHeap} from '../../../../src';
|
|
1
|
+
import { Comparator, MaxHeap } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('MaxHeap', () => {
|
|
4
4
|
const numberComparator: Comparator<number> = (a, b) => b - a;
|
|
5
5
|
let maxHeap: MaxHeap<number>;
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
8
|
-
maxHeap = new MaxHeap({comparator: numberComparator});
|
|
8
|
+
maxHeap = new MaxHeap({ comparator: numberComparator });
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
it('add and poll elements in descending order', () => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {Comparator, MinHeap} from '../../../../src';
|
|
1
|
+
import { Comparator, MinHeap } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('MinHeap', () => {
|
|
4
4
|
const numberComparator: Comparator<number> = (a, b) => a - b;
|
|
5
5
|
let minHeap: MinHeap<number>;
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
8
|
-
minHeap = new MinHeap({comparator: numberComparator});
|
|
8
|
+
minHeap = new MinHeap({ comparator: numberComparator });
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
it('add and poll elements in ascending order', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src';
|
|
1
|
+
import { DoublyLinkedList, DoublyLinkedListNode } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('DoublyLinkedListNode', () => {
|
|
4
4
|
it('should DoublyLinkedListNode', () => {
|
|
@@ -370,9 +370,9 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
370
370
|
});
|
|
371
371
|
|
|
372
372
|
it('should insert and manipulate objects with numeric properties', () => {
|
|
373
|
-
const obj1 = {keyA: 10};
|
|
374
|
-
const obj2 = {keyA: 20};
|
|
375
|
-
const obj3 = {keyA: 30};
|
|
373
|
+
const obj1 = { keyA: 10 };
|
|
374
|
+
const obj2 = { keyA: 20 };
|
|
375
|
+
const obj3 = { keyA: 30 };
|
|
376
376
|
|
|
377
377
|
objectList.push(obj1);
|
|
378
378
|
objectList.push(obj2);
|
|
@@ -380,7 +380,7 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
380
380
|
|
|
381
381
|
expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
|
|
382
382
|
|
|
383
|
-
const newObj = {keyA: 25}; // Corrected newObj value
|
|
383
|
+
const newObj = { keyA: 25 }; // Corrected newObj value
|
|
384
384
|
const insertSuccess = objectList.insertBefore(obj2, newObj);
|
|
385
385
|
expect(insertSuccess).toBe(true);
|
|
386
386
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {SinglyLinkedList, SinglyLinkedListNode} from '../../../../src';
|
|
1
|
+
import { SinglyLinkedList, SinglyLinkedListNode } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('SinglyLinkedListNode', () => {
|
|
4
4
|
it('should SinglyLinkedList', () => {
|
|
@@ -366,9 +366,9 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
366
366
|
});
|
|
367
367
|
|
|
368
368
|
it('should insert and manipulate objects with numeric properties', () => {
|
|
369
|
-
const obj1 = {keyA: 1};
|
|
370
|
-
const obj2 = {keyA: 2};
|
|
371
|
-
const obj3 = {keyA: 3};
|
|
369
|
+
const obj1 = { keyA: 1 };
|
|
370
|
+
const obj2 = { keyA: 2 };
|
|
371
|
+
const obj3 = { keyA: 3 };
|
|
372
372
|
|
|
373
373
|
objectList.push(obj1);
|
|
374
374
|
objectList.push(obj2);
|
|
@@ -376,7 +376,7 @@ describe('SinglyLinkedList Operation Test', () => {
|
|
|
376
376
|
|
|
377
377
|
expect(objectList.toArray()).toEqual([obj1, obj2, obj3]);
|
|
378
378
|
|
|
379
|
-
const newObj = {keyA: 2.5}; // Corrected newObj value
|
|
379
|
+
const newObj = { keyA: 2.5 }; // Corrected newObj value
|
|
380
380
|
const insertSuccess = objectList.insertBefore(obj2, newObj);
|
|
381
381
|
expect(insertSuccess).toBe(true);
|
|
382
382
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {MatrixNTI2D} from '../../../../src';
|
|
1
|
+
import { MatrixNTI2D } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('MatrixNTI2D', () => {
|
|
4
4
|
it('should initialize a matrix with rows and columns', () => {
|
|
5
5
|
const numRows = 3;
|
|
6
6
|
const numCols = 4;
|
|
7
|
-
const matrix = new MatrixNTI2D({row: numRows, col: numCols});
|
|
7
|
+
const matrix = new MatrixNTI2D({ row: numRows, col: numCols });
|
|
8
8
|
|
|
9
9
|
expect(matrix.toArray().length).toBe(numRows);
|
|
10
10
|
expect(matrix.toArray()[0].length).toBe(numCols);
|
|
@@ -14,7 +14,7 @@ describe('MatrixNTI2D', () => {
|
|
|
14
14
|
const numRows = 3;
|
|
15
15
|
const numCols = 4;
|
|
16
16
|
const initialValue = 42;
|
|
17
|
-
const matrix = new MatrixNTI2D({row: numRows, col: numCols, initialVal: initialValue});
|
|
17
|
+
const matrix = new MatrixNTI2D({ row: numRows, col: numCols, initialVal: initialValue });
|
|
18
18
|
|
|
19
19
|
const matrixArray = matrix.toArray();
|
|
20
20
|
for (let i = 0; i < numRows; i++) {
|
|
@@ -27,7 +27,7 @@ describe('MatrixNTI2D', () => {
|
|
|
27
27
|
it('should initialize all elements with 0 if no initial value is provided', () => {
|
|
28
28
|
const numRows = 3;
|
|
29
29
|
const numCols = 4;
|
|
30
|
-
const matrix = new MatrixNTI2D({row: numRows, col: numCols});
|
|
30
|
+
const matrix = new MatrixNTI2D({ row: numRows, col: numCols });
|
|
31
31
|
|
|
32
32
|
const matrixArray = matrix.toArray();
|
|
33
33
|
for (let i = 0; i < numRows; i++) {
|
|
@@ -40,7 +40,7 @@ describe('MatrixNTI2D', () => {
|
|
|
40
40
|
it('should convert the matrix to a two-dimensional array', () => {
|
|
41
41
|
const numRows = 2;
|
|
42
42
|
const numCols = 3;
|
|
43
|
-
const matrix = new MatrixNTI2D({row: numRows, col: numCols, initialVal: 1});
|
|
43
|
+
const matrix = new MatrixNTI2D({ row: numRows, col: numCols, initialVal: 1 });
|
|
44
44
|
|
|
45
45
|
const matrixArray = matrix.toArray();
|
|
46
46
|
expect(matrixArray.length).toBe(numRows);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {Matrix2D, Vector2D} from '../../../../src';
|
|
2
|
-
import {isDebugTest} from '../../../config';
|
|
1
|
+
import { Matrix2D, Vector2D } from '../../../../src';
|
|
2
|
+
import { isDebugTest } from '../../../config';
|
|
3
3
|
|
|
4
4
|
const isDebug = isDebugTest;
|
|
5
5
|
describe('Matrix2D', () => {
|
|
@@ -288,7 +288,7 @@ describe('Matrix2D', () => {
|
|
|
288
288
|
const vector = new Vector2D(2, 3);
|
|
289
289
|
const result = Matrix2D.multiplyByVector(matrix, vector);
|
|
290
290
|
isDebug && console.log(JSON.stringify(result));
|
|
291
|
-
expect(result).toEqual({x: 17, y: 35, w: 1});
|
|
291
|
+
expect(result).toEqual({ x: 17, y: 35, w: 1 });
|
|
292
292
|
});
|
|
293
293
|
|
|
294
294
|
it('should correctly create a view matrix', () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {Character, Navigator, NavigatorParams, Turning} from '../../../../src';
|
|
2
|
-
import {isDebugTest} from '../../../config';
|
|
1
|
+
import { Character, Navigator, NavigatorParams, Turning } from '../../../../src';
|
|
2
|
+
import { isDebugTest } from '../../../config';
|
|
3
3
|
|
|
4
4
|
const isDebug = isDebugTest;
|
|
5
5
|
const exampleMatrix: number[][] = [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {MaxPriorityQueue} from '../../../../src';
|
|
1
|
+
import { MaxPriorityQueue } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('MaxPriorityQueue Operation Test', () => {
|
|
4
4
|
it('should add elements and maintain heap property', () => {
|
|
@@ -16,9 +16,9 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
16
16
|
});
|
|
17
17
|
|
|
18
18
|
it('should add elements and maintain heap property in a object MaxPriorityQueue', () => {
|
|
19
|
-
const priorityQueue = new MaxPriorityQueue<{ keyA: number }>({comparator: (a, b) => b.keyA - a.keyA});
|
|
20
|
-
priorityQueue.refill([{keyA: 5}, {keyA: 3}, {keyA: 1}]);
|
|
21
|
-
priorityQueue.add({keyA: 7});
|
|
19
|
+
const priorityQueue = new MaxPriorityQueue<{ keyA: number }>({ comparator: (a, b) => b.keyA - a.keyA });
|
|
20
|
+
priorityQueue.refill([{ keyA: 5 }, { keyA: 3 }, { keyA: 1 }]);
|
|
21
|
+
priorityQueue.add({ keyA: 7 });
|
|
22
22
|
|
|
23
23
|
expect(priorityQueue.poll()?.keyA).toBe(7);
|
|
24
24
|
expect(priorityQueue.poll()?.keyA).toBe(5);
|
|
@@ -52,7 +52,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
52
52
|
|
|
53
53
|
it('should correctly heapify an array', () => {
|
|
54
54
|
const array = [5, 3, 7, 1];
|
|
55
|
-
const heap = MaxPriorityQueue.heapify<number>({nodes: array, comparator: (a, b) => b - a});
|
|
55
|
+
const heap = MaxPriorityQueue.heapify<number>({ nodes: array, comparator: (a, b) => b - a });
|
|
56
56
|
heap.refill(array);
|
|
57
57
|
|
|
58
58
|
expect(heap.poll()).toBe(7);
|
|
@@ -62,8 +62,8 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
it('should correctly heapify an object array', () => {
|
|
65
|
-
const nodes = [{keyA: 5}, {keyA: 3}, {keyA: 7}, {keyA: 1}];
|
|
66
|
-
const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>({nodes: nodes, comparator: (a, b) => b.keyA - a.keyA});
|
|
65
|
+
const nodes = [{ keyA: 5 }, { keyA: 3 }, { keyA: 7 }, { keyA: 1 }];
|
|
66
|
+
const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>({ nodes: nodes, comparator: (a, b) => b.keyA - a.keyA });
|
|
67
67
|
|
|
68
68
|
expect(maxPQ.poll()?.keyA).toBe(7);
|
|
69
69
|
expect(maxPQ.poll()?.keyA).toBe(5);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {PriorityQueue} from '../../../../src';
|
|
2
|
-
import {PriorityQueue as CPriorityQueue} from 'js-sdsl';
|
|
3
|
-
import {isDebugTest} from '../../../config';
|
|
1
|
+
import { PriorityQueue } from '../../../../src';
|
|
2
|
+
import { PriorityQueue as CPriorityQueue } from 'js-sdsl';
|
|
3
|
+
import { isDebugTest } from '../../../config';
|
|
4
4
|
|
|
5
5
|
const isDebug = isDebugTest;
|
|
6
6
|
describe('PriorityQueue Operation Test', () => {
|
|
7
7
|
it('should PriorityQueue poll, pee, heapify, toArray work well', function () {
|
|
8
|
-
const minPQ = new PriorityQueue<number>({comparator: (a, b) => a - b});
|
|
8
|
+
const minPQ = new PriorityQueue<number>({ comparator: (a, b) => a - b });
|
|
9
9
|
minPQ.refill([5, 2, 3, 4, 6, 1]);
|
|
10
10
|
expect(minPQ.toArray()).toEqual([1, 2, 3, 4, 6, 5]);
|
|
11
11
|
minPQ.poll();
|
|
@@ -13,16 +13,16 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
13
13
|
minPQ.poll();
|
|
14
14
|
expect(minPQ.toArray()).toEqual([4, 5, 6]);
|
|
15
15
|
expect(minPQ.peek()).toBe(4);
|
|
16
|
-
expect(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
]);
|
|
16
|
+
expect(
|
|
17
|
+
PriorityQueue.heapify({
|
|
18
|
+
nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
|
|
19
|
+
comparator: (a, b) => a - b
|
|
20
|
+
}).toArray()
|
|
21
|
+
).toEqual([1, 2, 3, 5, 6, 7, 8, 9, 10]);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () {
|
|
25
|
-
const maxPriorityQueue = new PriorityQueue<number>({comparator: (a, b) => b - a});
|
|
25
|
+
const maxPriorityQueue = new PriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
26
26
|
maxPriorityQueue.refill([5, 2, 3, 4, 6, 1]);
|
|
27
27
|
expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]);
|
|
28
28
|
maxPriorityQueue.poll();
|
|
@@ -30,16 +30,16 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
30
30
|
maxPriorityQueue.poll();
|
|
31
31
|
expect(maxPriorityQueue.toArray()).toEqual([3, 2, 1]);
|
|
32
32
|
expect(maxPriorityQueue.peek()).toBe(3);
|
|
33
|
-
expect(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
]);
|
|
33
|
+
expect(
|
|
34
|
+
PriorityQueue.heapify({
|
|
35
|
+
nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10],
|
|
36
|
+
comparator: (a, b) => a - b
|
|
37
|
+
}).toArray()
|
|
38
|
+
).toEqual([1, 2, 3, 5, 6, 7, 8, 9, 10]);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
it('should PriorityQueue clone, sort, getNodes, dfs work well', function () {
|
|
42
|
-
const minPQ1 = new PriorityQueue<number>({comparator: (a, b) => a - b});
|
|
42
|
+
const minPQ1 = new PriorityQueue<number>({ comparator: (a, b) => a - b });
|
|
43
43
|
minPQ1.refill([2, 5, 8, 3, 1, 6, 7, 4]);
|
|
44
44
|
const clonedPriorityQueue = minPQ1.clone();
|
|
45
45
|
expect(clonedPriorityQueue.getNodes()).toEqual(minPQ1.getNodes());
|
|
@@ -52,7 +52,7 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
52
52
|
|
|
53
53
|
describe('Priority Queue Performance Test', () => {
|
|
54
54
|
it('should numeric heap work well', function () {
|
|
55
|
-
const pq = new PriorityQueue({comparator: (a, b) => b - a});
|
|
55
|
+
const pq = new PriorityQueue({ comparator: (a, b) => b - a });
|
|
56
56
|
|
|
57
57
|
const tS = performance.now();
|
|
58
58
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {ArrayDeque, Deque, ObjectDeque} from '../../../../src';
|
|
2
|
-
import {bigO} from '../../../utils';
|
|
3
|
-
import {isDebugTest} from '../../../config';
|
|
1
|
+
import { ArrayDeque, Deque, ObjectDeque } from '../../../../src';
|
|
2
|
+
import { bigO } from '../../../utils';
|
|
3
|
+
import { isDebugTest } from '../../../config';
|
|
4
4
|
|
|
5
5
|
const isDebug = isDebugTest;
|
|
6
6
|
describe('Deque Tests', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {LinkedListQueue, Queue} from '../../../../src';
|
|
2
|
-
import {bigO} from '../../../utils';
|
|
3
|
-
import {isDebugTest} from '../../../config';
|
|
1
|
+
import { LinkedListQueue, Queue } from '../../../../src';
|
|
2
|
+
import { bigO } from '../../../utils';
|
|
3
|
+
import { isDebugTest } from '../../../config';
|
|
4
4
|
|
|
5
5
|
const isDebug = isDebugTest;
|
|
6
6
|
describe('Queue Operation Test', () => {
|
package/test/utils/array.ts
CHANGED
package/test/utils/big-o.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {AnyFunction} from '../types';
|
|
2
|
-
import {isDebugTest} from '../config';
|
|
1
|
+
import { AnyFunction } from '../types';
|
|
2
|
+
import { isDebugTest } from '../config';
|
|
3
3
|
|
|
4
4
|
const isDebug = isDebugTest;
|
|
5
5
|
const orderReducedBy = 1; // reduction of bigO's order compared to the baseline bigO
|
|
@@ -32,7 +32,7 @@ export const bigO = {
|
|
|
32
32
|
|
|
33
33
|
function findPotentialN(input: any): number {
|
|
34
34
|
let longestArray: any[] = [];
|
|
35
|
-
let mostProperties: {[key: string]: any} = {};
|
|
35
|
+
let mostProperties: { [key: string]: any } = {};
|
|
36
36
|
|
|
37
37
|
function recurse(obj: any) {
|
|
38
38
|
if (Array.isArray(obj)) {
|
|
@@ -81,7 +81,7 @@ function linearRegression(x: number[], y: number[]) {
|
|
|
81
81
|
|
|
82
82
|
const rSquared = 1 - totalVariation / explainedVariation;
|
|
83
83
|
|
|
84
|
-
return {slope, intercept, rSquared};
|
|
84
|
+
return { slope, intercept, rSquared };
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
function estimateBigO(runtimes: number[], dataSizes: number[]): string {
|
package/test/utils/index.ts
CHANGED
package/test/utils/json2html.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _ from './is';
|
|
2
|
-
import {Json2htmlOptions} from '../types';
|
|
2
|
+
import { Json2htmlOptions } from '../types';
|
|
3
3
|
|
|
4
4
|
function toggleJS(options?: Json2htmlOptions): string {
|
|
5
5
|
if (options?.plainHtml) {
|
|
@@ -14,7 +14,9 @@ function makeLabelDiv(options: any, level: number, keyName: string | number, dat
|
|
|
14
14
|
return `<div class='index'><span class='json-to-html-label'>${keyName} </span></div>`;
|
|
15
15
|
} else if (typeof keyName === 'string') {
|
|
16
16
|
if (datatype === 'array') {
|
|
17
|
-
return `<div class='collapsible level${level}' ${toggleJS(
|
|
17
|
+
return `<div class='collapsible level${level}' ${toggleJS(
|
|
18
|
+
options
|
|
19
|
+
)}><span class='json-to-html-label'>${keyName}</span></div>`;
|
|
18
20
|
} else if (datatype === 'object') {
|
|
19
21
|
return `<div class='attribute collapsible level${level}' ${toggleJS(
|
|
20
22
|
options
|
|
@@ -120,7 +122,9 @@ function _render(name: string, data: any, options: Json2htmlOptions, level: numb
|
|
|
120
122
|
} else {
|
|
121
123
|
subs =
|
|
122
124
|
"<div class='altRows'>" +
|
|
123
|
-
data
|
|
125
|
+
data
|
|
126
|
+
.map((val: any, idx: number) => _render(idx.toString(), val, options, level + 1, idx % 2))
|
|
127
|
+
.join("</div><div class='altRows'>") +
|
|
124
128
|
'</div>';
|
|
125
129
|
}
|
|
126
130
|
return `<div class="json-to-html-collapse clearfix ${altRow}">
|