@@ -26,21 +26,22 @@ public static ShortestPathResult Dijkstra<T, TEdgeCustom>(this IGraph<T, TEdgeCu
26
26
/// <param name="to">End node</param>
27
27
/// <param name="depth">Depth of path</param>
28
28
/// <returns>Value with path</returns>
29
- public static ShortestPathResult Dijkstra < T , TEdgeCustom > ( this IGraph < T , TEdgeCustom > graph , uint from , uint to , int depth )
29
+ public static ShortestPathResult Dijkstra < T , TEdgeCustom > ( this IGraph < T , TEdgeCustom > graph , uint from , uint to ,
30
+ int depth )
30
31
where TEdgeCustom : IEquatable < TEdgeCustom >
31
32
{
32
33
var path = new Dictionary < uint , uint > ( ) ;
33
- var distance = new Dictionary < uint , int > { [ from ] = 0 } ;
34
- var d = new Dictionary < uint , int > { [ from ] = 0 } ;
35
- var q = new SortedSet < uint > ( new [ ] { from } , new NodeComparer ( distance ) ) ;
34
+ var distance = new Dictionary < uint , int > { [ from ] = 0 } ;
35
+ var d = new Dictionary < uint , int > { [ from ] = 0 } ;
36
+ var q = new SortedSet < uint > ( new [ ] { from } , new NodeComparer ( distance ) ) ;
36
37
var current = new HashSet < uint > ( ) ;
37
38
38
39
int Distance ( uint key )
39
40
{
40
41
return distance . ContainsKey ( key ) ? distance [ key ] : Int32 . MaxValue ;
41
42
}
42
43
43
- while ( q . Count > 0 )
44
+ do
44
45
{
45
46
uint u = q . Deque ( ) ;
46
47
@@ -72,7 +73,8 @@ int Distance(uint key)
72
73
d[ e . Node . Key ] = d [ u ] + 1 ;
73
74
}
74
75
} ) ;
75
- }
76
+
77
+ } while ( q . Count > 0 && depth > 0 ) ;
76
78
77
79
return new ShortestPathResult ( from , to ) ;
78
80
}
0 commit comments