diff --git a/ICD.Common.Utils/RecursionUtils.cs b/ICD.Common.Utils/RecursionUtils.cs index 826f35f..7f3c853 100644 --- a/ICD.Common.Utils/RecursionUtils.cs +++ b/ICD.Common.Utils/RecursionUtils.cs @@ -163,7 +163,7 @@ namespace ICD.Common.Utils } /// - /// Returns all of the nodes in the tree via breadth-first search. + /// Returns all of the nodes in the graph via breadth-first search. /// /// /// @@ -171,6 +171,7 @@ namespace ICD.Common.Utils /// private static IEnumerable BreadthFirstSearchIterator(T root, Func> getChildren) { + IcdHashSet visited = new IcdHashSet {root}; Queue process = new Queue(); process.Enqueue(root); @@ -179,8 +180,11 @@ namespace ICD.Common.Utils { yield return current; - foreach (T child in getChildren(current)) + foreach (T child in getChildren(current).Where(c => !visited.Contains(c))) + { + visited.Add(child); process.Enqueue(child); + } } }