Class StandardMutableGraph<N>
- java.lang.Object
-
- com.google.common.graph.AbstractBaseGraph<N>
-
- com.google.common.graph.AbstractGraph<N>
-
- com.google.common.graph.ForwardingGraph<N>
-
- com.google.common.graph.StandardMutableGraph<N>
-
- Type Parameters:
N- Node parameter type
- All Implemented Interfaces:
BaseGraph<N>,Graph<N>,MutableGraph<N>,PredecessorsFunction<N>,SuccessorsFunction<N>
final class StandardMutableGraph<N> extends ForwardingGraph<N> implements MutableGraph<N>
Standard implementation ofMutableGraphthat 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 StandardMutableGraph(AbstractGraphBuilder<? super N> builder)Constructs aMutableGraphwith the properties specified inbuilder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddNode(N node)Addsnodeif it is not already present.protected BaseGraph<N>delegate()booleanputEdge(EndpointPair<N> endpoints)Adds an edge connectingendpoints(in the order, if any, specified byendpoints) if one is not already present.booleanputEdge(N nodeU, N nodeV)Adds an edge connectingnodeUtonodeVif one is not already present.booleanremoveEdge(EndpointPair<N> endpoints)Removes the edge connectingendpoints, if it is present.booleanremoveEdge(N nodeU, N nodeV)Removes the edge connectingnodeUtonodeV, if it is present.booleanremoveNode(N node)Removesnodeif it is present; all edges incident tonodewill also be removed.-
Methods inherited from class com.google.common.graph.ForwardingGraph
adjacentNodes, allowsSelfLoops, degree, edgeCount, hasEdgeConnecting, hasEdgeConnecting, incidentEdgeOrder, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
Methods inherited from class com.google.common.graph.AbstractGraph
equals, hashCode, toString
-
Methods inherited from class com.google.common.graph.AbstractBaseGraph
edges, isOrderingCompatible, validateEndpoints
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.google.common.graph.Graph
adjacentNodes, allowsSelfLoops, degree, edges, equals, hasEdgeConnecting, hasEdgeConnecting, hashCode, incidentEdgeOrder, incidentEdges, inDegree, isDirected, nodeOrder, nodes, outDegree, predecessors, successors
-
-
-
-
Field Detail
-
backingValueGraph
private final MutableValueGraph<N,GraphConstants.Presence> backingValueGraph
-
-
Constructor Detail
-
StandardMutableGraph
StandardMutableGraph(AbstractGraphBuilder<? super N> builder)
Constructs aMutableGraphwith the properties specified inbuilder.
-
-
Method Detail
-
delegate
protected BaseGraph<N> delegate()
- Specified by:
delegatein classForwardingGraph<N>
-
addNode
public boolean addNode(N node)
Description copied from interface:MutableGraphAddsnodeif it is not already present.Nodes must be unique, just as
Mapkeys must be. They must also be non-null.- Specified by:
addNodein interfaceMutableGraph<N>- Returns:
trueif the graph was modified as a result of this call
-
putEdge
public boolean putEdge(N nodeU, N nodeV)
Description copied from interface:MutableGraphAdds an edge connectingnodeUtonodeVif one is not already present.If the graph is directed, the resultant edge will be directed; otherwise, it will be undirected.
If
nodeUandnodeVare not already present in this graph, this method will silentlyaddnodeUandnodeVto the graph.- Specified by:
putEdgein interfaceMutableGraph<N>- Returns:
trueif the graph was modified as a result of this call
-
putEdge
public boolean putEdge(EndpointPair<N> endpoints)
Description copied from interface:MutableGraphAdds an edge connectingendpoints(in the order, if any, specified byendpoints) if one is not already present.If this graph is directed,
endpointsmust be ordered and the added edge will be directed; if it is undirected, the added edge will be undirected.If this graph is directed,
endpointsmust be ordered.If either or both endpoints are not already present in this graph, this method will silently
addeach missing endpoint to the graph.- Specified by:
putEdgein interfaceMutableGraph<N>- Returns:
trueif the graph was modified as a result of this call
-
removeNode
public boolean removeNode(N node)
Description copied from interface:MutableGraphRemovesnodeif it is present; all edges incident tonodewill also be removed.- Specified by:
removeNodein interfaceMutableGraph<N>- Returns:
trueif the graph was modified as a result of this call
-
removeEdge
public boolean removeEdge(N nodeU, N nodeV)
Description copied from interface:MutableGraphRemoves the edge connectingnodeUtonodeV, if it is present.- Specified by:
removeEdgein interfaceMutableGraph<N>- Returns:
trueif the graph was modified as a result of this call
-
removeEdge
public boolean removeEdge(EndpointPair<N> endpoints)
Description copied from interface:MutableGraphRemoves the edge connectingendpoints, if it is present.If this graph is directed,
endpointsmust be ordered.- Specified by:
removeEdgein interfaceMutableGraph<N>- Returns:
trueif the graph was modified as a result of this call
-
-