Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate looking for bitset.nextSetBit() in BitSetIterator.next() and hasNext() #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.nio.ByteBuffer;
import java.util.BitSet;
import java.util.NoSuchElementException;

/**
* WrappedImmutableBitSetBitmap implements ImmutableBitmap for java.util.BitSet
Expand Down Expand Up @@ -47,26 +48,35 @@ public WrappedImmutableBitSetBitmap(ByteBuffer byteBuffer){

private class BitSetIterator implements IntIterator
{
private int pos = -1;
private int nextPos;

BitSetIterator()
{
nextPos = bitmap.nextSetBit(0);
}

@Override
public boolean hasNext()
{
return bitmap.nextSetBit(pos + 1) >= 0;
return nextPos >= 0;
}

@Override
public int next()
{
pos = bitmap.nextSetBit(pos + 1);
int pos = nextPos;
if (pos < 0) {
throw new NoSuchElementException();
}
nextPos = bitmap.nextSetBit(pos + 1);
return pos;
}

@Override
public IntIterator clone()
{
BitSetIterator newIt = new BitSetIterator();
newIt.pos = pos;
newIt.nextPos = nextPos;
return newIt;
}
}
Expand Down