mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 03:57:32 +00:00
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:
parent
7cc5a47d6a
commit
2d401959b6
1 changed files with 8 additions and 4 deletions
|
|
@ -36,14 +36,18 @@ namespace ICD.Common.Utils
|
|||
/// Gets the clique containing the given node.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="nodes"></param>
|
||||
/// <param name="node"></param>
|
||||
/// <param name="getAdjacent"></param>
|
||||
/// <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);
|
||||
return GetClique(map, node);
|
||||
if (node == null)
|
||||
throw new ArgumentNullException("node");
|
||||
|
||||
if (getAdjacent == null)
|
||||
throw new ArgumentNullException("getAdjacent");
|
||||
|
||||
return BreadthFirstSearch(node, getAdjacent);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue