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); 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> /// <summary>
/// Returns the shortest path from root to destination via breadth-first search. /// Returns the shortest path from root to destination via breadth-first search.
/// </summary> /// </summary>
@@ -81,7 +72,7 @@ namespace ICD.Common.Utils
// Edge case - root and destination are the same // Edge case - root and destination are the same
if (comparer.Equals(root, destination)) if (comparer.Equals(root, destination))
return new[] { root }; return new[] {root};
Queue<T> queue = new Queue<T>(); Queue<T> queue = new Queue<T>();
queue.Enqueue(root); queue.Enqueue(root);
@@ -110,13 +101,32 @@ namespace ICD.Common.Utils
} }
[NotNull] [NotNull]
public static Dictionary<T2, IEnumerable<T>> BreadthFirstSearchPathManyDestinations<T, T2>(T root, Dictionary<T2, T> destinations, public static Dictionary<T2, IEnumerable<T>> BreadthFirstSearchManyDestinations<T, T2>(T root,
Func<T, IEnumerable<T>> getChildren, Dictionary<T2, T> destinations,
IEqualityComparer<T> comparer) Func<T, IEnumerable<T>>
getChildren)
{ {
if (getChildren == null) if (getChildren == null)
throw new ArgumentNullException("getChildren"); 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) if (comparer == null)
throw new ArgumentNullException("comparer"); throw new ArgumentNullException("comparer");
@@ -124,14 +134,16 @@ namespace ICD.Common.Utils
List<T> destinationsProcessed = new List<T>(); List<T> destinationsProcessed = new List<T>();
Dictionary<T2, IEnumerable<T>> pathsToReturn = new Dictionary<T2, IEnumerable<T>>(); Dictionary<T2, IEnumerable<T>> pathsToReturn = new Dictionary<T2, IEnumerable<T>>();
//Edge case, root is the destination // 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); destinationsProcessed.Add(destination.Value);
pathsToReturn.Add(destination.Key, new[] { root }); pathsToReturn.Add(destination.Key, new[] {root});
} }
foreach (var destination in destinationsProcessed) foreach (T destination in destinationsProcessed)
{ {
destinationsToBeProcessed.RemoveValue(destination); destinationsToBeProcessed.RemoveValue(destination);
} }
@@ -155,22 +167,23 @@ namespace ICD.Common.Utils
queue.Enqueue(node); queue.Enqueue(node);
nodeParents.Add(node, current); 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); destinationsProcessed.Add(destination.Value);
pathsToReturn.Add(destination.Key, GetPath(destination.Value, nodeParents).Reverse()); pathsToReturn.Add(destination.Key, GetPath(destination.Value, nodeParents).Reverse());
} }
foreach (var destination in destinationsProcessed)
{ foreach (T destination in destinationsProcessed)
destinationsToBeProcessed.RemoveValue(destination); destinationsToBeProcessed.RemoveValue(destination);
}
destinationsProcessed.Clear(); destinationsProcessed.Clear();
if (destinationsToBeProcessed.Count == 0) if (destinationsToBeProcessed.Count == 0)
{
return pathsToReturn; return pathsToReturn;
} }
} }
}
return pathsToReturn; return pathsToReturn;
} }