MCPcopy
hub / github.com/google/guava / transitiveClosure

Method transitiveClosure

guava/src/com/google/common/graph/Graphs.java:190–203  ·  view source on GitHub ↗
(
      Graph<N> graph, TransitiveClosureSelfLoopStrategy strategy)

Source from the content-addressed store, hash-verified

188 */
189 // TODO(b/31438252): Consider optimizing for undirected graphs.
190 public static <N> ImmutableGraph<N> transitiveClosure(
191 Graph<N> graph, TransitiveClosureSelfLoopStrategy strategy) {
192 ImmutableGraph.Builder<N> transitiveClosure =
193 GraphBuilder.from(graph).allowsSelfLoops(true).<N>immutable();
194
195 for (N node : graph.nodes()) {
196 // add each node explicitly to include isolated nodes
197 transitiveClosure.addNode(node);
198 for (N reachableNode : getReachableNodes(graph, node, strategy)) {
199 transitiveClosure.putEdge(node, reachableNode);
200 }
201 }
202 return transitiveClosure.build();
203 }
204
205 /**
206 * Equivalent to {@code transitiveClosure(graph, ADD_SELF_LOOPS_ALWAYS)}. Callers should look at

Calls 8

fromMethod · 0.95
getReachableNodesMethod · 0.95
allowsSelfLoopsMethod · 0.65
nodesMethod · 0.65
addNodeMethod · 0.65
putEdgeMethod · 0.65
immutableMethod · 0.45
buildMethod · 0.45