data-structure-typed 1.34.6 → 1.34.8

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 (98) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +74 -35
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +70 -70
  4. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  5. package/dist/data-structures/binary-tree/avl-tree.js +8 -8
  6. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  7. package/dist/data-structures/binary-tree/binary-tree.js +4 -4
  8. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  9. package/dist/data-structures/binary-tree/bst.js +59 -59
  10. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  11. package/dist/data-structures/binary-tree/rb-tree.js +4 -4
  12. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
  13. package/dist/data-structures/binary-tree/tree-multiset.js +39 -39
  14. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  15. package/dist/data-structures/graph/abstract-graph.js +49 -49
  16. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  17. package/dist/data-structures/graph/directed-graph.js +33 -33
  18. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  19. package/dist/data-structures/graph/map-graph.js +4 -4
  20. package/dist/data-structures/graph/map-graph.js.map +1 -1
  21. package/dist/data-structures/graph/undirected-graph.js +14 -14
  22. package/dist/data-structures/graph/undirected-graph.js.map +1 -1
  23. package/dist/data-structures/tree/tree.js +5 -5
  24. package/dist/data-structures/tree/tree.js.map +1 -1
  25. package/lib/data-structures/binary-tree/abstract-binary-tree.d.ts +71 -71
  26. package/lib/data-structures/binary-tree/abstract-binary-tree.js +110 -110
  27. package/lib/data-structures/binary-tree/avl-tree.d.ts +10 -10
  28. package/lib/data-structures/binary-tree/avl-tree.js +13 -13
  29. package/lib/data-structures/binary-tree/binary-tree.d.ts +6 -6
  30. package/lib/data-structures/binary-tree/binary-tree.js +7 -7
  31. package/lib/data-structures/binary-tree/bst.d.ts +34 -34
  32. package/lib/data-structures/binary-tree/bst.js +80 -80
  33. package/lib/data-structures/binary-tree/rb-tree.d.ts +3 -3
  34. package/lib/data-structures/binary-tree/rb-tree.js +4 -4
  35. package/lib/data-structures/binary-tree/tree-multiset.d.ts +27 -27
  36. package/lib/data-structures/binary-tree/tree-multiset.js +55 -55
  37. package/lib/data-structures/graph/abstract-graph.d.ts +60 -60
  38. package/lib/data-structures/graph/abstract-graph.js +81 -81
  39. package/lib/data-structures/graph/directed-graph.d.ts +51 -51
  40. package/lib/data-structures/graph/directed-graph.js +63 -63
  41. package/lib/data-structures/graph/map-graph.d.ts +13 -13
  42. package/lib/data-structures/graph/map-graph.js +12 -12
  43. package/lib/data-structures/graph/undirected-graph.d.ts +30 -30
  44. package/lib/data-structures/graph/undirected-graph.js +32 -32
  45. package/lib/data-structures/heap/heap.d.ts +1 -1
  46. package/lib/data-structures/tree/tree.d.ts +4 -4
  47. package/lib/data-structures/tree/tree.js +6 -6
  48. package/lib/interfaces/abstract-binary-tree.d.ts +24 -24
  49. package/lib/interfaces/abstract-graph.d.ts +13 -13
  50. package/lib/interfaces/avl-tree.d.ts +3 -3
  51. package/lib/interfaces/bst.d.ts +8 -8
  52. package/lib/interfaces/directed-graph.d.ts +5 -5
  53. package/lib/interfaces/rb-tree.d.ts +2 -2
  54. package/lib/interfaces/undirected-graph.d.ts +2 -2
  55. package/lib/types/data-structures/abstract-binary-tree.d.ts +3 -3
  56. package/lib/types/data-structures/abstract-graph.d.ts +2 -2
  57. package/lib/types/data-structures/bst.d.ts +2 -2
  58. package/lib/types/data-structures/tree-multiset.d.ts +1 -1
  59. package/lib/types/utils/validate-type.d.ts +8 -8
  60. package/package.json +1 -1
  61. package/scripts/rename_clear_files.sh +29 -0
  62. package/src/data-structures/binary-tree/abstract-binary-tree.ts +147 -147
  63. package/src/data-structures/binary-tree/avl-tree.ts +14 -14
  64. package/src/data-structures/binary-tree/binary-tree.ts +8 -8
  65. package/src/data-structures/binary-tree/bst.ts +98 -90
  66. package/src/data-structures/binary-tree/rb-tree.ts +9 -9
  67. package/src/data-structures/binary-tree/tree-multiset.ts +62 -62
  68. package/src/data-structures/graph/abstract-graph.ts +109 -104
  69. package/src/data-structures/graph/directed-graph.ts +77 -77
  70. package/src/data-structures/graph/map-graph.ts +20 -15
  71. package/src/data-structures/graph/undirected-graph.ts +39 -39
  72. package/src/data-structures/heap/heap.ts +1 -1
  73. package/src/data-structures/tree/tree.ts +7 -7
  74. package/src/interfaces/abstract-binary-tree.ts +24 -24
  75. package/src/interfaces/abstract-graph.ts +13 -13
  76. package/src/interfaces/avl-tree.ts +3 -3
  77. package/src/interfaces/bst.ts +8 -8
  78. package/src/interfaces/directed-graph.ts +5 -5
  79. package/src/interfaces/rb-tree.ts +2 -2
  80. package/src/interfaces/undirected-graph.ts +2 -2
  81. package/src/types/data-structures/abstract-binary-tree.ts +3 -3
  82. package/src/types/data-structures/abstract-graph.ts +2 -2
  83. package/src/types/data-structures/bst.ts +2 -2
  84. package/src/types/data-structures/tree-multiset.ts +1 -1
  85. package/src/types/utils/validate-type.ts +10 -10
  86. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +24 -24
  87. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +3 -3
  88. package/test/unit/data-structures/binary-tree/bst.test.ts +71 -71
  89. package/test/unit/data-structures/binary-tree/overall.test.ts +19 -19
  90. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +72 -72
  91. package/test/unit/data-structures/graph/directed-graph.test.ts +8 -8
  92. package/test/unit/data-structures/graph/map-graph.test.ts +4 -4
  93. package/test/unit/data-structures/graph/overall.test.ts +2 -2
  94. package/test/unit/data-structures/graph/undirected-graph.test.ts +1 -1
  95. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
  96. package/test/unit/data-structures/tree/tree.test.ts +2 -2
  97. package/umd/bundle.min.js +1 -1
  98. package/umd/bundle.min.js.map +1 -1
@@ -10,23 +10,23 @@ import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
10
10
  export class DirectedVertex extends AbstractVertex {
11
11
  /**
12
12
  * The constructor function initializes a vertex with an optional value.
13
- * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
13
+ * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
14
14
  * used to uniquely identify the vertex within a graph or data structure.
15
15
  * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
16
16
  * vertex. If no value is provided, the vertex will be initialized with a default value.
17
17
  */
18
- constructor(id, val) {
19
- super(id, val);
18
+ constructor(key, val) {
19
+ super(key, val);
20
20
  }
21
21
  }
22
22
  export class DirectedEdge extends AbstractEdge {
23
23
  /**
24
24
  * The constructor function initializes the source and destination vertices of an edge, along with an optional weight
25
25
  * and value.
26
- * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
26
+ * @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
27
27
  * a graph.
28
- * @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
29
- * `VertexId`, which is likely a unique identifier for a vertex in a graph.
28
+ * @param {VertexKey} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
29
+ * `VertexKey`, which is likely a unique identifier for a vertex in a graph.
30
30
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
31
31
  * @param {V} [val] - The `val` parameter is an optional parameter of type `V`. It represents the value associated with
32
32
  * the edge.
@@ -70,15 +70,15 @@ export class DirectedGraph extends AbstractGraph {
70
70
  */
71
71
  /**
72
72
  * The function creates a new vertex with an optional value and returns it.
73
- * @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
73
+ * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
74
74
  * could be a number or a string depending on how you want to identify your vertices.
75
75
  * @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
76
76
  * it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
77
- * assigned the same value as the 'id' parameter
77
+ * assigned the same value as the 'key' parameter
78
78
  * @returns a new instance of a DirectedVertex object, casted as type V.
79
79
  */
80
- createVertex(id, val) {
81
- return new DirectedVertex(id, val !== null && val !== void 0 ? val : id);
80
+ createVertex(key, val) {
81
+ return new DirectedVertex(key, val !== null && val !== void 0 ? val : key);
82
82
  }
83
83
  /**
84
84
  * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
@@ -86,8 +86,8 @@ export class DirectedGraph extends AbstractGraph {
86
86
  */
87
87
  /**
88
88
  * The function creates a directed edge between two vertices with an optional weight and value.
89
- * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
90
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
89
+ * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
90
+ * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
91
91
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
92
92
  * weight is provided, it defaults to 1.
93
93
  * @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
@@ -99,21 +99,21 @@ export class DirectedGraph extends AbstractGraph {
99
99
  }
100
100
  /**
101
101
  * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
102
- * @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
103
- * @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
104
- * destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
102
+ * @param {V | null | VertexKey} srcOrKey - The source vertex or its ID. It can be either a vertex object or a vertex ID.
103
+ * @param {V | null | VertexKey} destOrKey - The `destOrKey` parameter in the `getEdge` function represents the
104
+ * destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexKey`), or `null` if the
105
105
  * destination is not specified.
106
106
  * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
107
107
  */
108
- getEdge(srcOrId, destOrId) {
108
+ getEdge(srcOrKey, destOrKey) {
109
109
  let edges = [];
110
- if (srcOrId !== null && destOrId !== null) {
111
- const src = this._getVertex(srcOrId);
112
- const dest = this._getVertex(destOrId);
110
+ if (srcOrKey !== null && destOrKey !== null) {
111
+ const src = this._getVertex(srcOrKey);
112
+ const dest = this._getVertex(destOrKey);
113
113
  if (src && dest) {
114
114
  const srcOutEdges = this._outEdgeMap.get(src);
115
115
  if (srcOutEdges) {
116
- edges = srcOutEdges.filter(edge => edge.dest === dest.id);
116
+ edges = srcOutEdges.filter(edge => edge.dest === dest.key);
117
117
  }
118
118
  }
119
119
  }
@@ -121,24 +121,24 @@ export class DirectedGraph extends AbstractGraph {
121
121
  }
122
122
  /**
123
123
  * The function removes an edge between two vertices in a graph and returns the removed edge.
124
- * @param {V | VertexId} srcOrId - The source vertex or its ID.
125
- * @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
124
+ * @param {V | VertexKey} srcOrKey - The source vertex or its ID.
125
+ * @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID.
126
126
  * @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
127
127
  */
128
- removeEdgeSrcToDest(srcOrId, destOrId) {
129
- const src = this._getVertex(srcOrId);
130
- const dest = this._getVertex(destOrId);
128
+ removeEdgeSrcToDest(srcOrKey, destOrKey) {
129
+ const src = this._getVertex(srcOrKey);
130
+ const dest = this._getVertex(destOrKey);
131
131
  let removed = null;
132
132
  if (!src || !dest) {
133
133
  return null;
134
134
  }
135
135
  const srcOutEdges = this._outEdgeMap.get(src);
136
136
  if (srcOutEdges) {
137
- arrayRemove(srcOutEdges, (edge) => edge.dest === dest.id);
137
+ arrayRemove(srcOutEdges, (edge) => edge.dest === dest.key);
138
138
  }
139
139
  const destInEdges = this._inEdgeMap.get(dest);
140
140
  if (destInEdges) {
141
- removed = arrayRemove(destInEdges, (edge) => edge.src === src.id)[0] || null;
141
+ removed = arrayRemove(destInEdges, (edge) => edge.src === src.key)[0] || null;
142
142
  }
143
143
  return removed;
144
144
  }
@@ -155,20 +155,20 @@ export class DirectedGraph extends AbstractGraph {
155
155
  if (src && dest) {
156
156
  const srcOutEdges = this._outEdgeMap.get(src);
157
157
  if (srcOutEdges && srcOutEdges.length > 0) {
158
- arrayRemove(srcOutEdges, (edge) => edge.src === src.id);
158
+ arrayRemove(srcOutEdges, (edge) => edge.src === src.key);
159
159
  }
160
160
  const destInEdges = this._inEdgeMap.get(dest);
161
161
  if (destInEdges && destInEdges.length > 0) {
162
- removed = arrayRemove(destInEdges, (edge) => edge.dest === dest.id)[0];
162
+ removed = arrayRemove(destInEdges, (edge) => edge.dest === dest.key)[0];
163
163
  }
164
164
  }
165
165
  return removed;
166
166
  }
167
167
  /**
168
168
  * The function removes edges between two vertices and returns the removed edges.
169
- * @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
169
+ * @param {VertexKey | V} v1 - The parameter `v1` can be either a `VertexKey` or a `V`. A `VertexKey` represents the
170
170
  * unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
171
- * @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
171
+ * @param {VertexKey | V} v2 - The parameter `v2` represents either a `VertexKey` or a `V` object. It is used to specify
172
172
  * the second vertex in the edge that needs to be removed.
173
173
  * @returns an array of removed edges (E[]).
174
174
  */
@@ -184,12 +184,12 @@ export class DirectedGraph extends AbstractGraph {
184
184
  }
185
185
  /**
186
186
  * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
187
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
188
- * (`VertexId`).
187
+ * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
188
+ * (`VertexKey`).
189
189
  * @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
190
190
  */
191
- incomingEdgesOf(vertexOrId) {
192
- const target = this._getVertex(vertexOrId);
191
+ incomingEdgesOf(vertexOrKey) {
192
+ const target = this._getVertex(vertexOrKey);
193
193
  if (target) {
194
194
  return this.inEdgeMap.get(target) || [];
195
195
  }
@@ -197,12 +197,12 @@ export class DirectedGraph extends AbstractGraph {
197
197
  }
198
198
  /**
199
199
  * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
200
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
201
- * (`VertexId`).
200
+ * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can accept either a vertex object (`V`) or a vertex ID
201
+ * (`VertexKey`).
202
202
  * @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
203
203
  */
204
- outgoingEdgesOf(vertexOrId) {
205
- const target = this._getVertex(vertexOrId);
204
+ outgoingEdgesOf(vertexOrKey) {
205
+ const target = this._getVertex(vertexOrKey);
206
206
  if (target) {
207
207
  return this._outEdgeMap.get(target) || [];
208
208
  }
@@ -210,35 +210,35 @@ export class DirectedGraph extends AbstractGraph {
210
210
  }
211
211
  /**
212
212
  * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
213
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
213
+ * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
214
214
  * @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
215
215
  */
216
- degreeOf(vertexOrId) {
217
- return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
216
+ degreeOf(vertexOrKey) {
217
+ return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
218
218
  }
219
219
  /**
220
220
  * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
221
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
221
+ * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
222
222
  * @returns The number of incoming edges of the specified vertex or vertex ID.
223
223
  */
224
- inDegreeOf(vertexOrId) {
225
- return this.incomingEdgesOf(vertexOrId).length;
224
+ inDegreeOf(vertexOrKey) {
225
+ return this.incomingEdgesOf(vertexOrKey).length;
226
226
  }
227
227
  /**
228
228
  * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
229
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
229
+ * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
230
230
  * @returns The number of outgoing edges from the specified vertex or vertex ID.
231
231
  */
232
- outDegreeOf(vertexOrId) {
233
- return this.outgoingEdgesOf(vertexOrId).length;
232
+ outDegreeOf(vertexOrKey) {
233
+ return this.outgoingEdgesOf(vertexOrKey).length;
234
234
  }
235
235
  /**
236
236
  * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
237
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
237
+ * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
238
238
  * @returns The function `edgesOf` returns an array of edges.
239
239
  */
240
- edgesOf(vertexOrId) {
241
- return [...this.outgoingEdgesOf(vertexOrId), ...this.incomingEdgesOf(vertexOrId)];
240
+ edgesOf(vertexOrKey) {
241
+ return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
242
242
  }
243
243
  /**
244
244
  * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
@@ -258,8 +258,8 @@ export class DirectedGraph extends AbstractGraph {
258
258
  }
259
259
  /**
260
260
  * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
261
- * @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
262
- * find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
261
+ * @param {V | VertexKey | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
262
+ * find the destinations. It can be either a `V` object, a `VertexKey` value, or `null`.
263
263
  * @returns an array of vertices (V[]).
264
264
  */
265
265
  getDestinations(vertex) {
@@ -279,13 +279,13 @@ export class DirectedGraph extends AbstractGraph {
279
279
  /**
280
280
  * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
281
281
  * in the sorted order, or null if the graph contains a cycle.
282
- * @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
283
- * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
284
- * specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
282
+ * @param {'vertex' | 'key'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
283
+ * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'key'. If 'vertex' is
284
+ * specified, the vertices themselves will be used for sorting. If 'key' is specified, the ids of
285
285
  * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
286
286
  */
287
287
  topologicalSort(propertyName) {
288
- propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
288
+ propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'key';
289
289
  // When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
290
290
  // When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
291
291
  const statusMap = new Map();
@@ -316,8 +316,8 @@ export class DirectedGraph extends AbstractGraph {
316
316
  }
317
317
  if (hasCycle)
318
318
  return null;
319
- if (propertyName === 'id')
320
- sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.id : vertex));
319
+ if (propertyName === 'key')
320
+ sorted = sorted.map(vertex => (vertex instanceof DirectedVertex ? vertex.key : vertex));
321
321
  return sorted.reverse();
322
322
  }
323
323
  /**
@@ -333,13 +333,13 @@ export class DirectedGraph extends AbstractGraph {
333
333
  }
334
334
  /**
335
335
  * The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
336
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
337
- * (`VertexId`).
336
+ * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
337
+ * (`VertexKey`).
338
338
  * @returns an array of vertices (V[]).
339
339
  */
340
- getNeighbors(vertexOrId) {
340
+ getNeighbors(vertexOrKey) {
341
341
  const neighbors = [];
342
- const vertex = this._getVertex(vertexOrId);
342
+ const vertex = this._getVertex(vertexOrKey);
343
343
  if (vertex) {
344
344
  const outEdges = this.outgoingEdgesOf(vertex);
345
345
  for (const outEdge of outEdges) {
@@ -1,9 +1,9 @@
1
- import { MapGraphCoordinate, VertexId } from '../../types';
1
+ import { MapGraphCoordinate, VertexKey } from '../../types';
2
2
  import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
3
3
  export declare class MapVertex<V = any> extends DirectedVertex<V> {
4
4
  /**
5
- * The constructor function initializes an object with an id, latitude, longitude, and an optional value.
6
- * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex.
5
+ * The constructor function initializes an object with an key, latitude, longitude, and an optional value.
6
+ * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
7
7
  * @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
8
8
  * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
9
9
  * values representing points north of the equator and negative values representing points south of the equator.
@@ -13,7 +13,7 @@ export declare class MapVertex<V = any> extends DirectedVertex<V> {
13
13
  * @param {V} [val] - The "val" parameter is an optional value of type V. It is not required to be provided when
14
14
  * creating an instance of the class.
15
15
  */
16
- constructor(id: VertexId, lat: number, long: number, val?: V);
16
+ constructor(key: VertexKey, lat: number, long: number, val?: V);
17
17
  private _lat;
18
18
  get lat(): number;
19
19
  set lat(value: number);
@@ -25,14 +25,14 @@ export declare class MapEdge<V = any> extends DirectedEdge<V> {
25
25
  /**
26
26
  * The constructor function initializes a new instance of a class with the given source, destination, weight, and
27
27
  * value.
28
- * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
28
+ * @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
29
29
  * a graph.
30
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
30
+ * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
31
31
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
32
32
  * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store additional
33
33
  * information or data associated with the edge.
34
34
  */
35
- constructor(src: VertexId, dest: VertexId, weight?: number, val?: V);
35
+ constructor(src: VertexKey, dest: VertexKey, weight?: number, val?: V);
36
36
  }
37
37
  export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E extends MapEdge = MapEdge> extends DirectedGraph<V, E> {
38
38
  /**
@@ -52,8 +52,8 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
52
52
  get bottomRight(): MapGraphCoordinate | undefined;
53
53
  set bottomRight(value: MapGraphCoordinate | undefined);
54
54
  /**
55
- * The function creates a new vertex with the given id, value, latitude, and longitude.
56
- * @param {VertexId} id - The id parameter is the unique identifier for the vertex. It is of type VertexId, which could
55
+ * The function creates a new vertex with the given key, value, latitude, and longitude.
56
+ * @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
57
57
  * be a string or a number depending on how you define it in your code.
58
58
  * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
59
59
  * is of type `V['val']`, which means it should be of the same type as the `val` property of the vertex class `V`.
@@ -62,11 +62,11 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
62
62
  * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
63
63
  * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
64
64
  */
65
- createVertex(id: VertexId, val?: V['val'], lat?: number, long?: number): V;
65
+ createVertex(key: VertexKey, val?: V['val'], lat?: number, long?: number): V;
66
66
  /**
67
67
  * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
68
- * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
69
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
68
+ * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
69
+ * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
70
70
  * created.
71
71
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
72
72
  * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
@@ -75,5 +75,5 @@ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E exten
75
75
  * depending on the specific implementation of the `MapEdge` class.
76
76
  * @returns a new instance of the `MapEdge` class, casted as type `E`.
77
77
  */
78
- createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
78
+ createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E;
79
79
  }
@@ -1,8 +1,8 @@
1
1
  import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
2
2
  export class MapVertex extends DirectedVertex {
3
3
  /**
4
- * The constructor function initializes an object with an id, latitude, longitude, and an optional value.
5
- * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex.
4
+ * The constructor function initializes an object with an key, latitude, longitude, and an optional value.
5
+ * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex.
6
6
  * @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
7
7
  * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
8
8
  * values representing points north of the equator and negative values representing points south of the equator.
@@ -12,8 +12,8 @@ export class MapVertex extends DirectedVertex {
12
12
  * @param {V} [val] - The "val" parameter is an optional value of type V. It is not required to be provided when
13
13
  * creating an instance of the class.
14
14
  */
15
- constructor(id, lat, long, val) {
16
- super(id, val);
15
+ constructor(key, lat, long, val) {
16
+ super(key, val);
17
17
  this._lat = lat;
18
18
  this._long = long;
19
19
  }
@@ -34,9 +34,9 @@ export class MapEdge extends DirectedEdge {
34
34
  /**
35
35
  * The constructor function initializes a new instance of a class with the given source, destination, weight, and
36
36
  * value.
37
- * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
37
+ * @param {VertexKey} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
38
38
  * a graph.
39
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
39
+ * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
40
40
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
41
41
  * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store additional
42
42
  * information or data associated with the edge.
@@ -74,8 +74,8 @@ export class MapGraph extends DirectedGraph {
74
74
  this._bottomRight = value;
75
75
  }
76
76
  /**
77
- * The function creates a new vertex with the given id, value, latitude, and longitude.
78
- * @param {VertexId} id - The id parameter is the unique identifier for the vertex. It is of type VertexId, which could
77
+ * The function creates a new vertex with the given key, value, latitude, and longitude.
78
+ * @param {VertexKey} key - The key parameter is the unique identifier for the vertex. It is of type VertexKey, which could
79
79
  * be a string or a number depending on how you define it in your code.
80
80
  * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
81
81
  * is of type `V['val']`, which means it should be of the same type as the `val` property of the vertex class `V`.
@@ -84,13 +84,13 @@ export class MapGraph extends DirectedGraph {
84
84
  * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
85
85
  * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
86
86
  */
87
- createVertex(id, val, lat = this.origin[0], long = this.origin[1]) {
88
- return new MapVertex(id, lat, long, val);
87
+ createVertex(key, val, lat = this.origin[0], long = this.origin[1]) {
88
+ return new MapVertex(key, lat, long, val);
89
89
  }
90
90
  /**
91
91
  * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
92
- * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
93
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
92
+ * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
93
+ * @param {VertexKey} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
94
94
  * created.
95
95
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
96
96
  * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
@@ -1,31 +1,31 @@
1
1
  import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
2
- import type { VertexId } from '../../types';
2
+ import type { VertexKey } from '../../types';
3
3
  import { IUNDirectedGraph } from '../../interfaces';
4
4
  export declare class UndirectedVertex<V = any> extends AbstractVertex<V> {
5
5
  /**
6
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
7
+ * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
8
8
  * used to uniquely identify the vertex within a graph or network.
9
9
  * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to initialize the value of the
10
10
  * vertex. If no value is provided, the vertex will be initialized with a default value.
11
11
  */
12
- constructor(id: VertexId, val?: V);
12
+ constructor(key: VertexKey, val?: V);
13
13
  }
14
14
  export declare class UndirectedEdge<V = number> extends AbstractEdge<V> {
15
15
  /**
16
16
  * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
17
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
18
+ * @param {VertexKey} v1 - The first vertex ID of the edge.
19
+ * @param {VertexKey} v2 - The parameter `v2` is a `VertexKey`, which represents the identifier of the second vertex in a
20
20
  * graph edge.
21
21
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
22
22
  * @param {V} [val] - The "val" parameter is an optional parameter of type V. It is used to store a value associated
23
23
  * with the edge.
24
24
  */
25
- constructor(v1: VertexId, v2: VertexId, weight?: number, val?: V);
25
+ constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: V);
26
26
  private _vertices;
27
- get vertices(): [VertexId, VertexId];
28
- set vertices(v: [VertexId, VertexId]);
27
+ get vertices(): [VertexKey, VertexKey];
28
+ set vertices(v: [VertexKey, VertexKey]);
29
29
  }
30
30
  export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {
31
31
  /**
@@ -36,42 +36,42 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
36
36
  get edges(): Map<V, E[]>;
37
37
  /**
38
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
39
+ * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is used to distinguish one
40
40
  * vertex from another in the graph.
41
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
42
+ * it will be used as the value of the vertex. If no value is provided, the `key` parameter will be used as the value of
43
43
  * the vertex.
44
44
  * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
45
45
  */
46
- createVertex(id: VertexId, val?: V['val']): V;
46
+ createVertex(key: VertexKey, val?: V['val']): V;
47
47
  /**
48
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.
49
+ * @param {VertexKey} v1 - The parameter `v1` represents the first vertex of the edge.
50
+ * @param {VertexKey} v2 - The parameter `v2` represents the second vertex of the edge.
51
51
  * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
52
52
  * no weight is provided, it defaults to 1.
53
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
54
  * is used to store additional information or data associated with the edge.
55
55
  * @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
56
56
  */
57
- createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E;
57
+ createEdge(v1: VertexKey, v2: VertexKey, weight?: number, val?: E['val']): E;
58
58
  /**
59
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).
60
+ * @param {V | null | VertexKey} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
61
+ * object), `null`, or `VertexKey` (a string or number representing the ID of a vertex).
62
+ * @param {V | null | VertexKey} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
63
+ * object), `null`, or `VertexKey` (vertex ID).
64
64
  * @returns an edge (E) or null.
65
65
  */
66
- getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
66
+ getEdge(v1: V | null | VertexKey, v2: V | null | VertexKey): E | null;
67
67
  /**
68
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.
69
+ * @param {V | VertexKey} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexKey`).
70
+ * @param {V | VertexKey} v2 - V | VertexKey - This parameter can be either a vertex object (V) or a vertex ID
71
+ * (VertexKey). It represents the second vertex of the edge that needs to be removed.
72
72
  * @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
73
73
  */
74
- removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
74
+ removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null;
75
75
  /**
76
76
  * The removeEdge function removes an edge between two vertices in a graph.
77
77
  * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
@@ -81,18 +81,18 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
81
81
  /**
82
82
  * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
83
83
  * vertex.
84
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
84
+ * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`.
85
85
  * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
86
86
  * edges connected to that vertex.
87
87
  */
88
- degreeOf(vertexOrId: VertexId | V): number;
88
+ degreeOf(vertexOrKey: VertexKey | V): number;
89
89
  /**
90
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
91
+ * @param {VertexKey | V} vertexOrKey - The parameter `vertexOrKey` can be either a `VertexKey` or a `V`. A `VertexKey` is a
92
92
  * unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
93
93
  * @returns an array of edges.
94
94
  */
95
- edgesOf(vertexOrId: VertexId | V): E[];
95
+ edgesOf(vertexOrKey: VertexKey | V): E[];
96
96
  /**
97
97
  * The function "edgeSet" returns an array of unique edges from a set of edges.
98
98
  * @returns The method `edgeSet()` returns an array of type `E[]`.
@@ -100,11 +100,11 @@ export declare class UndirectedGraph<V extends UndirectedVertex<any> = Undirecte
100
100
  edgeSet(): E[];
101
101
  /**
102
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`).
103
+ * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID
104
+ * (`VertexKey`).
105
105
  * @returns an array of vertices (V[]).
106
106
  */
107
- getNeighbors(vertexOrId: V | VertexId): V[];
107
+ getNeighbors(vertexOrKey: V | VertexKey): V[];
108
108
  /**
109
109
  * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
110
110
  * it returns null.