data-structure-typed 1.54.1 → 1.54.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cjs/types/data-structures/binary-tree/index.d.ts +1 -1
  3. package/dist/cjs/types/data-structures/binary-tree/index.js +1 -1
  4. package/dist/cjs/types/data-structures/binary-tree/index.js.map +1 -1
  5. package/dist/cjs/types/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +1 -1
  6. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js.map +1 -0
  7. package/dist/cjs/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
  8. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  9. package/dist/esm/types/data-structures/binary-tree/index.d.ts +1 -1
  10. package/dist/esm/types/data-structures/binary-tree/index.js +1 -1
  11. package/dist/esm/types/data-structures/binary-tree/index.js.map +1 -1
  12. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js +2 -0
  13. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js.map +1 -0
  14. package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
  15. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  16. package/package.json +8 -13
  17. package/src/types/data-structures/binary-tree/index.ts +1 -1
  18. package/src/types/data-structures/binary-tree/tree-counter.ts +1 -1
  19. package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
  20. package/test/integration/compile.mjs +135 -0
  21. package/test/performance/data-structures/binary-tree/avl-tree.test.js +45 -0
  22. package/test/performance/reportor.js +249 -0
  23. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +1 -1
  24. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +1 -1
  25. package/dist/cjs/types/data-structures/binary-tree/rb-tree.js.map +0 -1
  26. package/dist/esm/types/data-structures/binary-tree/rb-tree.js +0 -2
  27. package/dist/esm/types/data-structures/binary-tree/rb-tree.js.map +0 -1
  28. /package/dist/cjs/types/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +0 -0
  29. /package/dist/esm/types/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +0 -0
  30. /package/src/types/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
8
8
  - [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
9
9
  - [`auto-changelog`](https://github.com/CookPete/auto-changelog)
10
10
 
11
- ## [v1.54.1](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming)
11
+ ## [v1.54.2](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming)
12
12
 
13
13
  ### Changes
14
14
 
@@ -3,7 +3,7 @@ export * from './bst';
3
3
  export * from './avl-tree';
4
4
  export * from './segment-tree';
5
5
  export * from './avl-tree-multi-map';
6
- export * from './rb-tree';
6
+ export * from './red-black-tree';
7
7
  export * from './tree-multi-map';
8
8
  export * from './tree-counter';
9
9
  export * from './avl-tree-counter';
@@ -19,7 +19,7 @@ __exportStar(require("./bst"), exports);
19
19
  __exportStar(require("./avl-tree"), exports);
20
20
  __exportStar(require("./segment-tree"), exports);
21
21
  __exportStar(require("./avl-tree-multi-map"), exports);
22
- __exportStar(require("./rb-tree"), exports);
22
+ __exportStar(require("./red-black-tree"), exports);
23
23
  __exportStar(require("./tree-multi-map"), exports);
24
24
  __exportStar(require("./tree-counter"), exports);
25
25
  __exportStar(require("./avl-tree-counter"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,wCAAsB;AACtB,6CAA2B;AAC3B,iDAA+B;AAC/B,uDAAqC;AACrC,4CAA0B;AAC1B,mDAAiC;AACjC,iDAA+B;AAC/B,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,wCAAsB;AACtB,6CAA2B;AAC3B,iDAA+B;AAC/B,uDAAqC;AACrC,mDAAiC;AACjC,mDAAiC;AACjC,iDAA+B;AAC/B,qDAAmC"}
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=rb-tree.js.map
3
+ //# sourceMappingURL=red-black-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"red-black-tree.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/red-black-tree.ts"],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
- import type { RedBlackTreeOptions } from './rb-tree';
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
2
  export type TreeCounterOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
@@ -1,2 +1,2 @@
1
- import type { RedBlackTreeOptions } from './rb-tree';
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
2
  export type TreeMultiMapOptions<K, V, R> = Omit<RedBlackTreeOptions<K, V, R>, 'isMapMode'> & {};
@@ -3,7 +3,7 @@ export * from './bst';
3
3
  export * from './avl-tree';
4
4
  export * from './segment-tree';
5
5
  export * from './avl-tree-multi-map';
6
- export * from './rb-tree';
6
+ export * from './red-black-tree';
7
7
  export * from './tree-multi-map';
8
8
  export * from './tree-counter';
9
9
  export * from './avl-tree-counter';
@@ -3,7 +3,7 @@ export * from './bst';
3
3
  export * from './avl-tree';
4
4
  export * from './segment-tree';
5
5
  export * from './avl-tree-multi-map';
6
- export * from './rb-tree';
6
+ export * from './red-black-tree';
7
7
  export * from './tree-multi-map';
8
8
  export * from './tree-counter';
9
9
  export * from './avl-tree-counter';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=red-black-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"red-black-tree.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/red-black-tree.ts"],"names":[],"mappings":""}
@@ -1,2 +1,2 @@
1
- import type { RedBlackTreeOptions } from './rb-tree';
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
2
  export type TreeCounterOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
@@ -1,2 +1,2 @@
1
- import type { RedBlackTreeOptions } from './rb-tree';
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
2
  export type TreeMultiMapOptions<K, V, R> = Omit<RedBlackTreeOptions<K, V, R>, 'isMapMode'> & {};
package/package.json CHANGED
@@ -1,23 +1,18 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.54.1",
3
+ "version": "1.54.2",
4
4
  "description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "browser": "dist/umd/data-structure-typed.min.js",
8
8
  "types": "dist/esm/index.d.ts",
9
9
  "umd:main": "dist/umd/data-structure-typed.min.js",
10
- "exports": {
11
- ".": {
12
- "import": "./dist/esm/index.js",
13
- "require": "./dist/cjs/index.js"
14
- }
15
- },
16
10
  "scripts": {
17
- "build": "npm run build:esm && npm run build:cjs && npm run build:umd && npm run build:docs-class",
11
+ "build": "npm run build:ecu && npm run build:docs-class",
18
12
  "build:esm": "rm -rf dist/esm && tsc -p tsconfig-esm.json",
19
13
  "build:cjs": "rm -rf dist/cjs && tsc -p tsconfig-cjs.json",
20
14
  "build:umd": "tsup",
15
+ "build:ecu": "npm run build:esm && npm run build:cjs && npm run build:umd",
21
16
  "build:docs": "npm run gen:examples && typedoc --out docs ./src",
22
17
  "build:docs-class": "npm run gen:examples && typedoc --out docs ./src/data-structures",
23
18
  "gen:examples": "ts-node scripts/testToExample.ts",
@@ -70,11 +65,11 @@
70
65
  "@typescript-eslint/eslint-plugin": "^8.12.1",
71
66
  "@typescript-eslint/parser": "^8.12.1",
72
67
  "auto-changelog": "^2.5.0",
73
- "avl-tree-typed": "^1.54.0",
68
+ "avl-tree-typed": "^1.54.1",
74
69
  "benchmark": "^2.1.4",
75
- "binary-tree-typed": "^1.54.0",
76
- "bst-typed": "^1.54.0",
77
- "data-structure-typed": "^1.54.0",
70
+ "binary-tree-typed": "^1.54.1",
71
+ "bst-typed": "^1.54.1",
72
+ "data-structure-typed": "^1.54.1",
78
73
  "dependency-cruiser": "^16.5.0",
79
74
  "doctoc": "^2.2.1",
80
75
  "eslint": "^9.13.0",
@@ -83,7 +78,7 @@
83
78
  "eslint-import-resolver-typescript": "^3.6.3",
84
79
  "eslint-plugin-import": "^2.31.0",
85
80
  "fast-glob": "^3.3.2",
86
- "heap-typed": "^1.54.0",
81
+ "heap-typed": "^1.54.1",
87
82
  "istanbul-badges-readme": "^1.9.0",
88
83
  "jest": "^29.7.0",
89
84
  "js-sdsl": "^4.4.2",
@@ -3,7 +3,7 @@ export * from './bst';
3
3
  export * from './avl-tree';
4
4
  export * from './segment-tree';
5
5
  export * from './avl-tree-multi-map';
6
- export * from './rb-tree';
6
+ export * from './red-black-tree';
7
7
  export * from './tree-multi-map';
8
8
  export * from './tree-counter';
9
9
  export * from './avl-tree-counter';
@@ -1,3 +1,3 @@
1
- import type { RedBlackTreeOptions } from './rb-tree';
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
2
 
3
3
  export type TreeCounterOptions<K, V, R> = RedBlackTreeOptions<K, V, R> & {};
@@ -1,3 +1,3 @@
1
- import type { RedBlackTreeOptions } from './rb-tree';
1
+ import type { RedBlackTreeOptions } from './red-black-tree';
2
2
 
3
3
  export type TreeMultiMapOptions<K, V, R> = Omit<RedBlackTreeOptions<K, V, R>, 'isMapMode'> & {}
@@ -0,0 +1,135 @@
1
+ import { AVLTree, BinaryTree, BST, Deque, DoublyLinkedList, HashMap, Heap, MaxPriorityQueue, MinHeap, MinPriorityQueue, Queue, RedBlackTree, SinglyLinkedList, Stack, TreeMultiMap, Trie } from 'data-structure-typed';
2
+ const orgArr = [6, 1, 2, 7, 5, 3, 4, 9, 8];
3
+ const orgStrArr = ['trie', 'trial', 'trick', 'trip', 'tree', 'trend', 'triangle', 'track', 'trace', 'transmit'];
4
+ const entries = [
5
+ [6, '6'],
6
+ [1, '1'],
7
+ [2, '2'],
8
+ [7, '7'],
9
+ [5, '5'],
10
+ [3, '3'],
11
+ [4, '4'],
12
+ [9, '9'],
13
+ [8, '8']
14
+ ];
15
+ const queue = new Queue(orgArr);
16
+ queue.print();
17
+ // [6, 1, 2, 7, 5, 3, 4, 9, 8]
18
+ const deque = new Deque(orgArr);
19
+ deque.print();
20
+ // [6, 1, 2, 7, 5, 3, 4, 9, 8]
21
+ const sList = new SinglyLinkedList(orgArr);
22
+ sList.print();
23
+ // [6, 1, 2, 7, 5, 3, 4, 9, 8]
24
+ const dList = new DoublyLinkedList(orgArr);
25
+ dList.print();
26
+ // [6, 1, 2, 7, 5, 3, 4, 9, 8]
27
+ const stack = new Stack(orgArr);
28
+ stack.print();
29
+ // [6, 1, 2, 7, 5, 3, 4, 9, 8]
30
+ const minHeap = new MinHeap(orgArr);
31
+ minHeap.print();
32
+ // [1, 5, 2, 7, 6, 3, 4, 9, 8]
33
+ const maxPQ = new MaxPriorityQueue(orgArr);
34
+ maxPQ.print();
35
+ // [9, 8, 4, 7, 5, 2, 3, 1, 6]
36
+ const biTree = new BinaryTree(entries);
37
+ biTree.print();
38
+ // ___6___
39
+ // / \
40
+ // ___1_ _2_
41
+ // / \ / \
42
+ // _7_ 5 3 4
43
+ // / \
44
+ // 9 8
45
+ const bst = new BST(entries);
46
+ bst.print();
47
+ // _____5___
48
+ // / \
49
+ // _2_ _7_
50
+ // / \ / \
51
+ // 1 3_ 6 8_
52
+ // \ \
53
+ // 4 9
54
+ const rbTree = new RedBlackTree(entries);
55
+ rbTree.print();
56
+ // ___4___
57
+ // / \
58
+ // _2_ _6___
59
+ // / \ / \
60
+ // 1 3 5 _8_
61
+ // / \
62
+ // 7 9
63
+ const avl = new AVLTree(entries);
64
+ avl.print();
65
+ // ___4___
66
+ // / \
67
+ // _2_ _6___
68
+ // / \ / \
69
+ // 1 3 5 _8_
70
+ // / \
71
+ // 7 9
72
+ const treeMulti = new TreeMultiMap(entries);
73
+ treeMulti.print();
74
+ // ___4___
75
+ // / \
76
+ // _2_ _6___
77
+ // / \ / \
78
+ // 1 3 5 _8_
79
+ // / \
80
+ // 7 9
81
+ const hm = new HashMap(entries);
82
+ hm.print();
83
+ // [[6, "6"], [1, "1"], [2, "2"], [7, "7"], [5, "5"], [3, "3"], [4, "4"], [9, "9"], [8, "8"]]
84
+ const rbTreeH = new RedBlackTree(hm);
85
+ rbTreeH.print();
86
+ // ___4___
87
+ // / \
88
+ // _2_ _6___
89
+ // / \ / \
90
+ // 1 3 5 _8_
91
+ // / \
92
+ // 7 9
93
+ const pq = new MinPriorityQueue(orgArr);
94
+ pq.print();
95
+ // [1, 5, 2, 7, 6, 3, 4, 9, 8]
96
+ const bst1 = new BST(pq);
97
+ bst1.print();
98
+ // _____5___
99
+ // / \
100
+ // _2_ _7_
101
+ // / \ / \
102
+ // 1 3_ 6 8_
103
+ // \ \
104
+ // 4 9
105
+ const dq1 = new Deque(orgArr);
106
+ dq1.print();
107
+ // [6, 1, 2, 7, 5, 3, 4, 9, 8]
108
+ const rbTree1 = new RedBlackTree(dq1);
109
+ rbTree1.print();
110
+ // _____5___
111
+ // / \
112
+ // _2___ _7___
113
+ // / \ / \
114
+ // 1 _4 6 _9
115
+ // / /
116
+ // 3 8
117
+ const trie2 = new Trie(orgStrArr);
118
+ trie2.print();
119
+ // ['trie', 'trial', 'triangle', 'trick', 'trip', 'tree', 'trend', 'track', 'trace', 'transmit']
120
+ const heap2 = new Heap(trie2, { comparator: (a, b) => Number(a) - Number(b) });
121
+ heap2.print();
122
+ // ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
123
+ const dq2 = new Deque(heap2);
124
+ dq2.print();
125
+ // ['transmit', 'trace', 'tree', 'trend', 'track', 'trial', 'trip', 'trie', 'trick', 'triangle']
126
+ const entries2 = dq2.map((el, i) => [i, el]);
127
+ const avl2 = new AVLTree(entries2);
128
+ avl2.print();
129
+ // ___3_______
130
+ // / \
131
+ // _1_ ___7_
132
+ // / \ / \
133
+ // 0 2 _5_ 8_
134
+ // / \ \
135
+ // 4 6 9
@@ -0,0 +1,45 @@
1
+ import { AVLTree } from '../../../../';
2
+ import * as Benchmark from 'benchmark';
3
+ // import { getRandomIntArray, magnitude } from '../../../utils';
4
+ // const suite = new Benchmark.Suite();
5
+ // const avlTree = new AVLTree();
6
+ // const { HUNDRED_THOUSAND } = magnitude;
7
+ // const randomArray = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND - 1, true);
8
+ // suite
9
+ // .add(`${HUNDRED_THOUSAND.toLocaleString()} add randomly`, () => {
10
+ // avlTree.clear();
11
+ // for (let i = 0; i < randomArray.length; i++)
12
+ // avlTree.add(randomArray[i]);
13
+ // })
14
+ // .add(`${HUNDRED_THOUSAND.toLocaleString()} add`, () => {
15
+ // avlTree.clear();
16
+ // for (let i = 0; i < randomArray.length; i++)
17
+ // avlTree.add(i);
18
+ // })
19
+ // .add(`${HUNDRED_THOUSAND.toLocaleString()} get`, () => {
20
+ // for (let i = 0; i < randomArray.length; i++)
21
+ // avlTree.get(randomArray[i]);
22
+ // })
23
+ // .add(`${HUNDRED_THOUSAND.toLocaleString()} getNode`, () => {
24
+ // for (let i = 0; i < randomArray.length; i++)
25
+ // avlTree.getNode(randomArray[i]);
26
+ // })
27
+ // .add(`${HUNDRED_THOUSAND.toLocaleString()} iterator`, () => {
28
+ // const entries = [...avlTree];
29
+ // return entries.length === HUNDRED_THOUSAND;
30
+ // })
31
+ // .add(`${HUNDRED_THOUSAND.toLocaleString()} add & delete orderly`, () => {
32
+ // avlTree.clear();
33
+ // for (let i = 0; i < randomArray.length; i++)
34
+ // avlTree.add(i);
35
+ // for (let i = 0; i < randomArray.length; i++)
36
+ // avlTree.delete(i);
37
+ // })
38
+ // .add(`${HUNDRED_THOUSAND.toLocaleString()} add & delete randomly`, () => {
39
+ // avlTree.clear();
40
+ // for (let i = 0; i < randomArray.length; i++)
41
+ // avlTree.add(randomArray[i]);
42
+ // for (let i = 0; i < randomArray.length; i++)
43
+ // avlTree.delete(randomArray[i]);
44
+ // });
45
+ // export { suite };
@@ -0,0 +1,249 @@
1
+ import * as path from 'path';
2
+ import * as fs from 'fs';
3
+ import * as fastGlob from 'fast-glob';
4
+ import { ConsoleColor, numberFix, render } from '../utils';
5
+
6
+ const args = process.argv.slice(2);
7
+ const { GREEN, BOLD, END, YELLOW, GRAY, CYAN, BG_YELLOW } = ConsoleColor;
8
+ const isOnlyOrdered = true;
9
+ const runOrder = [
10
+ 'heap',
11
+ 'avl-tree',
12
+ 'rb-tree',
13
+ 'doubly-linked-list',
14
+ 'directed-graph',
15
+ 'queue',
16
+ 'deque',
17
+ 'hash-map',
18
+ 'trie',
19
+ 'stack'
20
+ // 'singly-linked-list',
21
+ // 'priority-queue',
22
+ // 'binary-tree-overall'
23
+ ];
24
+ const getRelativePath = file => {
25
+ return path.relative(__dirname, file);
26
+ };
27
+ const coloredLabeled = (label, file) => {
28
+ const relativeFilePath = getRelativePath(file);
29
+ const directory = path.dirname(relativeFilePath);
30
+ const fileName = path.basename(relativeFilePath);
31
+ return `${BG_YELLOW} ${label} ${END} ${GRAY}${directory}/${END}${CYAN}${fileName}${END}`;
32
+ };
33
+ const parentDirectory = path.resolve(__dirname, '../..');
34
+ const reportDistPath = path.join(parentDirectory, 'benchmark');
35
+ const testDir = path.join(__dirname, 'data-structures');
36
+ const allFiles = fastGlob.sync(path.join(testDir, '**', '*.test.js'));
37
+ let testFiles;
38
+ let isIndividual = false;
39
+ if (args.length > 0) {
40
+ console.log(`arguments: ${args.join(' ')}`);
41
+ testFiles = allFiles.filter(file => args.every(word => file.includes(word)));
42
+ isIndividual = true;
43
+ console.log(
44
+ `${testFiles.map(file => coloredLabeled('Found', file)).join(`
45
+ `)}`
46
+ );
47
+ } else {
48
+ isIndividual = false;
49
+ testFiles = allFiles;
50
+ }
51
+ const report = {};
52
+ let completedCount = 0;
53
+ const performanceTests = [];
54
+ testFiles.forEach(file => {
55
+ const testName = path.basename(file, '.test.ts');
56
+ const testFunction = require(file);
57
+ const { suite } = testFunction;
58
+ if (suite)
59
+ performanceTests.push({
60
+ testName,
61
+ suite,
62
+ file
63
+ });
64
+ });
65
+ const composeReport = () => {
66
+ if (!fs.existsSync(reportDistPath))
67
+ fs.mkdirSync(reportDistPath, {
68
+ recursive: true
69
+ });
70
+ const filePath = path.join(reportDistPath, 'report.json');
71
+ const htmlFilePath = path.join(reportDistPath, 'report.html');
72
+ fs.writeFileSync(filePath, JSON.stringify(report, null, 2));
73
+ let html = `<!DOCTYPE html>
74
+ <html lang="en">
75
+ <head>
76
+ <meta charset="UTF-8">
77
+ <title>performance of data-structure-typed</title>
78
+ <style>
79
+ *{
80
+ box-sizing: border-box;
81
+ }
82
+ #json-to-html {
83
+ padding: 0 10px 20px;
84
+ }
85
+
86
+ .json-to-html-label {
87
+ font-size: 2rem;
88
+ margin: 2rem 0 0 3px;
89
+ }
90
+ .content table {
91
+ width: 100%;
92
+ table-layout: fixed;
93
+ border-collapse: collapse;
94
+ margin-top: 10px;
95
+ font-size: 16px;
96
+ }
97
+
98
+ .content table th,
99
+ .content table td {
100
+ padding: 8px 12px;
101
+ text-align: left;
102
+ border: 1px solid #ddd;
103
+ }
104
+
105
+ .content table th {
106
+ background-color: #f2f2f2;
107
+ font-weight: bold;
108
+ }
109
+
110
+ .content table tr:nth-child(odd) {
111
+ background-color: #ffffff;
112
+ }
113
+ </style>
114
+ </head>
115
+ <body>
116
+ <div id="json-to-html">`;
117
+ let htmlTables = '';
118
+ for (const r in report) {
119
+ if (report.hasOwnProperty(r)) {
120
+ htmlTables += render(report[r].testName, report[r].benchmarks, {
121
+ plainHtml: true,
122
+ '<>': 'table',
123
+ html: [
124
+ {
125
+ '<>': 'tr',
126
+ html: [
127
+ {
128
+ '<>': 'td',
129
+ html: '${name}'
130
+ },
131
+ {
132
+ '<>': 'td',
133
+ html: '${periodMS}'
134
+ },
135
+ {
136
+ '<>': 'td',
137
+ html: '${mean}'
138
+ }
139
+ ]
140
+ }
141
+ ]
142
+ });
143
+ }
144
+ }
145
+ htmlTables += `
146
+
147
+ `;
148
+ html += htmlTables;
149
+ html += `</div>
150
+ </body>
151
+ </html>`;
152
+ if (!isIndividual)
153
+ replaceMarkdownContent(
154
+ '[//]: # (No deletion!!! Start of Replace Section)', // Start tag
155
+ '[//]: # (No deletion!!! End of Replace Section)', // end identifier
156
+ htmlTables // New content to be inserted
157
+ );
158
+ fs.writeFileSync(htmlFilePath, html);
159
+ console.log(`Performance ${BOLD}${GREEN}report${END} file generated in file://${BOLD}${GREEN}${htmlFilePath}${END}`);
160
+ };
161
+ function replaceMarkdownContent(startMarker, endMarker, newText) {
162
+ const filePath = path.join(parentDirectory, 'README.md'); // Path to README.md file
163
+ fs.readFile(filePath, 'utf8', (err, data) => {
164
+ if (err) {
165
+ console.error(`Unable to read ${filePath}:`, err);
166
+ return;
167
+ }
168
+ // Find the start and end markers in the content
169
+ const startIndex = data.indexOf(startMarker);
170
+ const endIndex = data.indexOf(endMarker, startIndex + 1);
171
+ if (startIndex === -1 || endIndex === -1) {
172
+ console.error('Unable to find start or end marker');
173
+ return;
174
+ }
175
+ // Replace the old content with the new text
176
+ const updatedMarkdown = data.slice(0, startIndex + startMarker.length) + '\n' + newText + data.slice(endIndex);
177
+ // Try writing the modified content back to the file
178
+ fs.writeFile(filePath, updatedMarkdown, 'utf8', err => {
179
+ if (err) {
180
+ console.error(`Unable to write to ${filePath}:`, err);
181
+ } else {
182
+ console.log(`The content has been successfully replaced in file://${BOLD}${GREEN}${filePath}${END}`);
183
+ }
184
+ });
185
+ });
186
+ }
187
+ const sortedPerformanceTests = (
188
+ isOnlyOrdered ? [...performanceTests].filter(test => runOrder.includes(test.testName)) : [...performanceTests]
189
+ ).sort((a, b) => {
190
+ const indexA = runOrder.indexOf(a.testName);
191
+ const indexB = runOrder.indexOf(b.testName);
192
+ // If both a and b are in the runOrder, sort them according to their indices in the runOrder.
193
+ if (indexA !== -1 && indexB !== -1) {
194
+ return indexA - indexB;
195
+ }
196
+ // If there is only 'a' in the runOrder, then place 'b' in front.
197
+ if (indexA !== -1) {
198
+ return 1;
199
+ }
200
+ // If only b is in the runOrder, then a should be placed before it.
201
+ if (indexB !== -1) {
202
+ return -1;
203
+ }
204
+ // If neither a nor b are in runOrder, keep their original runOrder
205
+ return 0;
206
+ });
207
+ console.log(
208
+ `${GREEN} Matched Suites (${performanceTests.length})${END}: ${performanceTests.map(test => test.testName)}`
209
+ );
210
+ console.log(
211
+ `${GREEN} Running Suites (${sortedPerformanceTests.length})${END}: ${sortedPerformanceTests.map(test => test.testName)}`
212
+ );
213
+ sortedPerformanceTests.forEach(item => {
214
+ const { suite, testName, file } = item;
215
+ console.log(coloredLabeled('Running', file));
216
+ if (suite) {
217
+ let runTime = 0;
218
+ suite
219
+ .on('complete', function () {
220
+ completedCount++;
221
+ report[testName] = {};
222
+ report[testName].benchmarks = this.map(benchmark => {
223
+ runTime += benchmark.times.elapsed;
224
+ return {
225
+ 'test name': benchmark.name,
226
+ 'time taken (ms)': numberFix(benchmark.times.period * 1000, 2),
227
+ // 'executions per sec': numberFix(benchmark.hz, 2),
228
+ // 'executed times': numberFix(benchmark.count, 0),
229
+ 'sample mean (secs)': numberFix(benchmark.stats.mean, 2),
230
+ 'sample deviation': numberFix(benchmark.stats.deviation, 2)
231
+ };
232
+ });
233
+ report[testName].testName = testName;
234
+ const isDone = completedCount === sortedPerformanceTests.length;
235
+ runTime = Number(runTime.toFixed(2));
236
+ const isTimeWarn = runTime > 120;
237
+ console.log(
238
+ // `Files: ${GREEN}${testFileCount}${END} `,
239
+ // `Suites: ${GREEN}${performanceTests.length}${END} `,
240
+ `Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${sortedPerformanceTests.length}${END}`,
241
+ `Time Costs: ${isTimeWarn ? YELLOW : GREEN}${runTime}s${END}`
242
+ );
243
+ if (isDone) {
244
+ composeReport();
245
+ }
246
+ })
247
+ .run({ async: false });
248
+ }
249
+ });
@@ -435,7 +435,7 @@ describe('AVLTreeMultiMap iterative methods test', () => {
435
435
  });
436
436
 
437
437
  it('map should return a new avlTmm with modified elements', () => {
438
- const avlTmmMapped = avlTmm.map((key, value) => [(key * 2).toString(), value ? value :[]]);
438
+ const avlTmmMapped = avlTmm.map((key, value) => [(key * 2).toString(), value ? value : []]);
439
439
  expect(avlTmmMapped.size).toBe(3);
440
440
  expect([...avlTmmMapped]).toEqual([
441
441
  ['2', ['a']],
@@ -664,7 +664,7 @@ describe('TreeMultiMap 2', () => {
664
664
  });
665
665
 
666
666
  it('map should return a new tmm with modified elements', () => {
667
- const tmmMapped = tmm.map((key, value) => [(key * 2).toString(), value ? value :[]]);
667
+ const tmmMapped = tmm.map((key, value) => [(key * 2).toString(), value ? value : []]);
668
668
  expect(tmmMapped.size).toBe(3);
669
669
  expect([...tmmMapped]).toEqual([
670
670
  ['2', ['a']],
@@ -1 +0,0 @@
1
- {"version":3,"file":"rb-tree.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/rb-tree.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=rb-tree.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rb-tree.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/binary-tree/rb-tree.ts"],"names":[],"mappings":""}