Class StandardMutableValueGraph<N,V>
- Type Parameters:
N
- Node parameter typeV
- Value parameter type
- All Implemented Interfaces:
BaseGraph<N>
,MutableValueGraph<N,
,V> PredecessorsFunction<N>
,SuccessorsFunction<N>
,ValueGraph<N,
V>
MutableValueGraph
that supports both directed and undirected
graphs. Instances of this class should be constructed with ValueGraphBuilder
.
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 of node
.
-
Field Summary
FieldsFields inherited from class com.google.common.graph.StandardValueGraph
edgeCount, nodeConnections
-
Constructor Summary
ConstructorsConstructorDescriptionStandardMutableValueGraph
(AbstractGraphBuilder<? super N> builder) Constructs a mutable graph with the properties specified inbuilder
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Addsnode
if it is not already present.private GraphConnections
<N, V> addNodeInternal
(N node) Addsnode
to the graph and returns the associatedGraphConnections
.Returns anElementOrder
that specifies the order of iteration for the elements ofBaseGraph.edges()
,BaseGraph.adjacentNodes(Object)
,BaseGraph.predecessors(Object)
,BaseGraph.successors(Object)
andBaseGraph.incidentEdges(Object)
.private GraphConnections
<N, V> putEdgeValue
(EndpointPair<N> endpoints, V value) Adds an edge connectingendpoints
if one is not already present, and sets a value for that edge tovalue
(overwriting the existing value, if any).putEdgeValue
(N nodeU, N nodeV, V value) Adds an edge connectingnodeU
tonodeV
if one is not already present, and sets a value for that edge tovalue
(overwriting the existing value, if any).removeEdge
(EndpointPair<N> endpoints) Removes the edge connectingendpoints
, if it is present.removeEdge
(N nodeU, N nodeV) Removes the edge connectingnodeU
tonodeV
, if it is present.boolean
removeNode
(N node) Removesnode
if it is present; all edges incident tonode
will also be removed.Methods inherited from class com.google.common.graph.StandardValueGraph
adjacentNodes, allowsSelfLoops, containsNode, edgeCount, edgeValueOrDefault, edgeValueOrDefault, hasEdgeConnecting, hasEdgeConnecting, incidentEdges, isDirected, nodeOrder, nodes, predecessors, successors
Methods inherited from class com.google.common.graph.AbstractValueGraph
asGraph, edgeValue, edgeValue, equals, hashCode, toString
Methods inherited from class com.google.common.graph.AbstractBaseGraph
degree, edges, inDegree, isOrderingCompatible, nodeInvalidatableSet, nodePairInvalidatableSet, outDegree, validateEndpoints
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.google.common.graph.ValueGraph
adjacentNodes, allowsSelfLoops, asGraph, degree, edges, edgeValue, edgeValue, edgeValueOrDefault, edgeValueOrDefault, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
Field Details
-
incidentEdgeOrder
-
-
Constructor Details
-
StandardMutableValueGraph
StandardMutableValueGraph(AbstractGraphBuilder<? super N> builder) Constructs a mutable graph with the properties specified inbuilder
.
-
-
Method Details
-
incidentEdgeOrder
Description copied from interface:BaseGraph
Returns anElementOrder
that specifies the order of iteration for the elements ofBaseGraph.edges()
,BaseGraph.adjacentNodes(Object)
,BaseGraph.predecessors(Object)
,BaseGraph.successors(Object)
andBaseGraph.incidentEdges(Object)
.- Specified by:
incidentEdgeOrder
in interfaceBaseGraph<N>
- Specified by:
incidentEdgeOrder
in interfaceValueGraph<N,
V> - Overrides:
incidentEdgeOrder
in classAbstractBaseGraph<N>
-
addNode
Description copied from interface:MutableValueGraph
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 interfaceMutableValueGraph<N,
V> - Returns:
true
if the graph was modified as a result of this call
-
addNodeInternal
Addsnode
to the graph and returns the associatedGraphConnections
.- Throws:
IllegalStateException
- ifnode
is already present
-
putEdgeValue
Description copied from interface:MutableValueGraph
Adds an edge connectingnodeU
tonodeV
if one is not already present, and sets a value for that edge tovalue
(overwriting the existing value, if any).If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
Values do not have to be unique. However, values must be non-null.
If
nodeU
andnodeV
are not already present in this graph, this method will silentlyadd
nodeU
andnodeV
to the graph.- Specified by:
putEdgeValue
in interfaceMutableValueGraph<N,
V> - Returns:
- the value previously associated with the edge connecting
nodeU
tonodeV
, or null if there was no such edge.
-
putEdgeValue
Description copied from interface:MutableValueGraph
Adds an edge connectingendpoints
if one is not already present, and sets a value for that edge tovalue
(overwriting the existing value, if any).If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
If this graph is directed,
endpoints
must be ordered.Values do not have to be unique. However, values must be non-null.
If either or both endpoints are not already present in this graph, this method will silently
add
each missing endpoint to the graph.- Specified by:
putEdgeValue
in interfaceMutableValueGraph<N,
V> - Returns:
- the value previously associated with the edge connecting
nodeU
tonodeV
, or null if there was no such edge.
-
removeNode
Description copied from interface:MutableValueGraph
Removesnode
if it is present; all edges incident tonode
will also be removed.- Specified by:
removeNode
in interfaceMutableValueGraph<N,
V> - Returns:
true
if the graph was modified as a result of this call
-
removeEdge
Description copied from interface:MutableValueGraph
Removes the edge connectingnodeU
tonodeV
, if it is present.- Specified by:
removeEdge
in interfaceMutableValueGraph<N,
V> - Returns:
- the value previously associated with the edge connecting
nodeU
tonodeV
, or null if there was no such edge.
-
removeEdge
Description copied from interface:MutableValueGraph
Removes the edge connectingendpoints
, if it is present.If this graph is directed,
endpoints
must be ordered.- Specified by:
removeEdge
in interfaceMutableValueGraph<N,
V> - Returns:
- the value previously associated with the edge connecting
endpoints
, or null if there was no such edge.
-
newConnections
-