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.
Files changed (154) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -3
  3. package/README_zh-CN.md +1 -1
  4. package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
  5. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -13
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -49
  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.d.ts +0 -16
  13. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +1 -43
  14. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  15. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -1
  16. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -2
  17. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  18. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  19. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  21. package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
  22. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  23. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  24. package/dist/cjs/data-structures/heap/heap.js +2 -3
  25. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  26. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  27. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  28. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  29. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  30. package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
  31. package/dist/cjs/data-structures/matrix/index.js +0 -2
  32. package/dist/cjs/data-structures/matrix/index.js.map +1 -1
  33. package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
  34. package/dist/cjs/data-structures/matrix/matrix.js +400 -15
  35. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  36. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  37. package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
  38. package/dist/cjs/data-structures/queue/deque.js +5 -7
  39. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  40. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  41. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  42. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  43. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  44. package/dist/cjs/utils/utils.d.ts +1 -0
  45. package/dist/cjs/utils/utils.js +6 -1
  46. package/dist/cjs/utils/utils.js.map +1 -1
  47. package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
  48. package/dist/mjs/data-structures/binary-tree/avl-tree.js +2 -1
  49. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -13
  50. package/dist/mjs/data-structures/binary-tree/binary-tree.js +20 -50
  51. package/dist/mjs/data-structures/binary-tree/bst.js +2 -1
  52. package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -1
  53. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
  54. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -44
  55. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
  56. package/dist/mjs/data-structures/graph/abstract-graph.js +4 -3
  57. package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
  58. package/dist/mjs/data-structures/hash/hash-map.js +2 -2
  59. package/dist/mjs/data-structures/heap/heap.js +2 -3
  60. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  61. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
  62. package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
  63. package/dist/mjs/data-structures/matrix/index.js +0 -2
  64. package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
  65. package/dist/mjs/data-structures/matrix/matrix.js +399 -16
  66. package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
  67. package/dist/mjs/data-structures/queue/deque.js +7 -9
  68. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  69. package/dist/mjs/data-structures/queue/queue.js +1 -1
  70. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  71. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  72. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  73. package/dist/mjs/utils/utils.d.ts +1 -0
  74. package/dist/mjs/utils/utils.js +4 -0
  75. package/dist/umd/data-structure-typed.js +356 -524
  76. package/dist/umd/data-structure-typed.min.js +2 -2
  77. package/dist/umd/data-structure-typed.min.js.map +1 -1
  78. package/package.json +4 -3
  79. package/src/data-structures/base/index.ts +1 -1
  80. package/src/data-structures/base/iterable-base.ts +7 -10
  81. package/src/data-structures/binary-tree/avl-tree.ts +15 -8
  82. package/src/data-structures/binary-tree/binary-tree.ts +57 -74
  83. package/src/data-structures/binary-tree/bst.ts +16 -13
  84. package/src/data-structures/binary-tree/rb-tree.ts +16 -10
  85. package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
  86. package/src/data-structures/graph/abstract-graph.ts +13 -11
  87. package/src/data-structures/graph/directed-graph.ts +1 -3
  88. package/src/data-structures/graph/map-graph.ts +6 -1
  89. package/src/data-structures/graph/undirected-graph.ts +3 -6
  90. package/src/data-structures/hash/hash-map.ts +18 -16
  91. package/src/data-structures/heap/heap.ts +7 -10
  92. package/src/data-structures/heap/max-heap.ts +2 -1
  93. package/src/data-structures/heap/min-heap.ts +2 -1
  94. package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
  95. package/src/data-structures/matrix/index.ts +0 -2
  96. package/src/data-structures/matrix/matrix.ts +442 -13
  97. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  98. package/src/data-structures/queue/deque.ts +18 -39
  99. package/src/data-structures/queue/queue.ts +1 -1
  100. package/src/interfaces/binary-tree.ts +7 -2
  101. package/src/types/common.ts +4 -4
  102. package/src/types/data-structures/base/base.ts +14 -3
  103. package/src/types/data-structures/base/index.ts +1 -1
  104. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  105. package/src/types/data-structures/hash/hash-map.ts +3 -3
  106. package/src/types/data-structures/heap/heap.ts +2 -2
  107. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  108. package/src/utils/utils.ts +7 -1
  109. package/test/integration/avl-tree.test.ts +18 -1
  110. package/test/integration/bst.test.ts +2 -2
  111. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +1 -1
  112. package/test/performance/data-structures/comparison/comparison.test.ts +6 -11
  113. package/test/performance/data-structures/hash/hash-map.test.ts +3 -4
  114. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -1
  115. package/test/performance/data-structures/queue/deque.test.ts +6 -7
  116. package/test/performance/data-structures/queue/queue.test.ts +10 -9
  117. package/test/performance/reportor.ts +14 -15
  118. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
  119. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +59 -24
  120. package/test/unit/data-structures/binary-tree/bst.test.ts +52 -26
  121. package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
  122. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
  123. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
  124. package/test/unit/data-structures/graph/directed-graph.test.ts +104 -45
  125. package/test/unit/data-structures/graph/undirected-graph.test.ts +57 -40
  126. package/test/unit/data-structures/hash/hash-map.test.ts +48 -28
  127. package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
  128. package/test/unit/data-structures/heap/heap.test.ts +0 -1
  129. package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
  130. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +10 -11
  131. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
  132. package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
  133. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  134. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
  135. package/test/unit/data-structures/queue/deque.test.ts +0 -6
  136. package/test/unit/data-structures/queue/queue.test.ts +1 -1
  137. package/test/unit/data-structures/stack/stack.test.ts +3 -4
  138. package/test/unit/unrestricted-interconversion.test.ts +50 -44
  139. package/test/utils/performanc.ts +1 -1
  140. package/typedoc.json +30 -0
  141. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
  142. package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
  143. package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
  144. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
  145. package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
  146. package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
  147. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
  148. package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
  149. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
  150. package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
  151. package/src/data-structures/matrix/matrix2d.ts +0 -211
  152. package/src/data-structures/matrix/vector2d.ts +0 -315
  153. package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
  154. package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
@@ -1,6 +1,17 @@
1
- import { IterableElementBase, IterableEntryBase } from "../../../data-structures";
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> = (accumulator: R, value: V, key: K, index: number, container: IterableEntryBase<K, V>) => R;
6
- export type ReduceElementCallback<V, R> = (accumulator: R, element: V, index: number, container: IterableElementBase<V>) => R;
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
- } | undefined;
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, value: V };
13
+ export type HashMapStoreItem<K, V> = { key: K; value: V };
@@ -1,3 +1,3 @@
1
- import { Comparator } from "../../common";
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 "../heap";
1
+ import { HeapOptions } from '../heap';
2
2
 
3
- export type PriorityQueueOptions<T> = HeapOptions<T> & {}
3
+ export type PriorityQueueOptions<T> = HeapOptions<T> & {};
@@ -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) => Math.floor((totalQuantity + unitSize - 1) / unitSize)
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][] = [[11, 11], [3, 3], [15, 15], [1, 1], [8, 8], [13, 13], [16, 16], [2, 2], [6, 6], [9, 9], [12, 12], [14, 14], [4, 4], [7, 7], [10, 10], [5, 5]];
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, false);
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, false);
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.add(`CPT PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
72
- const pq = new CPriorityQueue<number>();
65
+ suite
66
+ .add(`CPT PQ ${TEN_THOUSAND.toLocaleString()} add & pop`, () => {
67
+ const pq = new CPriorityQueue<number>();
73
68
 
74
- for (let i = 0; i < TEN_THOUSAND; i++) pq.push(i);
75
- for (let i = 0; i < TEN_THOUSAND; i++) pq.pop();
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++) {
@@ -13,7 +13,6 @@ suite.add(`${MILLION.toLocaleString()} push`, () => {
13
13
  for (let i = 0; i < MILLION; i++) list.push(i);
14
14
  });
15
15
 
16
-
17
16
  if (isCompetitor) {
18
17
  suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
19
18
  const list = new CLinkedList<number>();
@@ -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
- suite.add(`${MILLION.toLocaleString()} push & pop`, () => {
24
- const _deque = new Deque<number>();
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.add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
37
- const arr = new Array<number>();
36
+ suite
37
+ .add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
38
+ const arr = new Array<number>();
38
39
 
39
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
40
- arr.push(i);
41
- }
42
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
43
- arr.shift();
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(`${testFiles.map(file => coloredLabeled('Matched', file)).join(`
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) replaceMarkdownContent(
136
- '[//]: # (No deletion!!! Start of Replace Section)', // Start tag
137
- '[//]: # (No deletion!!! End of Replace Section)', // end identifier
138
- htmlTables // New content to be inserted
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([[2, 'b'], [3, 'c']]);
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([[1, '2'], [2, '4'], [3, '6']]);
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([[1, 'a'], [2, 'b'], [3, 'c']]);
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([-10, 9, 20, null, null, 15, 7, 8, null, 2, null, 6, null, null])
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', (node) => node.value);
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([[3, "B"], [5, "A"], [7, "C"]]);
560
+ expect([...tree]).toEqual([
561
+ [3, 'B'],
562
+ [5, 'A'],
563
+ [7, 'C']
564
+ ]);
552
565
  tree.iterationType = IterationType.RECURSIVE;
553
- expect([...tree]).toEqual([[3, "B"], [5, "A"], [7, "C"]]);
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([[3, 'c'], [2, 'b']]);
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([[1, '2'], [2, '4'], [3, '6']]);
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([[2, 'b'], [1, 'a'], [3, 'c']]);
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, 9,
649
- 20, undefined,
650
- undefined, 15,
651
- 7, 8,
652
- undefined, 2,
653
- undefined, 6,
654
- undefined, undefined
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][] = [[15, 15], [1, 1], [8, 8], [13, 13], [16, 16], [2, 2], [6, 6], [9, 9], [12, 12], [14, 14], [4, 4], [7, 7], [10, 10], [5, 5]];
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([15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5], [
198
- { "name": "Alice", "age": 15 },
199
- { "name": "Bob", "age": 1 },
200
- { "name": "Charlie", "age": 8 },
201
- { "name": "David", "age": 13 },
202
- { "name": "Emma", "age": 16 },
203
- { "name": "Frank", "age": 2 },
204
- { "name": "Grace", "age": 6 },
205
- { "name": "Hannah", "age": 9 },
206
- { "name": "Isaac", "age": 12 },
207
- { "name": "Jack", "age": 14 },
208
- { "name": "Katie", "age": 4 },
209
- { "name": "Liam", "age": 7 },
210
- { "name": "Mia", "age": 10 },
211
- { "name": "Noah", "age": 5 }
212
- ], false);
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([[2, 'b'], [3, 'c']]);
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([[1, '2'], [2, '4'], [3, '6']]);
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([[1, 'a'], [2, 'b'], [3, 'c']]);
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
+ });