data-structure-typed 2.0.5 → 2.1.0

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 (260) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/COMMANDS.md +17 -0
  3. package/benchmark/report.html +13 -77
  4. package/benchmark/report.json +145 -177
  5. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
  6. package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
  7. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
  9. package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  11. package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
  12. package/dist/cjs/data-structures/base/linear-base.js +137 -274
  13. package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  19. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
  22. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.js +594 -865
  25. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
  27. package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
  28. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
  31. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  32. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
  34. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  35. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  38. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
  39. package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
  40. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  41. package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
  42. package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
  43. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  44. package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
  45. package/dist/cjs/data-structures/graph/map-graph.js +56 -59
  46. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  47. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
  48. package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
  49. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  50. package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
  51. package/dist/cjs/data-structures/hash/hash-map.js +270 -457
  52. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  53. package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
  54. package/dist/cjs/data-structures/heap/heap.js +340 -349
  55. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  56. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
  57. package/dist/cjs/data-structures/heap/max-heap.js +11 -66
  58. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  59. package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
  60. package/dist/cjs/data-structures/heap/min-heap.js +11 -66
  61. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  62. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  63. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
  64. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  65. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  66. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
  67. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  68. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  69. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
  70. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  71. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  72. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
  73. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  74. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  75. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
  76. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  77. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
  78. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
  79. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  80. package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
  81. package/dist/cjs/data-structures/queue/deque.js +309 -348
  82. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  83. package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
  84. package/dist/cjs/data-structures/queue/queue.js +265 -248
  85. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  86. package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
  87. package/dist/cjs/data-structures/stack/stack.js +181 -125
  88. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  89. package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
  90. package/dist/cjs/data-structures/trie/trie.js +189 -172
  91. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  92. package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
  93. package/dist/cjs/interfaces/graph.d.ts +16 -0
  94. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  95. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
  96. package/dist/cjs/types/utils/utils.d.ts +1 -0
  97. package/dist/cjs/utils/utils.d.ts +1 -1
  98. package/dist/cjs/utils/utils.js +2 -1
  99. package/dist/cjs/utils/utils.js.map +1 -1
  100. package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
  101. package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
  102. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  103. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
  104. package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
  105. package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
  106. package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
  107. package/dist/esm/data-structures/base/linear-base.js +137 -274
  108. package/dist/esm/data-structures/base/linear-base.js.map +1 -1
  109. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  110. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
  111. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  112. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  113. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
  114. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  115. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
  116. package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
  117. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  118. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
  119. package/dist/esm/data-structures/binary-tree/binary-tree.js +598 -874
  120. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  121. package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
  122. package/dist/esm/data-structures/binary-tree/bst.js +507 -487
  123. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  124. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  125. package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
  126. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  127. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
  128. package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
  129. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  130. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  131. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
  132. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  133. package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
  134. package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
  135. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  136. package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
  137. package/dist/esm/data-structures/graph/directed-graph.js +145 -233
  138. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
  139. package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
  140. package/dist/esm/data-structures/graph/map-graph.js +56 -59
  141. package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
  142. package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
  143. package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
  144. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
  145. package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
  146. package/dist/esm/data-structures/hash/hash-map.js +270 -457
  147. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  148. package/dist/esm/data-structures/heap/heap.d.ts +214 -289
  149. package/dist/esm/data-structures/heap/heap.js +329 -349
  150. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  151. package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
  152. package/dist/esm/data-structures/heap/max-heap.js +11 -66
  153. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  154. package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
  155. package/dist/esm/data-structures/heap/min-heap.js +11 -66
  156. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  157. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  158. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
  159. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  160. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  161. package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
  162. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  163. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  164. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
  165. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
  166. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  167. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
  168. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  169. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  170. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
  171. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  172. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
  173. package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
  174. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  175. package/dist/esm/data-structures/queue/deque.d.ts +227 -254
  176. package/dist/esm/data-structures/queue/deque.js +313 -348
  177. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  178. package/dist/esm/data-structures/queue/queue.d.ts +180 -201
  179. package/dist/esm/data-structures/queue/queue.js +263 -248
  180. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  181. package/dist/esm/data-structures/stack/stack.d.ts +124 -102
  182. package/dist/esm/data-structures/stack/stack.js +181 -125
  183. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  184. package/dist/esm/data-structures/trie/trie.d.ts +164 -165
  185. package/dist/esm/data-structures/trie/trie.js +193 -172
  186. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  187. package/dist/esm/interfaces/binary-tree.d.ts +56 -6
  188. package/dist/esm/interfaces/graph.d.ts +16 -0
  189. package/dist/esm/types/data-structures/base/base.d.ts +1 -1
  190. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
  191. package/dist/esm/types/utils/utils.d.ts +1 -0
  192. package/dist/esm/utils/utils.d.ts +1 -1
  193. package/dist/esm/utils/utils.js +2 -1
  194. package/dist/esm/utils/utils.js.map +1 -1
  195. package/dist/umd/data-structure-typed.js +4685 -6477
  196. package/dist/umd/data-structure-typed.min.js +8 -6
  197. package/dist/umd/data-structure-typed.min.js.map +1 -1
  198. package/package.json +3 -4
  199. package/src/data-structures/base/iterable-element-base.ts +238 -115
  200. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  201. package/src/data-structures/base/linear-base.ts +271 -277
  202. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  203. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  204. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  205. package/src/data-structures/binary-tree/binary-tree.ts +660 -889
  206. package/src/data-structures/binary-tree/bst.ts +568 -570
  207. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  208. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  209. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  210. package/src/data-structures/graph/abstract-graph.ts +339 -264
  211. package/src/data-structures/graph/directed-graph.ts +146 -236
  212. package/src/data-structures/graph/map-graph.ts +63 -60
  213. package/src/data-structures/graph/undirected-graph.ts +129 -152
  214. package/src/data-structures/hash/hash-map.ts +274 -496
  215. package/src/data-structures/heap/heap.ts +389 -402
  216. package/src/data-structures/heap/max-heap.ts +12 -76
  217. package/src/data-structures/heap/min-heap.ts +13 -76
  218. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  219. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  220. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  221. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  222. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  223. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  224. package/src/data-structures/queue/deque.ts +381 -357
  225. package/src/data-structures/queue/queue.ts +310 -264
  226. package/src/data-structures/stack/stack.ts +217 -131
  227. package/src/data-structures/trie/trie.ts +240 -175
  228. package/src/interfaces/binary-tree.ts +240 -6
  229. package/src/interfaces/graph.ts +37 -0
  230. package/src/types/data-structures/base/base.ts +5 -5
  231. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  232. package/src/types/utils/utils.ts +2 -0
  233. package/src/utils/utils.ts +9 -14
  234. package/test/integration/index.html +1 -1
  235. package/test/performance/benchmark-runner.ts +528 -0
  236. package/test/performance/reportor.mjs +43 -43
  237. package/test/performance/runner-config.json +39 -0
  238. package/test/performance/single-suite-runner.ts +69 -0
  239. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  240. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  241. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  242. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  243. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
  244. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  245. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  246. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  247. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  248. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  249. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  250. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  251. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  252. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  253. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  254. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  255. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  256. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  257. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  258. package/test/unit/utils/utils.test.ts +0 -1
  259. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  260. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
@@ -3,31 +3,31 @@ import * as fs from 'fs';
3
3
  import fastGlob from 'fast-glob';
4
4
  import { fileURLToPath } from 'url';
5
5
 
6
- const isNumber = (value) => {
6
+ const isNumber = value => {
7
7
  return typeof value === 'number';
8
8
  };
9
- const isString = (value) => {
9
+ const isString = value => {
10
10
  return typeof value === 'string';
11
11
  };
12
- const isBoolean = (value) => {
12
+ const isBoolean = value => {
13
13
  return typeof value === 'boolean';
14
14
  };
15
- const isDate = (value) => {
15
+ const isDate = value => {
16
16
  return value instanceof Date;
17
17
  };
18
- const isNull = (value) => {
18
+ const isNull = value => {
19
19
  return value === null;
20
20
  };
21
- const isUndefined = (value) => {
21
+ const isUndefined = value => {
22
22
  return typeof value === 'undefined';
23
23
  };
24
- const isFunction = (value) => {
24
+ const isFunction = value => {
25
25
  return typeof value === 'function';
26
26
  };
27
- const isObject = (value) => {
27
+ const isObject = value => {
28
28
  return typeof value === 'object';
29
29
  };
30
- const isArray = (value) => {
30
+ const isArray = value => {
31
31
  return Array.isArray(value);
32
32
  };
33
33
  const isEqual = (objA, objB) => {
@@ -56,38 +56,35 @@ const isEqual = (objA, objB) => {
56
56
  function toggleJS(options) {
57
57
  if (options === null || options === void 0 ? void 0 : options.plainHtml) {
58
58
  return '';
59
- }
60
- else {
59
+ } else {
61
60
  return 'onclick="json-to-html.toggleVisibility(this);return false"';
62
61
  }
63
62
  }
63
+
64
64
  function makeLabelDiv(options, level, keyName, datatype) {
65
65
  if (typeof keyName === 'number') {
66
66
  return `<div class='index'><span class='json-to-html-label'>${keyName}&nbsp;</span></div>`;
67
- }
68
- else if (typeof keyName === 'string') {
67
+ } else if (typeof keyName === 'string') {
69
68
  if (datatype === 'array') {
70
69
  return `<div class='collapsible level${level}' ${toggleJS(options)}><span class='json-to-html-label'>${keyName}</span></div>`;
71
- }
72
- else if (datatype === 'object') {
70
+ } else if (datatype === 'object') {
73
71
  return `<div class='attribute collapsible level${level}' ${toggleJS(options)}><span class='json-to-html-label'>${keyName}:</span></div>`;
74
- }
75
- else {
72
+ } else {
76
73
  return `<div class='leaf level${level}'><span class='json-to-html-label'>${keyName}:</span></div>`;
77
74
  }
78
- }
79
- else {
75
+ } else {
80
76
  return '';
81
77
  }
82
78
  }
79
+
83
80
  function getContentClass(keyName) {
84
81
  if (typeof keyName === 'string') {
85
82
  return 'content';
86
- }
87
- else {
83
+ } else {
88
84
  return '';
89
85
  }
90
86
  }
87
+
91
88
  function isPlainObject(val) {
92
89
  let lastKey;
93
90
  let lastOwnKey;
@@ -101,8 +98,10 @@ function isPlainObject(val) {
101
98
  }
102
99
  return lastOwnKey === lastKey;
103
100
  }
101
+
104
102
  function isLeafValue(val) {
105
- return (isNumber(val) ||
103
+ return (
104
+ isNumber(val) ||
106
105
  isString(val) ||
107
106
  isBoolean(val) ||
108
107
  isDate(val) ||
@@ -110,8 +109,10 @@ function isLeafValue(val) {
110
109
  isUndefined(val) ||
111
110
  isNaN(val) ||
112
111
  isFunction(val) ||
113
- !isPlainObject(val));
112
+ !isPlainObject(val)
113
+ );
114
114
  }
115
+
115
116
  function isLeafObject(obj) {
116
117
  if (!isObject(obj)) {
117
118
  return false;
@@ -124,35 +125,37 @@ function isLeafObject(obj) {
124
125
  }
125
126
  return true;
126
127
  }
128
+
127
129
  function isTable(arr) {
128
130
  if (!isArray(arr)) {
129
131
  return false;
130
132
  }
131
133
  if (arr.length === 0 || !isObject(arr[0])) {
132
134
  return false;
133
- }
134
- else {
135
+ } else {
135
136
  let nonCompliant = arr.find(row => !isLeafObject(row));
136
137
  if (nonCompliant) {
137
138
  return false;
138
- }
139
- else {
139
+ } else {
140
140
  const cols = Object.keys(arr[0]);
141
- nonCompliant = arr.find((row) => !isEqual(cols, Object.keys(row)));
141
+ nonCompliant = arr.find(row => !isEqual(cols, Object.keys(row)));
142
142
  return !nonCompliant;
143
143
  }
144
144
  }
145
145
  }
146
+
146
147
  function drawTable(arr) {
147
148
  function drawRow(headers, rowObj) {
148
149
  return '<td>' + headers.map(header => rowObj[header]).join('</td><td>') + '</td>';
149
150
  }
151
+
150
152
  const cols = Object.keys(arr[0]);
151
153
  const content = arr.map(rowObj => drawRow(cols, rowObj));
152
154
  const headingHtml = '<tr><th>' + cols.join('</th><th>') + '</th></tr>';
153
155
  const contentHtml = '<tr>' + content.join('</tr><tr>') + '</tr>';
154
156
  return '<table style="display: table; width:100%; table-layout: fixed;">' + headingHtml + contentHtml + '</table>';
155
157
  }
158
+
156
159
  function _render(name, data, options, level, altRow) {
157
160
  const contentClass = getContentClass(name);
158
161
  if (isArray(data)) {
@@ -160,8 +163,7 @@ function _render(name, data, options, level, altRow) {
160
163
  let subs;
161
164
  if (isTable(data)) {
162
165
  subs = drawTable(data);
163
- }
164
- else {
166
+ } else {
165
167
  subs =
166
168
  "<div class='altRows'>" +
167
169
  data
@@ -173,28 +175,24 @@ function _render(name, data, options, level, altRow) {
173
175
  ${title}
174
176
  <div class="${contentClass}">${subs}</div>
175
177
  </div>`;
176
- }
177
- else if (isLeafValue(data)) {
178
+ } else if (isLeafValue(data)) {
178
179
  const title = makeLabelDiv(options, level, name);
179
180
  if (isFunction(data)) {
180
181
  return `${title}<span class='json-to-html-value'>&nbsp;&nbsp;-function() can't _render-</span>`;
181
- }
182
- else if (!isPlainObject(data)) {
182
+ } else if (!isPlainObject(data)) {
183
183
  if (isFunction(data.toString)) {
184
184
  return `${title}<span class='json-to-html-value'>&nbsp;&nbsp;${data.toString()}</span>`;
185
- }
186
- else {
185
+ } else {
187
186
  return `${title}<span class='json-to-html-value'>&nbsp;&nbsp;-instance object, can't render-</span>`;
188
187
  }
189
- }
190
- else {
188
+ } else {
191
189
  return `${title}<span class='json-to-html-value'>&nbsp;&nbsp;${data}</span>`;
192
190
  }
193
- }
194
- else {
191
+ } else {
195
192
  const title = makeLabelDiv(options, level, name, 'object');
196
193
  let count = 0;
197
- const subs = '<div>' +
194
+ const subs =
195
+ '<div>' +
198
196
  Object.entries(data)
199
197
  .map(([key, val]) => _render(key, val, options, level + 1, count++ % 2))
200
198
  .join('</div><div>') +
@@ -208,11 +206,11 @@ function _render(name, data, options, level, altRow) {
208
206
  ${level === 0 ? '</div>' : ''}`;
209
207
  }
210
208
  }
209
+
211
210
  export function render(name, json, options) {
212
211
  return `${_render(name, json, options, 0, 0)}`;
213
212
  }
214
213
 
215
-
216
214
  const __filename = fileURLToPath(import.meta.url);
217
215
  const __dirname = path.dirname(__filename);
218
216
 
@@ -225,6 +223,7 @@ function numberFix(num, decimalPlaces) {
225
223
  return num.toFixed(decimalPlaces);
226
224
  }
227
225
  }
226
+
228
227
  const ConsoleColor = {
229
228
  END: '\x1b[0m',
230
229
  BOLD: '\x1b[1m',
@@ -278,7 +277,6 @@ const getRelativePath = file => {
278
277
  return path.relative(__dirname, file);
279
278
  };
280
279
  const coloredLabeled = (label, file) => {
281
-
282
280
  const relativeFilePath = getRelativePath(file);
283
281
  const directory = path.dirname(relativeFilePath);
284
282
  const fileName = path.basename(relativeFilePath);
@@ -414,6 +412,7 @@ const composeReport = () => {
414
412
  fs.writeFileSync(htmlFilePath, html);
415
413
  console.log(`Performance ${BOLD}${GREEN}report${END} file generated in file://${BOLD}${GREEN}${htmlFilePath}${END}`);
416
414
  };
415
+
417
416
  function replaceMarkdownContent(startMarker, endMarker, newText) {
418
417
  const filePath = path.join(parentDirectory, 'README.md'); // Path to README.md file
419
418
  fs.readFile(filePath, 'utf8', (err, data) => {
@@ -440,6 +439,7 @@ function replaceMarkdownContent(startMarker, endMarker, newText) {
440
439
  });
441
440
  });
442
441
  }
442
+
443
443
  const sortedPerformanceTests = (
444
444
  isOnlyOrdered ? [...performanceTests].filter(test => runOrder.includes(test.testName)) : [...performanceTests]
445
445
  ).sort((a, b) => {
@@ -0,0 +1,39 @@
1
+ {
2
+ "label": "default-plan",
3
+ "include": [
4
+ "binary-tree/avl-tree.test.ts",
5
+ "binary-tree/binary-tree.test.ts",
6
+ "binary-tree/bst.test.ts",
7
+ "binary-tree/red-black-tree.test.ts",
8
+ "graph/directed-graph.test.ts",
9
+ "hash/hash-map.test.ts",
10
+ "heap/heap.test.ts",
11
+ "queue/queue.test.ts",
12
+ "queue/deque.test.ts",
13
+ "stack/**",
14
+ "trie/**"
15
+ ],
16
+ "exclude": [
17
+ "**/experimental/**"
18
+ ],
19
+ "order": [
20
+ "heap",
21
+ "avl-tree",
22
+ "red-black-tree",
23
+ "doubly-linked-list",
24
+ "linked-hash-map",
25
+ "hash-map",
26
+ "map-graph",
27
+ "graph",
28
+ "directed-graph",
29
+ "undirected-graph",
30
+ "queue",
31
+ "deque",
32
+ "priority-queue",
33
+ "singly-linked-list",
34
+ "binary-tree-overall",
35
+ "bst",
36
+ "trie",
37
+ "stack"
38
+ ]
39
+ }
@@ -0,0 +1,69 @@
1
+ import * as path from 'path';
2
+ import * as url from 'url';
3
+ import * as Benchmark from 'benchmark';
4
+ import { numberFix } from '../utils';
5
+
6
+ function fileToURL(file: string) {
7
+ return url.pathToFileURL(file).href;
8
+ }
9
+
10
+ async function loadTestModule(file: string): Promise<any> {
11
+ if (file.endsWith('.mjs')) {
12
+ return await import(fileToURL(file));
13
+ }
14
+ try {
15
+ // @ts-ignore
16
+ return require(file);
17
+ } catch (e: any) {
18
+ if (e && e.code === 'ERR_REQUIRE_ESM') {
19
+ return await import(fileToURL(file));
20
+ }
21
+ throw e;
22
+ }
23
+ }
24
+
25
+ const file = process.argv[2];
26
+ if (!file) {
27
+ console.error('single-suite-runner requires a test file path.');
28
+ process.exit(1);
29
+ }
30
+
31
+ (async () => {
32
+ const testName = path.basename(file).replace(/\.test\.[^.]+$/, '');
33
+ const mod = await loadTestModule(file);
34
+ const suite: Benchmark.Suite | undefined = mod?.suite || mod?.default?.suite;
35
+
36
+ if (!suite) {
37
+ if (process.send) process.send({ testName, benchmarks: [], file });
38
+ process.exit(0);
39
+ }
40
+
41
+ try {
42
+ suite.forEach((b: any) => {
43
+ if (typeof b.fn === 'function') b.fn.call(b);
44
+ });
45
+ } catch {}
46
+
47
+ if (global.gc) global.gc();
48
+
49
+ let runTime = 0;
50
+ suite
51
+ .on('complete', function (this: Benchmark.Suite) {
52
+ const benchmarks = this.map((benchmark: any) => {
53
+ runTime += benchmark.times.elapsed;
54
+ return {
55
+ 'test name': benchmark.name,
56
+ 'time taken (ms)': numberFix(benchmark.times.period * 1000, 2),
57
+ 'sample mean (secs)': numberFix(benchmark.stats.mean, 2),
58
+ 'sample deviation': numberFix(benchmark.stats.deviation, 2)
59
+ };
60
+ });
61
+ runTime = Number(runTime.toFixed(2));
62
+ if (process.send) process.send({ testName, benchmarks, runTime, file });
63
+ process.exit(0);
64
+ })
65
+ .run({ async: false });
66
+ })().catch(err => {
67
+ console.error(err);
68
+ process.exit(1);
69
+ });
@@ -1,4 +1,4 @@
1
- import { AVLTreeCounter, AVLTreeCounterNode, AVLTreeNode, BinaryTreeNode, BSTNode } from '../../../../src';
1
+ import { AVLTreeCounter, AVLTreeCounterNode, AVLTreeNode, BinaryTreeNode, BSTNode, IBinaryTree } from '../../../../src';
2
2
  import { isDebugTest } from '../../../config';
3
3
 
4
4
  const isDebug = isDebugTest;
@@ -571,7 +571,7 @@ describe('AVLTreeCounter Performance test', function () {
571
571
  });
572
572
 
573
573
  it('should the clone method', () => {
574
- function checkTreeStructure(avlCounter: AVLTreeCounter<string, number>) {
574
+ function checkTreeStructure(avlCounter: IBinaryTree<string, number>) {
575
575
  expect(avlCounter.size).toBe(4);
576
576
  expect(avlCounter.root?.key).toBe('2');
577
577
  expect(avlCounter.root?.left?.key).toBe('1');
@@ -738,7 +738,7 @@ describe('AVLTreeCounter toEntryFn', () => {
738
738
  { obj: { id: 5 } }
739
739
  ])
740
740
  ).toThrowError(
741
- `When comparing object types, a custom specifyComparable must be defined in the constructor's options parameter.`
741
+ `When comparing object types, a custom specifyComparable must be defined in the constructor's options.`
742
742
  );
743
743
  });
744
744
 
@@ -1,4 +1,4 @@
1
- import { AVLTreeMultiMap, AVLTreeMultiMapNode } from '../../../../src';
1
+ import { AVLTreeMultiMap, AVLTreeMultiMapNode, IBinaryTree } from '../../../../src';
2
2
  // import { isDebugTest } from '../../../config';
3
3
 
4
4
  // const isDebug = isDebugTest;
@@ -70,7 +70,7 @@ describe('AVLTreeMultiMap Test', () => {
70
70
 
71
71
  expect(avlTmm.delete(avlTmm.getNode(11))[0].deleted?.key).toBe(11);
72
72
  expect(avlTmm.isAVLBalanced()).toBe(true);
73
- expect(node15 && avlTmm.getHeight(node15)).toBe(2);
73
+ expect(node15 && avlTmm.getHeight(node15)).toBe(1);
74
74
 
75
75
  expect(avlTmm.delete(1)[0].deleted?.key).toBe(1);
76
76
  expect(avlTmm.isAVLBalanced()).toBe(true);
@@ -198,7 +198,7 @@ describe('AVLTreeMultiMap Test recursively', () => {
198
198
 
199
199
  expect(avlTmm.delete(11)[0].deleted?.key).toBe(11);
200
200
  expect(avlTmm.isAVLBalanced()).toBe(true);
201
- expect(node15 && avlTmm.getHeight(node15)).toBe(2);
201
+ expect(node15 && avlTmm.getHeight(node15)).toBe(1);
202
202
 
203
203
  expect(avlTmm.delete(1)[0].deleted?.key).toBe(1);
204
204
  expect(avlTmm.isAVLBalanced()).toBe(true);
@@ -286,7 +286,7 @@ describe('AVLTreeMultiMap APIs test', () => {
286
286
  });
287
287
 
288
288
  it('should the clone method', () => {
289
- function checkTreeStructure(avlTmm: AVLTreeMultiMap<string, number>) {
289
+ function checkTreeStructure(avlTmm: IBinaryTree<string, number[]>) {
290
290
  expect(avlTmm.size).toBe(4);
291
291
  expect(avlTmm.root?.key).toBe('2');
292
292
  expect(avlTmm.root?.left?.key).toBe('1');
@@ -399,7 +399,7 @@ describe('AVLTreeMultiMap', () => {
399
399
  });
400
400
 
401
401
  describe('AVLTreeMultiMap iterative methods test', () => {
402
- let avlTmm: AVLTreeMultiMap<number, string, object, string, string, object>;
402
+ let avlTmm: AVLTreeMultiMap<number, string, object>;
403
403
  beforeEach(() => {
404
404
  avlTmm = new AVLTreeMultiMap();
405
405
  avlTmm.add([1, ['a']]);
@@ -1,4 +1,4 @@
1
- import { AVLTree, AVLTreeNode, BinaryTreeNode, BSTNode } from '../../../../src';
1
+ import { AVLTree, AVLTreeNode, BinaryTreeNode, BSTNode, IBinaryTree } from '../../../../src';
2
2
 
3
3
  describe('AVL Tree Test', () => {
4
4
  it('should perform various operations on a AVL Tree', () => {
@@ -44,7 +44,7 @@ describe('AVL Tree Test', () => {
44
44
 
45
45
  expect(avlTree.delete(avlTree.getNode(11))[0].deleted?.key).toBe(11);
46
46
  expect(avlTree.isAVLBalanced()).toBe(true);
47
- expect(node15 && avlTree.getHeight(node15)).toBe(2);
47
+ expect(node15 && avlTree.getHeight(node15)).toBe(1);
48
48
 
49
49
  expect(avlTree.delete(1)[0].deleted?.key).toBe(1);
50
50
  expect(avlTree.isAVLBalanced()).toBe(true);
@@ -172,7 +172,7 @@ describe('AVL Tree Test recursively', () => {
172
172
 
173
173
  expect(avlTree.delete(11)[0].deleted?.key).toBe(11);
174
174
  expect(avlTree.isAVLBalanced()).toBe(true);
175
- expect(node15 && avlTree.getHeight(node15)).toBe(2);
175
+ expect(node15 && avlTree.getHeight(node15)).toBe(1);
176
176
 
177
177
  expect(avlTree.delete(1)[0].deleted?.key).toBe(1);
178
178
  expect(avlTree.isAVLBalanced()).toBe(true);
@@ -258,7 +258,7 @@ describe('AVLTree APIs test', () => {
258
258
  });
259
259
 
260
260
  it('should the clone method', () => {
261
- function checkTreeStructure(avlTree: AVLTree<string, number>) {
261
+ function checkTreeStructure(avlTree: IBinaryTree<string, number>) {
262
262
  expect(avlTree.size).toBe(4);
263
263
  expect(avlTree.root?.key).toBe('2');
264
264
  expect(avlTree.root?.left?.key).toBe('1');