data-structure-typed 1.49.4 → 1.49.5
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 +1 -3
- package/README_zh-CN.md +1 -1
- package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -13
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -49
- 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.d.ts +0 -16
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +1 -43
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -2
- 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 +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +2 -3
- 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/singly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
- package/dist/cjs/data-structures/matrix/index.js +0 -2
- package/dist/cjs/data-structures/matrix/index.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/cjs/data-structures/matrix/matrix.js +400 -15
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
- package/dist/cjs/data-structures/queue/deque.js +5 -7
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/cjs/utils/utils.d.ts +1 -0
- package/dist/cjs/utils/utils.js +6 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +2 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -13
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +20 -50
- package/dist/mjs/data-structures/binary-tree/bst.js +2 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -1
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -44
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
- package/dist/mjs/data-structures/graph/abstract-graph.js +4 -3
- package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/mjs/data-structures/hash/hash-map.js +2 -2
- package/dist/mjs/data-structures/heap/heap.js +2 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
- package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
- package/dist/mjs/data-structures/matrix/index.js +0 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/mjs/data-structures/matrix/matrix.js +399 -16
- package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
- package/dist/mjs/data-structures/queue/deque.js +7 -9
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/queue/queue.js +1 -1
- package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/mjs/utils/utils.d.ts +1 -0
- package/dist/mjs/utils/utils.js +4 -0
- package/dist/umd/data-structure-typed.js +356 -524
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +4 -3
- package/src/data-structures/base/index.ts +1 -1
- package/src/data-structures/base/iterable-base.ts +7 -10
- package/src/data-structures/binary-tree/avl-tree.ts +15 -8
- package/src/data-structures/binary-tree/binary-tree.ts +57 -74
- package/src/data-structures/binary-tree/bst.ts +16 -13
- package/src/data-structures/binary-tree/rb-tree.ts +16 -10
- package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
- package/src/data-structures/graph/abstract-graph.ts +13 -11
- package/src/data-structures/graph/directed-graph.ts +1 -3
- package/src/data-structures/graph/map-graph.ts +6 -1
- package/src/data-structures/graph/undirected-graph.ts +3 -6
- package/src/data-structures/hash/hash-map.ts +18 -16
- package/src/data-structures/heap/heap.ts +7 -10
- package/src/data-structures/heap/max-heap.ts +2 -1
- package/src/data-structures/heap/min-heap.ts +2 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
- package/src/data-structures/matrix/index.ts +0 -2
- package/src/data-structures/matrix/matrix.ts +442 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
- package/src/data-structures/queue/deque.ts +18 -39
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +7 -2
- package/src/types/common.ts +4 -4
- package/src/types/data-structures/base/base.ts +14 -3
- package/src/types/data-structures/base/index.ts +1 -1
- package/src/types/data-structures/graph/abstract-graph.ts +4 -2
- package/src/types/data-structures/hash/hash-map.ts +3 -3
- package/src/types/data-structures/heap/heap.ts +2 -2
- package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/utils/utils.ts +7 -1
- package/test/integration/avl-tree.test.ts +18 -1
- package/test/integration/bst.test.ts +2 -2
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +1 -1
- package/test/performance/data-structures/comparison/comparison.test.ts +6 -11
- package/test/performance/data-structures/hash/hash-map.test.ts +3 -4
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
- package/test/performance/data-structures/queue/deque.test.ts +6 -7
- package/test/performance/data-structures/queue/queue.test.ts +10 -9
- package/test/performance/reportor.ts +14 -15
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +59 -24
- package/test/unit/data-structures/binary-tree/bst.test.ts +52 -26
- package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
- package/test/unit/data-structures/graph/directed-graph.test.ts +104 -45
- package/test/unit/data-structures/graph/undirected-graph.test.ts +57 -40
- package/test/unit/data-structures/hash/hash-map.test.ts +48 -28
- package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
- package/test/unit/data-structures/heap/heap.test.ts +0 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +10 -11
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
- package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
- package/test/unit/data-structures/queue/deque.test.ts +0 -6
- package/test/unit/data-structures/queue/queue.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +3 -4
- package/test/unit/unrestricted-interconversion.test.ts +50 -44
- package/test/utils/performanc.ts +1 -1
- package/typedoc.json +30 -0
- package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
- package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
- package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
- package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
- package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
- package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
- package/src/data-structures/matrix/matrix2d.ts +0 -211
- package/src/data-structures/matrix/vector2d.ts +0 -315
- package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
- package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import { IterableElementBase, IterableEntryBase } from
|
|
1
|
+
import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
|
|
2
2
|
|
|
3
3
|
export type EntryCallback<K, V, R> = (value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
|
|
4
4
|
export type ElementCallback<V, R> = (element: V, index: number, container: IterableElementBase<V>) => R;
|
|
5
|
-
export type ReduceEntryCallback<K, V, R> = (
|
|
6
|
-
|
|
5
|
+
export type ReduceEntryCallback<K, V, R> = (
|
|
6
|
+
accumulator: R,
|
|
7
|
+
value: V,
|
|
8
|
+
key: K,
|
|
9
|
+
index: number,
|
|
10
|
+
container: IterableEntryBase<K, V>
|
|
11
|
+
) => R;
|
|
12
|
+
export type ReduceElementCallback<V, R> = (
|
|
13
|
+
accumulator: R,
|
|
14
|
+
element: V,
|
|
15
|
+
index: number,
|
|
16
|
+
container: IterableElementBase<V>
|
|
17
|
+
) => R;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './base';
|
|
1
|
+
export * from './base';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type VertexKey = string | number;
|
|
2
2
|
|
|
3
|
-
export type DijkstraResult<V> =
|
|
3
|
+
export type DijkstraResult<V> =
|
|
4
|
+
| {
|
|
4
5
|
distMap: Map<V, number>;
|
|
5
6
|
distPaths?: Map<V, V[]>;
|
|
6
7
|
preMap: Map<V, V | undefined>;
|
|
@@ -8,4 +9,5 @@ export type DijkstraResult<V> = {
|
|
|
8
9
|
paths: V[][];
|
|
9
10
|
minDist: number;
|
|
10
11
|
minPath: V[];
|
|
11
|
-
}
|
|
12
|
+
}
|
|
13
|
+
| undefined;
|
|
@@ -7,7 +7,7 @@ export type HashMapLinkedNode<K, V> = {
|
|
|
7
7
|
|
|
8
8
|
export type HashMapOptions<K> = {
|
|
9
9
|
hashFn: (key: K) => string;
|
|
10
|
-
objHashFn: (key: K) => object
|
|
11
|
-
}
|
|
10
|
+
objHashFn: (key: K) => object;
|
|
11
|
+
};
|
|
12
12
|
|
|
13
|
-
export type HashMapStoreItem<K, V> = { key: K
|
|
13
|
+
export type HashMapStoreItem<K, V> = { key: K; value: V };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Comparator } from
|
|
1
|
+
import { Comparator } from '../../common';
|
|
2
2
|
|
|
3
|
-
export type HeapOptions<T> = { comparator: Comparator<T> }
|
|
3
|
+
export type HeapOptions<T> = { comparator: Comparator<T> };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { HeapOptions } from
|
|
1
|
+
import { HeapOptions } from '../heap';
|
|
2
2
|
|
|
3
|
-
export type PriorityQueueOptions<T> = HeapOptions<T> & {}
|
|
3
|
+
export type PriorityQueueOptions<T> = HeapOptions<T> & {};
|
package/src/utils/utils.ts
CHANGED
|
@@ -98,4 +98,10 @@ export const isWeakKey = (input: unknown): input is object => {
|
|
|
98
98
|
return (inputType === 'object' && input !== null) || inputType === 'function';
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
export const calcMinUnitsRequired = (totalQuantity: number, unitSize: number) =>
|
|
101
|
+
export const calcMinUnitsRequired = (totalQuantity: number, unitSize: number) =>
|
|
102
|
+
Math.floor((totalQuantity + unitSize - 1) / unitSize);
|
|
103
|
+
|
|
104
|
+
export const roundFixed = (num: number, digit: number = 10) => {
|
|
105
|
+
const multiplier = Math.pow(10, digit);
|
|
106
|
+
return Math.round(num * multiplier) / multiplier;
|
|
107
|
+
};
|
|
@@ -2,7 +2,24 @@ import { AVLTree, CP } from 'avl-tree-typed';
|
|
|
2
2
|
|
|
3
3
|
describe('AVL Tree Test', () => {
|
|
4
4
|
it('should perform various operations on a AVL Tree', () => {
|
|
5
|
-
const arr: [number, number][] = [
|
|
5
|
+
const arr: [number, number][] = [
|
|
6
|
+
[11, 11],
|
|
7
|
+
[3, 3],
|
|
8
|
+
[15, 15],
|
|
9
|
+
[1, 1],
|
|
10
|
+
[8, 8],
|
|
11
|
+
[13, 13],
|
|
12
|
+
[16, 16],
|
|
13
|
+
[2, 2],
|
|
14
|
+
[6, 6],
|
|
15
|
+
[9, 9],
|
|
16
|
+
[12, 12],
|
|
17
|
+
[14, 14],
|
|
18
|
+
[4, 4],
|
|
19
|
+
[7, 7],
|
|
20
|
+
[10, 10],
|
|
21
|
+
[5, 5]
|
|
22
|
+
];
|
|
6
23
|
const tree = new AVLTree();
|
|
7
24
|
|
|
8
25
|
for (const i of arr) tree.add(i);
|
|
@@ -7,7 +7,7 @@ describe('Individual package BST operations test', () => {
|
|
|
7
7
|
bst.add([11, 11]);
|
|
8
8
|
bst.add([3, 3]);
|
|
9
9
|
const idsOrValues = [15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
|
|
10
|
-
bst.addMany(idsOrValues,
|
|
10
|
+
bst.addMany(idsOrValues, undefined);
|
|
11
11
|
expect(bst.root).toBeInstanceOf(BSTNode);
|
|
12
12
|
|
|
13
13
|
if (bst.root) expect(bst.root.key).toBe(11);
|
|
@@ -204,7 +204,7 @@ describe('Individual package BST operations test', () => {
|
|
|
204
204
|
[5, { key: 5, keyA: 5 }]
|
|
205
205
|
];
|
|
206
206
|
|
|
207
|
-
objBST.addMany(values,
|
|
207
|
+
objBST.addMany(values, undefined);
|
|
208
208
|
|
|
209
209
|
expect(objBST.root).toBeInstanceOf(BSTNode);
|
|
210
210
|
|
|
@@ -45,7 +45,7 @@ suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add & iterator`, () => {
|
|
|
45
45
|
rbTree.clear();
|
|
46
46
|
for (let i = 0; i < arr.length; i++) rbTree.add(arr[i]);
|
|
47
47
|
const entries = [...rbTree];
|
|
48
|
-
return entries.length === HUNDRED_THOUSAND
|
|
48
|
+
return entries.length === HUNDRED_THOUSAND;
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
export { suite };
|
|
@@ -22,25 +22,20 @@ const arrHundredThousand = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSA
|
|
|
22
22
|
|
|
23
23
|
suite
|
|
24
24
|
.add(`SRC PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
25
|
-
|
|
26
25
|
const pq = new SRCPriorityQueue<number>();
|
|
27
26
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
28
27
|
})
|
|
29
28
|
.add(`CJS PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
30
|
-
|
|
31
|
-
|
|
32
29
|
const pq = new CJSPriorityQueue<number>();
|
|
33
30
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
34
31
|
})
|
|
35
32
|
.add(`MJS PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
36
|
-
|
|
37
33
|
const pq = new MJSPriorityQueue<number>([], { comparator: (a, b) => b - a });
|
|
38
34
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.add(i);
|
|
39
35
|
});
|
|
40
36
|
|
|
41
37
|
if (isCompetitor) {
|
|
42
38
|
suite.add(`CPT PQ ${TEN_THOUSAND.toLocaleString()} add`, () => {
|
|
43
|
-
|
|
44
39
|
const pq = new CPriorityQueue<number>();
|
|
45
40
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.push(i);
|
|
46
41
|
});
|
|
@@ -66,14 +61,14 @@ suite
|
|
|
66
61
|
for (let i = 0; i < TEN_THOUSAND; i++) pq.poll();
|
|
67
62
|
});
|
|
68
63
|
|
|
69
|
-
|
|
70
64
|
if (isCompetitor) {
|
|
71
|
-
suite
|
|
72
|
-
|
|
65
|
+
suite
|
|
66
|
+
.add(`CPT PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
|
|
67
|
+
const pq = new CPriorityQueue<number>();
|
|
73
68
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.push(i);
|
|
70
|
+
for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
|
|
71
|
+
})
|
|
77
72
|
.add(`CPT OM ${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
|
|
78
73
|
for (let i = 0; i < arrHundredThousand.length; i++) {
|
|
79
74
|
cOrderedMap.setElement(arrHundredThousand[i], arrHundredThousand[i]);
|
|
@@ -78,7 +78,6 @@ suite.add(`Native Set ${MILLION.toLocaleString()} add & has`, () => {
|
|
|
78
78
|
for (let i = 0; i < MILLION; i++) hs.add(i);
|
|
79
79
|
|
|
80
80
|
for (let i = 0; i < MILLION; i++) hs.has(i);
|
|
81
|
-
|
|
82
81
|
});
|
|
83
82
|
|
|
84
83
|
suite.add(`${MILLION.toLocaleString()} ObjKey set & get`, () => {
|
|
@@ -86,7 +85,7 @@ suite.add(`${MILLION.toLocaleString()} ObjKey set & get`, () => {
|
|
|
86
85
|
const objKeys: [number, number][] = [];
|
|
87
86
|
for (let i = 0; i < MILLION; i++) {
|
|
88
87
|
const obj: [number, number] = [i, i];
|
|
89
|
-
objKeys.push(obj)
|
|
88
|
+
objKeys.push(obj);
|
|
90
89
|
hm.set(obj, i);
|
|
91
90
|
}
|
|
92
91
|
for (let i = 0; i < MILLION; i++) {
|
|
@@ -99,7 +98,7 @@ suite.add(`Native Map ${MILLION.toLocaleString()} ObjKey set & get`, () => {
|
|
|
99
98
|
const objs: [number, number][] = [];
|
|
100
99
|
for (let i = 0; i < MILLION; i++) {
|
|
101
100
|
const obj: [number, number] = [i, i];
|
|
102
|
-
objs.push(obj)
|
|
101
|
+
objs.push(obj);
|
|
103
102
|
hm.set(obj, i);
|
|
104
103
|
}
|
|
105
104
|
for (let i = 0; i < MILLION; i++) {
|
|
@@ -112,7 +111,7 @@ suite.add(`Native Set ${MILLION.toLocaleString()} ObjKey add & has`, () => {
|
|
|
112
111
|
const objs: [number, number][] = [];
|
|
113
112
|
for (let i = 0; i < MILLION; i++) {
|
|
114
113
|
const obj: [number, number] = [i, i];
|
|
115
|
-
objs.push(obj)
|
|
114
|
+
objs.push(obj);
|
|
116
115
|
hs.add(obj);
|
|
117
116
|
}
|
|
118
117
|
for (let i = 0; i < MILLION; i++) {
|
|
@@ -19,14 +19,13 @@ if (isCompetitor) {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
suite
|
|
23
|
+
.add(`${MILLION.toLocaleString()} push & pop`, () => {
|
|
24
|
+
const _deque = new Deque<number>();
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < MILLION; i++) _deque.push(i);
|
|
27
|
-
for (let i = 0; i < MILLION; i++) _deque.pop();
|
|
28
|
-
|
|
29
|
-
})
|
|
26
|
+
for (let i = 0; i < MILLION; i++) _deque.push(i);
|
|
27
|
+
for (let i = 0; i < MILLION; i++) _deque.pop();
|
|
28
|
+
})
|
|
30
29
|
.add(`${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
|
|
31
30
|
const _deque = new Deque<number>();
|
|
32
31
|
|
|
@@ -33,16 +33,17 @@ suite.add(`${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
|
|
|
33
33
|
queue.shift();
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
|
-
suite
|
|
37
|
-
|
|
36
|
+
suite
|
|
37
|
+
.add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
|
|
38
|
+
const arr = new Array<number>();
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
})
|
|
40
|
+
for (let i = 0; i < HUNDRED_THOUSAND; i++) {
|
|
41
|
+
arr.push(i);
|
|
42
|
+
}
|
|
43
|
+
for (let i = 0; i < HUNDRED_THOUSAND; i++) {
|
|
44
|
+
arr.shift();
|
|
45
|
+
}
|
|
46
|
+
})
|
|
46
47
|
.add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & pop`, () => {
|
|
47
48
|
const arr = new Array<number>();
|
|
48
49
|
|
|
@@ -5,20 +5,19 @@ import * as fastGlob from 'fast-glob';
|
|
|
5
5
|
import { Color, numberFix, render } from '../utils';
|
|
6
6
|
import { PerformanceTest } from './types';
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
const args = process.argv.slice(2);
|
|
10
9
|
|
|
11
10
|
const { GREEN, BOLD, END, YELLOW, GRAY, CYAN, BG_YELLOW } = Color;
|
|
12
11
|
|
|
13
12
|
const getRelativePath = (file: string) => {
|
|
14
13
|
return path.relative(__dirname, file);
|
|
15
|
-
}
|
|
14
|
+
};
|
|
16
15
|
const coloredLabeled = (label: string, file: string) => {
|
|
17
16
|
const relativeFilePath = getRelativePath(file);
|
|
18
17
|
const directory = path.dirname(relativeFilePath);
|
|
19
18
|
const fileName = path.basename(relativeFilePath);
|
|
20
19
|
return `${BG_YELLOW} ${label} ${END} ${GRAY}${directory}/${END}${CYAN}${fileName}${END}`;
|
|
21
|
-
}
|
|
20
|
+
};
|
|
22
21
|
|
|
23
22
|
const parentDirectory = path.resolve(__dirname, '../..');
|
|
24
23
|
const reportDistPath = path.join(parentDirectory, 'benchmark');
|
|
@@ -29,20 +28,19 @@ let testFiles: string[];
|
|
|
29
28
|
|
|
30
29
|
let isIndividual = false;
|
|
31
30
|
if (args.length > 0) {
|
|
32
|
-
console.log(`arguments: ${args.join(' ')}`)
|
|
31
|
+
console.log(`arguments: ${args.join(' ')}`);
|
|
33
32
|
|
|
34
|
-
testFiles = allFiles.filter(file =>
|
|
35
|
-
args.every(word => file.includes(word))
|
|
36
|
-
);
|
|
33
|
+
testFiles = allFiles.filter(file => args.every(word => file.includes(word)));
|
|
37
34
|
isIndividual = true;
|
|
38
|
-
console.log(
|
|
39
|
-
|
|
35
|
+
console.log(
|
|
36
|
+
`${testFiles.map(file => coloredLabeled('Matched', file)).join(`
|
|
37
|
+
`)}`
|
|
38
|
+
);
|
|
40
39
|
} else {
|
|
41
40
|
isIndividual = false;
|
|
42
41
|
testFiles = allFiles;
|
|
43
42
|
}
|
|
44
43
|
|
|
45
|
-
|
|
46
44
|
const report: { [key: string]: any } = {};
|
|
47
45
|
|
|
48
46
|
let completedCount = 0;
|
|
@@ -132,11 +130,12 @@ const composeReport = () => {
|
|
|
132
130
|
html += `</div>
|
|
133
131
|
</body>
|
|
134
132
|
</html>`;
|
|
135
|
-
if (!isIndividual)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
if (!isIndividual)
|
|
134
|
+
replaceMarkdownContent(
|
|
135
|
+
'[//]: # (No deletion!!! Start of Replace Section)', // Start tag
|
|
136
|
+
'[//]: # (No deletion!!! End of Replace Section)', // end identifier
|
|
137
|
+
htmlTables // New content to be inserted
|
|
138
|
+
);
|
|
140
139
|
fs.writeFileSync(htmlFilePath, html);
|
|
141
140
|
console.log(`Performance ${BOLD}${GREEN}report${END} file generated in file://${BOLD}${GREEN}${htmlFilePath}${END}`);
|
|
142
141
|
};
|
|
@@ -318,13 +318,20 @@ describe('AVLTree iterative methods test', () => {
|
|
|
318
318
|
test('filter should return a new tree with filtered elements', () => {
|
|
319
319
|
const filteredTree = avl.filter((value, key) => key > 1);
|
|
320
320
|
expect(filteredTree.size).toBe(2);
|
|
321
|
-
expect([...filteredTree]).toEqual([
|
|
321
|
+
expect([...filteredTree]).toEqual([
|
|
322
|
+
[2, 'b'],
|
|
323
|
+
[3, 'c']
|
|
324
|
+
]);
|
|
322
325
|
});
|
|
323
326
|
|
|
324
327
|
test('map should return a new tree with modified elements', () => {
|
|
325
328
|
const mappedTree = avl.map((value, key) => (key * 2).toString());
|
|
326
329
|
expect(mappedTree.size).toBe(3);
|
|
327
|
-
expect([...mappedTree]).toEqual([
|
|
330
|
+
expect([...mappedTree]).toEqual([
|
|
331
|
+
[1, '2'],
|
|
332
|
+
[2, '4'],
|
|
333
|
+
[3, '6']
|
|
334
|
+
]);
|
|
328
335
|
});
|
|
329
336
|
|
|
330
337
|
test('reduce should accumulate values', () => {
|
|
@@ -339,7 +346,11 @@ describe('AVLTree iterative methods test', () => {
|
|
|
339
346
|
}
|
|
340
347
|
|
|
341
348
|
expect(entries.length).toBe(3);
|
|
342
|
-
expect(entries).toEqual([
|
|
349
|
+
expect(entries).toEqual([
|
|
350
|
+
[1, 'a'],
|
|
351
|
+
[2, 'b'],
|
|
352
|
+
[3, 'c']
|
|
353
|
+
]);
|
|
343
354
|
});
|
|
344
355
|
|
|
345
356
|
test('should clone work well', () => {
|
|
@@ -265,7 +265,22 @@ describe('BinaryTree', () => {
|
|
|
265
265
|
tree.clear();
|
|
266
266
|
tree.addMany([-10, -10, -10, 9, 9, 20, null, null, 15, 7, 8, null, 2, null, 6, null, null, 8, 8, 8]);
|
|
267
267
|
|
|
268
|
-
expect(tree.bfs(node => node ? node.key : null, undefined, undefined, true)).toEqual([
|
|
268
|
+
expect(tree.bfs(node => (node ? node.key : null), undefined, undefined, true)).toEqual([
|
|
269
|
+
-10,
|
|
270
|
+
9,
|
|
271
|
+
20,
|
|
272
|
+
null,
|
|
273
|
+
null,
|
|
274
|
+
15,
|
|
275
|
+
7,
|
|
276
|
+
8,
|
|
277
|
+
null,
|
|
278
|
+
2,
|
|
279
|
+
null,
|
|
280
|
+
6,
|
|
281
|
+
null,
|
|
282
|
+
null
|
|
283
|
+
]);
|
|
269
284
|
});
|
|
270
285
|
});
|
|
271
286
|
|
|
@@ -525,18 +540,12 @@ describe('BinaryTree', () => {
|
|
|
525
540
|
tree.add([3, 'B']);
|
|
526
541
|
tree.add([7, 'C']);
|
|
527
542
|
|
|
528
|
-
const nodes = tree.getNodes('B',
|
|
543
|
+
const nodes = tree.getNodes('B', node => node.value);
|
|
529
544
|
|
|
530
545
|
expect(nodes.length).toBe(1);
|
|
531
546
|
expect(nodes[0].key).toBe(3);
|
|
532
547
|
|
|
533
|
-
const nodesRec = tree.getNodes(
|
|
534
|
-
'B',
|
|
535
|
-
(node) => node.value,
|
|
536
|
-
false,
|
|
537
|
-
tree.root,
|
|
538
|
-
IterationType.RECURSIVE
|
|
539
|
-
);
|
|
548
|
+
const nodesRec = tree.getNodes('B', node => node.value, false, tree.root, IterationType.RECURSIVE);
|
|
540
549
|
|
|
541
550
|
expect(nodesRec.length).toBe(1);
|
|
542
551
|
expect(nodesRec[0].key).toBe(3);
|
|
@@ -548,9 +557,17 @@ describe('BinaryTree', () => {
|
|
|
548
557
|
tree.add([7, 'C']);
|
|
549
558
|
|
|
550
559
|
tree.iterationType = IterationType.ITERATIVE;
|
|
551
|
-
expect([...tree]).toEqual([
|
|
560
|
+
expect([...tree]).toEqual([
|
|
561
|
+
[3, 'B'],
|
|
562
|
+
[5, 'A'],
|
|
563
|
+
[7, 'C']
|
|
564
|
+
]);
|
|
552
565
|
tree.iterationType = IterationType.RECURSIVE;
|
|
553
|
-
expect([...tree]).toEqual([
|
|
566
|
+
expect([...tree]).toEqual([
|
|
567
|
+
[3, 'B'],
|
|
568
|
+
[5, 'A'],
|
|
569
|
+
[7, 'C']
|
|
570
|
+
]);
|
|
554
571
|
tree.iterationType = IterationType.ITERATIVE;
|
|
555
572
|
|
|
556
573
|
const result = tree.morris();
|
|
@@ -600,13 +617,20 @@ describe('BinaryTree iterative methods test', () => {
|
|
|
600
617
|
test('filter should return a new tree with filtered elements', () => {
|
|
601
618
|
const filteredTree = binaryTree.filter((value, key) => key > 1);
|
|
602
619
|
expect(filteredTree.size).toBe(2);
|
|
603
|
-
expect([...filteredTree]).toEqual([
|
|
620
|
+
expect([...filteredTree]).toEqual([
|
|
621
|
+
[3, 'c'],
|
|
622
|
+
[2, 'b']
|
|
623
|
+
]);
|
|
604
624
|
});
|
|
605
625
|
|
|
606
626
|
test('map should return a new tree with modified elements', () => {
|
|
607
627
|
const mappedTree = binaryTree.map((value, key) => (key * 2).toString());
|
|
608
628
|
expect(mappedTree.size).toBe(3);
|
|
609
|
-
expect([...mappedTree]).toEqual([
|
|
629
|
+
expect([...mappedTree]).toEqual([
|
|
630
|
+
[1, '2'],
|
|
631
|
+
[2, '4'],
|
|
632
|
+
[3, '6']
|
|
633
|
+
]);
|
|
610
634
|
});
|
|
611
635
|
|
|
612
636
|
test('reduce should accumulate values', () => {
|
|
@@ -621,7 +645,11 @@ describe('BinaryTree iterative methods test', () => {
|
|
|
621
645
|
}
|
|
622
646
|
|
|
623
647
|
expect(entries.length).toBe(3);
|
|
624
|
-
expect(entries).toEqual([
|
|
648
|
+
expect(entries).toEqual([
|
|
649
|
+
[2, 'b'],
|
|
650
|
+
[1, 'a'],
|
|
651
|
+
[3, 'c']
|
|
652
|
+
]);
|
|
625
653
|
});
|
|
626
654
|
|
|
627
655
|
test('should clone work well', () => {
|
|
@@ -641,17 +669,24 @@ describe('BinaryTree iterative methods test', () => {
|
|
|
641
669
|
});
|
|
642
670
|
|
|
643
671
|
test('should iterative method return undefined when the node is null', () => {
|
|
644
|
-
const tree = new BinaryTree()
|
|
672
|
+
const tree = new BinaryTree();
|
|
645
673
|
tree.addMany([-10, -10, -10, 9, 9, 20, null, null, 15, 7, 8, null, 2, null, 6, null, null, 8, 8, 8]);
|
|
646
674
|
const bfsResult = tree.bfs(undefined, undefined, undefined, true);
|
|
647
675
|
expect(bfsResult).toEqual([
|
|
648
|
-
-10,
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
undefined,
|
|
653
|
-
|
|
654
|
-
|
|
676
|
+
-10,
|
|
677
|
+
9,
|
|
678
|
+
20,
|
|
679
|
+
undefined,
|
|
680
|
+
undefined,
|
|
681
|
+
15,
|
|
682
|
+
7,
|
|
683
|
+
8,
|
|
684
|
+
undefined,
|
|
685
|
+
2,
|
|
686
|
+
undefined,
|
|
687
|
+
6,
|
|
688
|
+
undefined,
|
|
689
|
+
undefined
|
|
655
690
|
]);
|
|
656
|
-
})
|
|
657
|
-
});
|
|
691
|
+
});
|
|
692
|
+
});
|
|
@@ -9,7 +9,22 @@ describe('BST operations test', () => {
|
|
|
9
9
|
expect(bst).toBeInstanceOf(BST);
|
|
10
10
|
bst.add([11, 11]);
|
|
11
11
|
bst.add([3, 3]);
|
|
12
|
-
const idsAndValues: [number, number][] = [
|
|
12
|
+
const idsAndValues: [number, number][] = [
|
|
13
|
+
[15, 15],
|
|
14
|
+
[1, 1],
|
|
15
|
+
[8, 8],
|
|
16
|
+
[13, 13],
|
|
17
|
+
[16, 16],
|
|
18
|
+
[2, 2],
|
|
19
|
+
[6, 6],
|
|
20
|
+
[9, 9],
|
|
21
|
+
[12, 12],
|
|
22
|
+
[14, 14],
|
|
23
|
+
[4, 4],
|
|
24
|
+
[7, 7],
|
|
25
|
+
[10, 10],
|
|
26
|
+
[5, 5]
|
|
27
|
+
];
|
|
13
28
|
bst.addMany(idsAndValues, undefined, false);
|
|
14
29
|
expect(bst.root).toBeInstanceOf(BSTNode);
|
|
15
30
|
|
|
@@ -194,22 +209,26 @@ describe('BST operations test', () => {
|
|
|
194
209
|
objBST.add([11, { name: '11', age: 11 }]);
|
|
195
210
|
objBST.add([3, { name: '3', age: 3 }]);
|
|
196
211
|
|
|
197
|
-
objBST.addMany(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
212
|
+
objBST.addMany(
|
|
213
|
+
[15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5],
|
|
214
|
+
[
|
|
215
|
+
{ name: 'Alice', age: 15 },
|
|
216
|
+
{ name: 'Bob', age: 1 },
|
|
217
|
+
{ name: 'Charlie', age: 8 },
|
|
218
|
+
{ name: 'David', age: 13 },
|
|
219
|
+
{ name: 'Emma', age: 16 },
|
|
220
|
+
{ name: 'Frank', age: 2 },
|
|
221
|
+
{ name: 'Grace', age: 6 },
|
|
222
|
+
{ name: 'Hannah', age: 9 },
|
|
223
|
+
{ name: 'Isaac', age: 12 },
|
|
224
|
+
{ name: 'Jack', age: 14 },
|
|
225
|
+
{ name: 'Katie', age: 4 },
|
|
226
|
+
{ name: 'Liam', age: 7 },
|
|
227
|
+
{ name: 'Mia', age: 10 },
|
|
228
|
+
{ name: 'Noah', age: 5 }
|
|
229
|
+
],
|
|
230
|
+
false
|
|
231
|
+
);
|
|
213
232
|
|
|
214
233
|
expect(objBST.root).toBeInstanceOf(BSTNode);
|
|
215
234
|
|
|
@@ -596,11 +615,7 @@ describe('BST operations test recursively', () => {
|
|
|
596
615
|
[5, { key: 5, keyA: 5 }]
|
|
597
616
|
];
|
|
598
617
|
|
|
599
|
-
objBST.addMany(
|
|
600
|
-
entries,
|
|
601
|
-
undefined,
|
|
602
|
-
false
|
|
603
|
-
);
|
|
618
|
+
objBST.addMany(entries, undefined, false);
|
|
604
619
|
|
|
605
620
|
expect(objBST.root).toBeInstanceOf(BSTNode);
|
|
606
621
|
|
|
@@ -878,13 +893,20 @@ describe('BST iterative methods test', () => {
|
|
|
878
893
|
test('filter should return a new tree with filtered elements', () => {
|
|
879
894
|
const filteredTree = bst.filter((value, key) => key > 1);
|
|
880
895
|
expect(filteredTree.size).toBe(2);
|
|
881
|
-
expect([...filteredTree]).toEqual([
|
|
896
|
+
expect([...filteredTree]).toEqual([
|
|
897
|
+
[2, 'b'],
|
|
898
|
+
[3, 'c']
|
|
899
|
+
]);
|
|
882
900
|
});
|
|
883
901
|
|
|
884
902
|
test('map should return a new tree with modified elements', () => {
|
|
885
903
|
const mappedTree = bst.map((value, key) => (key * 2).toString());
|
|
886
904
|
expect(mappedTree.size).toBe(3);
|
|
887
|
-
expect([...mappedTree]).toEqual([
|
|
905
|
+
expect([...mappedTree]).toEqual([
|
|
906
|
+
[1, '2'],
|
|
907
|
+
[2, '4'],
|
|
908
|
+
[3, '6']
|
|
909
|
+
]);
|
|
888
910
|
});
|
|
889
911
|
|
|
890
912
|
test('reduce should accumulate values', () => {
|
|
@@ -899,7 +921,11 @@ describe('BST iterative methods test', () => {
|
|
|
899
921
|
}
|
|
900
922
|
|
|
901
923
|
expect(entries.length).toBe(3);
|
|
902
|
-
expect(entries).toEqual([
|
|
924
|
+
expect(entries).toEqual([
|
|
925
|
+
[1, 'a'],
|
|
926
|
+
[2, 'b'],
|
|
927
|
+
[3, 'c']
|
|
928
|
+
]);
|
|
903
929
|
});
|
|
904
930
|
|
|
905
931
|
test('should clone work well', () => {
|
|
@@ -917,4 +943,4 @@ describe('BST iterative methods test', () => {
|
|
|
917
943
|
const values = bst.values();
|
|
918
944
|
expect([...values]).toEqual(['a', 'b', 'c']);
|
|
919
945
|
});
|
|
920
|
-
});
|
|
946
|
+
});
|