Skip to content

Commit

Permalink
IndirectDepencies are not duplicated anymore. The shortest path wins
Browse files Browse the repository at this point in the history
  • Loading branch information
manitra committed Jan 5, 2016
1 parent 2f7c674 commit 1704336
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/DependencyReader.CLI/Impl/IndirectDependencyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ private IEnumerable<DependencyInfo> GetDescendantDeps(IEnumerable<Node> parents)
{
foreach (var parent in parents)
{
var todo = parent.Children.ToDictionary(

var result = parent.Children.ToDictionary(
child => child.Key,
child => new TraversingInfo(child, 1, false));

var todo = new Queue<TraversingInfo>(result.Values);

while (todo.Count > 0)
{
var current = todo.First().Value;
todo.Remove(current.Node.Key);
var current = todo.Dequeue();

yield return new DependencyInfo
{
Expand All @@ -58,9 +60,11 @@ private IEnumerable<DependencyInfo> GetDescendantDeps(IEnumerable<Node> parents)

foreach (var child in current.Node.Children)
{
if (!todo.ContainsKey(child.Key))
if (!result.ContainsKey(child.Key))
{
todo.Add(child.Key, new TraversingInfo(child, current.Distance + 1, false));
var item = new TraversingInfo(child, current.Distance + 1, false);
result.Add(child.Key, item);
todo.Enqueue(item);
}
}
}
Expand Down

0 comments on commit 1704336

Please sign in to comment.