接口 PeekableIntIterator

所有超级接口:
Cloneable, IntIterator
所有已知子接口:
PeekableIntRankIterator
所有已知实现类:
BufferIntIteratorFlyweight, IntIteratorFlyweight

public interface PeekableIntIterator extends IntIterator
Simple extension to the IntIterator interface. It allows you to "skip" values using the advanceIfNeeded method, and to look at the value without advancing (peekNext). This richer interface enables efficient algorithms over iterators of integers.
  • 方法概要

    修饰符和类型
    方法
    说明
    void
    advanceIfNeeded(int minval)
    If needed, advance as long as the next value is smaller than minval The advanceIfNeeded method is used for performance reasons, to skip over unnecessary repeated calls to next.
    Creates a copy of the iterator.
    int
    Look at the next value without advancing The peek is useful when working with several iterators at once.

    从接口继承的方法 org.bitlap.roaringbitmap.IntIterator

    hasNext, next
  • 方法详细资料

    • advanceIfNeeded

      void advanceIfNeeded(int minval)
      If needed, advance as long as the next value is smaller than minval The advanceIfNeeded method is used for performance reasons, to skip over unnecessary repeated calls to next. Suppose for example that you wish to compute the intersection between an ordered list of integers (e.g., int[] x = {1,4,5}) and a PeekableIntIterator. You might do it as follows...
      
           PeekableIntIterator j = // get an iterator
           int val = // first value from my other data structure
           j.advanceIfNeeded(val);
           while ( j.hasNext() ) {
             if(j.next() == val) {
               // ah! ah! val is in the intersection...
               // do something here
               val = // get next value?
             }
             j.advanceIfNeeded(val);
           }
           
      The benefit of calling advanceIfNeeded is that each such call can be much faster than repeated calls to "next". The underlying implementation can "skip" over some data.
      参数:
      minval - threshold
    • peekNext

      int peekNext()
      Look at the next value without advancing The peek is useful when working with several iterators at once. Suppose that you have 100 iterators, and you want to compute their intersections without materializing the result. You might do it as follows...
      
          PriorityQueue pq = new PriorityQueue(100,
            new Comparator<PeekableIntIterator>() {
                   public int compare(PeekableIntIterator a,
                                      PeekableIntIterator b) {
                       return a.peek() - b.peek();
                   }
               });
       
          //...  populate pq
          
          while(! pq.isEmpty() ) {
            // get iterator with a smallest value
            PeekableIntIterator pi = pq.poll();
            int x = pi.next(); // advance
            // do something with x
            if(pi.hasNext()) pq.add(pi)
          }
          
      Notice how the peek method allows you to compare iterators in a way that the next method could not do.
      返回:
      next value
    • clone

      Creates a copy of the iterator.
      指定者:
      clone 在接口中 IntIterator
      返回:
      a clone of the current iterator