如何获取图形给定节点的所有后继者?

时间:2017-08-23 09:05:23

标签: scala collections scala-collections

我有一个scalax.collection.Graph,想要获得给定节点的所有后继者的集合。

import scalax.collection.Graph

...

val node = Graph('f~>'g, 'g~>'y, 'f~>'h).get('f)
val successors = <statement to get successors of f> // = collection with g and h

我刚刚学习Scala并且已经搜索并尝试了几个小时如何做到这一点,但我无法弄清楚。

1 个答案:

答案 0 :(得分:1)

scala> import scalax.collection.Graph
import scalax.collection.Graph

scala> import scalax.collection.GraphPredef._
import scalax.collection.GraphPredef._

scala> val node = Graph('f~>'g, 'g~>'y, 'f~>'h).get('f)
node: scalax.collection.Graph[Symbol,scalax.collection.GraphEdge.DiEdge]#NodeT = 'f

scala> val successors = node.outgoing.map(_.to.value)
successors: scala.collection.immutable.Set[Symbol] = Set('g, 'h)