binary-tree-typed 2.4.5 → 2.5.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.
- package/README.md +0 -84
- package/dist/cjs/index.cjs +867 -404
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +864 -401
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +867 -404
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +864 -401
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +128 -51
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +210 -164
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +429 -78
- package/dist/types/data-structures/binary-tree/bst.d.ts +311 -28
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +212 -32
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +218 -152
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1281 -5
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1087 -201
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +858 -65
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1133 -5
- package/dist/types/data-structures/graph/directed-graph.d.ts +219 -47
- package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +204 -59
- package/dist/types/data-structures/hash/hash-map.d.ts +230 -77
- package/dist/types/data-structures/heap/heap.d.ts +287 -99
- package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
- package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +286 -44
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +278 -65
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +415 -12
- package/dist/types/data-structures/matrix/matrix.d.ts +331 -0
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
- package/dist/types/data-structures/queue/deque.d.ts +272 -65
- package/dist/types/data-structures/queue/queue.d.ts +211 -42
- package/dist/types/data-structures/stack/stack.d.ts +174 -32
- package/dist/types/data-structures/trie/trie.d.ts +213 -43
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
- package/dist/umd/binary-tree-typed.js +860 -397
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +2 -2
- package/dist/umd/binary-tree-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +4 -5
- package/src/data-structures/binary-tree/avl-tree.ts +134 -51
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +302 -247
- package/src/data-structures/binary-tree/binary-tree.ts +429 -79
- package/src/data-structures/binary-tree/bst.ts +335 -34
- package/src/data-structures/binary-tree/red-black-tree.ts +290 -97
- package/src/data-structures/binary-tree/segment-tree.ts +372 -248
- package/src/data-structures/binary-tree/tree-map.ts +1284 -6
- package/src/data-structures/binary-tree/tree-multi-map.ts +1094 -211
- package/src/data-structures/binary-tree/tree-multi-set.ts +858 -65
- package/src/data-structures/binary-tree/tree-set.ts +1136 -9
- package/src/data-structures/graph/directed-graph.ts +219 -47
- package/src/data-structures/graph/map-graph.ts +59 -1
- package/src/data-structures/graph/undirected-graph.ts +204 -59
- package/src/data-structures/hash/hash-map.ts +230 -77
- package/src/data-structures/heap/heap.ts +287 -99
- package/src/data-structures/heap/max-heap.ts +46 -0
- package/src/data-structures/heap/min-heap.ts +59 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +286 -44
- package/src/data-structures/linked-list/singly-linked-list.ts +278 -65
- package/src/data-structures/linked-list/skip-linked-list.ts +689 -90
- package/src/data-structures/matrix/matrix.ts +416 -12
- package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
- package/src/data-structures/priority-queue/priority-queue.ts +60 -0
- package/src/data-structures/queue/deque.ts +272 -65
- package/src/data-structures/queue/queue.ts +211 -42
- package/src/data-structures/stack/stack.ts +174 -32
- package/src/data-structures/trie/trie.ts +213 -43
- package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
- package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
|
@@ -65,53 +65,6 @@ export declare class DirectedEdge<E = any> extends AbstractEdge<E> {
|
|
|
65
65
|
* console.log(neighborsA[0].key); // 'B';
|
|
66
66
|
* console.log(neighborsA[1].key); // 'C';
|
|
67
67
|
* @example
|
|
68
|
-
* // DirectedGraph deleteEdge and vertex operations
|
|
69
|
-
* const graph = new DirectedGraph<string>();
|
|
70
|
-
*
|
|
71
|
-
* // Build a small graph
|
|
72
|
-
* graph.addVertex('X');
|
|
73
|
-
* graph.addVertex('Y');
|
|
74
|
-
* graph.addVertex('Z');
|
|
75
|
-
* graph.addEdge('X', 'Y', 1);
|
|
76
|
-
* graph.addEdge('Y', 'Z', 2);
|
|
77
|
-
*
|
|
78
|
-
* // Delete an edge
|
|
79
|
-
* graph.deleteEdgeSrcToDest('X', 'Y');
|
|
80
|
-
* console.log(graph.hasEdge('X', 'Y')); // false;
|
|
81
|
-
*
|
|
82
|
-
* // Edge in other direction should not exist
|
|
83
|
-
* console.log(graph.hasEdge('Y', 'X')); // false;
|
|
84
|
-
*
|
|
85
|
-
* // Other edges should remain
|
|
86
|
-
* console.log(graph.hasEdge('Y', 'Z')); // true;
|
|
87
|
-
*
|
|
88
|
-
* // Delete a vertex
|
|
89
|
-
* graph.deleteVertex('Y');
|
|
90
|
-
* console.log(graph.hasVertex('Y')); // false;
|
|
91
|
-
* console.log(graph.size); // 2;
|
|
92
|
-
* @example
|
|
93
|
-
* // DirectedGraph topologicalSort for task scheduling
|
|
94
|
-
* const graph = new DirectedGraph<string>();
|
|
95
|
-
*
|
|
96
|
-
* // Build a DAG (Directed Acyclic Graph) for task dependencies
|
|
97
|
-
* graph.addVertex('Design');
|
|
98
|
-
* graph.addVertex('Implement');
|
|
99
|
-
* graph.addVertex('Test');
|
|
100
|
-
* graph.addVertex('Deploy');
|
|
101
|
-
*
|
|
102
|
-
* // Add dependency edges
|
|
103
|
-
* graph.addEdge('Design', 'Implement', 1); // Design must come before Implement
|
|
104
|
-
* graph.addEdge('Implement', 'Test', 1); // Implement must come before Test
|
|
105
|
-
* graph.addEdge('Test', 'Deploy', 1); // Test must come before Deploy
|
|
106
|
-
*
|
|
107
|
-
* // Topological sort gives valid execution order
|
|
108
|
-
* const executionOrder = graph.topologicalSort();
|
|
109
|
-
* console.log(executionOrder); // defined;
|
|
110
|
-
* console.log(executionOrder); // ['Design', 'Implement', 'Test', 'Deploy'];
|
|
111
|
-
*
|
|
112
|
-
* // All vertices should be included
|
|
113
|
-
* console.log(executionOrder?.length); // 4;
|
|
114
|
-
* @example
|
|
115
68
|
* // DirectedGraph dijkstra shortest path for network routing
|
|
116
69
|
* // Build a weighted directed graph representing network nodes and costs
|
|
117
70
|
* const network = new DirectedGraph<string>();
|
|
@@ -204,6 +157,22 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
204
157
|
* @param destOrKey - Destination vertex or key.
|
|
205
158
|
* @returns Edge instance or `undefined`.
|
|
206
159
|
* @remarks Time O(1) avg, Space O(1)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
* @example
|
|
169
|
+
* // Get edge between vertices
|
|
170
|
+
* const g = new DirectedGraph();
|
|
171
|
+
* g.addVertex('A');
|
|
172
|
+
* g.addVertex('B');
|
|
173
|
+
* g.addEdge('A', 'B', 5);
|
|
174
|
+
* const edge = g.getEdge('A', 'B');
|
|
175
|
+
* console.log(edge?.weight); // 5;
|
|
207
176
|
*/
|
|
208
177
|
getEdge(srcOrKey: VO | VertexKey | undefined, destOrKey: VO | VertexKey | undefined): EO | undefined;
|
|
209
178
|
/**
|
|
@@ -220,8 +189,64 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
220
189
|
* @param destVertexKey - Optional destination vertex/key when deleting by pair.
|
|
221
190
|
* @returns Removed edge or `undefined`.
|
|
222
191
|
* @remarks Time O(1) avg, Space O(1)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
* @example
|
|
204
|
+
* // DirectedGraph deleteEdge and vertex operations
|
|
205
|
+
* const graph = new DirectedGraph<string>();
|
|
206
|
+
*
|
|
207
|
+
* // Build a small graph
|
|
208
|
+
* graph.addVertex('X');
|
|
209
|
+
* graph.addVertex('Y');
|
|
210
|
+
* graph.addVertex('Z');
|
|
211
|
+
* graph.addEdge('X', 'Y', 1);
|
|
212
|
+
* graph.addEdge('Y', 'Z', 2);
|
|
213
|
+
*
|
|
214
|
+
* // Delete an edge
|
|
215
|
+
* graph.deleteEdgeSrcToDest('X', 'Y');
|
|
216
|
+
* console.log(graph.hasEdge('X', 'Y')); // false;
|
|
217
|
+
*
|
|
218
|
+
* // Edge in other direction should not exist
|
|
219
|
+
* console.log(graph.hasEdge('Y', 'X')); // false;
|
|
220
|
+
*
|
|
221
|
+
* // Other edges should remain
|
|
222
|
+
* console.log(graph.hasEdge('Y', 'Z')); // true;
|
|
223
|
+
*
|
|
224
|
+
* // Delete a vertex
|
|
225
|
+
* graph.deleteVertex('Y');
|
|
226
|
+
* console.log(graph.hasVertex('Y')); // false;
|
|
227
|
+
* console.log(graph.size); // 2;
|
|
223
228
|
*/
|
|
224
229
|
deleteEdge(edgeOrSrcVertexKey: EO | VertexKey, destVertexKey?: VertexKey): EO | undefined;
|
|
230
|
+
/**
|
|
231
|
+
* Remove a vertex
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
* @example
|
|
241
|
+
* // Remove a vertex
|
|
242
|
+
* const g = new DirectedGraph();
|
|
243
|
+
* g.addVertex('A');
|
|
244
|
+
* g.addVertex('B');
|
|
245
|
+
* g.addEdge('A', 'B');
|
|
246
|
+
* g.deleteVertex('A');
|
|
247
|
+
* console.log(g.hasVertex('A')); // false;
|
|
248
|
+
* console.log(g.hasEdge('A', 'B')); // false;
|
|
249
|
+
*/
|
|
225
250
|
deleteVertex(vertexOrKey: VO | VertexKey): boolean;
|
|
226
251
|
deleteEdgesBetween(v1: VertexKey | VO, v2: VertexKey | VO): EO[];
|
|
227
252
|
/**
|
|
@@ -229,6 +254,23 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
229
254
|
* @param vertexOrKey - Vertex or key.
|
|
230
255
|
* @returns Array of incoming edges.
|
|
231
256
|
* @remarks Time O(deg_in), Space O(deg_in)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
* @example
|
|
266
|
+
* // Get incoming edges
|
|
267
|
+
* const g = new DirectedGraph();
|
|
268
|
+
* g.addVertex('A');
|
|
269
|
+
* g.addVertex('B');
|
|
270
|
+
* g.addVertex('C');
|
|
271
|
+
* g.addEdge('A', 'C');
|
|
272
|
+
* g.addEdge('B', 'C');
|
|
273
|
+
* console.log(g.incomingEdgesOf('C').length); // 2;
|
|
232
274
|
*/
|
|
233
275
|
incomingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
234
276
|
/**
|
|
@@ -236,6 +278,23 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
236
278
|
* @param vertexOrKey - Vertex or key.
|
|
237
279
|
* @returns Array of outgoing edges.
|
|
238
280
|
* @remarks Time O(deg_out), Space O(deg_out)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
* @example
|
|
290
|
+
* // Get outgoing edges
|
|
291
|
+
* const g = new DirectedGraph();
|
|
292
|
+
* g.addVertex('A');
|
|
293
|
+
* g.addVertex('B');
|
|
294
|
+
* g.addVertex('C');
|
|
295
|
+
* g.addEdge('A', 'B');
|
|
296
|
+
* g.addEdge('A', 'C');
|
|
297
|
+
* console.log(g.outgoingEdgesOf('A').length); // 2;
|
|
239
298
|
*/
|
|
240
299
|
outgoingEdgesOf(vertexOrKey: VO | VertexKey): EO[];
|
|
241
300
|
/**
|
|
@@ -268,9 +327,82 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
268
327
|
* @param propertyName - `'key'` to map to keys; `'vertex'` to keep instances.
|
|
269
328
|
* @returns Array of keys/vertices, or `undefined` when cycle is found.
|
|
270
329
|
* @remarks Time O(V + E), Space O(V)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
* @example
|
|
342
|
+
* // DirectedGraph topologicalSort for task scheduling
|
|
343
|
+
* const graph = new DirectedGraph<string>();
|
|
344
|
+
*
|
|
345
|
+
* // Build a DAG (Directed Acyclic Graph) for task dependencies
|
|
346
|
+
* graph.addVertex('Design');
|
|
347
|
+
* graph.addVertex('Implement');
|
|
348
|
+
* graph.addVertex('Test');
|
|
349
|
+
* graph.addVertex('Deploy');
|
|
350
|
+
*
|
|
351
|
+
* // Add dependency edges
|
|
352
|
+
* graph.addEdge('Design', 'Implement', 1); // Design must come before Implement
|
|
353
|
+
* graph.addEdge('Implement', 'Test', 1); // Implement must come before Test
|
|
354
|
+
* graph.addEdge('Test', 'Deploy', 1); // Test must come before Deploy
|
|
355
|
+
*
|
|
356
|
+
* // Topological sort gives valid execution order
|
|
357
|
+
* const executionOrder = graph.topologicalSort();
|
|
358
|
+
* console.log(executionOrder); // defined;
|
|
359
|
+
* console.log(executionOrder); // ['Design', 'Implement', 'Test', 'Deploy'];
|
|
360
|
+
*
|
|
361
|
+
* // All vertices should be included
|
|
362
|
+
* console.log(executionOrder?.length); // 4;
|
|
271
363
|
*/
|
|
272
364
|
topologicalSort(propertyName?: 'vertex' | 'key'): Array<VO | VertexKey> | undefined;
|
|
365
|
+
/**
|
|
366
|
+
* Get all edges
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
* @example
|
|
376
|
+
* // Get all edges
|
|
377
|
+
* const g = new DirectedGraph();
|
|
378
|
+
* g.addVertex('A');
|
|
379
|
+
* g.addVertex('B');
|
|
380
|
+
* g.addEdge('A', 'B', 3);
|
|
381
|
+
* console.log(g.edgeSet().length); // 1;
|
|
382
|
+
*/
|
|
273
383
|
edgeSet(): EO[];
|
|
384
|
+
/**
|
|
385
|
+
* Get outgoing neighbors
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
* @example
|
|
396
|
+
* // Get outgoing neighbors
|
|
397
|
+
* const g = new DirectedGraph();
|
|
398
|
+
* g.addVertex('A');
|
|
399
|
+
* g.addVertex('B');
|
|
400
|
+
* g.addVertex('C');
|
|
401
|
+
* g.addEdge('A', 'B');
|
|
402
|
+
* g.addEdge('A', 'C');
|
|
403
|
+
* const neighbors = g.getNeighbors('A');
|
|
404
|
+
* console.log(neighbors.map(v => v.key).sort()); // ['B', 'C'];
|
|
405
|
+
*/
|
|
274
406
|
getNeighbors(vertexOrKey: VO | VertexKey): VO[];
|
|
275
407
|
/**
|
|
276
408
|
* Resolve an edge's `[src, dest]` endpoints to vertex instances.
|
|
@@ -299,6 +431,27 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
299
431
|
* Tarjan's algorithm for strongly connected components.
|
|
300
432
|
* @returns `{ dfnMap, lowMap, SCCs }`.
|
|
301
433
|
* @remarks Time O(V + E), Space O(V + E)
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
* @example
|
|
443
|
+
* // Find strongly connected components
|
|
444
|
+
* const g = new DirectedGraph();
|
|
445
|
+
* g.addVertex('A');
|
|
446
|
+
* g.addVertex('B');
|
|
447
|
+
* g.addVertex('C');
|
|
448
|
+
* g.addEdge('A', 'B');
|
|
449
|
+
* g.addEdge('B', 'C');
|
|
450
|
+
* g.addEdge('C', 'A');
|
|
451
|
+
* const { SCCs } = g.tarjan();
|
|
452
|
+
* // A→B→C→A forms one SCC with 3 members
|
|
453
|
+
* const sccArrays = [...SCCs.values()];
|
|
454
|
+
* console.log(sccArrays.some(scc => scc.length === 3)); // true;
|
|
302
455
|
*/
|
|
303
456
|
tarjan(): {
|
|
304
457
|
dfnMap: Map<VO, number>;
|
|
@@ -321,6 +474,25 @@ export declare class DirectedGraph<V = any, E = any, VO extends DirectedVertex<V
|
|
|
321
474
|
* Strongly connected components computed by `tarjan()`.
|
|
322
475
|
* @returns Map from SCC id to vertices.
|
|
323
476
|
* @remarks Time O(#SCC + V), Space O(V)
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
* @example
|
|
486
|
+
* // Get strongly connected components
|
|
487
|
+
* const g = new DirectedGraph();
|
|
488
|
+
* g.addVertex(1);
|
|
489
|
+
* g.addVertex(2);
|
|
490
|
+
* g.addVertex(3);
|
|
491
|
+
* g.addEdge(1, 2);
|
|
492
|
+
* g.addEdge(2, 3);
|
|
493
|
+
* g.addEdge(3, 1);
|
|
494
|
+
* const sccs = g.getSCCs(); // Map<number, VO[]>
|
|
495
|
+
* console.log(sccs.size); // >= 1;
|
|
324
496
|
*/
|
|
325
497
|
getSCCs(): Map<number, VO[]>;
|
|
326
498
|
/**
|
|
@@ -22,7 +22,65 @@ export declare class MapEdge<E = any> extends DirectedEdge<E> {
|
|
|
22
22
|
* @template VO - Concrete vertex class (MapVertex<V>).
|
|
23
23
|
* @template EO - Concrete edge class (MapEdge<E>).
|
|
24
24
|
* @remarks Time O(1), Space O(1)
|
|
25
|
-
* @example
|
|
25
|
+
* @example
|
|
26
|
+
* // City navigation with shortest path
|
|
27
|
+
* const map = new MapGraph([0, 0], [10, 10]);
|
|
28
|
+
*
|
|
29
|
+
* map.addVertex(new MapVertex('Home', '', 0, 0));
|
|
30
|
+
* map.addVertex(new MapVertex('Office', '', 3, 4));
|
|
31
|
+
* map.addVertex(new MapVertex('Cafe', '', 1, 2));
|
|
32
|
+
* map.addVertex(new MapVertex('Park', '', 2, 1));
|
|
33
|
+
*
|
|
34
|
+
* map.addEdge('Home', 'Cafe', 2.2);
|
|
35
|
+
* map.addEdge('Cafe', 'Office', 3.5);
|
|
36
|
+
* map.addEdge('Home', 'Park', 2.0);
|
|
37
|
+
* map.addEdge('Park', 'Office', 4.0);
|
|
38
|
+
* map.addEdge('Home', 'Office', 7.0);
|
|
39
|
+
*
|
|
40
|
+
* // Find shortest path
|
|
41
|
+
* const result = map.dijkstra('Home', 'Office', true, true);
|
|
42
|
+
* console.log(result?.minDist); // 5.7; // Home → Cafe → Office
|
|
43
|
+
* console.log(result?.minPath.map(v => v.key)); // ['Home', 'Cafe', 'Office'];
|
|
44
|
+
* @example
|
|
45
|
+
* // Delivery route optimization
|
|
46
|
+
* const routes = new MapGraph([0, 0], [10, 10]);
|
|
47
|
+
*
|
|
48
|
+
* routes.addVertex(new MapVertex('Warehouse', '', 0, 0));
|
|
49
|
+
* routes.addVertex(new MapVertex('Customer A', '', 2, 3));
|
|
50
|
+
* routes.addVertex(new MapVertex('Customer B', '', 5, 1));
|
|
51
|
+
* routes.addVertex(new MapVertex('Customer C', '', 3, 5));
|
|
52
|
+
*
|
|
53
|
+
* routes.addEdge('Warehouse', 'Customer A', 3.6);
|
|
54
|
+
* routes.addEdge('Warehouse', 'Customer B', 5.1);
|
|
55
|
+
* routes.addEdge('Customer A', 'Customer C', 2.2);
|
|
56
|
+
* routes.addEdge('Customer A', 'Customer B', 3.6);
|
|
57
|
+
* routes.addEdge('Customer B', 'Customer C', 4.5);
|
|
58
|
+
*
|
|
59
|
+
* // Check outgoing neighbors of Customer A
|
|
60
|
+
* const neighbors = routes.getNeighbors('Customer A');
|
|
61
|
+
* console.log(neighbors.map(n => n.key).sort()); // ['Customer B', 'Customer C'];
|
|
62
|
+
*
|
|
63
|
+
* // Shortest path from Warehouse to Customer C
|
|
64
|
+
* const path = routes.getMinPathBetween('Warehouse', 'Customer C', true);
|
|
65
|
+
* console.log(path?.map(v => v.key)); // ['Warehouse', 'Customer A', 'Customer C'];
|
|
66
|
+
* @example
|
|
67
|
+
* // Campus map with building connections
|
|
68
|
+
* const campus = new MapGraph([0, 0], [5, 5]);
|
|
69
|
+
*
|
|
70
|
+
* campus.addVertex(new MapVertex('Library', '', 0, 0));
|
|
71
|
+
* campus.addVertex(new MapVertex('Lab', '', 1, 1));
|
|
72
|
+
* campus.addVertex(new MapVertex('Cafeteria', '', 2, 0));
|
|
73
|
+
*
|
|
74
|
+
* campus.addEdge('Library', 'Lab', 5);
|
|
75
|
+
* campus.addEdge('Lab', 'Cafeteria', 3);
|
|
76
|
+
* campus.addEdge('Library', 'Cafeteria', 10);
|
|
77
|
+
*
|
|
78
|
+
* console.log(campus.hasVertex('Library')); // true;
|
|
79
|
+
* console.log(campus.hasVertex('Gym')); // false;
|
|
80
|
+
*
|
|
81
|
+
* // Direct distance vs shortest path
|
|
82
|
+
* const direct = campus.dijkstra('Library', 'Cafeteria', true, true);
|
|
83
|
+
* console.log(direct?.minDist); // 8;
|
|
26
84
|
*/
|
|
27
85
|
export declare class MapGraph<V = any, E = any, VO extends MapVertex<V> = MapVertex<V>, EO extends MapEdge<E> = MapEdge<E>> extends DirectedGraph<V, E, VO, EO> {
|
|
28
86
|
/**
|