Class ImmutableBitSet
java.lang.Object
com.googlecode.javaewah.datastructure.ImmutableBitSet
This is an immutable version of the BitSet class in this same package.
It is meant to be used with memory-file mapping.
final FileOutputStream fos = new FileOutputStream(tmpfile); BitSet Bitmap = BitSet.bitmapOf(0, 2, 55, 64, 512); Bitmap.serialize(new DataOutputStream(fos)); RandomAccessFile memoryMappedFile = new RandomAccessFile(tmpfile, "r"); ByteBuffer bb = memoryMappedFile.getChannel().map( FileChannel.MapMode.READ_ONLY, 0, totalcount); ImmutableBitSet mapped = new ImmutableBitSet(bb.asLongBuffer());
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a ImmutableBitSet from the content of the LongBuffer which should have been initialized with BitSet.serialize (from the BitSet in this same package). -
Method Summary
Modifier and TypeMethodDescriptionasBitSet()
Get a copy of this ImmutableBitSet as a mutable BitSet.int
Compute the number of bits set to 1clone()
boolean
empty()
Check whether a bitset contains a set bit.boolean
boolean
get(int i)
get value of bit iint
long
getWord(int index)
int
hashCode()
boolean
intersects(BitSet bs)
Checks whether two bitsets intersect.Iterate over the set bitsiterator()
int
nextSetBit(int i)
Usage: for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) { operate on index i here }int
nextUnsetBit(int i)
Usage: for(int i=bs.nextUnsetBit(0); i>=0; i=bs.nextUnsetBit(i+1)) { operate on index i here }int
size()
Query the sizetoString()
Iterate over the unset bitsMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ImmutableBitSet
Construct a ImmutableBitSet from the content of the LongBuffer which should have been initialized with BitSet.serialize (from the BitSet in this same package). The input is not modified.- Parameters:
bs
- the data source
-
-
Method Details
-
asBitSet
Get a copy of this ImmutableBitSet as a mutable BitSet.- Returns:
- a copy
-
cardinality
public int cardinality()Compute the number of bits set to 1- Returns:
- the number of bits
-
clone
-
equals
-
empty
public boolean empty()Check whether a bitset contains a set bit.- Returns:
- true if no set bit is found
-
get
public boolean get(int i)get value of bit i- Parameters:
i
- index- Returns:
- value of the bit
-
hashCode
public int hashCode() -
intIterator
Iterate over the set bits- Returns:
- an iterator
-
iterator
-
intersects
Checks whether two bitsets intersect.- Parameters:
bs
- other bitset- Returns:
- true if they have a non-empty intersection (result of AND)
-
nextSetBit
public int nextSetBit(int i)Usage: for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) { operate on index i here }- Parameters:
i
- current set bit- Returns:
- next set bit or -1
-
nextUnsetBit
public int nextUnsetBit(int i)Usage: for(int i=bs.nextUnsetBit(0); i>=0; i=bs.nextUnsetBit(i+1)) { operate on index i here }- Parameters:
i
- current unset bit- Returns:
- next unset bit or -1
-
size
public int size()Query the size- Returns:
- the size in bits.
-
unsetIntIterator
Iterate over the unset bits- Returns:
- an iterator
-
getNumberOfWords
public int getNumberOfWords() -
getWord
public long getWord(int index) -
toString
-