Skip to content

Commit 0d78bec

Browse files
committed
Merge branch 'master' into beta
2 parents 7185d3c + c9468b3 commit 0d78bec

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/Advanced.Algorithms/Graph/Coloring/MColorer.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,26 @@ public class MColorer<T, C>
1414
/// </summary>
1515
public MColorResult<T, C> Color(IGraph<T> graph, C[] colors)
1616
{
17-
var totalProgress = new Dictionary<IGraphVertex<T>, C>();
17+
var progress = new Dictionary<IGraphVertex<T>, C>();
1818

1919
foreach (var vertex in graph.VerticesAsEnumberable)
2020
{
21-
var progress = canColor(vertex, colors,
22-
new Dictionary<IGraphVertex<T>, C>(),
23-
new HashSet<IGraphVertex<T>>());
24-
25-
foreach(var item in progress)
21+
if (!progress.ContainsKey(vertex))
2622
{
27-
if (!totalProgress.ContainsKey(item.Key))
28-
{
29-
totalProgress.Add(item.Key, item.Value);
30-
}
23+
canColor(vertex, colors,
24+
progress,
25+
new HashSet<IGraphVertex<T>>());
3126
}
32-
3327
}
3428

35-
if (totalProgress.Count != graph.VerticesCount)
29+
if (progress.Count != graph.VerticesCount)
3630
{
3731
return new MColorResult<T, C>(false, null);
3832
}
3933

4034
var result = new Dictionary<C, List<T>>();
4135

42-
foreach (var vertex in totalProgress)
36+
foreach (var vertex in progress)
4337
{
4438
if (!result.ContainsKey(vertex.Value))
4539
{

0 commit comments

Comments
 (0)