@@ -26,21 +26,22 @@ public static ShortestPathResult Dijkstra<T, TEdgeCustom>(this IGraph<T, TEdgeCu
2626 /// <param name="to">End node</param>
2727 /// <param name="depth">Depth of path</param>
2828 /// <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 )
3031 where TEdgeCustom : IEquatable < TEdgeCustom >
3132 {
3233 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 ) ) ;
3637 var current = new HashSet < uint > ( ) ;
3738
3839 int Distance ( uint key )
3940 {
4041 return distance . ContainsKey ( key ) ? distance [ key ] : Int32 . MaxValue ;
4142 }
4243
43- while ( q . Count > 0 )
44+ do
4445 {
4546 uint u = q . Deque ( ) ;
4647
@@ -72,7 +73,8 @@ int Distance(uint key)
7273 d[ e . Node . Key ] = d [ u ] + 1 ;
7374 }
7475 } ) ;
75- }
76+
77+ } while ( q . Count > 0 && depth > 0 ) ;
7678
7779 return new ShortestPathResult ( from , to ) ;
7880 }
0 commit comments