diff --git a/ICD.Common.Utils/RecursionUtils.cs b/ICD.Common.Utils/RecursionUtils.cs index 755d705..06890b9 100644 --- a/ICD.Common.Utils/RecursionUtils.cs +++ b/ICD.Common.Utils/RecursionUtils.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using ICD.Common.Properties; using ICD.Common.Utils.Collections; +using ICD.Common.Utils.Extensions; namespace ICD.Common.Utils { @@ -97,23 +98,23 @@ namespace ICD.Common.Utils } /// - /// Returns true if there is a path from the given root to the given child node. + /// Returns true if there is a path from the given root to the given destination node. /// /// /// - /// + /// /// /// - public static bool BreadthFirstSearch(T root, T child, Func> getChildren) + public static bool BreadthFirstSearch(T root, T destination, Func> getChildren) { if (getChildren == null) throw new ArgumentNullException("getChildren"); - return BreadthFirstSearch(root, child, getChildren, EqualityComparer.Default); + return BreadthFirstSearch(root, destination, getChildren, EqualityComparer.Default); } /// - /// Returns true if there is a path from the given root to the given child node. + /// Returns true if there is a path from the given root to the given destination node. /// /// /// @@ -159,9 +160,9 @@ namespace ICD.Common.Utils Queue process = new Queue(); process.Enqueue(root); - while (process.Count > 0) + T current; + while (process.Dequeue(out current)) { - T current = process.Dequeue(); yield return current; foreach (T child in getChildren(current)) @@ -214,10 +215,9 @@ namespace ICD.Common.Utils Dictionary nodeParents = new Dictionary(comparer); - while (queue.Count > 0) + T current; + while (queue.Dequeue(out current)) { - T current = queue.Dequeue(); - foreach (T node in getChildren(current)) { if (nodeParents.ContainsKey(node))