data-structure-typed 1.49.4 → 1.49.6

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 (186) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +15 -26
  3. package/README_zh-CN.md +1 -1
  4. package/benchmark/report.html +14 -23
  5. package/benchmark/report.json +163 -256
  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.d.ts +53 -48
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +55 -49
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +154 -143
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +211 -198
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +83 -71
  15. package/dist/cjs/data-structures/binary-tree/bst.js +113 -89
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +62 -59
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +46 -55
  21. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +59 -94
  22. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -1
  24. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -2
  25. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  27. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  28. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  29. package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
  30. package/dist/cjs/data-structures/hash/hash-map.js +2 -2
  31. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  32. package/dist/cjs/data-structures/heap/heap.js +2 -3
  33. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  34. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  35. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  36. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  37. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  38. package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
  39. package/dist/cjs/data-structures/matrix/index.js +0 -2
  40. package/dist/cjs/data-structures/matrix/index.js.map +1 -1
  41. package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
  42. package/dist/cjs/data-structures/matrix/matrix.js +400 -15
  43. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  44. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  45. package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
  46. package/dist/cjs/data-structures/queue/deque.js +5 -7
  47. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  48. package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
  49. package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
  50. package/dist/cjs/types/common.d.ts +3 -3
  51. package/dist/cjs/types/common.js +2 -2
  52. package/dist/cjs/types/common.js.map +1 -1
  53. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  54. package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
  55. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  56. package/dist/cjs/utils/utils.d.ts +1 -0
  57. package/dist/cjs/utils/utils.js +6 -1
  58. package/dist/cjs/utils/utils.js.map +1 -1
  59. package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
  60. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +53 -48
  61. package/dist/mjs/data-structures/binary-tree/avl-tree.js +57 -50
  62. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +154 -143
  63. package/dist/mjs/data-structures/binary-tree/binary-tree.js +212 -199
  64. package/dist/mjs/data-structures/binary-tree/bst.d.ts +83 -71
  65. package/dist/mjs/data-structures/binary-tree/bst.js +115 -90
  66. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +37 -35
  67. package/dist/mjs/data-structures/binary-tree/rb-tree.js +64 -60
  68. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +46 -55
  69. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +61 -95
  70. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -1
  71. package/dist/mjs/data-structures/graph/abstract-graph.js +4 -3
  72. package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
  73. package/dist/mjs/data-structures/hash/hash-map.js +2 -2
  74. package/dist/mjs/data-structures/heap/heap.js +2 -3
  75. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  76. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
  77. package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
  78. package/dist/mjs/data-structures/matrix/index.js +0 -2
  79. package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
  80. package/dist/mjs/data-structures/matrix/matrix.js +399 -16
  81. package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
  82. package/dist/mjs/data-structures/queue/deque.js +7 -9
  83. package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
  84. package/dist/mjs/data-structures/queue/queue.js +1 -1
  85. package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
  86. package/dist/mjs/types/common.d.ts +3 -3
  87. package/dist/mjs/types/common.js +2 -2
  88. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  89. package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
  90. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  91. package/dist/mjs/utils/utils.d.ts +1 -0
  92. package/dist/mjs/utils/utils.js +4 -0
  93. package/dist/umd/data-structure-typed.js +853 -943
  94. package/dist/umd/data-structure-typed.min.js +2 -2
  95. package/dist/umd/data-structure-typed.min.js.map +1 -1
  96. package/package.json +4 -3
  97. package/src/data-structures/base/index.ts +1 -1
  98. package/src/data-structures/base/iterable-base.ts +7 -10
  99. package/src/data-structures/binary-tree/avl-tree.ts +73 -61
  100. package/src/data-structures/binary-tree/binary-tree.ts +301 -270
  101. package/src/data-structures/binary-tree/bst.ts +139 -115
  102. package/src/data-structures/binary-tree/rb-tree.ts +81 -73
  103. package/src/data-structures/binary-tree/tree-multimap.ts +72 -103
  104. package/src/data-structures/graph/abstract-graph.ts +13 -11
  105. package/src/data-structures/graph/directed-graph.ts +1 -3
  106. package/src/data-structures/graph/map-graph.ts +6 -1
  107. package/src/data-structures/graph/undirected-graph.ts +3 -6
  108. package/src/data-structures/hash/hash-map.ts +18 -16
  109. package/src/data-structures/heap/heap.ts +7 -10
  110. package/src/data-structures/heap/max-heap.ts +2 -1
  111. package/src/data-structures/heap/min-heap.ts +2 -1
  112. package/src/data-structures/linked-list/singly-linked-list.ts +2 -3
  113. package/src/data-structures/matrix/index.ts +0 -2
  114. package/src/data-structures/matrix/matrix.ts +442 -13
  115. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
  116. package/src/data-structures/queue/deque.ts +18 -39
  117. package/src/data-structures/queue/queue.ts +1 -1
  118. package/src/interfaces/binary-tree.ts +9 -4
  119. package/src/types/common.ts +5 -5
  120. package/src/types/data-structures/base/base.ts +14 -3
  121. package/src/types/data-structures/base/index.ts +1 -1
  122. package/src/types/data-structures/graph/abstract-graph.ts +4 -2
  123. package/src/types/data-structures/hash/hash-map.ts +3 -3
  124. package/src/types/data-structures/heap/heap.ts +2 -2
  125. package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
  126. package/src/utils/utils.ts +7 -1
  127. package/test/integration/avl-tree.test.ts +18 -1
  128. package/test/integration/bst.test.ts +2 -2
  129. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +4 -12
  130. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +37 -0
  131. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +6 -16
  132. package/test/performance/data-structures/binary-tree/bst.test.ts +5 -13
  133. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +6 -16
  134. package/test/performance/data-structures/comparison/comparison.test.ts +19 -47
  135. package/test/performance/data-structures/graph/directed-graph.test.ts +3 -14
  136. package/test/performance/data-structures/hash/hash-map.test.ts +14 -38
  137. package/test/performance/data-structures/heap/heap.test.ts +5 -18
  138. package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +0 -2
  139. package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +0 -2
  140. package/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +2 -4
  141. package/test/performance/data-structures/priority-queue/priority-queue.test.ts +4 -14
  142. package/test/performance/data-structures/queue/deque.test.ts +6 -7
  143. package/test/performance/data-structures/queue/queue.test.ts +13 -29
  144. package/test/performance/data-structures/stack/stack.test.ts +6 -18
  145. package/test/performance/data-structures/trie/trie.test.ts +2 -6
  146. package/test/performance/reportor.ts +14 -15
  147. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
  148. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +65 -29
  149. package/test/unit/data-structures/binary-tree/bst.test.ts +69 -27
  150. package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
  151. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
  152. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
  153. package/test/unit/data-structures/graph/directed-graph.test.ts +104 -45
  154. package/test/unit/data-structures/graph/undirected-graph.test.ts +57 -40
  155. package/test/unit/data-structures/hash/hash-map.test.ts +48 -28
  156. package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
  157. package/test/unit/data-structures/heap/heap.test.ts +0 -1
  158. package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
  159. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +10 -11
  160. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
  161. package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
  162. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
  163. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
  164. package/test/unit/data-structures/queue/deque.test.ts +0 -6
  165. package/test/unit/data-structures/queue/queue.test.ts +1 -1
  166. package/test/unit/data-structures/stack/stack.test.ts +3 -4
  167. package/test/unit/unrestricted-interconversion.test.ts +50 -44
  168. package/test/utils/performanc.ts +1 -1
  169. package/typedoc.json +30 -0
  170. package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
  171. package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
  172. package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
  173. package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
  174. package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
  175. package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
  176. package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
  177. package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
  178. package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
  179. package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
  180. package/src/data-structures/matrix/matrix2d.ts +0 -211
  181. package/src/data-structures/matrix/vector2d.ts +0 -315
  182. package/test/performance/data-structures/binary-tree/overall.test.ts +0 -0
  183. package/test/performance/data-structures/matrix/matrix2d.test.ts +0 -0
  184. package/test/performance/data-structures/matrix/vector2d.test.ts +0 -0
  185. package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
  186. package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
@@ -9,31 +9,18 @@ suite
9
9
  .add(`${HUNDRED_THOUSAND.toLocaleString()} add & poll`, () => {
10
10
  const heap = new Heap<number>([], { comparator: (a, b) => b - a });
11
11
 
12
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
13
- heap.add(i);
14
- }
15
-
16
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
17
- heap.poll();
18
- }
12
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(i);
13
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.poll();
19
14
  })
20
15
  .add(`${HUNDRED_THOUSAND.toLocaleString()} add & dfs`, () => {
21
16
  const heap = new Heap<number>([], { comparator: (a, b) => b - a });
22
-
23
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
24
- heap.add(i);
25
- }
26
-
17
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) heap.add(i);
27
18
  heap.dfs();
28
19
  })
29
20
  .add(`${TEN_THOUSAND.toLocaleString()} fib add & pop`, () => {
30
21
  const fbHeap = new FibonacciHeap<number>();
31
- for (let i = 1; i <= TEN_THOUSAND; i++) {
32
- fbHeap.push(i);
33
- }
34
- for (let i = 1; i <= TEN_THOUSAND; i++) {
35
- fbHeap.pop();
36
- }
22
+ for (let i = 1; i <= TEN_THOUSAND; i++) fbHeap.push(i);
23
+ for (let i = 1; i <= TEN_THOUSAND; i++) fbHeap.pop();
37
24
  });
38
25
 
39
26
  export { suite };
@@ -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>();
@@ -41,7 +40,6 @@ suite
41
40
  const list = new DoublyLinkedList<number>();
42
41
 
43
42
  for (let i = 0; i < MILLION; i++) list.unshift(i);
44
-
45
43
  for (let i = 0; i < MILLION; i++) list.shift();
46
44
  })
47
45
  .add(`${MILLION.toLocaleString()} addBefore`, () => {
@@ -10,14 +10,12 @@ suite
10
10
  const list = new SinglyLinkedList<number>();
11
11
 
12
12
  for (let i = 0; i < MILLION; i++) list.push(i);
13
-
14
13
  for (let i = 0; i < MILLION; i++) list.shift();
15
14
  })
16
15
  .add(`${TEN_THOUSAND.toLocaleString()} push & pop`, () => {
17
16
  const list = new SinglyLinkedList<number>();
18
17
 
19
18
  for (let i = 0; i < TEN_THOUSAND; i++) list.push(i);
20
-
21
19
  for (let i = 0; i < TEN_THOUSAND; i++) list.pop();
22
20
  })
23
21
  .add(`${TEN_THOUSAND.toLocaleString()} addBefore`, () => {
@@ -11,9 +11,7 @@ suite.add(`${TEN_THOUSAND.toLocaleString()} refill & poll`, () => {
11
11
  );
12
12
  const maxPQ = new MaxPriorityQueue<number>();
13
13
  maxPQ.refill(nodes);
14
- while (maxPQ.size > 0) {
15
- maxPQ.poll();
16
- }
14
+ while (maxPQ.size > 0) maxPQ.poll();
17
15
  });
18
16
 
19
- export { suite };
17
+ // export { suite };
@@ -10,25 +10,15 @@ const { HUNDRED_THOUSAND } = magnitude;
10
10
  suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add & poll`, () => {
11
11
  const pq = new PriorityQueue<number>([], { comparator: (a, b) => b - a });
12
12
 
13
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
14
- pq.add(i);
15
- }
16
-
17
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
18
- pq.poll();
19
- }
13
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) pq.add(i);
14
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) pq.poll();
20
15
  });
21
16
  if (isCompetitor) {
22
17
  suite.add(`CPT ${HUNDRED_THOUSAND.toLocaleString()} add & pop`, () => {
23
18
  const pq = new CPriorityQueue<number>();
24
19
 
25
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
26
- pq.push(i);
27
- }
28
-
29
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
30
- pq.pop();
31
- }
20
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) pq.push(i);
21
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) pq.pop();
32
22
  });
33
23
  }
34
24
 
@@ -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
 
@@ -10,49 +10,33 @@ const { MILLION, HUNDRED_THOUSAND } = magnitude;
10
10
  suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const queue = new Queue<number>();
12
12
 
13
- for (let i = 0; i < MILLION; i++) {
14
- queue.push(i);
15
- }
13
+ for (let i = 0; i < MILLION; i++) queue.push(i);
16
14
  });
17
15
  if (isCompetitor) {
18
16
  suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
19
17
  const queue = new CQueue<number>();
20
18
 
21
- for (let i = 0; i < MILLION; i++) {
22
- queue.push(i);
23
- }
19
+ for (let i = 0; i < MILLION; i++) queue.push(i);
24
20
  });
25
21
  }
26
22
  suite.add(`${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
27
23
  const queue = new Queue<number>();
28
24
 
29
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
30
- queue.push(i);
31
- }
32
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
33
- queue.shift();
34
- }
25
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) queue.push(i);
26
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) queue.shift();
35
27
  });
36
- suite.add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
37
- const arr = new Array<number>();
38
-
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
- })
46
- .add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & pop`, () => {
28
+ suite
29
+ .add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & shift`, () => {
47
30
  const arr = new Array<number>();
48
31
 
49
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
50
- arr.push(i);
51
- }
32
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.push(i);
33
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.shift();
34
+ })
35
+ .add(`Native Array ${HUNDRED_THOUSAND.toLocaleString()} push & pop`, () => {
36
+ const arr = new Array<number>();
52
37
 
53
- for (let i = 0; i < HUNDRED_THOUSAND; i++) {
54
- arr.pop();
55
- }
38
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.push(i);
39
+ for (let i = 0; i < HUNDRED_THOUSAND; i++) arr.pop();
56
40
  });
57
41
 
58
42
  export { suite };
@@ -10,39 +10,27 @@ const { MILLION } = magnitude;
10
10
  suite.add(`${MILLION.toLocaleString()} push`, () => {
11
11
  const stack = new Stack<number>();
12
12
 
13
- for (let i = 0; i < MILLION; i++) {
14
- stack.push(i);
15
- }
13
+ for (let i = 0; i < MILLION; i++) stack.push(i);
16
14
  });
17
15
  if (isCompetitor) {
18
16
  suite.add(`CPT ${MILLION.toLocaleString()} push`, () => {
19
17
  const queue = new CStack<number>();
20
18
 
21
- for (let i = 0; i < MILLION; i++) {
22
- queue.push(i);
23
- }
19
+ for (let i = 0; i < MILLION; i++) queue.push(i);
24
20
  });
25
21
  }
26
22
  suite.add(`${MILLION.toLocaleString()} push & pop`, () => {
27
23
  const queue = new Stack<number>();
28
24
 
29
- for (let i = 0; i < MILLION; i++) {
30
- queue.push(i);
31
- }
32
- for (let i = 0; i < MILLION; i++) {
33
- queue.pop();
34
- }
25
+ for (let i = 0; i < MILLION; i++) queue.push(i);
26
+ for (let i = 0; i < MILLION; i++) queue.pop();
35
27
  });
36
28
  if (isCompetitor) {
37
29
  suite.add(`CPT ${MILLION.toLocaleString()} push & pop`, () => {
38
30
  const queue = new CStack<number>();
39
31
 
40
- for (let i = 0; i < MILLION; i++) {
41
- queue.push(i);
42
- }
43
- for (let i = 0; i < MILLION; i++) {
44
- queue.pop();
45
- }
32
+ for (let i = 0; i < MILLION; i++) queue.push(i);
33
+ for (let i = 0; i < MILLION; i++) queue.pop();
46
34
  });
47
35
  }
48
36
 
@@ -9,14 +9,10 @@ const randomWords = getRandomWords(HUNDRED_THOUSAND, false);
9
9
 
10
10
  suite
11
11
  .add(`${HUNDRED_THOUSAND.toLocaleString()} push`, () => {
12
- for (let i = 0; i < randomWords.length; i++) {
13
- trie.add(randomWords[i]);
14
- }
12
+ for (let i = 0; i < randomWords.length; i++) trie.add(randomWords[i]);
15
13
  })
16
14
  .add(`${HUNDRED_THOUSAND.toLocaleString()} getWords`, () => {
17
- for (let i = 0; i < randomWords.length; i++) {
18
- trie.getWords(randomWords[i]);
19
- }
15
+ for (let i = 0; i < randomWords.length; i++) trie.getWords(randomWords[i]);
20
16
  });
21
17
 
22
18
  export { suite };
@@ -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', () => {
@@ -106,7 +106,8 @@ describe('BinaryTree', () => {
106
106
  it('should delete nodes', () => {
107
107
  expect(tree.getHeight(tree.root, IterationType.ITERATIVE)).toBe(-1);
108
108
  expect(tree.getMinHeight()).toBe(-1);
109
- const node1 = tree.add(1);
109
+ const node1 = tree.createNode(1);
110
+ tree.add(node1);
110
111
  expect(tree.size).toBe(1);
111
112
 
112
113
  const leftChild = new BinaryTreeNode<number>(2);
@@ -224,15 +225,15 @@ describe('BinaryTree', () => {
224
225
  new BinaryTreeNode(4, 4)
225
226
  ]);
226
227
 
227
- expect(tree.isSubtreeBST(tree.getNode(4), IterationType.RECURSIVE)).toBe(true);
228
- expect(tree.isSubtreeBST(tree.getNode(4), IterationType.ITERATIVE)).toBe(true);
228
+ expect(tree.isBST(tree.getNode(4), IterationType.RECURSIVE)).toBe(true);
229
+ expect(tree.isBST(tree.getNode(4), IterationType.ITERATIVE)).toBe(true);
229
230
  });
230
231
 
231
232
  it('should isSubtreeBST', () => {
232
233
  tree.addMany([4, 2, 6, 1, 3, 5, 7, 4]);
233
234
 
234
- expect(tree.isSubtreeBST(tree.getNode(4), IterationType.RECURSIVE)).toBe(true);
235
- expect(tree.isSubtreeBST(tree.getNode(4), IterationType.ITERATIVE)).toBe(true);
235
+ expect(tree.isBST(tree.getNode(4), IterationType.RECURSIVE)).toBe(true);
236
+ expect(tree.isBST(tree.getNode(4), IterationType.ITERATIVE)).toBe(true);
236
237
  expect(tree.getNodes(2, undefined, false, null)).toEqual([]);
237
238
  expect(tree.getNodes(tree.getNodeByKey(2), undefined, false, tree.root)).toEqual([tree.getNodeByKey(2)]);
238
239
  });
@@ -265,7 +266,22 @@ describe('BinaryTree', () => {
265
266
  tree.clear();
266
267
  tree.addMany([-10, -10, -10, 9, 9, 20, null, null, 15, 7, 8, null, 2, null, 6, null, null, 8, 8, 8]);
267
268
 
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])
269
+ expect(tree.bfs(node => (node ? node.key : null), undefined, undefined, true)).toEqual([
270
+ -10,
271
+ 9,
272
+ 20,
273
+ null,
274
+ null,
275
+ 15,
276
+ 7,
277
+ 8,
278
+ null,
279
+ 2,
280
+ null,
281
+ 6,
282
+ null,
283
+ null
284
+ ]);
269
285
  });
270
286
  });
271
287
 
@@ -525,18 +541,12 @@ describe('BinaryTree', () => {
525
541
  tree.add([3, 'B']);
526
542
  tree.add([7, 'C']);
527
543
 
528
- const nodes = tree.getNodes('B', (node) => node.value);
544
+ const nodes = tree.getNodes('B', node => node.value);
529
545
 
530
546
  expect(nodes.length).toBe(1);
531
547
  expect(nodes[0].key).toBe(3);
532
548
 
533
- const nodesRec = tree.getNodes(
534
- 'B',
535
- (node) => node.value,
536
- false,
537
- tree.root,
538
- IterationType.RECURSIVE
539
- );
549
+ const nodesRec = tree.getNodes('B', node => node.value, false, tree.root, IterationType.RECURSIVE);
540
550
 
541
551
  expect(nodesRec.length).toBe(1);
542
552
  expect(nodesRec[0].key).toBe(3);
@@ -548,9 +558,17 @@ describe('BinaryTree', () => {
548
558
  tree.add([7, 'C']);
549
559
 
550
560
  tree.iterationType = IterationType.ITERATIVE;
551
- expect([...tree]).toEqual([[3, "B"], [5, "A"], [7, "C"]]);
561
+ expect([...tree]).toEqual([
562
+ [3, 'B'],
563
+ [5, 'A'],
564
+ [7, 'C']
565
+ ]);
552
566
  tree.iterationType = IterationType.RECURSIVE;
553
- expect([...tree]).toEqual([[3, "B"], [5, "A"], [7, "C"]]);
567
+ expect([...tree]).toEqual([
568
+ [3, 'B'],
569
+ [5, 'A'],
570
+ [7, 'C']
571
+ ]);
554
572
  tree.iterationType = IterationType.ITERATIVE;
555
573
 
556
574
  const result = tree.morris();
@@ -600,13 +618,20 @@ describe('BinaryTree iterative methods test', () => {
600
618
  test('filter should return a new tree with filtered elements', () => {
601
619
  const filteredTree = binaryTree.filter((value, key) => key > 1);
602
620
  expect(filteredTree.size).toBe(2);
603
- expect([...filteredTree]).toEqual([[3, 'c'], [2, 'b']]);
621
+ expect([...filteredTree]).toEqual([
622
+ [3, 'c'],
623
+ [2, 'b']
624
+ ]);
604
625
  });
605
626
 
606
627
  test('map should return a new tree with modified elements', () => {
607
628
  const mappedTree = binaryTree.map((value, key) => (key * 2).toString());
608
629
  expect(mappedTree.size).toBe(3);
609
- expect([...mappedTree]).toEqual([[1, '2'], [2, '4'], [3, '6']]);
630
+ expect([...mappedTree]).toEqual([
631
+ [1, '2'],
632
+ [2, '4'],
633
+ [3, '6']
634
+ ]);
610
635
  });
611
636
 
612
637
  test('reduce should accumulate values', () => {
@@ -621,7 +646,11 @@ describe('BinaryTree iterative methods test', () => {
621
646
  }
622
647
 
623
648
  expect(entries.length).toBe(3);
624
- expect(entries).toEqual([[2, 'b'], [1, 'a'], [3, 'c']]);
649
+ expect(entries).toEqual([
650
+ [2, 'b'],
651
+ [1, 'a'],
652
+ [3, 'c']
653
+ ]);
625
654
  });
626
655
 
627
656
  test('should clone work well', () => {
@@ -641,17 +670,24 @@ describe('BinaryTree iterative methods test', () => {
641
670
  });
642
671
 
643
672
  test('should iterative method return undefined when the node is null', () => {
644
- const tree = new BinaryTree()
673
+ const tree = new BinaryTree();
645
674
  tree.addMany([-10, -10, -10, 9, 9, 20, null, null, 15, 7, 8, null, 2, null, 6, null, null, 8, 8, 8]);
646
675
  const bfsResult = tree.bfs(undefined, undefined, undefined, true);
647
676
  expect(bfsResult).toEqual([
648
- -10, 9,
649
- 20, undefined,
650
- undefined, 15,
651
- 7, 8,
652
- undefined, 2,
653
- undefined, 6,
654
- undefined, undefined
677
+ -10,
678
+ 9,
679
+ 20,
680
+ undefined,
681
+ undefined,
682
+ 15,
683
+ 7,
684
+ 8,
685
+ undefined,
686
+ 2,
687
+ undefined,
688
+ 6,
689
+ undefined,
690
+ undefined
655
691
  ]);
656
- })
657
- });
692
+ });
693
+ });