mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-14 04:58:33 +00:00
Potential fix for infinite recursion in pathfinding
This commit is contained in:
parent
e4c529ca49
commit
e7116fdf4c
1 changed files with 12 additions and 1 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Utils.Collections;
|
||||||
|
|
||||||
namespace ICD.Common.Utils
|
namespace ICD.Common.Utils
|
||||||
{
|
{
|
||||||
|
|
@ -103,11 +104,21 @@ namespace ICD.Common.Utils
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static IEnumerable<T> GetPath<T>(T start, IDictionary<T, T> nodeParents)
|
private static IEnumerable<T> GetPath<T>(T start, IDictionary<T, T> nodeParents)
|
||||||
{
|
{
|
||||||
|
IcdHashSet<T> visited = new IcdHashSet<T>();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
yield return start;
|
yield return start;
|
||||||
if (!nodeParents.TryGetValue(start, out start))
|
visited.Add(start);
|
||||||
|
|
||||||
|
T next;
|
||||||
|
if (!nodeParents.TryGetValue(start, out next))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
if (visited.Contains(next))
|
||||||
|
break;
|
||||||
|
|
||||||
|
start = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue