public ICollection <Way> RemoveEndRoads() { var endRoads = new HashSet <Way>(); var e = GetEdges().Where(a => a.Value.Count < 2).Select(a => a.Key).ToList(); foreach (var way in Ways.ToList()) { if (e.Contains(way.Start) || e.Contains(way.End)) { endRoads.Add(way); Ways.Remove(way); } } return(endRoads); }
public ICollection <Way> RemoveDeadNodes() { var edges = GetEdges(); var deadWays = new HashSet <Way>(); var visited = new HashSet <long>(); var queue = new Queue <long>(); queue.Enqueue(Ways.First().Start); while (queue.Any()) { var node = queue.Dequeue(); foreach (var neighbour in edges[node]) { if (visited.Contains(neighbour)) { continue; } visited.Add(neighbour); queue.Enqueue(neighbour); } } foreach (var way in Ways.ToList()) { if (visited.Contains(way.Start)) { continue; } Ways.Remove(way); deadWays.Add(way); } return(deadWays); }