Package org.jgrapht

Interface GraphIterables<V,​E>

  • Type Parameters:
    V - the graph vertex type
    E - the graph edge type
    All Known Implementing Classes:
    DefaultGraphIterables

    public interface GraphIterables<V,​E>
    Presents a graph as a collection of views suitable for graphs which contain a very large number of vertices or edges. Graph algorithms written these methods can work with graphs without the restrictions imposed by 32-bit arithmetic.

    Whether the returned iterators support removal of elements is left to the graph implementation. It is the responsibility of callers who rely on this behavior to only use graph implementations which support it.

    Author:
    Dimitrios Michail
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      default Iterable<E> allEdges​(V sourceVertex, V targetVertex)
      Returns an iterable view over all edges connecting source vertex to target vertex if such vertices exist in this graph.
      default long degreeOf​(V vertex)
      Returns the degree of the specified vertex.
      default long edgeCount()
      Return the number of edges in the graph.
      default Iterable<E> edges()
      Returns an iterable over the edges of the graph.
      default Iterable<E> edgesOf​(V vertex)
      Returns an iterable view over all edges touching the specified vertex.
      Graph<V,​E> getGraph()
      Get the underlying graph.
      default Iterable<E> incomingEdgesOf​(V vertex)
      Returns an iterable view over all edges incoming into the specified vertex.
      default long inDegreeOf​(V vertex)
      Returns the "in degree" of the specified vertex.
      default long outDegreeOf​(V vertex)
      Returns the "out degree" of the specified vertex.
      default Iterable<E> outgoingEdgesOf​(V vertex)
      Returns an iterable view over all edges outgoing into the specified vertex.
      default long vertexCount()
      Return the number of vertices in the graph.
      default Iterable<V> vertices()
      Returns an iterable view over the vertices contained in this graph.
    • Method Detail

      • getGraph

        Graph<V,​E> getGraph()
        Get the underlying graph.
        Returns:
        the underlying graph
      • edges

        default Iterable<E> edges()
        Returns an iterable over the edges of the graph.

        Whether the ordering is deterministic, depends on the actual graph implementation. It is the responsibility of callers who rely on this behavior to only use graph implementations which support it.

        Returns:
        an iterable over the edges of the graph.
      • edgeCount

        default long edgeCount()
        Return the number of edges in the graph.
        Returns:
        the number of edges.
      • vertices

        default Iterable<V> vertices()
        Returns an iterable view over the vertices contained in this graph. The returned iterator is a live view of the vertices. If the graph is modified while an iteration is in progress, the results of the iteration are undefined.

        The graph implementation may maintain a particular ordering for deterministic iteration, but this is not required. It is the responsibility of callers who rely on this behavior to only use graph implementations which support it.

        Returns:
        an iterable view of the vertices contained in this graph
      • vertexCount

        default long vertexCount()
        Return the number of vertices in the graph.
        Returns:
        the number of vertices
      • edgesOf

        default Iterable<E> edgesOf​(V vertex)
        Returns an iterable view over all edges touching the specified vertex. The returned iterators are live views. If the graph is modified while an iteration is in progress, the results of the iteration are undefined. If no edges are touching the specified vertex, the returned iterators are already exhausted.
        Parameters:
        vertex - input vertex
        Returns:
        an iterable view of the vertices contained in this graph
        Throws:
        IllegalArgumentException - if vertex is not found in the graph.
        NullPointerException - if vertex is null.
      • degreeOf

        default long degreeOf​(V vertex)
        Returns the degree of the specified vertex.

        A degree of a vertex in an undirected graph is the number of edges touching that vertex. Edges with same source and target vertices (self-loops) are counted twice.

        In directed graphs this method returns the sum of the "in degree" and the "out degree".

        Parameters:
        vertex - vertex whose degree is to be calculated.
        Returns:
        the degree of the specified vertex.
        Throws:
        IllegalArgumentException - if vertex is not found in the graph.
        NullPointerException - if vertex is null.
      • incomingEdgesOf

        default Iterable<E> incomingEdgesOf​(V vertex)
        Returns an iterable view over all edges incoming into the specified vertex. The returned iterators are live views. If the graph is modified while an iteration is in progress, the results of the iteration are undefined.

        In the case of undirected graphs the returned iterators return all edges touching the vertex, thus, some of the returned edges may have their source and target vertices in the opposite order.

        Parameters:
        vertex - input vertex
        Returns:
        an iterable view of all edges incoming into the specified vertex
        Throws:
        IllegalArgumentException - if vertex is not found in the graph.
        NullPointerException - if vertex is null.
      • inDegreeOf

        default long inDegreeOf​(V vertex)
        Returns the "in degree" of the specified vertex.

        The "in degree" of a vertex in a directed graph is the number of inward directed edges from that vertex. See http://mathworld.wolfram.com/Indegree.html.

        In the case of undirected graphs this method returns the number of edges touching the vertex. Edges with same source and target vertices (self-loops) are counted twice.

        Parameters:
        vertex - vertex whose degree is to be calculated.
        Returns:
        the degree of the specified vertex.
        Throws:
        IllegalArgumentException - if vertex is not found in the graph.
        NullPointerException - if vertex is null.
      • outgoingEdgesOf

        default Iterable<E> outgoingEdgesOf​(V vertex)
        Returns an iterable view over all edges outgoing into the specified vertex. The returned iterators are live views. If the graph is modified while an iteration is in progress, the results of the iteration are undefined.

        In the case of undirected graphs the returned iterators return all edges touching the vertex, thus, some of the returned edges may have their source and target vertices in the opposite order.

        Parameters:
        vertex - input vertex
        Returns:
        an iterable view of all edges outgoing from the specified vertex
        Throws:
        IllegalArgumentException - if vertex is not found in the graph.
        NullPointerException - if vertex is null.
      • outDegreeOf

        default long outDegreeOf​(V vertex)
        Returns the "out degree" of the specified vertex.

        The "out degree" of a vertex in a directed graph is the number of outward directed edges from that vertex. See http://mathworld.wolfram.com/Outdegree.html.

        In the case of undirected graphs this method returns the number of edges touching the vertex. Edges with same source and target vertices (self-loops) are counted twice.

        Parameters:
        vertex - vertex whose degree is to be calculated.
        Returns:
        the degree of the specified vertex.
        Throws:
        IllegalArgumentException - if vertex is not found in the graph.
        NullPointerException - if vertex is null.
      • allEdges

        default Iterable<E> allEdges​(V sourceVertex,
                                     V targetVertex)
        Returns an iterable view over all edges connecting source vertex to target vertex if such vertices exist in this graph. The returned iterators are live views. If the graph is modified while an iteration is in progress, the results of the iteration are undefined. If any of the vertices does not exist or is null, returns null. If both vertices exist but no edges found, returns an iterable which returns exhausted iterators.

        In undirected graphs, some of the returned edges may have their source and target vertices in the opposite order. In simple graphs the returned set is either singleton set or empty set.

        Parameters:
        sourceVertex - source vertex of the edge.
        targetVertex - target vertex of the edge.
        Returns:
        an iterable view of all edges connecting source to target vertex.
        Throws:
        IllegalArgumentException - if vertex is not found in the graph.
        NullPointerException - if vertex is null.