public ICollection <TEdge> Path(TEdge startingEdge) { var path = new List <TEdge>(); TEdge currentEdge = startingEdge; path.Insert(0, currentEdge); while (EdgesPredecessors.TryGetValue(currentEdge, out TEdge edge)) { path.Insert(0, edge); currentEdge = edge; } return(path); }
public ICollection <TEdge> MergedPath( [NotNull] TEdge startingEdge, [NotNull] IDictionary <TEdge, GraphColor> colors) { if (startingEdge == null) { throw new ArgumentNullException(nameof(startingEdge)); } if (colors is null) { throw new ArgumentNullException(nameof(colors)); } var path = new List <TEdge>(); TEdge currentEdge = startingEdge; GraphColor color = colors[currentEdge]; if (color != GraphColor.White) { return(path); } colors[currentEdge] = GraphColor.Black; path.Add(currentEdge); while (EdgesPredecessors.TryGetValue(currentEdge, out TEdge edge)) { color = colors[edge]; if (color != GraphColor.White) { path.Reverse(); return(path); } colors[edge] = GraphColor.Black; path.Add(edge); currentEdge = edge; } path.Reverse(); return(path); }
public ICollection <TEdge> Path([NotNull] TEdge startingEdge) { if (startingEdge == null) { throw new ArgumentNullException(nameof(startingEdge)); } var path = new List <TEdge> { startingEdge }; TEdge currentEdge = startingEdge; while (EdgesPredecessors.TryGetValue(currentEdge, out TEdge edge)) { path.Add(edge); currentEdge = edge; } path.Reverse(); return(path); }