data-structure-typed 0.8.18 → 1.3.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 (272) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +690 -2
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -18
  8. package/dist/data-structures/binary-tree/avl-tree.js +110 -37
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +40 -2
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +44 -2
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -138
  12. package/dist/data-structures/binary-tree/binary-tree.js +27 -979
  13. package/dist/data-structures/binary-tree/bst.d.ts +118 -28
  14. package/dist/data-structures/binary-tree/bst.js +162 -124
  15. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  16. package/dist/data-structures/binary-tree/index.js +1 -0
  17. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  18. package/dist/data-structures/binary-tree/rb-tree.js +40 -2
  19. package/dist/data-structures/binary-tree/segment-tree.d.ts +63 -13
  20. package/dist/data-structures/binary-tree/segment-tree.js +80 -17
  21. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -10
  22. package/dist/data-structures/binary-tree/tree-multiset.js +682 -9
  23. package/dist/data-structures/graph/abstract-graph.d.ts +270 -64
  24. package/dist/data-structures/graph/abstract-graph.js +365 -92
  25. package/dist/data-structures/graph/directed-graph.d.ts +175 -26
  26. package/dist/data-structures/graph/directed-graph.js +249 -95
  27. package/dist/data-structures/graph/index.d.ts +1 -0
  28. package/dist/data-structures/graph/index.js +1 -0
  29. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  30. package/dist/data-structures/graph/map-graph.js +111 -0
  31. package/dist/data-structures/graph/undirected-graph.d.ts +111 -8
  32. package/dist/data-structures/graph/undirected-graph.js +154 -44
  33. package/dist/data-structures/hash/coordinate-map.d.ts +39 -2
  34. package/dist/data-structures/hash/coordinate-map.js +44 -3
  35. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  36. package/dist/data-structures/hash/coordinate-set.js +34 -0
  37. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  38. package/dist/data-structures/hash/hash-table.js +4 -0
  39. package/dist/data-structures/hash/index.d.ts +5 -0
  40. package/dist/data-structures/hash/index.js +5 -0
  41. package/dist/data-structures/hash/pair.d.ts +2 -1
  42. package/dist/data-structures/hash/pair.js +4 -0
  43. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  44. package/dist/data-structures/hash/tree-map.js +4 -0
  45. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-set.js +4 -0
  47. package/dist/data-structures/heap/heap.d.ts +62 -51
  48. package/dist/data-structures/heap/heap.js +106 -63
  49. package/dist/data-structures/heap/max-heap.d.ts +13 -4
  50. package/dist/data-structures/heap/max-heap.js +10 -2
  51. package/dist/data-structures/heap/min-heap.d.ts +14 -4
  52. package/dist/data-structures/heap/min-heap.js +11 -2
  53. package/dist/data-structures/index.d.ts +1 -0
  54. package/dist/data-structures/index.js +1 -0
  55. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -57
  56. package/dist/data-structures/linked-list/doubly-linked-list.js +461 -194
  57. package/dist/data-structures/linked-list/index.d.ts +1 -0
  58. package/dist/data-structures/linked-list/index.js +1 -0
  59. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -319
  60. package/dist/data-structures/linked-list/singly-linked-list.js +338 -557
  61. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  62. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  63. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  64. package/dist/data-structures/matrix/matrix.js +14 -0
  65. package/dist/data-structures/matrix/matrix2d.d.ts +87 -4
  66. package/dist/data-structures/matrix/matrix2d.js +91 -8
  67. package/dist/data-structures/matrix/navigator.d.ts +37 -16
  68. package/dist/data-structures/matrix/navigator.js +28 -0
  69. package/dist/data-structures/matrix/vector2d.d.ts +156 -29
  70. package/dist/data-structures/matrix/vector2d.js +184 -55
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -1
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +28 -4
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -1
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +29 -4
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +166 -22
  76. package/dist/data-structures/priority-queue/priority-queue.js +219 -75
  77. package/dist/data-structures/queue/deque.d.ts +141 -13
  78. package/dist/data-structures/queue/deque.js +151 -7
  79. package/dist/data-structures/queue/queue.d.ts +68 -42
  80. package/dist/data-structures/queue/queue.js +95 -51
  81. package/dist/data-structures/stack/stack.d.ts +30 -36
  82. package/dist/data-structures/stack/stack.js +31 -37
  83. package/dist/data-structures/tree/index.d.ts +1 -0
  84. package/dist/data-structures/tree/index.js +17 -0
  85. package/dist/data-structures/tree/tree.d.ts +14 -0
  86. package/dist/{types/utils.js → data-structures/tree/tree.js} +26 -19
  87. package/dist/data-structures/trie/trie.d.ts +39 -6
  88. package/dist/data-structures/trie/trie.js +81 -12
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.js +3 -0
  91. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  92. package/dist/interfaces/abstract-binary-tree.js +2 -0
  93. package/dist/interfaces/abstract-graph.d.ts +17 -0
  94. package/dist/interfaces/abstract-graph.js +2 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/avl-tree.js +2 -0
  97. package/dist/interfaces/binary-tree.d.ts +6 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/bst.d.ts +17 -0
  100. package/dist/interfaces/bst.js +2 -0
  101. package/dist/interfaces/directed-graph.d.ts +12 -0
  102. package/dist/interfaces/directed-graph.js +2 -0
  103. package/dist/interfaces/doubly-linked-list.js +2 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +15 -0
  106. package/dist/interfaces/index.js +31 -0
  107. package/dist/interfaces/navigator.js +2 -0
  108. package/dist/interfaces/priority-queue.js +2 -0
  109. package/dist/interfaces/rb-tree.d.ts +8 -0
  110. package/dist/interfaces/rb-tree.js +2 -0
  111. package/dist/interfaces/segment-tree.js +2 -0
  112. package/dist/interfaces/singly-linked-list.js +2 -0
  113. package/dist/interfaces/tree-multiset.d.ts +7 -0
  114. package/dist/interfaces/tree-multiset.js +2 -0
  115. package/dist/interfaces/undirected-graph.d.ts +5 -0
  116. package/dist/interfaces/undirected-graph.js +2 -0
  117. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  118. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  119. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  120. package/dist/types/data-structures/abstract-graph.js +2 -0
  121. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  122. package/dist/types/data-structures/avl-tree.js +2 -0
  123. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  124. package/dist/types/data-structures/binary-tree.js +2 -0
  125. package/dist/types/data-structures/bst.d.ts +13 -0
  126. package/dist/types/data-structures/bst.js +9 -0
  127. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  128. package/dist/types/data-structures/directed-graph.js +9 -0
  129. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  130. package/dist/types/data-structures/heap.d.ts +3 -0
  131. package/dist/types/data-structures/heap.js +2 -0
  132. package/dist/types/data-structures/index.d.ts +13 -7
  133. package/dist/types/data-structures/index.js +31 -0
  134. package/dist/types/data-structures/map-graph.d.ts +1 -0
  135. package/dist/types/data-structures/map-graph.js +2 -0
  136. package/dist/types/data-structures/navigator.d.ts +14 -0
  137. package/dist/types/data-structures/navigator.js +2 -0
  138. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  139. package/dist/types/data-structures/priority-queue.js +2 -0
  140. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  141. package/dist/types/data-structures/rb-tree.js +8 -0
  142. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  143. package/dist/types/data-structures/segment-tree.js +2 -0
  144. package/dist/types/data-structures/singly-linked-list.js +2 -0
  145. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  146. package/dist/types/data-structures/tree-multiset.js +2 -0
  147. package/dist/types/helpers.d.ts +1 -0
  148. package/dist/types/helpers.js +2 -0
  149. package/dist/types/index.d.ts +2 -0
  150. package/dist/types/index.js +2 -0
  151. package/dist/types/utils/index.d.ts +2 -0
  152. package/dist/types/utils/index.js +18 -0
  153. package/dist/types/utils/utils.d.ts +7 -0
  154. package/dist/types/utils/utils.js +2 -0
  155. package/dist/types/utils/validate-type.d.ts +19 -0
  156. package/dist/types/utils/validate-type.js +2 -0
  157. package/dist/utils/index.js +17 -0
  158. package/dist/utils/utils.d.ts +19 -0
  159. package/dist/{data-structures/trampoline.js → utils/utils.js} +26 -12
  160. package/package.json +106 -55
  161. package/.idea/data-structure-typed.iml +0 -12
  162. package/.idea/modules.xml +0 -8
  163. package/.idea/vcs.xml +0 -6
  164. package/dist/data-structures/trampoline.d.ts +0 -25
  165. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  167. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  169. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  170. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  171. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  172. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  173. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  174. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  175. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  176. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  177. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  178. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  179. package/dist/types/data-structures/graph/index.d.ts +0 -3
  180. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  181. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  182. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  185. package/dist/types/data-structures/heap/index.d.ts +0 -3
  186. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  187. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  188. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  189. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  190. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  191. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  192. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  193. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  194. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  195. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  196. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  199. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  200. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  201. package/dist/types/data-structures/queue/index.d.ts +0 -1
  202. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  203. package/dist/types/data-structures/stack/index.d.ts +0 -1
  204. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  205. package/dist/types/data-structures/trampoline.d.ts +0 -25
  206. package/dist/types/data-structures/trie/index.d.ts +0 -1
  207. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/types/utils.d.ts +0 -46
  210. package/dist/utils.d.ts +0 -122
  211. package/dist/utils.js +0 -569
  212. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  213. package/src/data-structures/binary-tree/avl-tree.ts +0 -232
  214. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  215. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  216. package/src/data-structures/binary-tree/binary-tree.ts +0 -1088
  217. package/src/data-structures/binary-tree/bst.ts +0 -404
  218. package/src/data-structures/binary-tree/index.ts +0 -11
  219. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  220. package/src/data-structures/binary-tree/segment-tree.ts +0 -164
  221. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  222. package/src/data-structures/binary-tree/tree-multiset.ts +0 -21
  223. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  224. package/src/data-structures/graph/abstract-graph.ts +0 -789
  225. package/src/data-structures/graph/directed-graph.ts +0 -322
  226. package/src/data-structures/graph/index.ts +0 -3
  227. package/src/data-structures/graph/undirected-graph.ts +0 -154
  228. package/src/data-structures/hash/coordinate-map.ts +0 -24
  229. package/src/data-structures/hash/coordinate-set.ts +0 -20
  230. package/src/data-structures/hash/hash-table.ts +0 -1
  231. package/src/data-structures/hash/index.ts +0 -1
  232. package/src/data-structures/heap/heap.ts +0 -136
  233. package/src/data-structures/heap/index.ts +0 -3
  234. package/src/data-structures/heap/max-heap.ts +0 -22
  235. package/src/data-structures/heap/min-heap.ts +0 -24
  236. package/src/data-structures/index.ts +0 -11
  237. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -258
  238. package/src/data-structures/linked-list/index.ts +0 -2
  239. package/src/data-structures/linked-list/singly-linked-list.ts +0 -750
  240. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  241. package/src/data-structures/matrix/index.ts +0 -4
  242. package/src/data-structures/matrix/matrix.ts +0 -13
  243. package/src/data-structures/matrix/matrix2d.ts +0 -125
  244. package/src/data-structures/matrix/navigator.ts +0 -99
  245. package/src/data-structures/matrix/vector2d.ts +0 -189
  246. package/src/data-structures/priority-queue/index.ts +0 -3
  247. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -12
  248. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -12
  249. package/src/data-structures/priority-queue/priority-queue.ts +0 -208
  250. package/src/data-structures/queue/deque.ts +0 -139
  251. package/src/data-structures/queue/index.ts +0 -2
  252. package/src/data-structures/queue/queue.ts +0 -123
  253. package/src/data-structures/stack/index.ts +0 -1
  254. package/src/data-structures/stack/stack.ts +0 -104
  255. package/src/data-structures/trampoline.ts +0 -91
  256. package/src/data-structures/trie/index.ts +0 -1
  257. package/src/data-structures/trie/trie.ts +0 -153
  258. package/src/index.ts +0 -1
  259. package/src/types/index.ts +0 -1
  260. package/src/types/patches/index.d.ts +0 -0
  261. package/src/types/utils.ts +0 -158
  262. package/src/utils.ts +0 -605
  263. package/tsconfig.json +0 -53
  264. /package/dist/{types/data-structures/hash/hash-table.d.ts → interfaces/doubly-linked-list.d.ts} +0 -0
  265. /package/dist/{types/data-structures/hash/pair.d.ts → interfaces/heap.d.ts} +0 -0
  266. /package/dist/{types/data-structures/hash/tree-map.d.ts → interfaces/navigator.d.ts} +0 -0
  267. /package/dist/{types/data-structures/hash/tree-set.d.ts → interfaces/priority-queue.d.ts} +0 -0
  268. /package/dist/{types/data-structures/linked-list/skip-linked-list.d.ts → interfaces/segment-tree.d.ts} +0 -0
  269. /package/{src/data-structures/hash/pair.ts → dist/interfaces/singly-linked-list.d.ts} +0 -0
  270. /package/{src/data-structures/hash/tree-map.ts → dist/types/data-structures/doubly-linked-list.d.ts} +0 -0
  271. /package/{src/data-structures/hash/tree-set.ts → dist/types/data-structures/singly-linked-list.d.ts} +0 -0
  272. /package/dist/{types/types → utils}/index.d.ts +0 -0
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MapGraph = exports.MapEdge = exports.MapVertex = void 0;
4
+ const directed_graph_1 = require("./directed-graph");
5
+ class MapVertex extends directed_graph_1.DirectedVertex {
6
+ /**
7
+ * The constructor function initializes an object with an id, latitude, longitude, and an optional value.
8
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` 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 {T} [val] - The "val" parameter is an optional value of type T. It is not required to be provided when
16
+ * creating an instance of the class.
17
+ */
18
+ constructor(id, lat, long, val) {
19
+ super(id, val);
20
+ this._lat = lat;
21
+ this._long = long;
22
+ }
23
+ get lat() {
24
+ return this._lat;
25
+ }
26
+ set lat(value) {
27
+ this._lat = value;
28
+ }
29
+ get long() {
30
+ return this._long;
31
+ }
32
+ set long(value) {
33
+ this._long = value;
34
+ }
35
+ }
36
+ exports.MapVertex = MapVertex;
37
+ class MapEdge extends directed_graph_1.DirectedEdge {
38
+ /**
39
+ * The constructor function initializes a new instance of a class with the given source, destination, weight, and
40
+ * value.
41
+ * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
42
+ * a graph.
43
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
44
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
45
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store additional
46
+ * information or data associated with the edge.
47
+ */
48
+ constructor(src, dest, weight, val) {
49
+ super(src, dest, weight, val);
50
+ }
51
+ }
52
+ exports.MapEdge = MapEdge;
53
+ class MapGraph extends directed_graph_1.DirectedGraph {
54
+ /**
55
+ * The constructor function initializes the origin and bottomRight properties of a MapGraphCoordinate object.
56
+ * @param {MapGraphCoordinate} origin - The `origin` parameter is a `MapGraphCoordinate` object that represents the
57
+ * starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
58
+ * graph.
59
+ * @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
60
+ * `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
61
+ * it will default to `undefined`.
62
+ */
63
+ constructor(origin, bottomRight) {
64
+ super();
65
+ this._origin = [0, 0];
66
+ this._origin = origin;
67
+ this._bottomRight = bottomRight;
68
+ }
69
+ get origin() {
70
+ return this._origin;
71
+ }
72
+ set origin(value) {
73
+ this._origin = value;
74
+ }
75
+ get bottomRight() {
76
+ return this._bottomRight;
77
+ }
78
+ set bottomRight(value) {
79
+ this._bottomRight = value;
80
+ }
81
+ /**
82
+ * The function creates a new vertex with the given id, value, latitude, and longitude.
83
+ * @param {VertexId} id - The id parameter is the unique identifier for the vertex. It is of type VertexId, which could
84
+ * be a string or a number depending on how you define it in your code.
85
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
86
+ * is of type `V['val']`, which means it should be of the same type as the `val` property of the vertex class `V`.
87
+ * @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
88
+ * position of the vertex on the Earth's surface in the north-south direction.
89
+ * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
90
+ * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
91
+ */
92
+ createVertex(id, val, lat = this.origin[0], long = this.origin[1]) {
93
+ return new MapVertex(id, lat, long, val);
94
+ }
95
+ /**
96
+ * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
97
+ * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
98
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
99
+ * created.
100
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
101
+ * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
102
+ * If the weight is not provided, it can be set to a default value or left undefined.
103
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type,
104
+ * depending on the specific implementation of the `MapEdge` class.
105
+ * @returns a new instance of the `MapEdge` class, casted as type `E`.
106
+ */
107
+ createEdge(src, dest, weight, val) {
108
+ return new MapEdge(src, dest, weight, val);
109
+ }
110
+ }
111
+ exports.MapGraph = MapGraph;
@@ -1,24 +1,127 @@
1
- import { AbstractEdge, AbstractGraph, AbstractVertex, VertexId } from './abstract-graph';
2
- export declare class UndirectedVertex extends AbstractVertex {
3
- constructor(id: VertexId);
1
+ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
2
+ import type { VertexId } from '../../types';
3
+ import { IUNDirectedGraph } from '../../interfaces';
4
+ export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
5
+ /**
6
+ * The constructor function initializes a vertex with an optional value.
7
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
8
+ * used to uniquely identify the vertex within a graph or network.
9
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
10
+ * vertex. If no value is provided, the vertex will be initialized with a default value.
11
+ */
12
+ constructor(id: VertexId, val?: T);
4
13
  }
5
- export declare class UndirectedEdge extends AbstractEdge {
14
+ export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
15
+ /**
16
+ * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
17
+ * value.
18
+ * @param {VertexId} v1 - The first vertex ID of the edge.
19
+ * @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
20
+ * graph edge.
21
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
22
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store a value associated
23
+ * with the edge.
24
+ */
25
+ constructor(v1: VertexId, v2: VertexId, weight?: number, val?: T);
6
26
  private _vertices;
7
27
  get vertices(): [VertexId, VertexId];
8
28
  set vertices(v: [VertexId, VertexId]);
9
- constructor(v1: VertexId, v2: VertexId, weight?: number);
10
29
  }
11
- export declare class UndirectedGraph<V extends UndirectedVertex, E extends UndirectedEdge> extends AbstractGraph<V, E> {
30
+ export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {
31
+ /**
32
+ * The constructor initializes a new Map object to store edges.
33
+ */
12
34
  constructor();
13
35
  protected _edges: Map<V, E[]>;
36
+ get edges(): Map<V, E[]>;
37
+ /**
38
+ * The function creates a new vertex with an optional value and returns it.
39
+ * @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
40
+ * vertex from another in the graph.
41
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
42
+ * it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
43
+ * the vertex.
44
+ * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
45
+ */
46
+ createVertex(id: VertexId, val?: V['val']): V;
47
+ /**
48
+ * The function creates an undirected edge between two vertices with an optional weight and value.
49
+ * @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
50
+ * @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
51
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
52
+ * no weight is provided, it defaults to 1.
53
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
54
+ * is used to store additional information or data associated with the edge.
55
+ * @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
56
+ */
57
+ createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E;
58
+ /**
59
+ * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
60
+ * @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
61
+ * object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
62
+ * @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
63
+ * object), `null`, or `VertexId` (vertex ID).
64
+ * @returns an edge (E) or null.
65
+ */
14
66
  getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
15
- addEdge(edge: E): boolean;
67
+ /**
68
+ * The function removes an edge between two vertices in a graph and returns the removed edge.
69
+ * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
70
+ * @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
71
+ * (VertexId). It represents the second vertex of the edge that needs to be removed.
72
+ * @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
73
+ */
16
74
  removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
75
+ /**
76
+ * The removeEdge function removes an edge between two vertices in a graph.
77
+ * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
78
+ * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
79
+ */
17
80
  removeEdge(edge: E): E | null;
81
+ /**
82
+ * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
83
+ * vertex.
84
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
85
+ * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
86
+ * edges connected to that vertex.
87
+ */
18
88
  degreeOf(vertexOrId: VertexId | V): number;
89
+ /**
90
+ * The function returns the edges of a given vertex or vertex ID.
91
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
92
+ * unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
93
+ * @returns an array of edges.
94
+ */
19
95
  edgesOf(vertexOrId: VertexId | V): E[];
96
+ /**
97
+ * The function "edgeSet" returns an array of unique edges from a set of edges.
98
+ * @returns The method `edgeSet()` returns an array of type `E[]`.
99
+ */
20
100
  edgeSet(): E[];
21
- getEdgesOf(vertexOrId: V | VertexId): E[];
101
+ /**
102
+ * The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
103
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
104
+ * (`VertexId`).
105
+ * @returns an array of vertices (V[]).
106
+ */
22
107
  getNeighbors(vertexOrId: V | VertexId): V[];
108
+ /**
109
+ * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
110
+ * it returns null.
111
+ * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
112
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
113
+ * graph. If the edge does not exist, it returns `null`.
114
+ */
23
115
  getEndsOfEdge(edge: E): [V, V] | null;
116
+ /**
117
+ * The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
118
+ * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
119
+ * @returns a boolean value.
120
+ */
121
+ protected _addEdgeOnly(edge: E): boolean;
122
+ /**
123
+ * The function sets the edges of a graph.
124
+ * @param v - A map where the keys are of type V and the values are arrays of type E.
125
+ */
126
+ protected _setEdges(v: Map<V, E[]>): void;
24
127
  }
@@ -1,84 +1,149 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UndirectedGraph = exports.UndirectedEdge = exports.UndirectedVertex = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  const utils_1 = require("../../utils");
5
12
  const abstract_graph_1 = require("./abstract-graph");
6
13
  class UndirectedVertex extends abstract_graph_1.AbstractVertex {
7
- constructor(id) {
8
- super(id);
14
+ /**
15
+ * The constructor function initializes a vertex with an optional value.
16
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
17
+ * used to uniquely identify the vertex within a graph or network.
18
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
19
+ * vertex. If no value is provided, the vertex will be initialized with a default value.
20
+ */
21
+ constructor(id, val) {
22
+ super(id, val);
9
23
  }
10
24
  }
11
25
  exports.UndirectedVertex = UndirectedVertex;
12
26
  class UndirectedEdge extends abstract_graph_1.AbstractEdge {
27
+ /**
28
+ * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
29
+ * value.
30
+ * @param {VertexId} v1 - The first vertex ID of the edge.
31
+ * @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
32
+ * graph edge.
33
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
34
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store a value associated
35
+ * with the edge.
36
+ */
37
+ constructor(v1, v2, weight, val) {
38
+ super(weight, val);
39
+ this._vertices = [v1, v2];
40
+ }
13
41
  get vertices() {
14
42
  return this._vertices;
15
43
  }
16
44
  set vertices(v) {
17
45
  this._vertices = v;
18
46
  }
19
- constructor(v1, v2, weight) {
20
- super(weight);
21
- this._vertices = [v1, v2];
22
- }
23
47
  }
24
48
  exports.UndirectedEdge = UndirectedEdge;
25
49
  class UndirectedGraph extends abstract_graph_1.AbstractGraph {
50
+ /**
51
+ * The constructor initializes a new Map object to store edges.
52
+ */
26
53
  constructor() {
27
54
  super();
28
55
  this._edges = new Map();
29
56
  }
57
+ get edges() {
58
+ return this._edges;
59
+ }
60
+ /**
61
+ * The function creates a new vertex with an optional value and returns it.
62
+ * @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
63
+ * vertex from another in the graph.
64
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
65
+ * it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
66
+ * the vertex.
67
+ * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
68
+ */
69
+ createVertex(id, val) {
70
+ return new UndirectedVertex(id, val !== null && val !== void 0 ? val : id);
71
+ }
72
+ /**
73
+ * The function creates an undirected edge between two vertices with an optional weight and value.
74
+ * @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
75
+ * @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
76
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
77
+ * no weight is provided, it defaults to 1.
78
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
79
+ * is used to store additional information or data associated with the edge.
80
+ * @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
81
+ */
82
+ createEdge(v1, v2, weight, val) {
83
+ return new UndirectedEdge(v1, v2, weight !== null && weight !== void 0 ? weight : 1, val);
84
+ }
85
+ /**
86
+ * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
87
+ * @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
88
+ * object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
89
+ * @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
90
+ * object), `null`, or `VertexId` (vertex ID).
91
+ * @returns an edge (E) or null.
92
+ */
30
93
  getEdge(v1, v2) {
31
94
  var _a;
32
95
  let edges = [];
33
96
  if (v1 !== null && v2 !== null) {
34
- const vertex1 = this.getVertex(v1);
35
- const vertex2 = this.getVertex(v2);
97
+ const vertex1 = this._getVertex(v1);
98
+ const vertex2 = this._getVertex(v2);
36
99
  if (vertex1 && vertex2) {
37
100
  edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(e => e.vertices.includes(vertex2.id));
38
101
  }
39
102
  }
40
103
  return edges ? edges[0] || null : null;
41
104
  }
42
- addEdge(edge) {
43
- for (const end of edge.vertices) {
44
- const endVertex = this.getVertex(end);
45
- if (endVertex === null)
46
- return false;
47
- if (endVertex) {
48
- const edges = this._edges.get(endVertex);
49
- if (edges) {
50
- edges.push(edge);
51
- }
52
- else {
53
- this._edges.set(endVertex, [edge]);
54
- }
55
- }
56
- }
57
- return true;
58
- }
105
+ /**
106
+ * The function removes an edge between two vertices in a graph and returns the removed edge.
107
+ * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
108
+ * @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
109
+ * (VertexId). It represents the second vertex of the edge that needs to be removed.
110
+ * @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
111
+ */
59
112
  removeEdgeBetween(v1, v2) {
60
- const vertex1 = this.getVertex(v1);
61
- const vertex2 = this.getVertex(v2);
113
+ const vertex1 = this._getVertex(v1);
114
+ const vertex2 = this._getVertex(v2);
62
115
  if (!vertex1 || !vertex2) {
63
116
  return null;
64
117
  }
65
118
  const v1Edges = this._edges.get(vertex1);
66
119
  let removed = null;
67
120
  if (v1Edges) {
68
- removed = (0, utils_1.arrayRemove)(v1Edges, e => e.vertices.includes(vertex2.id))[0] || null;
121
+ removed = (0, utils_1.arrayRemove)(v1Edges, (e) => e.vertices.includes(vertex2.id))[0] || null;
69
122
  }
70
123
  const v2Edges = this._edges.get(vertex2);
71
124
  if (v2Edges) {
72
- (0, utils_1.arrayRemove)(v2Edges, e => e.vertices.includes(vertex1.id));
125
+ (0, utils_1.arrayRemove)(v2Edges, (e) => e.vertices.includes(vertex1.id));
73
126
  }
74
127
  return removed;
75
128
  }
129
+ /**
130
+ * The removeEdge function removes an edge between two vertices in a graph.
131
+ * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
132
+ * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
133
+ */
76
134
  removeEdge(edge) {
77
135
  return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
78
136
  }
137
+ /**
138
+ * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
139
+ * vertex.
140
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
141
+ * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
142
+ * edges connected to that vertex.
143
+ */
79
144
  degreeOf(vertexOrId) {
80
145
  var _a;
81
- const vertex = this.getVertex(vertexOrId);
146
+ const vertex = this._getVertex(vertexOrId);
82
147
  if (vertex) {
83
148
  return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
84
149
  }
@@ -86,8 +151,14 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
86
151
  return 0;
87
152
  }
88
153
  }
154
+ /**
155
+ * The function returns the edges of a given vertex or vertex ID.
156
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
157
+ * unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
158
+ * @returns an array of edges.
159
+ */
89
160
  edgesOf(vertexOrId) {
90
- const vertex = this.getVertex(vertexOrId);
161
+ const vertex = this._getVertex(vertexOrId);
91
162
  if (vertex) {
92
163
  return this._edges.get(vertex) || [];
93
164
  }
@@ -95,6 +166,10 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
95
166
  return [];
96
167
  }
97
168
  }
169
+ /**
170
+ * The function "edgeSet" returns an array of unique edges from a set of edges.
171
+ * @returns The method `edgeSet()` returns an array of type `E[]`.
172
+ */
98
173
  edgeSet() {
99
174
  const edgeSet = new Set();
100
175
  this._edges.forEach(edges => {
@@ -104,20 +179,19 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
104
179
  });
105
180
  return [...edgeSet];
106
181
  }
107
- getEdgesOf(vertexOrId) {
108
- const vertex = this.getVertex(vertexOrId);
109
- if (!vertex) {
110
- return [];
111
- }
112
- return this._edges.get(vertex) || [];
113
- }
182
+ /**
183
+ * The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
184
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
185
+ * (`VertexId`).
186
+ * @returns an array of vertices (V[]).
187
+ */
114
188
  getNeighbors(vertexOrId) {
115
189
  const neighbors = [];
116
- const vertex = this.getVertex(vertexOrId);
190
+ const vertex = this._getVertex(vertexOrId);
117
191
  if (vertex) {
118
- const neighborEdges = this.getEdgesOf(vertex);
192
+ const neighborEdges = this.edgesOf(vertex);
119
193
  for (const edge of neighborEdges) {
120
- const neighbor = this.getVertex(edge.vertices.filter(e => e !== vertex.id)[0]);
194
+ const neighbor = this._getVertex(edge.vertices.filter(e => e !== vertex.id)[0]);
121
195
  if (neighbor) {
122
196
  neighbors.push(neighbor);
123
197
  }
@@ -125,12 +199,19 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
125
199
  }
126
200
  return neighbors;
127
201
  }
202
+ /**
203
+ * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
204
+ * it returns null.
205
+ * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
206
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
207
+ * graph. If the edge does not exist, it returns `null`.
208
+ */
128
209
  getEndsOfEdge(edge) {
129
- if (!this.containsEdge(edge.vertices[0], edge.vertices[1])) {
210
+ if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
130
211
  return null;
131
212
  }
132
- const v1 = this.getVertex(edge.vertices[0]);
133
- const v2 = this.getVertex(edge.vertices[1]);
213
+ const v1 = this._getVertex(edge.vertices[0]);
214
+ const v2 = this._getVertex(edge.vertices[1]);
134
215
  if (v1 && v2) {
135
216
  return [v1, v2];
136
217
  }
@@ -138,5 +219,34 @@ class UndirectedGraph extends abstract_graph_1.AbstractGraph {
138
219
  return null;
139
220
  }
140
221
  }
222
+ /**
223
+ * The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
224
+ * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
225
+ * @returns a boolean value.
226
+ */
227
+ _addEdgeOnly(edge) {
228
+ for (const end of edge.vertices) {
229
+ const endVertex = this._getVertex(end);
230
+ if (endVertex === null)
231
+ return false;
232
+ if (endVertex) {
233
+ const edges = this._edges.get(endVertex);
234
+ if (edges) {
235
+ edges.push(edge);
236
+ }
237
+ else {
238
+ this._edges.set(endVertex, [edge]);
239
+ }
240
+ }
241
+ }
242
+ return true;
243
+ }
244
+ /**
245
+ * The function sets the edges of a graph.
246
+ * @param v - A map where the keys are of type V and the values are arrays of type E.
247
+ */
248
+ _setEdges(v) {
249
+ this._edges = v;
250
+ }
141
251
  }
142
252
  exports.UndirectedGraph = UndirectedGraph;
@@ -1,8 +1,45 @@
1
- export declare class CoordinateSet<V> extends Map<any, V> {
2
- private readonly _joint;
1
+ /**
2
+ * data-structure-typed
3
+ *
4
+ * @author Tyler Zeng
5
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
+ * @license MIT License
7
+ */
8
+ export declare class CoordinateMap<V> extends Map<any, V> {
3
9
  constructor(joint?: string);
10
+ protected _joint: string;
11
+ get joint(): string;
12
+ /**
13
+ * The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
14
+ * key array with a specified delimiter.
15
+ * @param {number[]} key - The parameter "key" is an array of numbers.
16
+ * @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
17
+ * (`super.has`) with the `key` array joined together using the `_joint` property.
18
+ */
4
19
  has(key: number[]): boolean;
20
+ /**
21
+ * The function overrides the set method of a Map object to convert the key from an array to a string using a specified
22
+ * delimiter before calling the original set method.
23
+ * @param {number[]} key - The key parameter is an array of numbers.
24
+ * @param {V} value - The value parameter is the value that you want to associate with the specified key.
25
+ * @returns The `set` method is returning the result of calling the `set` method of the superclass
26
+ * (`super.set(key.join(this._joint), value)`).
27
+ */
5
28
  set(key: number[], value: V): this;
29
+ /**
30
+ * The function overrides the get method to join the key array with a specified joint and then calls the super get
31
+ * method.
32
+ * @param {number[]} key - An array of numbers
33
+ * @returns The code is returning the value associated with the specified key in the map.
34
+ */
6
35
  get(key: number[]): V | undefined;
36
+ /**
37
+ * The function overrides the delete method and joins the key array using a specified joint character before calling
38
+ * the super delete method.
39
+ * @param {number[]} key - An array of numbers that represents the key to be deleted.
40
+ * @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
41
+ * `key` array joined together using the `_joint` property.
42
+ */
7
43
  delete(key: number[]): boolean;
44
+ protected _setJoint(v: string): void;
8
45
  }
@@ -1,24 +1,65 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CoordinateSet = void 0;
4
- class CoordinateSet extends Map {
3
+ exports.CoordinateMap = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
11
+ class CoordinateMap extends Map {
5
12
  constructor(joint) {
6
13
  super();
7
14
  this._joint = '_';
8
15
  if (joint !== undefined)
9
16
  this._joint = joint;
10
17
  }
18
+ get joint() {
19
+ return this._joint;
20
+ }
21
+ /**
22
+ * The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
23
+ * key array with a specified delimiter.
24
+ * @param {number[]} key - The parameter "key" is an array of numbers.
25
+ * @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
26
+ * (`super.has`) with the `key` array joined together using the `_joint` property.
27
+ */
11
28
  has(key) {
12
29
  return super.has(key.join(this._joint));
13
30
  }
31
+ /**
32
+ * The function overrides the set method of a Map object to convert the key from an array to a string using a specified
33
+ * delimiter before calling the original set method.
34
+ * @param {number[]} key - The key parameter is an array of numbers.
35
+ * @param {V} value - The value parameter is the value that you want to associate with the specified key.
36
+ * @returns The `set` method is returning the result of calling the `set` method of the superclass
37
+ * (`super.set(key.join(this._joint), value)`).
38
+ */
14
39
  set(key, value) {
15
40
  return super.set(key.join(this._joint), value);
16
41
  }
42
+ /**
43
+ * The function overrides the get method to join the key array with a specified joint and then calls the super get
44
+ * method.
45
+ * @param {number[]} key - An array of numbers
46
+ * @returns The code is returning the value associated with the specified key in the map.
47
+ */
17
48
  get(key) {
18
49
  return super.get(key.join(this._joint));
19
50
  }
51
+ /**
52
+ * The function overrides the delete method and joins the key array using a specified joint character before calling
53
+ * the super delete method.
54
+ * @param {number[]} key - An array of numbers that represents the key to be deleted.
55
+ * @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
56
+ * `key` array joined together using the `_joint` property.
57
+ */
20
58
  delete(key) {
21
59
  return super.delete(key.join(this._joint));
22
60
  }
61
+ _setJoint(v) {
62
+ this._joint = v;
63
+ }
23
64
  }
24
- exports.CoordinateSet = CoordinateSet;
65
+ exports.CoordinateMap = CoordinateMap;