Package com.google.common.graph
Class AbstractBaseGraph<N>
- java.lang.Object
-
- com.google.common.graph.AbstractBaseGraph<N>
-
- Type Parameters:
N
- Node parameter type
- All Implemented Interfaces:
BaseGraph<N>
,PredecessorsFunction<N>
,SuccessorsFunction<N>
- Direct Known Subclasses:
AbstractGraph
,AbstractValueGraph
abstract class AbstractBaseGraph<N> extends java.lang.Object implements BaseGraph<N>
This class provides a skeletal implementation ofBaseGraph
.The methods implemented in this class should not be overridden unless the subclass admits a more efficient implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
AbstractBaseGraph.IncidentEdgeSet<N>
-
Constructor Summary
Constructors Constructor Description AbstractBaseGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
degree(N node)
Returns the count ofnode
's incident edges, counting self-loops twice (equivalently, the number of times an edge touchesnode
).protected long
edgeCount()
Returns the number of edges in this graph; used to calculate the size ofedges()
.java.util.Set<EndpointPair<N>>
edges()
An implementation ofBaseGraph.edges()
defined in terms ofBaseGraph.nodes()
andBaseGraph.successors(Object)
.boolean
hasEdgeConnecting(N nodeU, N nodeV)
Returns true if there is an edge directly connectingnodeU
tonodeV
.java.util.Set<EndpointPair<N>>
incidentEdges(N node)
Returns the edges in this graph whose endpoints includenode
.int
inDegree(N node)
Returns the count ofnode
's incoming edges (equal topredecessors(node).size()
) in a directed graph.int
outDegree(N node)
Returns the count ofnode
's outgoing edges (equal tosuccessors(node).size()
) in a directed graph.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.common.graph.BaseGraph
adjacentNodes, allowsSelfLoops, isDirected, nodeOrder, nodes, predecessors, successors
-
-
-
-
Method Detail
-
edgeCount
protected long edgeCount()
Returns the number of edges in this graph; used to calculate the size ofedges()
. This implementation requires O(|N|) time. Classes extending this one may manually keep track of the number of edges as the graph is updated, and override this method for better performance.
-
edges
public java.util.Set<EndpointPair<N>> edges()
An implementation ofBaseGraph.edges()
defined in terms ofBaseGraph.nodes()
andBaseGraph.successors(Object)
.
-
incidentEdges
public java.util.Set<EndpointPair<N>> incidentEdges(N node)
Description copied from interface:BaseGraph
Returns the edges in this graph whose endpoints includenode
.- Specified by:
incidentEdges
in interfaceBaseGraph<N>
-
degree
public int degree(N node)
Description copied from interface:BaseGraph
Returns the count ofnode
's incident edges, counting self-loops twice (equivalently, the number of times an edge touchesnode
).For directed graphs, this is equal to
inDegree(node) + outDegree(node)
.For undirected graphs, this is equal to
incidentEdges(node).size()
+ (number of self-loops incident tonode
).If the count is greater than
Integer.MAX_VALUE
, returnsInteger.MAX_VALUE
.
-
inDegree
public int inDegree(N node)
Description copied from interface:BaseGraph
Returns the count ofnode
's incoming edges (equal topredecessors(node).size()
) in a directed graph. In an undirected graph, returns theBaseGraph.degree(Object)
.If the count is greater than
Integer.MAX_VALUE
, returnsInteger.MAX_VALUE
.
-
outDegree
public int outDegree(N node)
Description copied from interface:BaseGraph
Returns the count ofnode
's outgoing edges (equal tosuccessors(node).size()
) in a directed graph. In an undirected graph, returns theBaseGraph.degree(Object)
.If the count is greater than
Integer.MAX_VALUE
, returnsInteger.MAX_VALUE
.
-
hasEdgeConnecting
public boolean hasEdgeConnecting(N nodeU, N nodeV)
Description copied from interface:BaseGraph
Returns true if there is an edge directly connectingnodeU
tonodeV
. This is equivalent tonodes().contains(nodeU) && successors(nodeU).contains(nodeV)
.In an undirected graph, this is equal to
hasEdgeConnecting(nodeV, nodeU)
.- Specified by:
hasEdgeConnecting
in interfaceBaseGraph<N>
-
-