data-structure-typed 1.49.3 → 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 (162) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +70 -69
  3. package/README_zh-CN.md +44 -49
  4. package/benchmark/report.html +16 -16
  5. package/benchmark/report.json +187 -187
  6. package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
  7. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +2 -14
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -49
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
  15. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +1 -43
  16. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  17. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -11
  18. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -19
  19. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/directed-graph.js +4 -0
  21. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  22. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  24. package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
  25. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  26. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  27. package/dist/cjs/data-structures/heap/heap.js +2 -3
  28. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  29. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  30. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  31. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  32. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  33. package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
  34. package/dist/cjs/data-structures/matrix/index.js +0 -2
  35. package/dist/cjs/data-structures/matrix/index.js.map +1 -1
  36. package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
  37. package/dist/cjs/data-structures/matrix/matrix.js +400 -15
  38. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  39. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  40. package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
  41. package/dist/cjs/data-structures/queue/deque.js +5 -7
  42. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  43. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  44. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  45. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  46. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  47. package/dist/cjs/utils/utils.d.ts +1 -0
  48. package/dist/cjs/utils/utils.js +6 -1
  49. package/dist/cjs/utils/utils.js.map +1 -1
  50. package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
  51. package/dist/mjs/data-structures/binary-tree/avl-tree.js +2 -1
  52. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +2 -14
  53. package/dist/mjs/data-structures/binary-tree/binary-tree.js +20 -50
  54. package/dist/mjs/data-structures/binary-tree/bst.js +2 -1
  55. package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -1
  56. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
  57. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -44
  58. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -11
  59. package/dist/mjs/data-structures/graph/abstract-graph.js +4 -20
  60. package/dist/mjs/data-structures/graph/directed-graph.js +4 -0
  61. package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
  62. package/dist/mjs/data-structures/hash/hash-map.js +2 -2
  63. package/dist/mjs/data-structures/heap/heap.js +2 -3
  64. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  65. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
  66. package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
  67. package/dist/mjs/data-structures/matrix/index.js +0 -2
  68. package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
  69. package/dist/mjs/data-structures/matrix/matrix.js +399 -16
  70. package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
  71. package/dist/mjs/data-structures/queue/deque.js +7 -9
  72. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  73. package/dist/mjs/data-structures/queue/queue.js +1 -1
  74. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  75. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  76. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  77. package/dist/mjs/utils/utils.d.ts +1 -0
  78. package/dist/mjs/utils/utils.js +4 -0
  79. package/dist/umd/data-structure-typed.js +361 -542
  80. package/dist/umd/data-structure-typed.min.js +2 -2
  81. package/dist/umd/data-structure-typed.min.js.map +1 -1
  82. package/package.json +4 -3
  83. package/src/data-structures/base/index.ts +1 -1
  84. package/src/data-structures/base/iterable-base.ts +7 -10
  85. package/src/data-structures/binary-tree/avl-tree.ts +15 -8
  86. package/src/data-structures/binary-tree/binary-tree.ts +57 -74
  87. package/src/data-structures/binary-tree/bst.ts +16 -13
  88. package/src/data-structures/binary-tree/rb-tree.ts +16 -10
  89. package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
  90. package/src/data-structures/graph/abstract-graph.ts +14 -24
  91. package/src/data-structures/graph/directed-graph.ts +8 -6
  92. package/src/data-structures/graph/map-graph.ts +6 -1
  93. package/src/data-structures/graph/undirected-graph.ts +4 -7
  94. package/src/data-structures/hash/hash-map.ts +18 -16
  95. package/src/data-structures/heap/heap.ts +7 -10
  96. package/src/data-structures/heap/max-heap.ts +2 -1
  97. package/src/data-structures/heap/min-heap.ts +2 -1
  98. package/src/data-structures/linked-list/singly-linked-list.ts +3 -5
  99. package/src/data-structures/matrix/index.ts +0 -2
  100. package/src/data-structures/matrix/matrix.ts +442 -13
  101. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  102. package/src/data-structures/queue/deque.ts +18 -39
  103. package/src/data-structures/queue/queue.ts +1 -1
  104. package/src/interfaces/binary-tree.ts +7 -2
  105. package/src/types/common.ts +4 -4
  106. package/src/types/data-structures/base/base.ts +14 -3
  107. package/src/types/data-structures/base/index.ts +1 -1
  108. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  109. package/src/types/data-structures/hash/hash-map.ts +3 -3
  110. package/src/types/data-structures/heap/heap.ts +2 -2
  111. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  112. package/src/utils/utils.ts +7 -1
  113. package/test/integration/avl-tree.test.ts +18 -1
  114. package/test/integration/bst.test.ts +2 -2
  115. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +1 -1
  116. package/test/performance/data-structures/comparison/comparison.test.ts +18 -23
  117. package/test/performance/data-structures/hash/hash-map.test.ts +3 -4
  118. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +16 -28
  119. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -12
  120. package/test/performance/data-structures/queue/deque.test.ts +11 -12
  121. package/test/performance/data-structures/queue/queue.test.ts +15 -14
  122. package/test/performance/data-structures/stack/stack.test.ts +11 -11
  123. package/test/performance/reportor.ts +14 -15
  124. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
  125. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +65 -15
  126. package/test/unit/data-structures/binary-tree/bst.test.ts +52 -26
  127. package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
  128. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
  129. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
  130. package/test/unit/data-structures/graph/abstract-graph.test.ts +11 -0
  131. package/test/unit/data-structures/graph/directed-graph.test.ts +112 -40
  132. package/test/unit/data-structures/graph/undirected-graph.test.ts +63 -33
  133. package/test/unit/data-structures/hash/hash-map.test.ts +64 -23
  134. package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
  135. package/test/unit/data-structures/heap/heap.test.ts +0 -1
  136. package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
  137. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -4
  138. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
  139. package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
  140. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  141. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
  142. package/test/unit/data-structures/queue/deque.test.ts +0 -6
  143. package/test/unit/data-structures/queue/queue.test.ts +1 -1
  144. package/test/unit/data-structures/stack/stack.test.ts +3 -4
  145. package/test/unit/unrestricted-interconversion.test.ts +50 -44
  146. package/test/utils/big-o.ts +14 -14
  147. package/test/utils/performanc.ts +1 -1
  148. package/typedoc.json +30 -0
  149. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
  150. package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
  151. package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
  152. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
  153. package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
  154. package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
  155. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
  156. package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
  157. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
  158. package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
  159. package/src/data-structures/matrix/matrix2d.ts +0 -211
  160. package/src/data-structures/matrix/vector2d.ts +0 -315
  161. package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
  162. 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 };
@@ -16,31 +16,26 @@ import { getRandomIntArray, magnitude } from '../../../utils';
16
16
  import { isCompetitor } from '../../../config';
17
17
 
18
18
  const suite = new Benchmark.Suite();
19
- const { TEN_THOUSAND, HUNDRED_THOUSAND, LINEAR } = magnitude;
19
+ const { TEN_THOUSAND, HUNDRED_THOUSAND, MILLION } = magnitude;
20
20
  const cOrderedMap = new OrderedMap<number, number>();
21
21
  const arrHundredThousand = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND, true);
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]);
@@ -96,10 +91,10 @@ if (isCompetitor) {
96
91
  hm.getElementByKey(i);
97
92
  }
98
93
  })
99
- .add(`CPT LL ${LINEAR.toLocaleString()} unshift`, () => {
94
+ .add(`CPT LL ${MILLION.toLocaleString()} unshift`, () => {
100
95
  const list = new CLinkedList<number>();
101
96
 
102
- for (let i = 0; i < LINEAR; i++) {
97
+ for (let i = 0; i < MILLION; i++) {
103
98
  list.pushFront(i);
104
99
  }
105
100
  })
@@ -114,33 +109,33 @@ if (isCompetitor) {
114
109
  pq.pop();
115
110
  }
116
111
  })
117
- .add(`CPT DQ ${LINEAR.toLocaleString()} push`, () => {
112
+ .add(`CPT DQ ${MILLION.toLocaleString()} push`, () => {
118
113
  const deque = new CDeque<number>();
119
- for (let i = 0; i < LINEAR; i++) {
114
+ for (let i = 0; i < MILLION; i++) {
120
115
  deque.pushBack(i);
121
116
  }
122
117
  })
123
- .add(`CPT Q ${LINEAR.toLocaleString()} push`, () => {
118
+ .add(`CPT Q ${MILLION.toLocaleString()} push`, () => {
124
119
  const queue = new CQueue<number>();
125
120
 
126
- for (let i = 0; i < LINEAR; i++) {
121
+ for (let i = 0; i < MILLION; i++) {
127
122
  queue.push(i);
128
123
  }
129
124
  })
130
- .add(`CPT ST ${LINEAR.toLocaleString()} push`, () => {
125
+ .add(`CPT ST ${MILLION.toLocaleString()} push`, () => {
131
126
  const queue = new CStack<number>();
132
127
 
133
- for (let i = 0; i < LINEAR; i++) {
128
+ for (let i = 0; i < MILLION; i++) {
134
129
  queue.push(i);
135
130
  }
136
131
  })
137
- .add(`CPT ST ${LINEAR.toLocaleString()} push & pop`, () => {
132
+ .add(`CPT ST ${MILLION.toLocaleString()} push & pop`, () => {
138
133
  const queue = new CStack<number>();
139
134
 
140
- for (let i = 0; i < LINEAR; i++) {
135
+ for (let i = 0; i < MILLION; i++) {
141
136
  queue.push(i);
142
137
  }
143
- for (let i = 0; i < LINEAR; i++) {
138
+ for (let i = 0; i < MILLION; i++) {
144
139
  queue.pop();
145
140
  }
146
141
  });
@@ -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++) {
@@ -5,61 +5,49 @@ import { magnitude } from '../../../utils';
5
5
  import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const { LINEAR } = magnitude;
8
+ const { MILLION } = magnitude;
9
9
 
10
- suite.add(`${LINEAR.toLocaleString()} push`, () => {
10
+ suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const list = new DoublyLinkedList<number>();
12
12
 
13
- for (let i = 0; i < LINEAR; i++) {
14
- list.push(i);
15
- }
13
+ for (let i = 0; i < MILLION; i++) list.push(i);
16
14
  });
17
15
 
18
-
19
16
  if (isCompetitor) {
20
- suite.add(`CPT ${LINEAR.toLocaleString()} push`, () => {
17
+ suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
21
18
  const list = new CLinkedList<number>();
22
19
 
23
- for (let i = 0; i < LINEAR; i++) {
24
- list.pushBack(i);
25
- }
20
+ for (let i = 0; i < MILLION; i++) list.pushBack(i);
26
21
  });
27
22
  }
28
23
 
29
- suite.add(`${LINEAR.toLocaleString()} unshift`, () => {
24
+ suite.add(`${MILLION.toLocaleString()} unshift`, () => {
30
25
  const list = new DoublyLinkedList<number>();
31
26
 
32
- for (let i = 0; i < LINEAR; i++) {
33
- list.unshift(i);
34
- }
27
+ for (let i = 0; i < MILLION; i++) list.unshift(i);
35
28
  });
36
29
 
37
30
  if (isCompetitor) {
38
- suite.add(`CPT ${LINEAR.toLocaleString()} unshift`, () => {
31
+ suite.add(`CPT ${MILLION.toLocaleString()} unshift`, () => {
39
32
  const list = new CLinkedList<number>();
40
33
 
41
- for (let i = 0; i < LINEAR; i++) {
42
- list.pushFront(i);
43
- }
34
+ for (let i = 0; i < MILLION; i++) list.pushFront(i);
44
35
  });
45
36
  }
46
37
 
47
38
  suite
48
- .add(`${LINEAR.toLocaleString()} unshift & shift`, () => {
39
+ .add(`${MILLION.toLocaleString()} unshift & shift`, () => {
49
40
  const list = new DoublyLinkedList<number>();
50
41
 
51
- for (let i = 0; i < LINEAR; i++) {
52
- list.unshift(i);
53
- }
54
- for (let i = 0; i < LINEAR; i++) {
55
- list.shift();
56
- }
42
+ for (let i = 0; i < MILLION; i++) list.unshift(i);
43
+
44
+ for (let i = 0; i < MILLION; i++) list.shift();
57
45
  })
58
- .add(`${LINEAR.toLocaleString()} addBefore`, () => {
46
+ .add(`${MILLION.toLocaleString()} addBefore`, () => {
59
47
  const doublyList = new DoublyLinkedList<number>();
60
48
  let midNode: DoublyLinkedListNode | undefined;
61
- const midIndex = Math.floor(LINEAR / 2);
62
- for (let i = 0; i < LINEAR; i++) {
49
+ const midIndex = Math.floor(MILLION / 2);
50
+ for (let i = 0; i < MILLION; i++) {
63
51
  doublyList.push(i);
64
52
  if (i === midIndex) {
65
53
  midNode = doublyList.getNode(i);
@@ -9,24 +9,16 @@ suite
9
9
  .add(`${MILLION.toLocaleString()} push & shift`, () => {
10
10
  const list = new SinglyLinkedList<number>();
11
11
 
12
- for (let i = 0; i < MILLION; i++) {
13
- list.push(i);
14
- }
12
+ for (let i = 0; i < MILLION; i++) list.push(i);
15
13
 
16
- for (let i = 0; i < MILLION; i++) {
17
- list.shift();
18
- }
14
+ for (let i = 0; i < MILLION; i++) list.shift();
19
15
  })
20
16
  .add(`${TEN_THOUSAND.toLocaleString()} push & pop`, () => {
21
17
  const list = new SinglyLinkedList<number>();
22
18
 
23
- for (let i = 0; i < TEN_THOUSAND; i++) {
24
- list.push(i);
25
- }
19
+ for (let i = 0; i < TEN_THOUSAND; i++) list.push(i);
26
20
 
27
- for (let i = 0; i < TEN_THOUSAND; i++) {
28
- list.pop();
29
- }
21
+ for (let i = 0; i < TEN_THOUSAND; i++) list.pop();
30
22
  })
31
23
  .add(`${TEN_THOUSAND.toLocaleString()} addBefore`, () => {
32
24
  const singlyList = new SinglyLinkedList<number>();
@@ -5,28 +5,27 @@ import { magnitude } from '../../../utils';
5
5
  import { isCompetitor } from '../../../config';
6
6
 
7
7
  export const suite = new Benchmark.Suite();
8
- const { LINEAR, HUNDRED_THOUSAND } = magnitude;
8
+ const { MILLION, HUNDRED_THOUSAND } = magnitude;
9
9
 
10
- suite.add(`${LINEAR.toLocaleString()} push`, () => {
10
+ suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const deque = new Deque<number>();
12
- for (let i = 0; i < LINEAR; i++) deque.push(i);
12
+ for (let i = 0; i < MILLION; i++) deque.push(i);
13
13
  });
14
14
 
15
15
  if (isCompetitor) {
16
- suite.add(`CPT ${LINEAR.toLocaleString()} push`, () => {
16
+ suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
17
17
  const _deque = new CDeque<number>();
18
- for (let i = 0; i < LINEAR; i++) _deque.pushBack(i);
18
+ for (let i = 0; i < MILLION; i++) _deque.pushBack(i);
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(`${LINEAR.toLocaleString()} push & pop`, () => {
24
- const _deque = new Deque<number>();
25
-
26
- for (let i = 0; i < LINEAR; i++) _deque.push(i);
27
- for (let i = 0; i < LINEAR; 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
 
@@ -5,20 +5,20 @@ import { magnitude } from '../../../utils';
5
5
  import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const { LINEAR, HUNDRED_THOUSAND } = magnitude;
8
+ const { MILLION, HUNDRED_THOUSAND } = magnitude;
9
9
 
10
- suite.add(`${LINEAR.toLocaleString()} push`, () => {
10
+ suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const queue = new Queue<number>();
12
12
 
13
- for (let i = 0; i < LINEAR; i++) {
13
+ for (let i = 0; i < MILLION; i++) {
14
14
  queue.push(i);
15
15
  }
16
16
  });
17
17
  if (isCompetitor) {
18
- suite.add(`CPT ${LINEAR.toLocaleString()} push`, () => {
18
+ suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
19
19
  const queue = new CQueue<number>();
20
20
 
21
- for (let i = 0; i < LINEAR; i++) {
21
+ for (let i = 0; i < MILLION; i++) {
22
22
  queue.push(i);
23
23
  }
24
24
  });
@@ -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,42 +5,42 @@ import { magnitude } from '../../../utils';
5
5
  import { isCompetitor } from '../../../config';
6
6
 
7
7
  const suite = new Benchmark.Suite();
8
- const { LINEAR } = magnitude;
8
+ const { MILLION } = magnitude;
9
9
 
10
- suite.add(`${LINEAR.toLocaleString()} push`, () => {
10
+ suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const stack = new Stack<number>();
12
12
 
13
- for (let i = 0; i < LINEAR; i++) {
13
+ for (let i = 0; i < MILLION; i++) {
14
14
  stack.push(i);
15
15
  }
16
16
  });
17
17
  if (isCompetitor) {
18
- suite.add(`CPT ${LINEAR.toLocaleString()} push`, () => {
18
+ suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
19
19
  const queue = new CStack<number>();
20
20
 
21
- for (let i = 0; i < LINEAR; i++) {
21
+ for (let i = 0; i < MILLION; i++) {
22
22
  queue.push(i);
23
23
  }
24
24
  });
25
25
  }
26
- suite.add(`${LINEAR.toLocaleString()} push & pop`, () => {
26
+ suite.add(`${MILLION.toLocaleString()} push & pop`, () => {
27
27
  const queue = new Stack<number>();
28
28
 
29
- for (let i = 0; i < LINEAR; i++) {
29
+ for (let i = 0; i < MILLION; i++) {
30
30
  queue.push(i);
31
31
  }
32
- for (let i = 0; i < LINEAR; i++) {
32
+ for (let i = 0; i < MILLION; i++) {
33
33
  queue.pop();
34
34
  }
35
35
  });
36
36
  if (isCompetitor) {
37
- suite.add(`CPT ${LINEAR.toLocaleString()} push & pop`, () => {
37
+ suite.add(`CPT ${MILLION.toLocaleString()} push & pop`, () => {
38
38
  const queue = new CStack<number>();
39
39
 
40
- for (let i = 0; i < LINEAR; i++) {
40
+ for (let i = 0; i < MILLION; i++) {
41
41
  queue.push(i);
42
42
  }
43
- for (let i = 0; i < LINEAR; i++) {
43
+ for (let i = 0; i < MILLION; i++) {
44
44
  queue.pop();
45
45
  }
46
46
  });
@@ -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', () => {