From 2d401959b651aeaf1330e9756bbe4a0b00f85a77 Mon Sep 17 00:00:00 2001 From: Austin Noska Date: Thu, 27 Jun 2019 10:57:55 -0400 Subject: [PATCH] feat: optimized get clique by using a bredth-first-search so it would not have to search the whole graph --- ICD.Common.Utils/RecursionUtils.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ICD.Common.Utils/RecursionUtils.cs b/ICD.Common.Utils/RecursionUtils.cs index 7f3c853..ad0e857 100644 --- a/ICD.Common.Utils/RecursionUtils.cs +++ b/ICD.Common.Utils/RecursionUtils.cs @@ -36,14 +36,18 @@ namespace ICD.Common.Utils /// Gets the clique containing the given node. /// /// - /// /// /// /// - public static IEnumerable GetClique(IEnumerable nodes, T node, Func> getAdjacent) + public static IEnumerable GetClique(T node, Func> getAdjacent) { - Dictionary> 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); } ///