@@ -23,23 +23,23 @@ public static IReadOnlyDictionary<string, string> AssignLabels(
2323
2424 var random = new Random ( config . Seed ) ;
2525 var labels = adjacency . Keys . ToDictionary ( node => node , node => node , StringComparer . OrdinalIgnoreCase ) ;
26- var nodes = adjacency . Keys . ToList ( ) ;
26+ var nodes = adjacency . Keys . ToArray ( ) ;
2727 var maxIterations = Math . Max ( 1 , config . MaxIterations ) ;
2828
2929 for ( var iteration = 0 ; iteration < maxIterations ; iteration ++ )
3030 {
31- var shuffled = nodes . OrderBy ( _ => random . Next ( ) ) . ToList ( ) ;
31+ random . Shuffle ( nodes ) ;
3232 var changed = false ;
3333
34- foreach ( var node in shuffled )
34+ var labelWeights = new Dictionary < string , double > ( StringComparer . OrdinalIgnoreCase ) ;
35+ foreach ( var node in nodes )
3536 {
3637 var neighbors = adjacency [ node ] ;
3738 if ( neighbors . Count == 0 )
3839 {
3940 continue ;
4041 }
4142
42- var labelWeights = new Dictionary < string , double > ( StringComparer . OrdinalIgnoreCase ) ;
4343 foreach ( var ( neighbor , weight ) in neighbors )
4444 {
4545 if ( ! labels . TryGetValue ( neighbor , out var neighborLabel ) )
@@ -57,7 +57,7 @@ public static IReadOnlyDictionary<string, string> AssignLabels(
5757
5858 var maxWeight = labelWeights . Values . Max ( ) ;
5959 var candidates = labelWeights
60- . Where ( pair => Math . Abs ( pair . Value - maxWeight ) < 1e-6 )
60+ . Where ( pair => Math . Abs ( pair . Value - maxWeight ) < double . Epsilon )
6161 . Select ( pair => pair . Key )
6262 . ToList ( ) ;
6363
@@ -70,6 +70,8 @@ public static IReadOnlyDictionary<string, string> AssignLabels(
7070 labels [ node ] = chosen ;
7171 changed = true ;
7272 }
73+
74+ labelWeights . Clear ( ) ;
7375 }
7476
7577 if ( ! changed )
0 commit comments