data-structure-typed 2.0.4 → 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 (261) hide show
  1. package/CHANGELOG.md +3 -1
  2. package/COMMANDS.md +17 -0
  3. package/README.md +11 -11
  4. package/benchmark/report.html +13 -77
  5. package/benchmark/report.json +158 -190
  6. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +186 -83
  7. package/dist/cjs/data-structures/base/iterable-element-base.js +149 -107
  8. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  9. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +95 -119
  10. package/dist/cjs/data-structures/base/iterable-entry-base.js +59 -116
  11. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  12. package/dist/cjs/data-structures/base/linear-base.d.ts +250 -192
  13. package/dist/cjs/data-structures/base/linear-base.js +137 -274
  14. package/dist/cjs/data-structures/base/linear-base.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +171 -205
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  19. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +135 -87
  20. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +138 -149
  22. package/dist/cjs/data-structures/binary-tree/avl-tree.js +208 -195
  23. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +476 -632
  25. package/dist/cjs/data-structures/binary-tree/binary-tree.js +608 -875
  26. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/bst.d.ts +258 -306
  28. package/dist/cjs/data-structures/binary-tree/bst.js +505 -481
  29. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  31. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +114 -209
  32. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +132 -154
  34. package/dist/cjs/data-structures/binary-tree/tree-counter.js +172 -203
  35. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  37. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -85
  38. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  39. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +238 -233
  40. package/dist/cjs/data-structures/graph/abstract-graph.js +267 -237
  41. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  42. package/dist/cjs/data-structures/graph/directed-graph.d.ts +108 -224
  43. package/dist/cjs/data-structures/graph/directed-graph.js +146 -233
  44. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  45. package/dist/cjs/data-structures/graph/map-graph.d.ts +49 -55
  46. package/dist/cjs/data-structures/graph/map-graph.js +56 -59
  47. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  48. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +103 -146
  49. package/dist/cjs/data-structures/graph/undirected-graph.js +129 -149
  50. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  51. package/dist/cjs/data-structures/hash/hash-map.d.ts +164 -338
  52. package/dist/cjs/data-structures/hash/hash-map.js +270 -457
  53. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  54. package/dist/cjs/data-structures/heap/heap.d.ts +214 -289
  55. package/dist/cjs/data-structures/heap/heap.js +340 -349
  56. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  57. package/dist/cjs/data-structures/heap/max-heap.d.ts +11 -47
  58. package/dist/cjs/data-structures/heap/max-heap.js +11 -66
  59. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  60. package/dist/cjs/data-structures/heap/min-heap.d.ts +12 -47
  61. package/dist/cjs/data-structures/heap/min-heap.js +11 -66
  62. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  63. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  64. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +368 -494
  65. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  66. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  67. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +447 -466
  68. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  69. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  70. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -100
  71. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  72. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  73. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +11 -78
  74. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  75. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  76. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +10 -79
  77. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  78. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -61
  79. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -83
  80. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  81. package/dist/cjs/data-structures/queue/deque.d.ts +227 -254
  82. package/dist/cjs/data-structures/queue/deque.js +309 -348
  83. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  84. package/dist/cjs/data-structures/queue/queue.d.ts +180 -201
  85. package/dist/cjs/data-structures/queue/queue.js +265 -248
  86. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  87. package/dist/cjs/data-structures/stack/stack.d.ts +124 -102
  88. package/dist/cjs/data-structures/stack/stack.js +181 -125
  89. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  90. package/dist/cjs/data-structures/trie/trie.d.ts +164 -165
  91. package/dist/cjs/data-structures/trie/trie.js +189 -172
  92. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  93. package/dist/cjs/interfaces/binary-tree.d.ts +56 -6
  94. package/dist/cjs/interfaces/graph.d.ts +16 -0
  95. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  96. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +4 -0
  97. package/dist/cjs/types/utils/utils.d.ts +6 -6
  98. package/dist/cjs/utils/utils.d.ts +110 -49
  99. package/dist/cjs/utils/utils.js +148 -73
  100. package/dist/cjs/utils/utils.js.map +1 -1
  101. package/dist/esm/data-structures/base/iterable-element-base.d.ts +186 -83
  102. package/dist/esm/data-structures/base/iterable-element-base.js +155 -107
  103. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  104. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +95 -119
  105. package/dist/esm/data-structures/base/iterable-entry-base.js +59 -116
  106. package/dist/esm/data-structures/base/iterable-entry-base.js.map +1 -1
  107. package/dist/esm/data-structures/base/linear-base.d.ts +250 -192
  108. package/dist/esm/data-structures/base/linear-base.js +137 -274
  109. package/dist/esm/data-structures/base/linear-base.js.map +1 -1
  110. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +126 -158
  111. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +171 -212
  112. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  113. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +100 -69
  114. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +133 -94
  115. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  116. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +138 -149
  117. package/dist/esm/data-structures/binary-tree/avl-tree.js +206 -200
  118. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  119. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +476 -632
  120. package/dist/esm/data-structures/binary-tree/binary-tree.js +613 -885
  121. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  122. package/dist/esm/data-structures/binary-tree/bst.d.ts +258 -306
  123. package/dist/esm/data-structures/binary-tree/bst.js +507 -487
  124. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  125. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +107 -179
  126. package/dist/esm/data-structures/binary-tree/red-black-tree.js +114 -215
  127. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  128. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +132 -154
  129. package/dist/esm/data-structures/binary-tree/tree-counter.js +175 -209
  130. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  131. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  132. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +103 -92
  133. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  134. package/dist/esm/data-structures/graph/abstract-graph.d.ts +238 -233
  135. package/dist/esm/data-structures/graph/abstract-graph.js +267 -237
  136. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  137. package/dist/esm/data-structures/graph/directed-graph.d.ts +108 -224
  138. package/dist/esm/data-structures/graph/directed-graph.js +145 -233
  139. package/dist/esm/data-structures/graph/directed-graph.js.map +1 -1
  140. package/dist/esm/data-structures/graph/map-graph.d.ts +49 -55
  141. package/dist/esm/data-structures/graph/map-graph.js +56 -59
  142. package/dist/esm/data-structures/graph/map-graph.js.map +1 -1
  143. package/dist/esm/data-structures/graph/undirected-graph.d.ts +103 -146
  144. package/dist/esm/data-structures/graph/undirected-graph.js +128 -149
  145. package/dist/esm/data-structures/graph/undirected-graph.js.map +1 -1
  146. package/dist/esm/data-structures/hash/hash-map.d.ts +164 -338
  147. package/dist/esm/data-structures/hash/hash-map.js +270 -457
  148. package/dist/esm/data-structures/hash/hash-map.js.map +1 -1
  149. package/dist/esm/data-structures/heap/heap.d.ts +214 -289
  150. package/dist/esm/data-structures/heap/heap.js +329 -349
  151. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  152. package/dist/esm/data-structures/heap/max-heap.d.ts +11 -47
  153. package/dist/esm/data-structures/heap/max-heap.js +11 -66
  154. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  155. package/dist/esm/data-structures/heap/min-heap.d.ts +12 -47
  156. package/dist/esm/data-structures/heap/min-heap.js +11 -66
  157. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  158. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +231 -347
  159. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +368 -495
  160. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  161. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +261 -310
  162. package/dist/esm/data-structures/linked-list/singly-linked-list.js +448 -467
  163. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  164. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -107
  165. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -100
  166. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +1 -1
  167. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +12 -56
  168. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +11 -78
  169. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  170. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +11 -57
  171. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +10 -79
  172. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  173. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -61
  174. package/dist/esm/data-structures/priority-queue/priority-queue.js +8 -83
  175. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  176. package/dist/esm/data-structures/queue/deque.d.ts +227 -254
  177. package/dist/esm/data-structures/queue/deque.js +313 -348
  178. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  179. package/dist/esm/data-structures/queue/queue.d.ts +180 -201
  180. package/dist/esm/data-structures/queue/queue.js +263 -248
  181. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  182. package/dist/esm/data-structures/stack/stack.d.ts +124 -102
  183. package/dist/esm/data-structures/stack/stack.js +181 -125
  184. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  185. package/dist/esm/data-structures/trie/trie.d.ts +164 -165
  186. package/dist/esm/data-structures/trie/trie.js +193 -172
  187. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  188. package/dist/esm/interfaces/binary-tree.d.ts +56 -6
  189. package/dist/esm/interfaces/graph.d.ts +16 -0
  190. package/dist/esm/types/data-structures/base/base.d.ts +1 -1
  191. package/dist/esm/types/data-structures/graph/abstract-graph.d.ts +4 -0
  192. package/dist/esm/types/utils/utils.d.ts +6 -6
  193. package/dist/esm/utils/utils.d.ts +110 -49
  194. package/dist/esm/utils/utils.js +139 -68
  195. package/dist/esm/utils/utils.js.map +1 -1
  196. package/dist/umd/data-structure-typed.js +4737 -6525
  197. package/dist/umd/data-structure-typed.min.js +8 -6
  198. package/dist/umd/data-structure-typed.min.js.map +1 -1
  199. package/package.json +3 -4
  200. package/src/data-structures/base/iterable-element-base.ts +238 -115
  201. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  202. package/src/data-structures/base/linear-base.ts +271 -277
  203. package/src/data-structures/binary-tree/avl-tree-counter.ts +198 -216
  204. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +192 -101
  205. package/src/data-structures/binary-tree/avl-tree.ts +239 -206
  206. package/src/data-structures/binary-tree/binary-tree.ts +677 -901
  207. package/src/data-structures/binary-tree/bst.ts +568 -570
  208. package/src/data-structures/binary-tree/red-black-tree.ts +161 -222
  209. package/src/data-structures/binary-tree/tree-counter.ts +199 -218
  210. package/src/data-structures/binary-tree/tree-multi-map.ts +131 -97
  211. package/src/data-structures/graph/abstract-graph.ts +339 -264
  212. package/src/data-structures/graph/directed-graph.ts +146 -236
  213. package/src/data-structures/graph/map-graph.ts +63 -60
  214. package/src/data-structures/graph/undirected-graph.ts +129 -152
  215. package/src/data-structures/hash/hash-map.ts +274 -496
  216. package/src/data-structures/heap/heap.ts +389 -402
  217. package/src/data-structures/heap/max-heap.ts +12 -76
  218. package/src/data-structures/heap/min-heap.ts +13 -76
  219. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  220. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  221. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  222. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  223. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  224. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  225. package/src/data-structures/queue/deque.ts +381 -357
  226. package/src/data-structures/queue/queue.ts +310 -264
  227. package/src/data-structures/stack/stack.ts +217 -131
  228. package/src/data-structures/trie/trie.ts +240 -175
  229. package/src/interfaces/binary-tree.ts +240 -6
  230. package/src/interfaces/graph.ts +37 -0
  231. package/src/types/data-structures/base/base.ts +5 -5
  232. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  233. package/src/types/utils/utils.ts +9 -5
  234. package/src/utils/utils.ts +152 -86
  235. package/test/integration/index.html +1 -1
  236. package/test/performance/benchmark-runner.ts +528 -0
  237. package/test/performance/reportor.mjs +43 -43
  238. package/test/performance/runner-config.json +39 -0
  239. package/test/performance/single-suite-runner.ts +69 -0
  240. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  241. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  242. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  243. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  244. package/test/unit/data-structures/binary-tree/bst.test.ts +84 -5
  245. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  246. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  247. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +3 -3
  248. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  249. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  250. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  251. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  252. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  253. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  254. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  255. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  256. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  257. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  258. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  259. package/test/unit/utils/utils.test.ts +0 -1
  260. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  261. 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');