public static bool FindShortestPath(List<ulong> currentPath, ref List<ulong> bestPath, IClrDump clrDump) { if(logger.IsDebugEnabled) logger.Debug("FindShortestPath: currentPath: " + Str(currentPath)+", best: "+Str(bestPath)); if( bestPath != null && currentPath.Count >= bestPath.Count) { return false; } bool res = false; foreach (var refAddress in clrDump.EnumerateReferers(currentPath[currentPath.Count-1])) { if(currentPath.Contains(refAddress)) { continue; } if (logger.IsDebugEnabled) logger.Debug($"Visiting: {refAddress:X}"); currentPath.Add(refAddress); if (! clrDump.HasReferers(refAddress)) { bestPath = new List<ulong>(currentPath); if (logger.IsDebugEnabled) logger.Debug("Root found !, best path: "+Str(bestPath)); currentPath.RemoveAt(currentPath.Count - 1); return true; } res |= FindShortestPath(currentPath, ref bestPath, clrDump); currentPath.RemoveAt(currentPath.Count - 1); } return res; }
public static bool FindShortestPath(List <ulong> currentPath, ref List <ulong> bestPath, IClrDump clrDump) { if (logger.IsDebugEnabled) { logger.Debug("FindShortestPath: currentPath: " + Str(currentPath) + ", best: " + Str(bestPath)); } if (bestPath != null && currentPath.Count >= bestPath.Count) { return(false); } bool res = false; foreach (var refAddress in clrDump.EnumerateReferers(currentPath[currentPath.Count - 1])) { if (currentPath.Contains(refAddress)) { continue; } if (logger.IsDebugEnabled) { logger.Debug($"Visiting: {refAddress:X}"); } currentPath.Add(refAddress); if (!clrDump.HasReferers(refAddress)) { bestPath = new List <ulong>(currentPath); if (logger.IsDebugEnabled) { logger.Debug("Root found !, best path: " + Str(bestPath)); } currentPath.RemoveAt(currentPath.Count - 1); return(true); } res |= FindShortestPath(currentPath, ref bestPath, clrDump); currentPath.RemoveAt(currentPath.Count - 1); } return(res); }