src/main/java/com/googlecode/javaewah/IteratorUtil.java
public static long materialize(final IteratingRLW i,
                                   final BitmapStorage c, long max) {
        final long origMax = max;
        while (true) {
            if (i.getRunningLength() > 0) {
                long L = i.getRunningLength();
                if (L > max)
                    L = max;
                c.addStreamOfEmptyWords(i.getRunningBit(), L);
                max -= L;
            }
            long L = i.getNumberOfLiteralWords();
            for (int k = 0; k < L; ++k)
                c.addWord(i.getLiteralWordAt(k));
            if (max > 0) {
                if (!i.next())
                    break;
            } else
                break;
        }
        return origMax - max;
    }
public static long materialize(final IteratingRLW i,
                                   final BitmapStorage c, long max) {
        final long origMax = max;
        while (true) {
            if (i.getRunningLength() > 0) {
                long L = i.getRunningLength();
                if (L > max)
                    L = max;
                c.addStreamOfEmptyWords(i.getRunningBit(), L);
                max -= L;
            }
            long L = i.getNumberOfLiteralWords();
            for (int k = 0; k < L; ++k)
                c.addWord(i.getLiteralWordAt(k));
            if (max > 0) {
                if (!i.next())
                    break;
            } else
                break;
        }
        return origMax - max;
    }
public static long materialize ( final IteratingRLW i , final BitmapStorage c , long max ) { final long origMax = max ; while ( true ) { if ( i . getRunningLength ( ) > 0 ) { long L = i . getRunningLength ( ) ; if ( L > max ) L = max ; c . addStreamOfEmptyWords ( i . getRunningBit ( ) , L ) ; max -= L ; } long L = i . getNumberOfLiteralWords ( ) ; for ( int k = 0 ; k < L ; ++ k ) c . addWord ( i . getLiteralWordAt ( k ) ) ; if ( max > 0 ) { if ( ! i . next ( ) ) break ; } else break ; } return origMax - max ; }
Turn an iterator into a bitmap.

@param i   iterator we wish to materialize
@param c   where we write
@param max maximum number of words we wish to materialize
@return how many words were actually materialized
Turn an iterator into a bitmap .