The largest distance of a node that a source reaches, or -1 if there are no sources (Java:
maxDistance()).
Time: O(1).
Returns a shortest path to node from the nearest source, or an empty array if no source
reaches node.
The path has distanceOf(node) + 1 nodes, with the source first and node last. Of several
shortest paths, this method returns the one that the search finds first.
Time: O(distanceOf(node)). Memory: 4 x (distanceOf(node) + 1) bytes for the result.
node ID in 0..nodeCount-1
the node IDs of the path, or an empty array; a new array that must not be modified (Java: unmodifiable)
StaticofReturns the distances of the nodes of graph from source. Equivalent to
of(graph, [source]).
Time: O(nodeCount + edgeCount). Memory: as for the form with a list of sources.
the graph to search
node ID in 0..nodeCount-1
the distances
Returns the distances of the nodes of graph from the nearest of sources.
A source given twice counts once, and with no sources, no node is reachable.
Time: O(number of sources + nodeCount + edgeCount). Memory: 8 x nodeCount bytes for the result; while it runs, 4 x nodeCount bytes more.
the distances
The distances of the nodes of a graph from one or several sources, with a shortest path to every node reached.
The sources are the nodes where the search starts. The distance of a node is the number of edges on a shortest path to it from the nearest source. A source has distance 0, and a node that no source reaches has distance
-1. Edges are followed in their direction. For distances against their direction, pass the transposed graph:BiAdjacentGraph.of(graph).transposed(). Here,callsare the calls between the methods of a program, and the search finds a shortest chain of calls frommaintoparse:Uses a breadth-first search that takes the sources in list order and the out-nodes of each node in ascending order. For the reachable nodes alone, Graphs.reachableFrom needs less memory.
Instances are immutable.
Memory: 8 x nodeCount bytes: the distance of each node and the node before it on its shortest path.