val g = Graph(1 ~ 2) // Graph[Int,UnDiEdge](1, 2, 1 ~ 2) val n1 = g.nodes.head // g.NodeT = 1 or 2 n1.toOuter // Int = 1 or 2 val e1 = g.edges.head // g.EdgeT = 1 ~ 2 e1.toOuter // UnDiEdge = 1 ~ 2 e1._1 // g.NodeT = 1 n1.diSuccessors // Set[g.NodeT] = Set(2) or Set(1) if n1 == 2 n1 % 2 // Int = 1 e1.toOuter // UnDiEdge[Int] = 1 ~ 2
UnDiEdgeare the concrete types for the node and edge type parameters. Here they are inferred from the outer edge being passed to the Graph factory.
g.NodeT. The node set does not guarantee any specific order of the contained nodes. See 4.2 for how to look up specific nodes.
toOuter, called on an inner node, returns the outer node of type
g.EdgeTare so called inner edges.
toOuter, called on an inner edge, returns the outer edge of type
n1allow for calling both graph (
toOuterreturns the outer edge
1 ~ 2while
g.edges.toEdgeInSetwould return all outer edges.
A basic understanding of inner and outer elements (nodes and edges) is essential for your smooth operation
Graph. From the perspective of
Graph we distinguish between
Intin the above example. Otherwise they will be rejected by the compiler.
NodeT, hence the term, and are implementing the
InnerNodeLikeinterface. An inner node acts as a container of the corresponding outer node also providing a wealth of graph functionality such as
pathTo. Inner nodes always equal to the contained, user-provided outer node thus facilitating interchangeability of inner and outer nodes in many situations. Note that
NodeTis a path dependent type meaning that it is bound to a specific
g.NodeTdenotes the type of inner nodes in
~. When added to a graph, they will be transparently wrapped by a corresponding inner edge. Outer edges must satisfy the upper bound of the edge type parameter of the graph, being
UnDiEdgein the above example. Otherwise, they will be rejected by the compiler. Note that
UnDiEdgeis, in contrast to
UnDiEdge[Int], a so called higher kinded type. Outer edge types must be derived from
EdgeTand are implementing the
InnerEdgeLikeinterface. An inner edge acts as a container of the corresponding outer edge adding graph functionality. Inner edges always equal to the contained, user-provided outer edge thus facilitating interchangeability of inner and outer edges. Note that
EdgeTis a path dependent type meaning that it is bound to a specific
g.EdgeTdenotes the type of inner edges in