Whitespace, tidying

This commit is contained in:
Chris Cameron
2018-01-02 14:20:52 -05:00
parent 02cae250a6
commit d1b87cc329

View File

@@ -51,15 +51,6 @@ namespace ICD.Common.Utils
return BreadthFirstSearchPath(root, destination, getChildren, EqualityComparer<T>.Default);
}
[NotNull]
public static Dictionary<T2, IEnumerable<T>> BreadthFirstSearchManyDestinations<T, T2>(T root, Dictionary<T2, T> destinations, Func<T, IEnumerable<T>> getChildren)
{
if (getChildren == null)
throw new ArgumentNullException("getChildren");
return BreadthFirstSearchPathManyDestinations(root, destinations, getChildren, EqualityComparer<T>.Default);
}
/// <summary>
/// Returns the shortest path from root to destination via breadth-first search.
/// </summary>
@@ -110,13 +101,32 @@ namespace ICD.Common.Utils
}
[NotNull]
public static Dictionary<T2, IEnumerable<T>> BreadthFirstSearchPathManyDestinations<T, T2>(T root, Dictionary<T2, T> destinations,
Func<T, IEnumerable<T>> getChildren,
IEqualityComparer<T> comparer)
public static Dictionary<T2, IEnumerable<T>> BreadthFirstSearchManyDestinations<T, T2>(T root,
Dictionary<T2, T> destinations,
Func<T, IEnumerable<T>>
getChildren)
{
if (getChildren == null)
throw new ArgumentNullException("getChildren");
return BreadthFirstSearchPathManyDestinations(root, destinations, getChildren, EqualityComparer<T>.Default);
}
[NotNull]
public static Dictionary<T2, IEnumerable<T>> BreadthFirstSearchPathManyDestinations<T, T2>(T root,
Dictionary<T2, T>
destinations,
Func<T, IEnumerable<T>>
getChildren,
IEqualityComparer<T>
comparer)
{
if (destinations == null)
throw new ArgumentNullException("destinations");
if (getChildren == null)
throw new ArgumentNullException("getChildren");
if (comparer == null)
throw new ArgumentNullException("comparer");
@@ -125,13 +135,15 @@ namespace ICD.Common.Utils
Dictionary<T2, IEnumerable<T>> pathsToReturn = new Dictionary<T2, IEnumerable<T>>();
// Edge case, root is the destination
foreach (var destination in destinationsToBeProcessed.Where(destination => comparer.Equals(root, destination.Value)))
foreach (
KeyValuePair<T2, T> destination in
destinationsToBeProcessed.Where(destination => comparer.Equals(root, destination.Value)))
{
destinationsProcessed.Add(destination.Value);
pathsToReturn.Add(destination.Key, new[] {root});
}
foreach (var destination in destinationsProcessed)
foreach (T destination in destinationsProcessed)
{
destinationsToBeProcessed.RemoveValue(destination);
}
@@ -155,22 +167,23 @@ namespace ICD.Common.Utils
queue.Enqueue(node);
nodeParents.Add(node, current);
foreach (var destination in destinationsToBeProcessed.Where(destination => comparer.Equals(node, destination.Value)))
foreach (
KeyValuePair<T2, T> destination in
destinationsToBeProcessed.Where(destination => comparer.Equals(node, destination.Value)))
{
destinationsProcessed.Add(destination.Value);
pathsToReturn.Add(destination.Key, GetPath(destination.Value, nodeParents).Reverse());
}
foreach (var destination in destinationsProcessed)
{
foreach (T destination in destinationsProcessed)
destinationsToBeProcessed.RemoveValue(destination);
}
destinationsProcessed.Clear();
if (destinationsToBeProcessed.Count == 0)
{
return pathsToReturn;
}
}
}
return pathsToReturn;
}