Package com.google.common.graph
Class ConfigurableMutableGraph<N>
- java.lang.Object
-
- com.google.common.graph.AbstractGraph<N>
-
- com.google.common.graph.ForwardingGraph<N>
-
- com.google.common.graph.ConfigurableMutableGraph<N>
-
- Type Parameters:
N
- Node parameter type
- All Implemented Interfaces:
Graph<N>
,MutableGraph<N>
final class ConfigurableMutableGraph<N> extends ForwardingGraph<N> implements MutableGraph<N>
Configurable implementation ofMutableGraph
that supports both directed and undirected graphs. Instances of this class should be constructed withGraphBuilder
.Time complexities for mutation methods are all O(1) except for
removeNode(N node)
, which is in O(d_node) where d_node is the degree ofnode
.
-
-
Field Summary
Fields Modifier and Type Field Description private MutableValueGraph<N,GraphConstants.Presence>
backingValueGraph
-
Constructor Summary
Constructors Constructor Description ConfigurableMutableGraph(AbstractGraphBuilder<? super N> builder)
Constructs aMutableGraph
with the properties specified inbuilder
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addNode(N node)
Addsnode
if it is not already present.protected Graph<N>
delegate()
boolean
putEdge(N nodeU, N nodeV)
Adds an edge connectingnodeU
tonodeV
if one is not already present.boolean
removeEdge(java.lang.Object nodeU, java.lang.Object nodeV)
Removes the edge connectingnodeU
tonodeV
, if it is present.boolean
removeNode(java.lang.Object node)
Removesnode
if it is present; all edges incident tonode
will also be removed.-
Methods inherited from class com.google.common.graph.ForwardingGraph
adjacentNodes, allowsSelfLoops, degree, edges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
Methods inherited from class com.google.common.graph.AbstractGraph
edgeCount, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.common.graph.Graph
adjacentNodes, allowsSelfLoops, degree, edges, equals, hashCode, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
-
-
-
Field Detail
-
backingValueGraph
private final MutableValueGraph<N,GraphConstants.Presence> backingValueGraph
-
-
Constructor Detail
-
ConfigurableMutableGraph
ConfigurableMutableGraph(AbstractGraphBuilder<? super N> builder)
Constructs aMutableGraph
with the properties specified inbuilder
.
-
-
Method Detail
-
delegate
protected Graph<N> delegate()
- Specified by:
delegate
in classForwardingGraph<N>
-
addNode
public boolean addNode(N node)
Description copied from interface:MutableGraph
Addsnode
if it is not already present.Nodes must be unique, just as
Map
keys must be. They must also be non-null.- Specified by:
addNode
in interfaceMutableGraph<N>
- Returns:
true
if the graph was modified as a result of this call
-
putEdge
public boolean putEdge(N nodeU, N nodeV)
Description copied from interface:MutableGraph
Adds an edge connectingnodeU
tonodeV
if one is not already present. In an undirected graph, the edge will also connectnodeV
tonodeU
.Behavior if
nodeU
andnodeV
are not already present in this graph is implementation-dependent. Suggested behaviors include (a) silentlyadding
nodeU
andnodeV
to the graph (this is the behavior of the default implementations) or (b) throwingIllegalArgumentException
.- Specified by:
putEdge
in interfaceMutableGraph<N>
- Returns:
true
if the graph was modified as a result of this call
-
removeNode
public boolean removeNode(java.lang.Object node)
Description copied from interface:MutableGraph
Removesnode
if it is present; all edges incident tonode
will also be removed.- Specified by:
removeNode
in interfaceMutableGraph<N>
- Returns:
true
if the graph was modified as a result of this call
-
removeEdge
public boolean removeEdge(java.lang.Object nodeU, java.lang.Object nodeV)
Description copied from interface:MutableGraph
Removes the edge connectingnodeU
tonodeV
, if it is present.- Specified by:
removeEdge
in interfaceMutableGraph<N>
- Returns:
true
if the graph was modified as a result of this call
-
-