Skip to content

Instantly share code, notes, and snippets.

@matriv
Created August 10, 2016 15:13
Show Gist options
  • Save matriv/29a64826d6690810ac1b9f5096ba98c2 to your computer and use it in GitHub Desktop.
Save matriv/29a64826d6690810ac1b9f5096ba98c2 to your computer and use it in GitHub Desktop.
private class CustomBitSetList {
final int bucket_size = 1024;
int offset = -1;
int currentBucketIdx = 0;
ArrayList<FixedBitSet> buckets = new ArrayList<>(16);
FixedBitSet currentBucket = new FixedBitSet(bucket_size);
CustomBitSetList() {
buckets.add(currentBucket);
}
void setNext(boolean bit) {
offset++;
if (offset == bucket_size) {
currentBucket = new FixedBitSet(bucket_size);
buckets.add(currentBucket);
offset = 0;
}
if (bit) {
currentBucket.set(offset);
}
}
boolean getNext() {
offset++;
if (offset == bucket_size) {
currentBucketIdx++;
currentBucket = buckets.get(currentBucketIdx);
offset = 0;
}
return currentBucket.get(offset);
}
void readMode() {
offset = -1;
currentBucket = buckets.get(0);
currentBucketIdx = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment