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
@@ -1,47 +1,35 @@
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Pablo Zeng
5
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
1
8
  import type { MapGraphCoordinate, VertexKey } from '../../types';
2
9
  import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
3
10
  export declare class MapVertex<V = any> extends DirectedVertex<V> {
4
11
  lat: number;
5
12
  long: number;
6
- /**
7
- * The constructor function initializes an object with an key, latitude, longitude, and an optional value.
8
- * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
9
- * @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
10
- * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
11
- * values representing points north of the equator and negative values representing points south of the equator.
12
- * @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
13
- * coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
14
- * values ranging from -180 to 180.
15
- * @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
16
- * creating an instance of the class.
17
- */
18
13
  constructor(key: VertexKey, value: V, lat: number, long: number);
19
14
  }
20
15
  export declare class MapEdge<E = any> extends DirectedEdge<E> {
21
- /**
22
- * The constructor function initializes a new instance of a class with the given source, destination, weight, and
23
- * value.
24
- * @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
25
- * a graph.
26
- * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
27
- * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
28
- * @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
29
- * information or data associated with the edge.
30
- */
31
16
  constructor(src: VertexKey, dest: VertexKey, weight?: number, value?: E);
32
17
  }
33
18
  /**
34
- *
19
+ * Directed graph variant carrying geospatial coordinates.
20
+ * @template V - Vertex value type.
21
+ * @template E - Edge value type.
22
+ * @template VO - Concrete vertex class (MapVertex<V>).
23
+ * @template EO - Concrete edge class (MapEdge<E>).
24
+ * @remarks Time O(1), Space O(1)
25
+ * @example examples will be generated by unit test
35
26
  */
36
27
  export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVertex<V>, EO extends MapEdge<E> = MapEdge<E>> extends DirectedGraph<V, E, VO, EO> {
37
28
  /**
38
- * The constructor function initializes the originCoord and bottomRight properties of a MapGraphCoordinate object.
39
- * @param {MapGraphCoordinate} originCoord - The `originCoord` parameter is a `MapGraphCoordinate` object that represents the
40
- * starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
41
- * graph.
42
- * @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
43
- * `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
44
- * it will default to `undefined`.
29
+ * Construct a MapGraph.
30
+ * @param originCoord - Origin coordinate `[lat, long]` used as default.
31
+ * @param bottomRight - Optional bottom-right coordinate for bounding boxes.
32
+ * @remarks Time O(1), Space O(1)
45
33
  */
46
34
  constructor(originCoord: MapGraphCoordinate, bottomRight?: MapGraphCoordinate);
47
35
  protected _originCoord: MapGraphCoordinate;
@@ -49,36 +37,42 @@ export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVer
49
37
  protected _bottomRight: MapGraphCoordinate | undefined;
50
38
  get bottomRight(): MapGraphCoordinate | undefined;
51
39
  /**
52
- * The function creates a new vertex with the given key, value, latitude, and longitude.
53
- * @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
54
- * be a string or a number depending on how you define it in your code.
55
- * @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
56
- * is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
57
- * @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
58
- * position of the vertex on the Earth's surface in the north-south direction.
59
- * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
60
- * @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
40
+ * Create a map vertex with optional coordinates.
41
+ * @param key - Vertex identifier.
42
+ * @param value - Optional payload.
43
+ * @param lat - Latitude (defaults to `originCoord[0]`).
44
+ * @param long - Longitude (defaults to `originCoord[1]`).
45
+ * @returns MapVertex instance.
46
+ * @remarks Time O(1), Space O(1)
61
47
  */
62
48
  createVertex(key: VertexKey, value?: V, lat?: number, long?: number): VO;
63
49
  /**
64
- * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
65
- * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
66
- * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
67
- * created.
68
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
69
- * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
70
- * If the weight is not provided, it can be set to a default value or left undefined.
71
- * @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
72
- * depending on the specific implementation of the `MapEdge` class.
73
- * @returns a new instance of the `MapEdge` class, cast as type `EO`.
50
+ * Create a map edge (directed) with optional weight/value.
51
+ * @param src - Source key.
52
+ * @param dest - Destination key.
53
+ * @param weight - Edge weight.
54
+ * @param value - Edge payload.
55
+ * @returns MapEdge instance.
56
+ * @remarks Time O(1), Space O(1)
74
57
  */
75
58
  createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO;
76
59
  /**
77
- * The override function is used to override the default behavior of a function.
78
- * In this case, we are overriding the clone() function from Graph&lt;V, E&gt;.
79
- * The clone() function returns a new graph that is an exact copy of the original graph.
80
- *
81
- * @return A mapgraph&lt;v, e, vo, eo&gt;
60
+ * Deep clone as the same concrete class.
61
+ * @returns A new graph of the same concrete class (`this` type).
62
+ * @remarks Time O(V + E), Space O(V + E)
63
+ */
64
+ clone(): this;
65
+ /**
66
+ * Include `originCoord` and `bottomRight` so `clone()/filter()` preserve geospatial settings.
67
+ * @returns Options bag extending super snapshot.
68
+ * @remarks Time O(1), Space O(1)
69
+ */
70
+ protected _snapshotOptions(): Record<string, unknown>;
71
+ /**
72
+ * Re-create a same-species MapGraph instance from snapshot options.
73
+ * @param options - Snapshot options providing `originCoord`/`bottomRight`.
74
+ * @returns Empty MapGraph instance of `this` type.
75
+ * @remarks Time O(1), Space O(1)
82
76
  */
83
- clone(): MapGraph<V, E, VO, EO>;
77
+ protected _createInstance(options?: Partial<Record<string, unknown>>): this;
84
78
  }
@@ -1,20 +1,15 @@
1
1
  "use strict";
2
+ /**
3
+ * data-structure-typed
4
+ *
5
+ * @author Pablo Zeng
6
+ * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
7
+ * @license MIT License
8
+ */
2
9
  Object.defineProperty(exports, "__esModule", { value: true });
3
10
  exports.MapGraph = exports.MapEdge = exports.MapVertex = void 0;
4
11
  const directed_graph_1 = require("./directed-graph");
5
12
  class MapVertex extends directed_graph_1.DirectedVertex {
6
- /**
7
- * The constructor function initializes an object with an key, latitude, longitude, and an optional value.
8
- * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
9
- * @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
10
- * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
11
- * values representing points north of the equator and negative values representing points south of the equator.
12
- * @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
13
- * coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
14
- * values ranging from -180 to 180.
15
- * @param {V} [value] - The "value" parameter is an optional value of type V. It is not required to be provided when
16
- * creating an instance of the class.
17
- */
18
13
  constructor(key, value, lat, long) {
19
14
  super(key, value);
20
15
  this.lat = lat;
@@ -23,33 +18,26 @@ class MapVertex extends directed_graph_1.DirectedVertex {
23
18
  }
24
19
  exports.MapVertex = MapVertex;
25
20
  class MapEdge extends directed_graph_1.DirectedEdge {
26
- /**
27
- * The constructor function initializes a new instance of a class with the given source, destination, weight, and
28
- * value.
29
- * @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
30
- * a graph.
31
- * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
32
- * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
33
- * @param {E} [value] - The "value" parameter is an optional parameter of type E. It is used to store additional
34
- * information or data associated with the edge.
35
- */
36
21
  constructor(src, dest, weight, value) {
37
22
  super(src, dest, weight, value);
38
23
  }
39
24
  }
40
25
  exports.MapEdge = MapEdge;
41
26
  /**
42
- *
27
+ * Directed graph variant carrying geospatial coordinates.
28
+ * @template V - Vertex value type.
29
+ * @template E - Edge value type.
30
+ * @template VO - Concrete vertex class (MapVertex<V>).
31
+ * @template EO - Concrete edge class (MapEdge<E>).
32
+ * @remarks Time O(1), Space O(1)
33
+ * @example examples will be generated by unit test
43
34
  */
44
35
  class MapGraph extends directed_graph_1.DirectedGraph {
45
36
  /**
46
- * The constructor function initializes the originCoord and bottomRight properties of a MapGraphCoordinate object.
47
- * @param {MapGraphCoordinate} originCoord - The `originCoord` parameter is a `MapGraphCoordinate` object that represents the
48
- * starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
49
- * graph.
50
- * @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
51
- * `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
52
- * it will default to `undefined`.
37
+ * Construct a MapGraph.
38
+ * @param originCoord - Origin coordinate `[lat, long]` used as default.
39
+ * @param bottomRight - Optional bottom-right coordinate for bounding boxes.
40
+ * @remarks Time O(1), Space O(1)
53
41
  */
54
42
  constructor(originCoord, bottomRight) {
55
43
  super();
@@ -64,47 +52,56 @@ class MapGraph extends directed_graph_1.DirectedGraph {
64
52
  return this._bottomRight;
65
53
  }
66
54
  /**
67
- * The function creates a new vertex with the given key, value, latitude, and longitude.
68
- * @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
69
- * be a string or a number depending on how you define it in your code.
70
- * @param [value] - The `value` parameter is an optional value that can be assigned to the `value` property of the vertex. It
71
- * is of type `V`, which means it should be of the same type as the `value` property of the vertex class `VO`.
72
- * @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
73
- * position of the vertex on the Earth's surface in the north-south direction.
74
- * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
75
- * @returns The method is returning a new instance of the `MapVertex` class, casted as type `VO`.
55
+ * Create a map vertex with optional coordinates.
56
+ * @param key - Vertex identifier.
57
+ * @param value - Optional payload.
58
+ * @param lat - Latitude (defaults to `originCoord[0]`).
59
+ * @param long - Longitude (defaults to `originCoord[1]`).
60
+ * @returns MapVertex instance.
61
+ * @remarks Time O(1), Space O(1)
76
62
  */
77
63
  createVertex(key, value, lat = this.originCoord[0], long = this.originCoord[1]) {
78
64
  return new MapVertex(key, value, lat, long);
79
65
  }
80
66
  /**
81
- * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
82
- * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
83
- * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
84
- * created.
85
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
86
- * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
87
- * If the weight is not provided, it can be set to a default value or left undefined.
88
- * @param [value] - The `value` parameter is an optional value that can be assigned to the edge. It can be of any type,
89
- * depending on the specific implementation of the `MapEdge` class.
90
- * @returns a new instance of the `MapEdge` class, cast as type `EO`.
67
+ * Create a map edge (directed) with optional weight/value.
68
+ * @param src - Source key.
69
+ * @param dest - Destination key.
70
+ * @param weight - Edge weight.
71
+ * @param value - Edge payload.
72
+ * @returns MapEdge instance.
73
+ * @remarks Time O(1), Space O(1)
91
74
  */
92
75
  createEdge(src, dest, weight, value) {
93
76
  return new MapEdge(src, dest, weight, value);
94
77
  }
95
78
  /**
96
- * The override function is used to override the default behavior of a function.
97
- * In this case, we are overriding the clone() function from Graph&lt;V, E&gt;.
98
- * The clone() function returns a new graph that is an exact copy of the original graph.
99
- *
100
- * @return A mapgraph&lt;v, e, vo, eo&gt;
79
+ * Deep clone as the same concrete class.
80
+ * @returns A new graph of the same concrete class (`this` type).
81
+ * @remarks Time O(V + E), Space O(V + E)
101
82
  */
102
83
  clone() {
103
- const cloned = new MapGraph(this.originCoord, this.bottomRight);
104
- cloned.vertexMap = new Map(this.vertexMap);
105
- cloned.inEdgeMap = new Map(this.inEdgeMap);
106
- cloned.outEdgeMap = new Map(this.outEdgeMap);
107
- return cloned;
84
+ return super.clone();
85
+ }
86
+ /**
87
+ * Include `originCoord` and `bottomRight` so `clone()/filter()` preserve geospatial settings.
88
+ * @returns Options bag extending super snapshot.
89
+ * @remarks Time O(1), Space O(1)
90
+ */
91
+ _snapshotOptions() {
92
+ return Object.assign(Object.assign({}, super._snapshotOptions()), { originCoord: this.originCoord, bottomRight: this.bottomRight });
93
+ }
94
+ /**
95
+ * Re-create a same-species MapGraph instance from snapshot options.
96
+ * @param options - Snapshot options providing `originCoord`/`bottomRight`.
97
+ * @returns Empty MapGraph instance of `this` type.
98
+ * @remarks Time O(1), Space O(1)
99
+ */
100
+ _createInstance(options) {
101
+ const { originCoord, bottomRight } = (options || {});
102
+ const oc = (originCoord !== null && originCoord !== void 0 ? originCoord : this.originCoord);
103
+ const br = (bottomRight !== null && bottomRight !== void 0 ? bottomRight : this.bottomRight);
104
+ return new MapGraph(oc, br);
108
105
  }
109
106
  }
110
107
  exports.MapGraph = MapGraph;
@@ -1 +1 @@
1
- {"version":3,"file":"map-graph.js","sourceRoot":"","sources":["../../../../src/data-structures/graph/map-graph.ts"],"names":[],"mappings":";;;AACA,qDAA+E;AAE/E,MAAa,SAAmB,SAAQ,+BAAiB;IAIvD;;;;;;;;;;;OAWG;IACH,YAAY,GAAc,EAAE,KAAQ,EAAE,GAAW,EAAE,IAAY;QAC7D,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AArBD,8BAqBC;AAED,MAAa,OAAiB,SAAQ,6BAAe;IACnD;;;;;;;;;OASG;IACH,YAAY,GAAc,EAAE,IAAe,EAAE,MAAe,EAAE,KAAS;QACrE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC;CACF;AAdD,0BAcC;AAED;;GAEG;AACH,MAAa,QAKX,SAAQ,8BAA2B;IACnC;;;;;;;;OAQG;IACH,YAAY,WAA+B,EAAE,WAAgC;QAC3E,KAAK,EAAE,CAAC;QAKA,iBAAY,GAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAJlD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAID,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAID,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;;;;;;;;OAUG;IACM,YAAY,CACnB,GAAc,EACd,KAAS,EACT,MAAc,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EACjC,OAAe,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QAElC,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAO,CAAC;IACpD,CAAC;IAED;;;;;;;;;;;OAWG;IACM,UAAU,CAAC,GAAc,EAAE,IAAe,EAAE,MAAe,EAAE,KAAS;QAC7E,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAO,CAAC;IACrD,CAAC;IAED;;;;;;OAMG;IACM,KAAK;QACZ,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAe,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC9E,MAAM,CAAC,SAAS,GAAG,IAAI,GAAG,CAAgB,IAAI,CAAC,SAAS,CAAC,CAAC;QAC1D,MAAM,CAAC,SAAS,GAAG,IAAI,GAAG,CAAW,IAAI,CAAC,SAAS,CAAC,CAAC;QACrD,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,CAAW,IAAI,CAAC,UAAU,CAAC,CAAC;QACvD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAnFD,4BAmFC"}
1
+ {"version":3,"file":"map-graph.js","sourceRoot":"","sources":["../../../../src/data-structures/graph/map-graph.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAGH,qDAA+E;AAE/E,MAAa,SAAmB,SAAQ,+BAAiB;IAIvD,YAAY,GAAc,EAAE,KAAQ,EAAE,GAAW,EAAE,IAAY;QAC7D,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAClB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AATD,8BASC;AAED,MAAa,OAAiB,SAAQ,6BAAe;IACnD,YAAY,GAAc,EAAE,IAAe,EAAE,MAAe,EAAE,KAAS;QACrE,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAClC,CAAC;CACF;AAJD,0BAIC;AAED;;;;;;;;GAQG;AACH,MAAa,QAKX,SAAQ,8BAA2B;IACnC;;;;;OAKG;IACH,YAAY,WAA+B,EAAE,WAAgC;QAC3E,KAAK,EAAE,CAAC;QAKA,iBAAY,GAAuB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAJlD,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAID,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAID,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAED;;;;;;;;OAQG;IACM,YAAY,CACnB,GAAc,EACd,KAAS,EACT,MAAc,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EACjC,OAAe,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC;QAElC,OAAO,IAAI,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,CAAO,CAAC;IACpD,CAAC;IAED;;;;;;;;OAQG;IACM,UAAU,CAAC,GAAc,EAAE,IAAe,EAAE,MAAe,EAAE,KAAS;QAC7E,OAAO,IAAI,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAO,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACM,KAAK;QACZ,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED;;;;OAIG;IACgB,gBAAgB;QACjC,uCAAa,KAAK,CAAC,gBAAgB,EAAU,KAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,IAAG;IAChH,CAAC;IAED;;;;;OAKG;IACgB,eAAe,CAAC,OAA0C;QAC3E,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,CAGlD,CAAC;QACF,MAAM,EAAE,GAAG,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,IAAI,CAAC,WAAW,CAAqB,CAAC;QACjE,MAAM,EAAE,GAAG,CAAC,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,IAAI,CAAC,WAAW,CAAiC,CAAC;QAC7E,OAAO,IAAI,QAAQ,CAAe,EAAE,EAAE,EAAE,CAAS,CAAC;IACpD,CAAC;CACF;AA9FD,4BA8FC"}