feat: optimized get clique by using a bredth-first-search so it would not have to search the whole graph

This commit is contained in:
Austin Noska
2019-06-27 10:57:55 -04:00
parent 7cc5a47d6a
commit 2d401959b6

View File

@@ -36,14 +36,18 @@ namespace ICD.Common.Utils
/// Gets the clique containing the given node. /// Gets the clique containing the given node.
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="nodes"></param>
/// <param name="node"></param> /// <param name="node"></param>
/// <param name="getAdjacent"></param> /// <param name="getAdjacent"></param>
/// <returns></returns> /// <returns></returns>
public static IEnumerable<T> GetClique<T>(IEnumerable<T> nodes, T node, Func<T, IEnumerable<T>> getAdjacent) public static IEnumerable<T> GetClique<T>(T node, Func<T, IEnumerable<T>> getAdjacent)
{ {
Dictionary<T, IEnumerable<T>> map = nodes.ToDictionary(n => n, getAdjacent); if (node == null)
return GetClique(map, node); throw new ArgumentNullException("node");
if (getAdjacent == null)
throw new ArgumentNullException("getAdjacent");
return BreadthFirstSearch(node, getAdjacent);
} }
/// <summary> /// <summary>