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
As to
Int
and UnDiEdge
are 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 Int
.
g.EdgeT
are so called inner edges.
toOuter
, called on an inner edge, returns the outer edge of type UnDiEdge
.
n1
allow for calling both graph (NodeT)
methods like diSuccessors
...
%
of Int
.
toOuter
reconstructs the outer edge 1~2
;
g.edges.toEdgeInSet
would reconstruct all outer edges.
A basic understanding of inner and outer objects (nodes and edges) is essential for working with Graph
efficiently. From the perspective of Graph
we distinguish between
Int
in the above example.
Otherwise they will be rejected by the compiler.
NodeT
, hence
the term, and are implementing the InnerNodeLike
interface.
An inner node acts as a container of the corresponding outer node also providing a wealth of graph functionality
such as diSuccessors
or 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 NodeT
is a path dependent type such as g.NodeT
with g
denoting a single graph instance.
~
.
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 UnDiEdge
in the above example. Otherwise they will be rejected by the compiler.
Note that UnDiEdge
is, in contrast to UnDiEdge[Int]
, a so called higher kinded type.
Outer edge types must be derived from EdgeLike
.
EdgeT
and are implementing
the InnerEdgeLike
interface.
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 EdgeT
is a path dependent type such as g.EdgeT
with g
denoting a single graph instance.
See also:
object scalax.collection.Graph#InnerNodeLike
object scalax.collection.Graph#InnerEdgeLike