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
@Beta public abstract class AbstractGraph<N> extends java.lang.Object implements Graph<N>
This class provides a skeletal implementation ofGraph
. It is recommended to extend this class rather than implementGraph
directly.- Since:
- 20.0
-
-
Constructor Summary
Constructors Constructor Description AbstractGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
degree(java.lang.Object 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()
A reasonable default implementation ofGraph.edges()
defined in terms ofGraph.nodes()
andGraph.successors(Object)
.int
inDegree(java.lang.Object node)
Returns the count ofnode
's incoming edges (equal topredecessors(node).size()
) in a directed graph.int
outDegree(java.lang.Object node)
Returns the count ofnode
's outgoing edges (equal tosuccessors(node).size()
) in a directed graph.java.lang.String
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
-
-
-
-
Method Detail
-
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
public java.util.Set<EndpointPair<N>> edges()
A reasonable default implementation ofGraph.edges()
defined in terms ofGraph.nodes()
andGraph.successors(Object)
.
-
degree
public int degree(java.lang.Object node)
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
public int inDegree(java.lang.Object node)
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
public int outDegree(java.lang.Object node)
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
public java.lang.String toString()
Returns a string representation of this graph.- Overrides:
toString
in classjava.lang.Object
-
-