/** * Gets an EWAHIterator over the data. This is a customized iterator * which iterates over run length words. For experts only. * * The current bitmap is not modified. * * @return the EWAHIterator */ public EWAHIterator getEWAHIterator() { return new EWAHIterator(this.buffer); }
/** * Instantiates a new iterating buffered running length word. * * @param iterator iterator */ public IteratingBufferedRunningLengthWord(final EWAHIterator iterator) { this.iterator = iterator; this.brlw = new BufferedRunningLengthWord(this.iterator.next()); this.literalWordStartPosition = this.iterator.literalWords() + this.brlw.literalWordOffset; this.buffer = this.iterator.buffer(); }
@Override public IteratingBufferedRunningLengthWord clone() throws CloneNotSupportedException { IteratingBufferedRunningLengthWord answer = (IteratingBufferedRunningLengthWord) super .clone(); answer.brlw = this.brlw.clone(); answer.iterator = this.iterator.clone(); return answer; }
@Override public void discardLiteralWords(long x) { this.literalWordStartPosition += x; this.brlw.numberOfLiteralWords -= x; if (this.brlw.numberOfLiteralWords == 0) { if (!this.iterator.hasNext()) { return; } this.brlw.reset(this.iterator.next()); this.literalWordStartPosition = this.iterator.literalWords(); } } @Override
/** * reports the number of bits set to true. Running time is proportional * to compressed size (as reported by sizeInBytes). * * @return the number of bits set to true */ public int cardinality() { int counter = 0; final EWAHIterator i = this.getEWAHIterator(); while (i.hasNext()) { RunningLengthWord localrlw = i.next(); if (localrlw.getRunningBit()) { counter += WORD_IN_BITS * localrlw.getRunningLength(); } final int numberOfLiteralWords = localrlw.getNumberOfLiteralWords(); final int literalWords = i.literalWords(); for (int j = 0; j < numberOfLiteralWords; ++j) { counter += Long.bitCount(i.buffer().getWord(literalWords + j)); } } return counter; }
/** * Write out the remaining words * * @param container target for writes */ public void discharge(BitmapStorage container) { this.brlw.literalWordOffset = this.literalWordStartPosition - this.iterator.literalWords(); discharge(this.brlw, this.iterator, container); }
IntIteratorImpl(EWAHIterator ewahIter) { this.ewahIter = ewahIter; this.buffer = ewahIter.buffer(); this.hasNext = this.moveToNext(); }
private boolean hasNextRLW() { return this.ewahIter.hasNext(); }
/** * Instantiates a new iterating buffered running length word. * * @param bitmap over which we want to iterate */ public IteratingBufferedRunningLengthWord( final EWAHCompressedBitmap bitmap) { this(EWAHIterator.getEWAHIterator(bitmap)); }
private RunningLengthWord nextRLW() { return this.ewahIter.next(); }
/** * reports the number of bits set to true. Running time is proportional * to compressed size (as reported by sizeInBytes). * * @return the number of bits set to true */ public int cardinality() { int counter = 0; final EWAHIterator i = this.getEWAHIterator(); while (i.hasNext()) { RunningLengthWord localrlw = i.next(); if (localrlw.getRunningBit()) { counter += WORD_IN_BITS * localrlw.getRunningLength(); } final int numberOfLiteralWords = localrlw.getNumberOfLiteralWords(); final int literalWords = i.literalWords(); for (int j = 0; j < numberOfLiteralWords; ++j) { counter += Long.bitCount(i.buffer().getWord(literalWords + j)); } } return counter; }
/** * Move to the next RunningLengthWord * * @return whether the move was possible */ @Override public boolean next() { if (!this.iterator.hasNext()) { this.brlw.numberOfLiteralWords = 0; this.brlw.runningLength = 0; return false; } this.brlw.reset(this.iterator.next()); this.literalWordStartPosition = this.iterator.literalWords(); // + // this.brlw.literalWordOffset // ==0 return true; }
/** * Write out the remaining words * * @param container target for writes */ public void discharge(BitmapStorage container) { this.brlw.literalWordOffset = this.literalWordStartPosition - this.iterator.literalWords(); discharge(this.brlw, this.iterator, container); }
ChunkIteratorImpl(EWAHIterator ewahIter, int sizeInBits) { this.ewahIter = ewahIter; this.sizeInBits = sizeInBits; this.buffer = ewahIter.buffer(); this.hasNext = moveToNextRLW(); }
private boolean hasNextRLW() { return this.ewahIter.hasNext(); }
/** * Instantiates a new iterating buffered running length word. * * @param bitmap over which we want to iterate */ public IteratingBufferedRunningLengthWord( final EWAHCompressedBitmap bitmap) { this(EWAHIterator.getEWAHIterator(bitmap)); }
private RunningLengthWord nextRLW() { return this.ewahIter.next(); }
/** * For internal use. (One could use the non-static discharge method * instead, but we expect them to be slower.) * * @param initialWord the initial word * @param iterator the iterator * @param container the container */ private static void discharge(final BufferedRunningLengthWord initialWord, final EWAHIterator iterator, final BitmapStorage container) { BufferedRunningLengthWord runningLengthWord = initialWord; for (; ; ) { final long runningLength = runningLengthWord.getRunningLength(); container.addStreamOfEmptyWords(runningLengthWord.getRunningBit(), runningLength); container.addStreamOfLiteralWords(iterator.buffer(), iterator.literalWords() + runningLengthWord.literalWordOffset, runningLengthWord.getNumberOfLiteralWords() ); if (!iterator.hasNext()) break; runningLengthWord = new BufferedRunningLengthWord(iterator.next()); } }