data-structure-typed 1.45.0 → 1.45.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/.eslintrc.js +6 -6
  2. package/CHANGELOG.md +1 -1
  3. package/COMMANDS.md +6 -1
  4. package/README.md +18 -15
  5. package/benchmark/report.html +18 -15
  6. package/benchmark/report.json +157 -116
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  13. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  14. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  16. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  17. package/dist/cjs/data-structures/hash/hash-map.d.ts +58 -58
  18. package/dist/cjs/data-structures/hash/hash-map.js +73 -73
  19. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  20. package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
  21. package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
  22. package/dist/cjs/data-structures/heap/heap.js +21 -12
  23. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  24. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  25. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  26. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  27. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  28. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  29. package/dist/cjs/data-structures/matrix/matrix2d.js.map +1 -1
  30. package/dist/cjs/data-structures/matrix/navigator.js.map +1 -1
  31. package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
  32. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  33. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  34. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  35. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  36. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  37. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  38. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  39. package/dist/cjs/utils/utils.js.map +1 -1
  40. package/dist/mjs/data-structures/hash/hash-map.d.ts +58 -58
  41. package/dist/mjs/data-structures/hash/hash-map.js +76 -76
  42. package/dist/mjs/data-structures/heap/heap.js +21 -12
  43. package/dist/umd/data-structure-typed.js +83 -83
  44. package/dist/umd/data-structure-typed.min.js +1 -1
  45. package/dist/umd/data-structure-typed.min.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/data-structures/binary-tree/avl-tree.ts +7 -7
  48. package/src/data-structures/binary-tree/binary-indexed-tree.ts +3 -3
  49. package/src/data-structures/binary-tree/binary-tree.ts +39 -31
  50. package/src/data-structures/binary-tree/bst.ts +12 -8
  51. package/src/data-structures/binary-tree/rb-tree.ts +17 -6
  52. package/src/data-structures/binary-tree/segment-tree.ts +1 -1
  53. package/src/data-structures/binary-tree/tree-multimap.ts +12 -9
  54. package/src/data-structures/graph/abstract-graph.ts +46 -31
  55. package/src/data-structures/graph/directed-graph.ts +10 -5
  56. package/src/data-structures/graph/map-graph.ts +8 -8
  57. package/src/data-structures/graph/undirected-graph.ts +9 -9
  58. package/src/data-structures/hash/hash-map.ts +103 -103
  59. package/src/data-structures/hash/hash-table.ts +1 -1
  60. package/src/data-structures/hash/tree-map.ts +2 -1
  61. package/src/data-structures/hash/tree-set.ts +2 -1
  62. package/src/data-structures/heap/heap.ts +30 -17
  63. package/src/data-structures/heap/max-heap.ts +3 -3
  64. package/src/data-structures/heap/min-heap.ts +3 -3
  65. package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
  66. package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
  67. package/src/data-structures/matrix/matrix.ts +2 -2
  68. package/src/data-structures/matrix/matrix2d.ts +1 -1
  69. package/src/data-structures/matrix/navigator.ts +3 -3
  70. package/src/data-structures/matrix/vector2d.ts +2 -1
  71. package/src/data-structures/priority-queue/max-priority-queue.ts +3 -3
  72. package/src/data-structures/priority-queue/min-priority-queue.ts +3 -3
  73. package/src/data-structures/priority-queue/priority-queue.ts +3 -3
  74. package/src/data-structures/queue/deque.ts +5 -4
  75. package/src/data-structures/queue/queue.ts +2 -2
  76. package/src/data-structures/tree/tree.ts +1 -1
  77. package/src/data-structures/trie/trie.ts +1 -1
  78. package/src/interfaces/binary-tree.ts +2 -2
  79. package/src/interfaces/graph.ts +1 -1
  80. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
  81. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  82. package/src/types/data-structures/binary-tree/bst.ts +2 -2
  83. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
  84. package/src/types/data-structures/binary-tree/tree-multimap.ts +2 -2
  85. package/src/types/data-structures/hash/hash-map.ts +6 -6
  86. package/src/types/data-structures/matrix/navigator.ts +1 -1
  87. package/src/types/utils/utils.ts +1 -1
  88. package/src/types/utils/validate-type.ts +18 -4
  89. package/src/utils/utils.ts +6 -6
  90. package/test/integration/all-in-one.ts +1 -1
  91. package/test/integration/avl-tree.test.ts +1 -1
  92. package/test/integration/bst.test.ts +19 -19
  93. package/test/integration/heap.test.js +1 -1
  94. package/test/integration/index.html +7 -7
  95. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -4
  96. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +4 -4
  97. package/test/performance/data-structures/binary-tree/bst.test.ts +4 -4
  98. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +9 -9
  99. package/test/performance/data-structures/comparation.test.ts +142 -0
  100. package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
  101. package/test/performance/data-structures/hash/hash-map.test.ts +8 -8
  102. package/test/performance/data-structures/heap/heap.test.ts +5 -5
  103. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +7 -7
  104. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -4
  105. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +7 -5
  106. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +8 -8
  107. package/test/performance/data-structures/queue/deque.test.ts +6 -6
  108. package/test/performance/data-structures/queue/queue.test.ts +7 -7
  109. package/test/performance/data-structures/stack/stack.test.ts +8 -8
  110. package/test/performance/data-structures/trie/trie.test.ts +4 -4
  111. package/test/performance/reportor.ts +48 -20
  112. package/test/performance/types/reportor.ts +1 -1
  113. package/test/types/utils/json2html.ts +1 -1
  114. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +6 -6
  115. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +12 -12
  116. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -76
  117. package/test/unit/data-structures/binary-tree/bst.test.ts +44 -40
  118. package/test/unit/data-structures/binary-tree/overall.test.ts +17 -17
  119. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +9 -9
  120. package/test/unit/data-structures/binary-tree/segment-tree.test.ts +1 -1
  121. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +35 -35
  122. package/test/unit/data-structures/graph/abstract-graph.test.ts +7 -7
  123. package/test/unit/data-structures/graph/directed-graph.test.ts +34 -14
  124. package/test/unit/data-structures/graph/map-graph.test.ts +1 -1
  125. package/test/unit/data-structures/graph/overall.test.ts +1 -1
  126. package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
  127. package/test/unit/data-structures/hash/coordinate-map.test.ts +1 -1
  128. package/test/unit/data-structures/hash/coordinate-set.test.ts +1 -1
  129. package/test/unit/data-structures/hash/hash-map.test.ts +10 -12
  130. package/test/unit/data-structures/hash/hash-table.test.ts +1 -1
  131. package/test/unit/data-structures/heap/heap.test.ts +73 -23
  132. package/test/unit/data-structures/heap/max-heap.test.ts +2 -2
  133. package/test/unit/data-structures/heap/min-heap.test.ts +2 -2
  134. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +5 -5
  135. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +5 -5
  136. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  137. package/test/unit/data-structures/matrix/matrix.test.ts +5 -5
  138. package/test/unit/data-structures/matrix/matrix2d.test.ts +3 -3
  139. package/test/unit/data-structures/matrix/navigator.test.ts +2 -2
  140. package/test/unit/data-structures/matrix/vector2d.test.ts +1 -1
  141. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +7 -7
  142. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -1
  143. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +19 -19
  144. package/test/unit/data-structures/queue/deque.test.ts +3 -3
  145. package/test/unit/data-structures/queue/queue.test.ts +3 -3
  146. package/test/unit/data-structures/stack/stack.test.ts +1 -1
  147. package/test/unit/data-structures/tree/tree.test.ts +1 -1
  148. package/test/unit/data-structures/trie/trie.test.ts +1 -1
  149. package/test/utils/array.ts +1 -1
  150. package/test/utils/big-o.ts +4 -4
  151. package/test/utils/index.ts +1 -0
  152. package/test/utils/json2html.ts +7 -3
  153. package/test/utils/performanc.ts +7 -0
@@ -1,13 +1,13 @@
1
- import {FibonacciHeap, Heap} from '../../../../src';
1
+ import { FibonacciHeap, Heap } from '../../../../src';
2
2
  import * as Benchmark from 'benchmark';
3
- import {magnitude} from '../../../utils';
3
+ import { magnitude } from '../../../utils';
4
4
 
5
5
  const suite = new Benchmark.Suite();
6
- const {TEN_THOUSAND} = magnitude;
6
+ const { TEN_THOUSAND } = magnitude;
7
7
 
8
8
  suite
9
9
  .add(`${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
10
- const heap = new Heap<number>({comparator: (a, b) => b - a});
10
+ const heap = new Heap<number>({ comparator: (a, b) => b - a });
11
11
 
12
12
  for (let i = 0; i < TEN_THOUSAND; i++) {
13
13
  heap.add(i);
@@ -27,4 +27,4 @@ suite
27
27
  }
28
28
  });
29
29
 
30
- export {suite};
30
+ export { suite };
@@ -1,11 +1,11 @@
1
- import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src';
2
- import {LinkList as CLinkedList} from 'js-sdsl';
1
+ import { DoublyLinkedList, DoublyLinkedListNode } from '../../../../src';
2
+ import { LinkList as CLinkedList } from 'js-sdsl';
3
3
  import * as Benchmark from 'benchmark';
4
- import {magnitude} from '../../../utils';
5
- import {isCompetitor} from '../../../config';
4
+ import { magnitude } from '../../../utils';
5
+ import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const {LINEAR} = magnitude;
8
+ const { LINEAR } = magnitude;
9
9
 
10
10
  suite.add(`${LINEAR.toLocaleString()} unshift`, () => {
11
11
  const list = new DoublyLinkedList<number>();
@@ -15,7 +15,7 @@ suite.add(`${LINEAR.toLocaleString()} unshift`, () => {
15
15
  }
16
16
  });
17
17
  if (isCompetitor) {
18
- suite.add(`${LINEAR.toLocaleString()} competitor unshift`, () => {
18
+ suite.add(`${LINEAR.toLocaleString()} CPT unshift`, () => {
19
19
  const list = new CLinkedList<number>();
20
20
 
21
21
  for (let i = 0; i < LINEAR; i++) {
@@ -48,4 +48,4 @@ suite
48
48
  }
49
49
  });
50
50
 
51
- export {suite};
51
+ export { suite };
@@ -1,9 +1,9 @@
1
- import {SinglyLinkedList, SinglyLinkedListNode} from '../../../../src';
1
+ import { SinglyLinkedList, SinglyLinkedListNode } from '../../../../src';
2
2
  import * as Benchmark from 'benchmark';
3
- import {magnitude} from '../../../utils';
3
+ import { magnitude } from '../../../utils';
4
4
 
5
5
  const suite = new Benchmark.Suite();
6
- const {TEN_THOUSAND} = magnitude;
6
+ const { TEN_THOUSAND } = magnitude;
7
7
 
8
8
  suite
9
9
  .add(`${TEN_THOUSAND.toLocaleString()} push & pop`, () => {
@@ -31,4 +31,4 @@ suite
31
31
  }
32
32
  });
33
33
 
34
- export {suite};
34
+ export { suite };
@@ -1,12 +1,14 @@
1
- import {MaxPriorityQueue} from '../../../../src';
1
+ import { MaxPriorityQueue } from '../../../../src';
2
2
  import * as Benchmark from 'benchmark';
3
- import {magnitude} from '../../../utils';
3
+ import { magnitude } from '../../../utils';
4
4
 
5
5
  const suite = new Benchmark.Suite();
6
- const {TEN_THOUSAND} = magnitude;
6
+ const { TEN_THOUSAND } = magnitude;
7
7
 
8
8
  suite.add(`${TEN_THOUSAND.toLocaleString()} refill & poll`, () => {
9
- const nodes = Array.from(new Set<number>(Array.from(new Array(TEN_THOUSAND), () => Math.floor(Math.random() * TEN_THOUSAND * 100))));
9
+ const nodes = Array.from(
10
+ new Set<number>(Array.from(new Array(TEN_THOUSAND), () => Math.floor(Math.random() * TEN_THOUSAND * 100)))
11
+ );
10
12
  const maxPQ = new MaxPriorityQueue<number>();
11
13
  maxPQ.refill(nodes);
12
14
  while (maxPQ.size > 0) {
@@ -14,4 +16,4 @@ suite.add(`${TEN_THOUSAND.toLocaleString()} refill & poll`, () => {
14
16
  }
15
17
  });
16
18
 
17
- export {suite};
19
+ export { suite };
@@ -1,14 +1,14 @@
1
- import {PriorityQueue as CPriorityQueue} from 'js-sdsl';
2
- import {PriorityQueue} from '../../../../src';
1
+ import { PriorityQueue as CPriorityQueue } from 'js-sdsl';
2
+ import { PriorityQueue } from '../../../../src';
3
3
  import * as Benchmark from 'benchmark';
4
- import {magnitude} from '../../../utils';
5
- import {isCompetitor} from '../../../config';
4
+ import { magnitude } from '../../../utils';
5
+ import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const {TEN_THOUSAND} = magnitude;
8
+ const { TEN_THOUSAND } = magnitude;
9
9
 
10
10
  suite.add(`${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
11
- const pq = new PriorityQueue<number>({comparator: (a, b) => b - a});
11
+ const pq = new PriorityQueue<number>({ comparator: (a, b) => b - a });
12
12
 
13
13
  for (let i = 0; i < TEN_THOUSAND; i++) {
14
14
  pq.add(i);
@@ -19,7 +19,7 @@ suite.add(`${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
19
19
  }
20
20
  });
21
21
  if (isCompetitor) {
22
- suite.add(`${TEN_THOUSAND.toLocaleString()} competitor add & pop`, () => {
22
+ suite.add(`${TEN_THOUSAND.toLocaleString()} CPT add & pop`, () => {
23
23
  const pq = new CPriorityQueue<number>();
24
24
 
25
25
  for (let i = 0; i < TEN_THOUSAND; i++) {
@@ -32,4 +32,4 @@ if (isCompetitor) {
32
32
  });
33
33
  }
34
34
 
35
- export {suite};
35
+ export { suite };
@@ -1,11 +1,11 @@
1
- import {Deque} from '../../../../src';
2
- import {Deque as CDeque} from 'js-sdsl';
1
+ import { Deque } from '../../../../src';
2
+ import { Deque as CDeque } from 'js-sdsl';
3
3
  import * as Benchmark from 'benchmark';
4
- import {magnitude} from '../../../utils';
5
- import {isCompetitor} from '../../../config';
4
+ import { magnitude } from '../../../utils';
5
+ import { isCompetitor } from '../../../config';
6
6
 
7
7
  export const suite = new Benchmark.Suite();
8
- const {LINEAR} = magnitude;
8
+ const { LINEAR } = magnitude;
9
9
 
10
10
  suite.add(`${LINEAR.toLocaleString()} push`, () => {
11
11
  const deque = new Deque<number>();
@@ -14,7 +14,7 @@ suite.add(`${LINEAR.toLocaleString()} push`, () => {
14
14
  }
15
15
  });
16
16
  if (isCompetitor) {
17
- suite.add(`${LINEAR.toLocaleString()} competitor push`, () => {
17
+ suite.add(`${LINEAR.toLocaleString()} CPT push`, () => {
18
18
  const deque = new CDeque<number>();
19
19
  for (let i = 0; i < LINEAR; i++) {
20
20
  deque.pushBack(i);
@@ -1,11 +1,11 @@
1
- import {Queue} from '../../../../src';
2
- import {Queue as CQueue} from 'js-sdsl';
1
+ import { Queue } from '../../../../src';
2
+ import { Queue as CQueue } from 'js-sdsl';
3
3
  import * as Benchmark from 'benchmark';
4
- import {magnitude} from '../../../utils';
5
- import {isCompetitor} from '../../../config';
4
+ import { magnitude } from '../../../utils';
5
+ import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const {LINEAR} = magnitude;
8
+ const { LINEAR } = magnitude;
9
9
 
10
10
  suite.add(`${LINEAR.toLocaleString()} push`, () => {
11
11
  const queue = new Queue<number>();
@@ -15,7 +15,7 @@ suite.add(`${LINEAR.toLocaleString()} push`, () => {
15
15
  }
16
16
  });
17
17
  if (isCompetitor) {
18
- suite.add(`${LINEAR.toLocaleString()} competitor push`, () => {
18
+ suite.add(`${LINEAR.toLocaleString()} CPT push`, () => {
19
19
  const queue = new CQueue<number>();
20
20
 
21
21
  for (let i = 0; i < LINEAR; i++) {
@@ -32,4 +32,4 @@ suite.add(`${LINEAR.toLocaleString()} push & shift`, () => {
32
32
  }
33
33
  });
34
34
 
35
- export {suite};
35
+ export { suite };
@@ -1,11 +1,11 @@
1
- import {Stack} from '../../../../src';
2
- import {Stack as CStack} from 'js-sdsl';
1
+ import { Stack } from '../../../../src';
2
+ import { Stack as CStack } from 'js-sdsl';
3
3
  import * as Benchmark from 'benchmark';
4
- import {magnitude} from '../../../utils';
5
- import {isCompetitor} from '../../../config';
4
+ import { magnitude } from '../../../utils';
5
+ import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const {LINEAR} = magnitude;
8
+ const { LINEAR } = magnitude;
9
9
 
10
10
  suite.add(`${LINEAR.toLocaleString()} push`, () => {
11
11
  const stack = new Stack<number>();
@@ -15,7 +15,7 @@ suite.add(`${LINEAR.toLocaleString()} push`, () => {
15
15
  }
16
16
  });
17
17
  if (isCompetitor) {
18
- suite.add(`${LINEAR.toLocaleString()} competitor push`, () => {
18
+ suite.add(`${LINEAR.toLocaleString()} CPT push`, () => {
19
19
  const queue = new CStack<number>();
20
20
 
21
21
  for (let i = 0; i < LINEAR; i++) {
@@ -34,7 +34,7 @@ suite.add(`${LINEAR.toLocaleString()} push & pop`, () => {
34
34
  }
35
35
  });
36
36
  if (isCompetitor) {
37
- suite.add(`${LINEAR.toLocaleString()} competitor push & pop`, () => {
37
+ suite.add(`${LINEAR.toLocaleString()} CPT push & pop`, () => {
38
38
  const queue = new CStack<number>();
39
39
 
40
40
  for (let i = 0; i < LINEAR; i++) {
@@ -46,4 +46,4 @@ if (isCompetitor) {
46
46
  });
47
47
  }
48
48
 
49
- export {suite};
49
+ export { suite };
@@ -1,9 +1,9 @@
1
- import {Trie} from '../../../../src';
1
+ import { Trie } from '../../../../src';
2
2
  import * as Benchmark from 'benchmark';
3
- import {getRandomWords, magnitude} from '../../../utils';
3
+ import { getRandomWords, magnitude } from '../../../utils';
4
4
 
5
5
  const suite = new Benchmark.Suite();
6
- const {HUNDRED_THOUSAND} = magnitude;
6
+ const { HUNDRED_THOUSAND } = magnitude;
7
7
  const trie = new Trie();
8
8
  const randomWords = getRandomWords(HUNDRED_THOUSAND, false);
9
9
 
@@ -19,4 +19,4 @@ suite
19
19
  }
20
20
  });
21
21
 
22
- export {suite};
22
+ export { suite };
@@ -2,31 +2,59 @@ import * as Benchmark from 'benchmark';
2
2
  import * as path from 'path';
3
3
  import * as fs from 'fs';
4
4
  import * as fastGlob from 'fast-glob';
5
- import {Color, numberFix, render} from '../utils';
6
- import {PerformanceTest} from './types';
5
+ import { Color, numberFix, render } from '../utils';
6
+ import { PerformanceTest } from './types';
7
+
8
+
9
+ const args = process.argv.slice(2);
10
+
11
+ const { GREEN, BOLD, END, YELLOW, GRAY, CYAN, BG_YELLOW } = Color;
12
+
13
+ const getRelativePath = (file: string) => {
14
+ return path.relative(__dirname, file);
15
+ }
16
+ const coloredLabeled = (label: string, file: string) => {
17
+ const relativeFilePath = getRelativePath(file);
18
+ const directory = path.dirname(relativeFilePath);
19
+ const fileName = path.basename(relativeFilePath);
20
+ return `${BG_YELLOW} ${label} ${END} ${GRAY}${directory}/${END}${CYAN}${fileName}${END}`;
21
+ }
7
22
 
8
23
  const parentDirectory = path.resolve(__dirname, '../..');
9
24
  const reportDistPath = path.join(parentDirectory, 'benchmark');
10
25
 
11
26
  const testDir = path.join(__dirname, 'data-structures');
12
- const testFiles = fastGlob.sync(path.join(testDir, '**', '*.test.ts'));
27
+ const allFiles = fastGlob.sync(path.join(testDir, '**', '*.test.ts'));
28
+ let testFiles: string[] = [];
29
+ if (args.length > 0) {
30
+ console.log(`arguments: ${args.join(' ')}`)
31
+
32
+ testFiles = allFiles.filter(file =>
33
+ args.every(word => file.includes(word))
34
+ );
35
+
36
+ console.log(`${testFiles.map(file => coloredLabeled('Matched', file)).join(`
37
+ `)}`);
38
+ } else {
39
+ testFiles = allFiles;
40
+ }
13
41
 
14
- const report: {[key: string]: any} = {};
42
+
43
+ const report: { [key: string]: any } = {};
15
44
 
16
45
  let completedCount = 0;
17
46
 
18
47
  const performanceTests: PerformanceTest[] = [];
19
- const {GREEN, BOLD, END, YELLOW, GRAY, CYAN, BG_YELLOW} = Color;
20
48
 
21
49
  testFiles.forEach((file: string) => {
22
50
  const testName = path.basename(file, '.test.ts');
23
51
  const testFunction = require(file);
24
- const {suite} = testFunction;
25
- if (suite) performanceTests.push({testName, suite, file});
52
+ const { suite } = testFunction;
53
+ if (suite) performanceTests.push({ testName, suite, file });
26
54
  });
27
55
 
28
56
  const composeReport = () => {
29
- if (!fs.existsSync(reportDistPath)) fs.mkdirSync(reportDistPath, {recursive: true});
57
+ if (!fs.existsSync(reportDistPath)) fs.mkdirSync(reportDistPath, { recursive: true });
30
58
 
31
59
  const filePath = path.join(reportDistPath, 'report.json');
32
60
  const htmlFilePath = path.join(reportDistPath, 'report.html');
@@ -85,9 +113,9 @@ const composeReport = () => {
85
113
  {
86
114
  '<>': 'tr',
87
115
  html: [
88
- {'<>': 'td', html: '${name}'},
89
- {'<>': 'td', html: '${periodMS}'},
90
- {'<>': 'td', html: '${mean}'}
116
+ { '<>': 'td', html: '${name}' },
117
+ { '<>': 'td', html: '${periodMS}' },
118
+ { '<>': 'td', html: '${mean}' }
91
119
  ]
92
120
  }
93
121
  ]
@@ -107,7 +135,7 @@ const composeReport = () => {
107
135
  htmlTables // New content to be inserted
108
136
  );
109
137
  fs.writeFileSync(htmlFilePath, html);
110
- console.log(`Performance ${BOLD}${GREEN}report${END} file generated in ${BOLD}${GREEN}${reportDistPath}${END}`);
138
+ console.log(`Performance ${BOLD}${GREEN}report${END} file generated in file://${BOLD}${GREEN}${htmlFilePath}${END}`);
111
139
  };
112
140
 
113
141
  function replaceMarkdownContent(startMarker: string, endMarker: string, newText: string) {
@@ -135,18 +163,16 @@ function replaceMarkdownContent(startMarker: string, endMarker: string, newText:
135
163
  if (err) {
136
164
  console.error(`Unable to write to ${filePath}:`, err);
137
165
  } else {
138
- console.log(`The content has been successfully replaced in ${BOLD}${GREEN}${filePath}!${END}`);
166
+ console.log(`The content has been successfully replaced in file://${BOLD}${GREEN}${filePath}${END}`);
139
167
  }
140
168
  });
141
169
  });
142
170
  }
143
171
 
144
172
  performanceTests.forEach(item => {
145
- const {suite, testName, file} = item;
146
- const relativeFilePath = path.relative(__dirname, file);
147
- const directory = path.dirname(relativeFilePath);
148
- const fileName = path.basename(relativeFilePath);
149
- console.log(`${BG_YELLOW} Running ${END} ${GRAY}${directory}/${END}${CYAN}${fileName}${END}`);
173
+ const { suite, testName, file } = item;
174
+
175
+ console.log(coloredLabeled('Running', file));
150
176
 
151
177
  if (suite) {
152
178
  let runTime = 0;
@@ -173,13 +199,15 @@ performanceTests.forEach(item => {
173
199
  console.log(
174
200
  // `Files: ${GREEN}${testFileCount}${END} `,
175
201
  // `Suites: ${GREEN}${performanceTests.length}${END} `,
176
- `Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${performanceTests.length}${END}`,
202
+ `Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${
203
+ performanceTests.length
204
+ }${END}`,
177
205
  `Time: ${isTimeWarn ? YELLOW : GREEN}${runTime}s${END}`
178
206
  );
179
207
  if (isDone) {
180
208
  composeReport();
181
209
  }
182
210
  })
183
- .run({async: false});
211
+ .run({ async: false });
184
212
  }
185
213
  });
@@ -1,3 +1,3 @@
1
1
  import * as Benchmark from 'benchmark';
2
2
 
3
- export type PerformanceTest = {testName: string; suite: Benchmark.Suite; file: string};
3
+ export type PerformanceTest = { testName: string; suite: Benchmark.Suite; file: string };
@@ -1 +1 @@
1
- export type Json2htmlOptions = {plainHtml?: boolean} & Partial<{[key: string]: any}>;
1
+ export type Json2htmlOptions = { plainHtml?: boolean } & Partial<{ [key: string]: any }>;
@@ -1,4 +1,4 @@
1
- import {AVLTree, AVLTreeNode, CP, IterationType} from '../../../../src';
1
+ import { AVLTree, AVLTreeNode, CP, IterationType } from '../../../../src';
2
2
 
3
3
  describe('AVL Tree Test', () => {
4
4
  it('should perform various operations on a AVL Tree', () => {
@@ -112,7 +112,7 @@ describe('AVL Tree Test', () => {
112
112
  describe('AVL Tree Test recursively', () => {
113
113
  it('should perform various operations on a AVL Tree', () => {
114
114
  const arr = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5];
115
- const tree = new AVLTree<number>({iterationType: IterationType.RECURSIVE});
115
+ const tree = new AVLTree<number>({ iterationType: IterationType.RECURSIVE });
116
116
 
117
117
  for (const i of arr) tree.add(i, i);
118
118
 
@@ -228,9 +228,9 @@ describe('AVLTree APIs test', () => {
228
228
  avl.add(1);
229
229
  const node2 = new AVLTreeNode(2);
230
230
  avl.add(node2);
231
- const node3 = new AVLTreeNode(3, {id: 3, text: 'text3'});
231
+ const node3 = new AVLTreeNode(3, { id: 3, text: 'text3' });
232
232
  avl.add(node3);
233
- avl.add(node3, {id: 3, text: 'text33'});
233
+ avl.add(node3, { id: 3, text: 'text33' });
234
234
 
235
235
  const bfsRes = avl.bfs(node => node.key);
236
236
  expect(bfsRes[0]).toBe(2);
@@ -277,9 +277,9 @@ describe('AVLTree', () => {
277
277
  avl.add(1);
278
278
  const node2 = new AVLTreeNode(2);
279
279
  avl.add(node2);
280
- const node3 = new AVLTreeNode(3, {id: 3, text: 'text3'});
280
+ const node3 = new AVLTreeNode(3, { id: 3, text: 'text3' });
281
281
  avl.add(node3);
282
- avl.add(node3, {id: 3, text: 'text33'});
282
+ avl.add(node3, { id: 3, text: 'text33' });
283
283
 
284
284
  const bfsRes = avl.bfs(node => node);
285
285
  expect(bfsRes[0]?.key).toBe(2);
@@ -1,4 +1,4 @@
1
- import {BinaryIndexedTree} from '../../../../src';
1
+ import { BinaryIndexedTree } from '../../../../src';
2
2
  // import {isDebugTest} from '../../../config';
3
3
 
4
4
  // const isDebug = isDebugTest;
@@ -8,13 +8,13 @@ describe('BinaryIndexedTree simple', () => {
8
8
 
9
9
  beforeEach(() => {
10
10
  //Create a new BinaryIndexedTree instance before each test case
11
- bit = new BinaryIndexedTree({frequency: 0, max: 10}); // Modify the value of max as needed
11
+ bit = new BinaryIndexedTree({ frequency: 0, max: 10 }); // Modify the value of max as needed
12
12
  });
13
13
 
14
14
  it('should initialize correctly', () => {
15
15
  expect(bit.freq).toBe(0);
16
16
  expect(bit.max).toBe(10);
17
- expect(bit.freqMap).toEqual({0: 0}); // Modify the initialized record value according to the actual situation
17
+ expect(bit.freqMap).toEqual({ 0: 0 }); // Modify the initialized record value according to the actual situation
18
18
  // More initialization checks can be added
19
19
  });
20
20
 
@@ -54,7 +54,7 @@ describe('BinaryIndexedTree', () => {
54
54
  let bit: BinaryIndexedTree;
55
55
 
56
56
  beforeEach(function () {
57
- bit = new BinaryIndexedTree({frequency, max});
57
+ bit = new BinaryIndexedTree({ frequency, max });
58
58
  });
59
59
  it('should validate the index', function () {
60
60
  expect(() => bit.readSingle(-1)).toThrow('Index out of range');
@@ -73,7 +73,7 @@ describe('BinaryIndexedTree', () => {
73
73
  it('should frequency and max', function () {
74
74
  const frequency = 200;
75
75
  const max = 1000;
76
- const bit = new BinaryIndexedTree({frequency, max});
76
+ const bit = new BinaryIndexedTree({ frequency, max });
77
77
 
78
78
  expect(bit.freq).toBe(frequency);
79
79
  expect(bit.max).toBe(max);
@@ -123,7 +123,7 @@ describe('designated values', function () {
123
123
  let bit: BinaryIndexedTree;
124
124
 
125
125
  beforeEach(function () {
126
- bit = new BinaryIndexedTree({max: array.length});
126
+ bit = new BinaryIndexedTree({ max: array.length });
127
127
  array.forEach((value, i) => bit.writeSingle(i, value));
128
128
  });
129
129
 
@@ -182,7 +182,7 @@ describe('descending sequence', function () {
182
182
  let bit: BinaryIndexedTree;
183
183
 
184
184
  beforeEach(function () {
185
- bit = new BinaryIndexedTree({max: array.length});
185
+ bit = new BinaryIndexedTree({ max: array.length });
186
186
  array.forEach((value, i) => bit.writeSingle(i, value));
187
187
  });
188
188
 
@@ -219,7 +219,7 @@ describe('descending sequence', function () {
219
219
 
220
220
  describe('BinaryIndexedTree additional tests', () => {
221
221
  it('should handle read method correctly', () => {
222
- const bit = new BinaryIndexedTree({max: 10});
222
+ const bit = new BinaryIndexedTree({ max: 10 });
223
223
  bit.writeSingle(2, 10);
224
224
  bit.writeSingle(5, 20);
225
225
  bit.writeSingle(8, 30);
@@ -227,7 +227,7 @@ describe('BinaryIndexedTree additional tests', () => {
227
227
  });
228
228
 
229
229
  it('should handle consecutive operations', () => {
230
- const bit = new BinaryIndexedTree({max: 10});
230
+ const bit = new BinaryIndexedTree({ max: 10 });
231
231
  bit.writeSingle(2, 10);
232
232
  bit.update(2, 5);
233
233
  expect(bit.readSingle(2)).toBe(15);
@@ -237,7 +237,7 @@ describe('BinaryIndexedTree additional tests', () => {
237
237
  });
238
238
 
239
239
  it('should handle frequent increment updates', () => {
240
- const bit = new BinaryIndexedTree({max: 10});
240
+ const bit = new BinaryIndexedTree({ max: 10 });
241
241
  for (let i = 0; i < 10; i++) {
242
242
  bit.update(2, 5);
243
243
  }
@@ -245,7 +245,7 @@ describe('BinaryIndexedTree additional tests', () => {
245
245
  });
246
246
 
247
247
  it('should handle edge cases', () => {
248
- const bit = new BinaryIndexedTree({max: 10});
248
+ const bit = new BinaryIndexedTree({ max: 10 });
249
249
  bit.writeSingle(9, 100);
250
250
  expect(bit.readSingle(9)).toBe(100);
251
251
  expect(bit.lowerBound(200)).toBe(10);
@@ -291,7 +291,7 @@ describe('', () => {
291
291
 
292
292
  constructor(nums: number[]) {
293
293
  this._nums = nums;
294
- this._tree = new BinaryIndexedTree({max: nums.length + 1});
294
+ this._tree = new BinaryIndexedTree({ max: nums.length + 1 });
295
295
  for (let i = 0; i < nums.length; i++) {
296
296
  this._tree.update(i + 1, nums[i]);
297
297
  }