A functional interface for
graph-structured data.
This interface is meant to be used as the type of a parameter to graph algorithms (such as
breadth first traversal) that only need a way of accessing the successors of a node in a graph.
Usage
Given an algorithm, for example:
public someGraphAlgorithm(N startNode, SuccessorsFunction successorsFunction);
you will invoke it depending on the graph representation you're using.
If you have an instance of one of the primary
common.graph types (
Graph,
ValueGraph, and
Network):
someGraphAlgorithm(startNode, graph);
This works because those types each implement
SuccessorsFunction. It will also work with
any other implementation of this interface.
If you have your own graph implementation based around a custom node type
MyNode,
which has a method
getChildren() that retrieves its successors in a graph:
someGraphAlgorithm(startNode, MyNode::getChildren);
If you have some other mechanism for returning the successors of a node, or one that doesn't
return an
Iterable, then you can use a lambda to perform a more general
transformation:
someGraphAlgorithm(startNode, node -> ImmutableList.of(node.leftChild(), node.rightChild()));
Graph algorithms that need additional capabilities (accessing both predecessors and
successors, iterating over the edges, etc.) should declare their input to be of a type that
provides those capabilities, such as
Graph,
ValueGraph, or
Network.
Additional documentation
See the Guava User Guide for the
common.graph package ("Graphs Explained") for
additional documentation, including notes for
implementors