Interface DiGraph<T>
- Type Parameters:
T
- the type of the graph nodes.
- All Known Implementing Classes:
AdjacencyMapDiGraph
,ArcListDiGraph
,ImplicitDiGraph
T
.
A directed graph \( G = (N, A) \) is a pair where \( N \) is a finite set of nodes
(of type T
) and \(A = \{(x, y) : x, y \in N \} \) is the set of arcs that are
ordered pairs of elements of \( N \); the first element of and arc is called source, and
the second one is called destination. Given a node \( x \in N \), the set of
outgoing nodes of \( x \) is the set \(\{y : (x, y) \in A \} \).
Classes implementing this interface can represent both immutable and mutable
directed graphs, default implementations of mutation methods addNode(Object)
and addArc(Object, Object)
rise UnsupportedOperationException
(while the default
implementation of addArc(Arc)
relies on addArc(Object, Object)
).
Every implementation must at least override nodes()
; moreover, since arcs()
has a default implementation in terms of such method and outgoing(Object)
, and
conversely outgoing(Object)
has a default implementation in terms of arcs()
, at
least one of these two methods must be overridden. All other methods have default implementations
based on outgoing(Object)
and/or arcs()
.
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
Adds an arc to this graph.default void
Adds an arc to this graph.default void
Adds a node to this graph.arcs()
Returns this graph arcs.default boolean
Tells whether an arc belongs to this graph, or not.default boolean
Tells whether an arc belongs to this graph, or not.default boolean
Tells whether a node belongs to this graph, or not.nodes()
Returns the graph nodes.Returns the set of outgoing nodes of a given node.default void
Performs a visit on the graph.
-
Method Details
-
nodes
Returns the graph nodes.- Returns:
- the graph nodes.
-
outgoing
Returns the set of outgoing nodes of a given node.- Parameters:
source
- the source node.- Returns:
- the nodes that have an arc with the given
source
in this graph (the collection is empty if thesource
does not belong to this graph).
-
addNode
Adds a node to this graph.- Parameters:
node
- the node to be added.
-
addArc
Adds an arc to this graph.It the source, or destination, node are not present in the graph, they are also added.
- Parameters:
source
- the source of the arc to be added.destination
- the destination of the arc to be added.
-
addArc
Adds an arc to this graph.It the source, or destination, node are not present in the graph, they are also added.
- Parameters:
arc
- the arc to be added.
-
hasArc
Tells whether an arc belongs to this graph, or not.- Parameters:
source
- the source of the arc to be queried.destination
- the destination of the arc to be queried.- Returns:
- whether the arc belongs to the graph, or not.
-
hasArc
Tells whether an arc belongs to this graph, or not.- Parameters:
arc
- the arc to be queried.- Returns:
- whether the arc belongs to the graph, or not.
-
hasNode
Tells whether a node belongs to this graph, or not.- Parameters:
node
- the node to be queried.- Returns:
- whether the node belongs to the graph, or not.
-
arcs
Returns this graph arcs.- Returns:
- the arcs belonging to this graph.
-
visit
Performs a visit on the graph.
-