@@ -3,8 +3,8 @@ import type { NoInfer } from '../../types.js';
33import { Graph } from '../../Graph.js' ;
44import { shortestPath } from './shortestPath.js' ;
55
6- export function shortestPaths < Node > (
7- graph : Graph < Node > ,
6+ export function shortestPaths < Node , LinkProps > (
7+ graph : Graph < Node , LinkProps > ,
88 source : NoInfer < Node > ,
99 destination : NoInfer < Node > ,
1010) {
@@ -13,19 +13,29 @@ export function shortestPaths<Node>(
1313 const paths = [ path ] ;
1414 const pathWeight = path . weight ;
1515
16- const removedEdges : { u : Node ; v : Node ; weight : number } [ ] = [ ] ;
16+ const removedEdges : Array < { u : Node ; v : Node ; weight : number ; props : LinkProps } > = [ ] ;
1717
1818 while ( path . weight ) {
1919 const u = path . nodes [ 0 ] ;
2020 const v = path . nodes [ 1 ] ;
2121
2222 if ( graph . hasEdge ( u , v ) ) {
23- removedEdges . push ( { u, v, weight : graph . getEdgeWeight ( u , v ) } ) ;
23+ removedEdges . push ( {
24+ u,
25+ v,
26+ weight : graph . getEdgeWeight ( u , v ) ,
27+ props : graph . getEdgeProperties ( u , v ) ,
28+ } ) ;
2429 graph . removeEdge ( u , v ) ;
2530 }
2631
2732 if ( graph . hasEdge ( v , u ) ) {
28- removedEdges . push ( { u : v , v : u , weight : graph . getEdgeWeight ( v , u ) } ) ;
33+ removedEdges . push ( {
34+ u : v ,
35+ v : u ,
36+ weight : graph . getEdgeWeight ( v , u ) ,
37+ props : graph . getEdgeProperties ( u , v ) ,
38+ } ) ;
2939 graph . removeEdge ( v , u ) ;
3040 }
3141
@@ -38,8 +48,8 @@ export function shortestPaths<Node>(
3848 }
3949 }
4050
41- for ( const { u, v, weight } of removedEdges ) {
42- graph . addEdge ( u , v , weight ) ;
51+ for ( const { u, v, weight, props } of removedEdges ) {
52+ graph . addEdge ( u , v , ... ( [ weight , props ] as never ) ) ;
4353 }
4454
4555 return paths ;
0 commit comments