it.unimi.dsi.webgraph
Class LazyIntIterators

java.lang.Object
  extended by it.unimi.dsi.webgraph.LazyIntIterators

public class LazyIntIterators
extends Object

A class providing static methods and objects that do useful things with lazy integer iterators.


Field Summary
static LazyIntIterator EMPTY_ITERATOR
          An empty lazy iterator.
 
Constructor Summary
protected LazyIntIterators()
           
 
Method Summary
static IntIterator eager(LazyIntIterator lazyIntIterator)
          Returns an eager IntIterator enumerating the same elements of a given lazy integer iterator.
static LazyIntIterator lazy(IntIterator eagerIntIterator)
          Returns a LazyIntIterator enumerating the same elements of a given eager integer iterator.
static int[] unwrap(LazyIntIterator lazyIntIterator)
          Unwraps the elements returned by a lazy iterator into a new array.
static int unwrap(LazyIntIterator lazyIntIterator, int[] array)
          Unwraps the elements returned by a lazy iterator into an array.
static int unwrap(LazyIntIterator lazyIntIterator, int[] array, int offset, int length)
          Unwraps the elements returned by a lazy iterator into an array fragment.
static int[] unwrapLoosely(LazyIntIterator lazyIntIterator)
          Unwraps the elements returned by a lazy iterator into a new array that can contain additional entries set to zero.
static LazyIntIterator wrap(int[] array)
          Returns a lazy integer iterator enumerating the elements of an array.
static LazyIntIterator wrap(int[] array, int length)
          Returns a lazy integer iterator enumerating the given number of elements of an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ITERATOR

public static final LazyIntIterator EMPTY_ITERATOR
An empty lazy iterator.

Constructor Detail

LazyIntIterators

protected LazyIntIterators()
Method Detail

unwrap

public static int unwrap(LazyIntIterator lazyIntIterator,
                         int[] array)
Unwraps the elements returned by a lazy iterator into an array.

Parameters:
lazyIntIterator - a lazy integer iterator.
array - an array.
Returns:
the number of elements unwrapped into array starting from index 0.

unwrap

public static int unwrap(LazyIntIterator lazyIntIterator,
                         int[] array,
                         int offset,
                         int length)
Unwraps the elements returned by a lazy iterator into an array fragment.

Parameters:
lazyIntIterator - a lazy integer iterator.
array - an array.
offset - the index of the first element ot array to be used.
length - the maximum number of elements to be unwrapped.
Returns:
the number of elements unwrapped into array starting from index offset.

unwrap

public static int[] unwrap(LazyIntIterator lazyIntIterator)
Unwraps the elements returned by a lazy iterator into a new array.

If you need the resulting array to contain the elements returned by lazyIntIterator, but some more elements set to zero would cause no harm, consider using unwrapLoosely(LazyIntIterator), which usually avoids a final call to IntArrays.trim(int[], int).

Parameters:
lazyIntIterator - a lazy integer iterator.
Returns:
an array containing the elements returned by lazyIntIterator.
See Also:
unwrapLoosely(LazyIntIterator)

unwrapLoosely

public static int[] unwrapLoosely(LazyIntIterator lazyIntIterator)
Unwraps the elements returned by a lazy iterator into a new array that can contain additional entries set to zero.

If you need the resulting array to contain exactly the elements returned by lazyIntIterator, consider using unwrap(LazyIntIterator), but this method avoids a final call to IntArrays.trim(int[], int).

Parameters:
lazyIntIterator - a lazy integer iterator.
Returns:
an array containing the elements returned by lazyIntIterator; note that in general it might contains some final zeroes beyond the elements returned by lazyIntIterator, so the number of elements actually written into array must be known externally.
See Also:
unwrap(LazyIntIterator)

wrap

public static LazyIntIterator wrap(int[] array,
                                   int length)
Returns a lazy integer iterator enumerating the given number of elements of an array.

Parameters:
array - an array.
length - the number of elements to enumerate.
Returns:
a lazy integer iterator enumerating the first length elements of array.

wrap

public static LazyIntIterator wrap(int[] array)
Returns a lazy integer iterator enumerating the elements of an array.

Parameters:
array - an array.
Returns:
a lazy integer iterator enumerating the elements of array.

eager

public static IntIterator eager(LazyIntIterator lazyIntIterator)
Returns an eager IntIterator enumerating the same elements of a given lazy integer iterator.

Parameters:
lazyIntIterator - a lazy integer iterator.
Returns:
an eager IntIterator enumerating the same elements of lazyIntIterator.

lazy

public static LazyIntIterator lazy(IntIterator eagerIntIterator)
Returns a LazyIntIterator enumerating the same elements of a given eager integer iterator.

Parameters:
eagerIntIterator - an eager integer iterator.
Returns:
a lazy integer iterator enumerating the same elements of eagerIntIterator.