Interface EdgeIter

  • All Superinterfaces:
    IntIterator, Iterator<Integer>, PrimitiveIterator<Integer,​IntConsumer>, PrimitiveIterator.OfInt

    public interface EdgeIter
    extends IntIterator
    Iterator used to iterate over edges of a vertex.

    Each int returned by IntIterator.nextInt() is an ID of an edge iterated by the iterator. The source and target of the last iterated edge are available by source() and target().

     
     Graph g = ...;
     int vertex = ...;
     for (EdgeIter eit = g.outEdges(vertex).iterator(); eit.hasNext();) {
     	int e = eit.nextInt();
     	int u = eit.source();
     	int v = eit.target();
     	assert vertex == u;
     	System.out.println("Out edge of " + vertex + ": " + e + "(" + u + ", " + v + ")");
     }
     
    Author:
    Barak Ugav
    See Also:
    EdgeSet
    • Method Detail

      • peekNext

        int peekNext()
        Peek at the next edge of the iterator without advancing it.

        Similar to IntIterator.nextInt() but without advancing the iterator.

        Returns:
        the next edge of the iterator
        Throws:
        NoSuchElementException - if there is no 'next' element
      • source

        int source()
        Get the source vertex of the last returned edge.

        The behavior is undefined if IntIterator.nextInt() was not called yet.

        Returns:
        the source vertex of the last returned edge
      • target

        int target()
        Get the target vertex of the last returned edge.

        The behavior is undefined if IntIterator.nextInt() was not called yet.

        Returns:
        the target vertex of the last returned edge
      • emptyIterator

        static EdgeIter emptyIterator()
        Get an empty edge iterator.
        Returns:
        an empty edge iterator