From 87aa2629beaef20bbc57f36316b73742c599e559 Mon Sep 17 00:00:00 2001 From: Colin Schmidt Date: Fri, 8 Jun 2018 17:25:25 -0700 Subject: Add a blacklist option for paths (#810) Useful if you want to find out how a node was reachable and you used a blacklist during the reachability analysis--- src/main/scala/firrtl/graph/DiGraph.scala | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/scala/firrtl/graph/DiGraph.scala b/src/main/scala/firrtl/graph/DiGraph.scala index 22f5fcc5..4b900be4 100644 --- a/src/main/scala/firrtl/graph/DiGraph.scala +++ b/src/main/scala/firrtl/graph/DiGraph.scala @@ -162,9 +162,19 @@ class DiGraph[T] private[graph] (private[graph] val edges: LinkedHashMap[T, Link * @throws PathNotFoundException * @return a Seq[T] of nodes defining an arbitrary valid path */ - def path(start: T, end: T): Seq[T] = { + def path(start: T, end: T): Seq[T] = path(start, end, Set.empty[T]) + + /** Finds a path (if one exists) from one node to another, with a blacklist + * + * @param start the start node + * @param end the destination node + * @param blacklist list of nodes which break path, if encountered + * @throws PathNotFoundException + * @return a Seq[T] of nodes defining an arbitrary valid path + */ + def path(start: T, end: T, blacklist: Set[T]): Seq[T] = { val nodePath = new mutable.ArrayBuffer[T] - val prev = BFS(start) + val prev = BFS(start, blacklist) nodePath += end while (nodePath.last != start && prev.contains(nodePath.last)) { nodePath += prev(nodePath.last) -- cgit v1.2.3