data-structure-typed 1.44.1 → 1.45.1
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/README.md +15 -15
- package/benchmark/report.html +15 -15
- package/benchmark/report.json +121 -121
- 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 +230 -37
- package/dist/cjs/data-structures/hash/hash-map.js +427 -115
- 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.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/types/data-structures/hash/hash-map.d.ts +15 -1
- package/dist/cjs/types/data-structures/hash/index.d.ts +6 -0
- package/dist/cjs/types/data-structures/hash/index.js +20 -0
- package/dist/cjs/types/data-structures/hash/index.js.map +1 -1
- package/dist/cjs/utils/utils.d.ts +3 -0
- package/dist/cjs/utils/utils.js +15 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/hash/hash-map.d.ts +230 -37
- package/dist/mjs/data-structures/hash/hash-map.js +433 -121
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +15 -1
- package/dist/mjs/types/data-structures/hash/index.d.ts +6 -0
- package/dist/mjs/types/data-structures/hash/index.js +6 -1
- package/dist/mjs/utils/utils.d.ts +3 -0
- package/dist/mjs/utils/utils.js +11 -0
- package/dist/umd/data-structure-typed.js +533 -207
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +2 -2
- 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 +430 -123
- 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 +8 -5
- 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 +17 -1
- package/src/types/data-structures/hash/index.ts +7 -0
- 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 +16 -3
- package/test/config.ts +1 -1
- 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 +6 -6
- package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/performance/data-structures/hash/hash-map.test.ts +6 -6
- package/test/performance/data-structures/heap/heap.test.ts +5 -5
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
- 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 +7 -7
- package/test/performance/data-structures/queue/deque.test.ts +5 -5
- package/test/performance/data-structures/queue/queue.test.ts +6 -6
- package/test/performance/data-structures/stack/stack.test.ts +6 -6
- package/test/performance/data-structures/trie/trie.test.ts +4 -4
- package/test/performance/reportor.ts +15 -13
- 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 +8 -8
- 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 +50 -46
- package/test/unit/data-structures/binary-tree/overall.test.ts +18 -18
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +21 -21
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -37
- package/test/unit/data-structures/graph/abstract-graph.test.ts +9 -8
- 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 +2 -2
- 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 +150 -21
- package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
- package/test/unit/data-structures/heap/heap.test.ts +41 -29
- package/test/unit/data-structures/heap/max-heap.test.ts +6 -6
- package/test/unit/data-structures/heap/min-heap.test.ts +6 -6
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +6 -6
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +7 -7
- package/test/unit/data-structures/linked-list/skip-list.test.ts +5 -5
- 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 -13
- package/test/unit/data-structures/queue/deque.test.ts +28 -28
- 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 +10 -10
- package/test/utils/array.ts +2 -2
- package/test/utils/big-o.ts +4 -4
- package/test/utils/json2html.ts +7 -3
- package/test/utils/number.ts +1 -1
|
@@ -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', () => {
|
|
@@ -11,10 +11,10 @@ describe('SinglyLinkedListNode', () => {
|
|
|
11
11
|
|
|
12
12
|
describe('SinglyLinkedList Operation Test', () => {
|
|
13
13
|
let list: SinglyLinkedList<number>;
|
|
14
|
-
let objectList: SinglyLinkedList<{keyA: number}>;
|
|
14
|
+
let objectList: SinglyLinkedList<{ keyA: number }>;
|
|
15
15
|
beforeEach(() => {
|
|
16
16
|
list = new SinglyLinkedList<number>();
|
|
17
|
-
objectList = new SinglyLinkedList<{keyA: number}>();
|
|
17
|
+
objectList = new SinglyLinkedList<{ keyA: number }>();
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
describe('push', () => {
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import {SkipList} from '../../../../src';
|
|
1
|
+
import { SkipList } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('SkipList', () => {
|
|
4
4
|
let skipList: SkipList<number, string>;
|
|
@@ -65,21 +65,21 @@ describe('SkipList', () => {
|
|
|
65
65
|
skipList.add(4, 'Four');
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
it('getFirst() should return the getFirst element', () => {
|
|
69
69
|
expect(skipList.getFirst()).toBe('One');
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
it('getLast() should return the getLast element', () => {
|
|
73
73
|
expect(skipList.getLast()).toBe('Four');
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
it('higher(key) should return the getFirst element greater than the given key', () => {
|
|
77
77
|
expect(skipList.higher(2)).toBe('Three');
|
|
78
78
|
expect(skipList.higher(3)).toBe('Four');
|
|
79
79
|
expect(skipList.higher(4)).toBeUndefined();
|
|
80
80
|
});
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
it('lower(key) should return the getLast element less than the given key', () => {
|
|
83
83
|
expect(skipList.lower(2)).toBe('One');
|
|
84
84
|
expect(skipList.lower(1)).toBe(null);
|
|
85
85
|
});
|
|
@@ -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,13 +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
|
-
|
|
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]);
|
|
19
22
|
});
|
|
20
23
|
|
|
21
24
|
it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () {
|
|
22
|
-
const maxPriorityQueue = new PriorityQueue<number>({comparator: (a, b) => b - a});
|
|
25
|
+
const maxPriorityQueue = new PriorityQueue<number>({ comparator: (a, b) => b - a });
|
|
23
26
|
maxPriorityQueue.refill([5, 2, 3, 4, 6, 1]);
|
|
24
27
|
expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]);
|
|
25
28
|
maxPriorityQueue.poll();
|
|
@@ -27,13 +30,16 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
27
30
|
maxPriorityQueue.poll();
|
|
28
31
|
expect(maxPriorityQueue.toArray()).toEqual([3, 2, 1]);
|
|
29
32
|
expect(maxPriorityQueue.peek()).toBe(3);
|
|
30
|
-
expect(
|
|
31
|
-
|
|
32
|
-
|
|
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]);
|
|
33
39
|
});
|
|
34
40
|
|
|
35
41
|
it('should PriorityQueue clone, sort, getNodes, dfs work well', function () {
|
|
36
|
-
const minPQ1 = new PriorityQueue<number>({comparator: (a, b) => a - b});
|
|
42
|
+
const minPQ1 = new PriorityQueue<number>({ comparator: (a, b) => a - b });
|
|
37
43
|
minPQ1.refill([2, 5, 8, 3, 1, 6, 7, 4]);
|
|
38
44
|
const clonedPriorityQueue = minPQ1.clone();
|
|
39
45
|
expect(clonedPriorityQueue.getNodes()).toEqual(minPQ1.getNodes());
|
|
@@ -46,7 +52,7 @@ describe('PriorityQueue Operation Test', () => {
|
|
|
46
52
|
|
|
47
53
|
describe('Priority Queue Performance Test', () => {
|
|
48
54
|
it('should numeric heap work well', function () {
|
|
49
|
-
const pq = new PriorityQueue({comparator: (a, b) => b - a});
|
|
55
|
+
const pq = new PriorityQueue({ comparator: (a, b) => b - a });
|
|
50
56
|
|
|
51
57
|
const tS = performance.now();
|
|
52
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', () => {
|
|
@@ -155,12 +155,12 @@ describe('Deque', () => {
|
|
|
155
155
|
deque = new Deque<number>();
|
|
156
156
|
});
|
|
157
157
|
|
|
158
|
-
|
|
158
|
+
it('should initialize an empty deque', () => {
|
|
159
159
|
expect(deque.size).toBe(0);
|
|
160
160
|
expect(deque.isEmpty()).toBe(true);
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
-
|
|
163
|
+
it('should add elements to the front and back', () => {
|
|
164
164
|
deque.addFirst(1);
|
|
165
165
|
deque.addLast(2);
|
|
166
166
|
|
|
@@ -169,7 +169,7 @@ describe('Deque', () => {
|
|
|
169
169
|
expect(deque.getLast()).toBe(2);
|
|
170
170
|
});
|
|
171
171
|
|
|
172
|
-
|
|
172
|
+
it('should remove elements from the front and back', () => {
|
|
173
173
|
deque.addFirst(1);
|
|
174
174
|
deque.addLast(2);
|
|
175
175
|
|
|
@@ -181,7 +181,7 @@ describe('Deque', () => {
|
|
|
181
181
|
expect(lastElement).toBe(2);
|
|
182
182
|
});
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
it('should get elements by index', () => {
|
|
185
185
|
deque.addLast(1);
|
|
186
186
|
deque.addLast(2);
|
|
187
187
|
deque.addLast(3);
|
|
@@ -191,13 +191,13 @@ describe('Deque', () => {
|
|
|
191
191
|
expect(deque.getAt(2)).toBe(3);
|
|
192
192
|
});
|
|
193
193
|
|
|
194
|
-
|
|
194
|
+
it('should return null for out-of-bounds index', () => {
|
|
195
195
|
expect(deque.getAt(0)).toBe(undefined);
|
|
196
196
|
expect(deque.getAt(1)).toBe(undefined);
|
|
197
197
|
expect(deque.getAt(-1)).toBe(undefined);
|
|
198
198
|
});
|
|
199
199
|
|
|
200
|
-
|
|
200
|
+
it('should check if the deque is empty', () => {
|
|
201
201
|
expect(deque.isEmpty()).toBe(true);
|
|
202
202
|
|
|
203
203
|
deque.addLast(1);
|
|
@@ -215,12 +215,12 @@ describe('ArrayDeque', () => {
|
|
|
215
215
|
deque = new ArrayDeque<number>();
|
|
216
216
|
});
|
|
217
217
|
|
|
218
|
-
|
|
218
|
+
it('should initialize an empty deque', () => {
|
|
219
219
|
expect(deque.size).toBe(0);
|
|
220
220
|
expect(deque.isEmpty()).toBe(true);
|
|
221
221
|
});
|
|
222
222
|
|
|
223
|
-
|
|
223
|
+
it('should add elements to the front and back', () => {
|
|
224
224
|
deque.addFirst(1);
|
|
225
225
|
deque.addLast(2);
|
|
226
226
|
|
|
@@ -229,7 +229,7 @@ describe('ArrayDeque', () => {
|
|
|
229
229
|
expect(deque.getLast()).toBe(2);
|
|
230
230
|
});
|
|
231
231
|
|
|
232
|
-
|
|
232
|
+
it('should remove elements from the front and back', () => {
|
|
233
233
|
deque.addFirst(1);
|
|
234
234
|
deque.addLast(2);
|
|
235
235
|
|
|
@@ -241,7 +241,7 @@ describe('ArrayDeque', () => {
|
|
|
241
241
|
expect(lastElement).toBe(2);
|
|
242
242
|
});
|
|
243
243
|
|
|
244
|
-
|
|
244
|
+
it('should get elements by index', () => {
|
|
245
245
|
deque.addLast(1);
|
|
246
246
|
deque.addLast(2);
|
|
247
247
|
deque.addLast(3);
|
|
@@ -251,13 +251,13 @@ describe('ArrayDeque', () => {
|
|
|
251
251
|
expect(deque.get(2)).toBe(3);
|
|
252
252
|
});
|
|
253
253
|
|
|
254
|
-
|
|
254
|
+
it('should return null for out-of-bounds index', () => {
|
|
255
255
|
expect(deque.get(0)).toBe(null);
|
|
256
256
|
expect(deque.get(1)).toBe(null);
|
|
257
257
|
expect(deque.get(-1)).toBe(null);
|
|
258
258
|
});
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
it('should check if the deque is empty', () => {
|
|
261
261
|
expect(deque.isEmpty()).toBe(true);
|
|
262
262
|
|
|
263
263
|
deque.addLast(1);
|
|
@@ -267,7 +267,7 @@ describe('ArrayDeque', () => {
|
|
|
267
267
|
expect(deque.isEmpty()).toBe(true);
|
|
268
268
|
});
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
it('should set elements at a specific index', () => {
|
|
271
271
|
deque.addLast(1);
|
|
272
272
|
deque.addLast(2);
|
|
273
273
|
deque.addLast(3);
|
|
@@ -279,7 +279,7 @@ describe('ArrayDeque', () => {
|
|
|
279
279
|
expect(deque.get(2)).toBe(3);
|
|
280
280
|
});
|
|
281
281
|
|
|
282
|
-
|
|
282
|
+
it('should insert elements at a specific index', () => {
|
|
283
283
|
deque.addLast(1);
|
|
284
284
|
deque.addLast(2);
|
|
285
285
|
deque.addLast(3);
|
|
@@ -293,7 +293,7 @@ describe('ArrayDeque', () => {
|
|
|
293
293
|
expect(deque.get(3)).toBe(3);
|
|
294
294
|
});
|
|
295
295
|
|
|
296
|
-
|
|
296
|
+
it('should delete elements at a specific index', () => {
|
|
297
297
|
deque.addLast(1);
|
|
298
298
|
deque.addLast(2);
|
|
299
299
|
deque.addLast(3);
|
|
@@ -314,7 +314,7 @@ describe('ObjectDeque', () => {
|
|
|
314
314
|
deque = new ObjectDeque<number>();
|
|
315
315
|
});
|
|
316
316
|
|
|
317
|
-
|
|
317
|
+
it('should add elements to the front of the deque', () => {
|
|
318
318
|
deque.addFirst(1);
|
|
319
319
|
deque.addFirst(2);
|
|
320
320
|
|
|
@@ -323,7 +323,7 @@ describe('ObjectDeque', () => {
|
|
|
323
323
|
expect(deque.getLast()).toBe(1);
|
|
324
324
|
});
|
|
325
325
|
|
|
326
|
-
|
|
326
|
+
it('should add elements to the end of the deque', () => {
|
|
327
327
|
deque.addLast(1);
|
|
328
328
|
deque.addLast(2);
|
|
329
329
|
|
|
@@ -332,7 +332,7 @@ describe('ObjectDeque', () => {
|
|
|
332
332
|
expect(deque.getLast()).toBe(2);
|
|
333
333
|
});
|
|
334
334
|
|
|
335
|
-
|
|
335
|
+
it('should remove elements from the front of the deque', () => {
|
|
336
336
|
deque.addLast(1);
|
|
337
337
|
deque.addLast(2);
|
|
338
338
|
|
|
@@ -343,7 +343,7 @@ describe('ObjectDeque', () => {
|
|
|
343
343
|
expect(deque.getFirst()).toBe(2);
|
|
344
344
|
});
|
|
345
345
|
|
|
346
|
-
|
|
346
|
+
it('should remove elements from the end of the deque', () => {
|
|
347
347
|
deque.addLast(1);
|
|
348
348
|
deque.addLast(2);
|
|
349
349
|
|
|
@@ -354,7 +354,7 @@ describe('ObjectDeque', () => {
|
|
|
354
354
|
expect(deque.getLast()).toBe(2);
|
|
355
355
|
});
|
|
356
356
|
|
|
357
|
-
|
|
357
|
+
it('should return the element at the front of the deque without removing it', () => {
|
|
358
358
|
deque.addFirst(1);
|
|
359
359
|
deque.addFirst(2);
|
|
360
360
|
|
|
@@ -362,7 +362,7 @@ describe('ObjectDeque', () => {
|
|
|
362
362
|
expect(deque.size).toBe(2);
|
|
363
363
|
});
|
|
364
364
|
|
|
365
|
-
|
|
365
|
+
it('should return the element at the end of the deque without removing it', () => {
|
|
366
366
|
deque.addLast(1);
|
|
367
367
|
deque.addLast(2);
|
|
368
368
|
|
|
@@ -370,7 +370,7 @@ describe('ObjectDeque', () => {
|
|
|
370
370
|
expect(deque.size).toBe(2);
|
|
371
371
|
});
|
|
372
372
|
|
|
373
|
-
|
|
373
|
+
it('should return the correct size of the deque', () => {
|
|
374
374
|
deque.addFirst(1);
|
|
375
375
|
deque.addLast(2);
|
|
376
376
|
deque.addLast(3);
|
|
@@ -378,7 +378,7 @@ describe('ObjectDeque', () => {
|
|
|
378
378
|
expect(deque.size).toBe(3);
|
|
379
379
|
});
|
|
380
380
|
|
|
381
|
-
|
|
381
|
+
it('should check if the deque is empty', () => {
|
|
382
382
|
expect(deque.isEmpty()).toBe(true);
|
|
383
383
|
|
|
384
384
|
deque.addFirst(1);
|
|
@@ -386,7 +386,7 @@ describe('ObjectDeque', () => {
|
|
|
386
386
|
expect(deque.isEmpty()).toBe(false);
|
|
387
387
|
});
|
|
388
388
|
|
|
389
|
-
|
|
389
|
+
it('should set elements at a specific index', () => {
|
|
390
390
|
deque.addFirst(1);
|
|
391
391
|
deque.addLast(2);
|
|
392
392
|
deque.addLast(3);
|
|
@@ -396,7 +396,7 @@ describe('ObjectDeque', () => {
|
|
|
396
396
|
expect(deque.getLast()).toBe(3);
|
|
397
397
|
});
|
|
398
398
|
|
|
399
|
-
|
|
399
|
+
it('should insert elements at a specific index', () => {
|
|
400
400
|
deque.addFirst(1);
|
|
401
401
|
deque.addLast(2);
|
|
402
402
|
deque.addLast(3);
|
|
@@ -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', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Trie, TrieNode} from '../../../../src';
|
|
1
|
+
import { Trie, TrieNode } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('TrieNode', () => {
|
|
4
4
|
it('should create a TrieNode with the given value', () => {
|
|
@@ -761,7 +761,7 @@ describe('Trie operations', () => {
|
|
|
761
761
|
trie = new Trie();
|
|
762
762
|
});
|
|
763
763
|
|
|
764
|
-
|
|
764
|
+
it('Add and Find Words', () => {
|
|
765
765
|
trie.add('apple');
|
|
766
766
|
trie.add('banana');
|
|
767
767
|
expect(trie.has('apple')).toBe(true);
|
|
@@ -769,7 +769,7 @@ describe('Trie operations', () => {
|
|
|
769
769
|
expect(trie.has('cherry')).toBe(false);
|
|
770
770
|
});
|
|
771
771
|
|
|
772
|
-
|
|
772
|
+
it('Remove Words', () => {
|
|
773
773
|
trie.add('apple');
|
|
774
774
|
trie.add('banana');
|
|
775
775
|
expect(trie.delete('apple')).toBe(true);
|
|
@@ -777,39 +777,39 @@ describe('Trie operations', () => {
|
|
|
777
777
|
expect(trie.delete('cherry')).toBe(false);
|
|
778
778
|
});
|
|
779
779
|
|
|
780
|
-
|
|
780
|
+
it('Case Sensitivity', () => {
|
|
781
781
|
const caseInsensitiveTrie = new Trie(['apple', 'Banana'], false);
|
|
782
782
|
expect(caseInsensitiveTrie.has('APPLE')).toBe(true);
|
|
783
783
|
expect(caseInsensitiveTrie.has('banana')).toBe(true);
|
|
784
784
|
expect(caseInsensitiveTrie.has('Cherry')).toBe(false);
|
|
785
785
|
});
|
|
786
786
|
|
|
787
|
-
|
|
787
|
+
it('Pure Prefix Check', () => {
|
|
788
788
|
trie.add('apple');
|
|
789
789
|
expect(trie.hasPurePrefix('appl')).toBe(true);
|
|
790
790
|
expect(trie.hasPurePrefix('apple')).toBe(false);
|
|
791
791
|
});
|
|
792
792
|
|
|
793
|
-
|
|
793
|
+
it('Prefix Check', () => {
|
|
794
794
|
trie.add('apple');
|
|
795
795
|
expect(trie.hasPrefix('app')).toBe(true);
|
|
796
796
|
expect(trie.hasPrefix('ban')).toBe(false);
|
|
797
797
|
});
|
|
798
798
|
|
|
799
|
-
|
|
799
|
+
it('Common Prefix Check', () => {
|
|
800
800
|
trie.add('apple');
|
|
801
801
|
trie.add('appetizer');
|
|
802
802
|
expect(trie.hasCommonPrefix('app')).toBe(true);
|
|
803
803
|
expect(trie.hasCommonPrefix('apple')).toBe(false);
|
|
804
804
|
});
|
|
805
805
|
|
|
806
|
-
|
|
806
|
+
it('Longest Common Prefix', () => {
|
|
807
807
|
trie.add('apple');
|
|
808
808
|
trie.add('appetizer');
|
|
809
809
|
expect(trie.getLongestCommonPrefix()).toBe('app');
|
|
810
810
|
});
|
|
811
811
|
|
|
812
|
-
|
|
812
|
+
it('Get Words by Prefix', () => {
|
|
813
813
|
trie.add('apple');
|
|
814
814
|
trie.add('appetizer');
|
|
815
815
|
trie.add('banana');
|
|
@@ -817,7 +817,7 @@ describe('Trie operations', () => {
|
|
|
817
817
|
expect(words).toEqual(['apple', 'appetizer']);
|
|
818
818
|
});
|
|
819
819
|
|
|
820
|
-
|
|
820
|
+
it('Tree Height', () => {
|
|
821
821
|
trie.add('apple');
|
|
822
822
|
trie.add('banana');
|
|
823
823
|
expect(trie.getHeight()).toBe(6); // Assuming 'apple' and 'banana' are the longest words.
|
package/test/utils/array.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {getRandomInt} from './number';
|
|
1
|
+
import { getRandomInt } from './number';
|
|
2
2
|
|
|
3
|
-
export function getRandomIntArray(length: number, min: number = -1000, max: number = 1000, isDistinct = true) {
|
|
3
|
+
export function getRandomIntArray(length: number = 1000, min: number = -1000, max: number = 1000, isDistinct = true) {
|
|
4
4
|
if (isDistinct) {
|
|
5
5
|
const set = new Set<number>();
|
|
6
6
|
const ans: number[] = [];
|
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/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}">
|
package/test/utils/number.ts
CHANGED