Package it.unimi.di.prog2.h24.digraph
Class AdjacencyMapDiGraph<T>
java.lang.Object
it.unimi.di.prog2.h24.digraph.AdjacencyMapDiGraph<T>
- Type Parameters:
T
- the type of the graph nodes.
- All Implemented Interfaces:
DiGraph<T>
A mutable directed graph implementation based on a
Map
between nodes and their
outgoing sets.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty graph.AdjacencyMapDiGraph
(DiGraph<? extends T> graph) Creates a graph with the same nodes and arcs of the given graph. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an arc to this graph.void
Adds a node to this graph.boolean
Tells whether an arc belongs to this graph, or not.nodes()
Returns the graph nodes.Returns the set of outgoing nodes of a given node.
-
Field Details
-
adjacency
AMap
between nodes and their outgoing sets.Every node in the graph is a key of this map, and viceversa. Isolated nodes map to
Collections.emptySet()
.
-
-
Constructor Details
-
AdjacencyMapDiGraph
public AdjacencyMapDiGraph()Creates an empty graph. -
AdjacencyMapDiGraph
Creates a graph with the same nodes and arcs of the given graph.- Parameters:
graph
- the graph to copy.- Throws:
NullPointerException
- ifgraph
isnull
.
-
-
Method Details
-
addArc
Description copied from interface:DiGraph
Adds an arc to this graph.It the source, or destination, node are not present in the graph, they are also added.
-
addNode
Description copied from interface:DiGraph
Adds a node to this graph. -
hasArc
Description copied from interface:DiGraph
Tells whether an arc belongs to this graph, or not. -
outgoing
Description copied from interface:DiGraph
Returns the set of outgoing nodes of a given node. -
nodes
Description copied from interface:DiGraph
Returns the graph nodes.
-