API: IGraph

IGraph is the interface for graph data structures, supporting both directed and undirected graphs with values associated with vertices (V) and edges (E).

Key Methods

IGraph<V, E> link(V from, V to, E edge)

Returns a new graph with an edge from vertex from to vertex to with the value edge. In an undirected graph, this creates a bidirectional link.

IGraph<V, E> unlink(V from, V to)

Returns a new graph with the edge between from and to removed.

IGraph<V, E> add(V vertex)

Returns a new graph with the specified vertex added. If the vertex already exists, returns an identical graph.

IGraph<V, E> remove(V vertex)

Returns a new graph with the specified vertex and all its incident edges removed.

ISet<V> vertices()

Returns a set of all vertices in the graph.

Iterable<IEdge<V, E>> edges()

Returns an iterable over all edges in the graph.

E edge(V from, V to)

Returns the value of the edge between from and to. Throws IllegalArgumentException if the edge does not exist.

ISet<V> in(V vertex)

Returns a set of vertices that have an edge pointing to the specified vertex. In an undirected graph, this is equivalent to out().

ISet<V> out(V vertex)

Returns a set of vertices that the specified vertex has an edge pointing to.

boolean isDirected()

Returns true if the graph is directed, false otherwise.

IGraph<V, E> transpose()

Returns a new graph with the direction of all edges reversed. For an undirected graph, this returns an identical graph.