Package com.google.common.graph
Class AbstractGraph<N>
java.lang.Object
com.google.common.graph.AbstractGraph<N>
- Type Parameters:
N
- Node parameter type
- All Implemented Interfaces:
Graph<N>
- Direct Known Subclasses:
AbstractValueGraph
,ImmutableGraph
This class provides a skeletal implementation of
Graph
. It is recommended to extend this
class rather than implement Graph
directly.- Since:
- 20.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the count ofnode
's incident edges, counting self-loops twice (equivalently, the number of times an edge touchesnode
).protected long
Returns the number of edges in this graph; used to calculate the size ofedges()
.Set
<EndpointPair<N>> edges()
A reasonable default implementation ofGraph.edges()
defined in terms ofGraph.nodes()
andGraph.successors(Object)
.int
Returns the count ofnode
's incoming edges (equal topredecessors(node).size()
) in a directed graph.int
Returns the count ofnode
's outgoing edges (equal tosuccessors(node).size()
) in a directed graph.toString()
Returns a string representation of this graph.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, equals, hashCode, isDirected, nodeOrder, nodes, predecessors, successors
-
Constructor Details
-
AbstractGraph
public AbstractGraph()
-
-
Method Details
-
edgeCount
protected long edgeCount()Returns the number of edges in this graph; used to calculate the size ofedges()
. The default implementation is O(|N|). You can manually keep track of the number of edges and override this method for better performance. -
edges
A reasonable default implementation ofGraph.edges()
defined in terms ofGraph.nodes()
andGraph.successors(Object)
. -
degree
Description copied from interface:Graph
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
adjacentNodes(node).size()
+ (1 ifnode
has an incident self-loop, 0 otherwise).If the count is greater than
Integer.MAX_VALUE
, returnsInteger.MAX_VALUE
. -
inDegree
Description copied from interface:Graph
Returns the count ofnode
's incoming edges (equal topredecessors(node).size()
) in a directed graph. In an undirected graph, returns theGraph.degree(Object)
.If the count is greater than
Integer.MAX_VALUE
, returnsInteger.MAX_VALUE
. -
outDegree
Description copied from interface:Graph
Returns the count ofnode
's outgoing edges (equal tosuccessors(node).size()
) in a directed graph. In an undirected graph, returns theGraph.degree(Object)
.If the count is greater than
Integer.MAX_VALUE
, returnsInteger.MAX_VALUE
. -
toString
Returns a string representation of this graph.
-