diff --git a/ICD.Common.Utils/RecursionUtils.cs b/ICD.Common.Utils/RecursionUtils.cs index b1617ee..6c370da 100644 --- a/ICD.Common.Utils/RecursionUtils.cs +++ b/ICD.Common.Utils/RecursionUtils.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using ICD.Common.Properties; +using ICD.Common.Utils.Collections; namespace ICD.Common.Utils { @@ -103,11 +104,21 @@ namespace ICD.Common.Utils /// private static IEnumerable GetPath(T start, IDictionary nodeParents) { + IcdHashSet visited = new IcdHashSet(); + while (true) { yield return start; - if (!nodeParents.TryGetValue(start, out start)) + visited.Add(start); + + T next; + if (!nodeParents.TryGetValue(start, out next)) break; + + if (visited.Contains(next)) + break; + + start = next; } } }