mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-09 01:35:06 +00:00
perf: BreadthFirstSearchPathManyDestinations optimizations
This commit is contained in:
@@ -245,20 +245,16 @@ namespace ICD.Common.Utils
|
||||
throw new ArgumentNullException("comparer");
|
||||
|
||||
IcdHashSet<T> destinationsToBeProcessed = new IcdHashSet<T>(destinations);
|
||||
IcdHashSet<T> destinationsProcessed = new IcdHashSet<T>();
|
||||
Dictionary<T, IEnumerable<T>> pathsToReturn = new Dictionary<T, IEnumerable<T>>();
|
||||
|
||||
// Edge case, root is the destination
|
||||
foreach (T destination in
|
||||
destinationsToBeProcessed.Where(destination => comparer.Equals(root, destination)))
|
||||
destinationsToBeProcessed.Where(destination => comparer.Equals(root, destination)).ToArray())
|
||||
{
|
||||
destinationsProcessed.Add(destination);
|
||||
destinationsToBeProcessed.Remove(destination);
|
||||
pathsToReturn.Add(destination, new[] {root});
|
||||
}
|
||||
|
||||
foreach (T destination in destinationsProcessed)
|
||||
destinationsToBeProcessed.Remove(destination);
|
||||
destinationsProcessed.Clear();
|
||||
if (destinationsToBeProcessed.Count == 0)
|
||||
return pathsToReturn;
|
||||
|
||||
@@ -278,17 +274,12 @@ namespace ICD.Common.Utils
|
||||
|
||||
T closureNode = node;
|
||||
foreach (T destination in
|
||||
destinationsToBeProcessed.Where(destination => comparer.Equals(closureNode, destination)))
|
||||
destinationsToBeProcessed.Where(destination => comparer.Equals(closureNode, destination)).ToArray())
|
||||
{
|
||||
destinationsProcessed.Add(destination);
|
||||
destinationsToBeProcessed.Remove(destination);
|
||||
pathsToReturn.Add(destination, GetPath(destination, root, nodeParents, comparer).Reverse());
|
||||
}
|
||||
|
||||
foreach (T destination in destinationsProcessed)
|
||||
destinationsToBeProcessed.Remove(destination);
|
||||
|
||||
destinationsProcessed.Clear();
|
||||
|
||||
if (destinationsToBeProcessed.Count == 0)
|
||||
return pathsToReturn;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user