diff --git a/ICD.Common.Utils.Tests/RecursionUtilsTest.cs b/ICD.Common.Utils.Tests/RecursionUtilsTest.cs index c9ed3a8..6e2896f 100644 --- a/ICD.Common.Utils.Tests/RecursionUtilsTest.cs +++ b/ICD.Common.Utils.Tests/RecursionUtilsTest.cs @@ -178,12 +178,12 @@ namespace ICD.Common.Utils.Tests [Test] public void BreadthFirstSearchManyDestinationsTest() { - Assert.Throws(() => RecursionUtils.BreadthFirstSearchManyDestinations(1, new[] { 1 }, null)); - Assert.Throws(() => RecursionUtils.BreadthFirstSearchManyDestinations(1, null, Graph)); - Assert.AreEqual(0, RecursionUtils.BreadthFirstSearchManyDestinations(1, new[] { 5 }, Graph).Count()); + Assert.Throws(() => RecursionUtils.BreadthFirstSearchPathManyDestinations(1, new[] { 1 }, null)); + Assert.Throws(() => RecursionUtils.BreadthFirstSearchPathManyDestinations(1, null, Graph)); + Assert.AreEqual(0, RecursionUtils.BreadthFirstSearchPathManyDestinations(1, new[] { 5 }, Graph).Count()); Dictionary> paths = - RecursionUtils.BreadthFirstSearchManyDestinations(1, new[] {21, 22, 31, 43, 62}, WideGraph) + RecursionUtils.BreadthFirstSearchPathManyDestinations(1, new[] {21, 22, 31, 43, 62}, WideGraph) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); //Make sure all paths were found diff --git a/ICD.Common.Utils/RecursionUtils.cs b/ICD.Common.Utils/RecursionUtils.cs index 8ff38bf..a57b482 100644 --- a/ICD.Common.Utils/RecursionUtils.cs +++ b/ICD.Common.Utils/RecursionUtils.cs @@ -235,12 +235,16 @@ namespace ICD.Common.Utils return null; } - - [NotNull] - public static IEnumerable>> BreadthFirstSearchManyDestinations(T root, - IEnumerable destinations, - Func> - getChildren) + /// + /// Returns the shortest path from root to each destination via breadth-first search. + /// + /// + /// + /// + /// + /// + public static IEnumerable>> + BreadthFirstSearchPathManyDestinations(T root, IEnumerable destinations, Func> getChildren) { if (destinations == null) throw new ArgumentNullException("destinations"); @@ -251,14 +255,18 @@ namespace ICD.Common.Utils return BreadthFirstSearchPathManyDestinations(root, destinations, getChildren, EqualityComparer.Default); } - [NotNull] - public static IEnumerable>> BreadthFirstSearchPathManyDestinations(T root, - IEnumerable - destinations, - Func> - getChildren, - IEqualityComparer - comparer) + /// + /// Returns the shortest path from root to each destination via breadth-first search. + /// + /// + /// + /// + /// + /// + /// + public static IEnumerable>> + BreadthFirstSearchPathManyDestinations(T root, IEnumerable destinations, Func> getChildren, + IEqualityComparer comparer) { if (destinations == null) throw new ArgumentNullException("destinations"); @@ -270,7 +278,6 @@ namespace ICD.Common.Utils throw new ArgumentNullException("comparer"); IcdHashSet destinationsToBeProcessed = new IcdHashSet(destinations); - Dictionary> pathsToReturn = new Dictionary>(); // Edge case, root is the destination foreach (T destination in @@ -303,7 +310,8 @@ namespace ICD.Common.Utils { destinationsToBeProcessed.Remove(destination); - yield return new KeyValuePair>(destination, GetPath(destination, root, nodeParents, comparer).Reverse()); + yield return + new KeyValuePair>(destination, GetPath(destination, root, nodeParents, comparer).Reverse()); } if (destinationsToBeProcessed.Count == 0)