aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchuyler Eldridge2020-03-02 14:07:37 -0500
committerGitHub2020-03-02 19:07:37 +0000
commitc6a201dd335c75d96e1a4547ea783b257bd6f644 (patch)
tree9c4f33cb83829f361f48dffaba3925c4009a6684 /src
parent2138164808370d6ce55881f9f317eff13c701c92 (diff)
Remove DiGraph.seededLinearize (#1413)
Signed-off-by: Schuyler Eldridge <schuyler.eldridge@ibm.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/firrtl/graph/DiGraph.scala65
1 files changed, 28 insertions, 37 deletions
diff --git a/src/main/scala/firrtl/graph/DiGraph.scala b/src/main/scala/firrtl/graph/DiGraph.scala
index ac2dd62f..d3015b5a 100644
--- a/src/main/scala/firrtl/graph/DiGraph.scala
+++ b/src/main/scala/firrtl/graph/DiGraph.scala
@@ -64,14 +64,37 @@ class DiGraph[T] private[graph] (private[graph] val edges: LinkedHashMap[T, Link
*/
def findSinks: Set[T] = reverse.findSources
- /** Linearizes (topologically sorts) a DAG using a DFS. This can be seeded with an order to use for the DFS if the user
- * wants to tease out a special ordering of the DAG.
- * @param seed an optional sequence of vertices to use. This will default to the vertices ordering provided by getVertices.
+ /**
+ * Finds a Seq of Nodes that form a loop
+ * @param node Node to start loop path search from.
+ * @return The found Seq, the Seq is empty if there is no loop
+ */
+ def findLoopAtNode(node: T): Seq[T] = {
+ var foundPath = Seq.empty[T]
+ getEdges(node).exists { vertex =>
+ try {
+ foundPath = path(vertex, node, blacklist = Set.empty)
+ true
+ }
+ catch {
+ case _: PathNotFoundException =>
+ foundPath = Seq.empty[T]
+ false
+ case t: Throwable =>
+ throw t
+
+ }
+ }
+ foundPath
+ }
+
+ /** Linearizes (topologically sorts) a DAG
+ *
* @throws CyclicException if the graph is cyclic
* @return a Map[T,T] from each visited node to its predecessor in the
* traversal
*/
- def seededLinearize(seed: Option[Seq[T]] = None): Seq[T] = {
+ def linearize: Seq[T] = {
// permanently marked nodes are implicitly held in order
val order = new mutable.ArrayBuffer[T]
// invariant: no intersection between unmarked and tempMarked
@@ -81,7 +104,7 @@ class DiGraph[T] private[graph] (private[graph] val edges: LinkedHashMap[T, Link
case class LinearizeFrame[A](v: A, expanded: Boolean)
val callStack = mutable.Stack[LinearizeFrame[T]]()
- unmarked ++= seed.getOrElse(getVertices)
+ unmarked ++= getVertices
while (unmarked.nonEmpty) {
callStack.push(LinearizeFrame(unmarked.head, false))
while (callStack.nonEmpty) {
@@ -110,38 +133,6 @@ class DiGraph[T] private[graph] (private[graph] val edges: LinkedHashMap[T, Link
order.reverse.toSeq
}
- /**
- * Finds a Seq of Nodes that form a loop
- * @param node Node to start loop path search from.
- * @return The found Seq, the Seq is empty if there is no loop
- */
- def findLoopAtNode(node: T): Seq[T] = {
- var foundPath = Seq.empty[T]
- getEdges(node).exists { vertex =>
- try {
- foundPath = path(vertex, node, blacklist = Set.empty)
- true
- }
- catch {
- case _: PathNotFoundException =>
- foundPath = Seq.empty[T]
- false
- case t: Throwable =>
- throw t
-
- }
- }
- foundPath
- }
-
- /** Linearizes (topologically sorts) a DAG
- *
- * @throws CyclicException if the graph is cyclic
- * @return a Map[T,T] from each visited node to its predecessor in the
- * traversal
- */
- def linearize: Seq[T] = seededLinearize(None)
-
/** Performs breadth-first search on the directed graph
*
* @param root the start node