Class ImmutableBitSet
- java.lang.Object
-
- com.googlecode.javaewah.datastructure.ImmutableBitSet
-
- All Implemented Interfaces:
WordArray,java.lang.Cloneable,java.lang.Iterable<java.lang.Integer>
public class ImmutableBitSet extends java.lang.Object implements java.lang.Cloneable, java.lang.Iterable<java.lang.Integer>, WordArray
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());
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.LongBufferdata
-
Constructor Summary
Constructors Constructor Description ImmutableBitSet(java.nio.LongBuffer bs)Construct 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BitSetasBitSet()Get a copy of this ImmutableBitSet as a mutable BitSet.intcardinality()Compute the number of bits set to 1ImmutableBitSetclone()booleanempty()Check whether a bitset contains a set bit.booleanequals(java.lang.Object o)booleanget(int i)intgetNumberOfWords()Get the total number of words contained in this data structure.longgetWord(int index)Get the word at the given indexinthashCode()booleanintersects(BitSet bs)Checks whether two bitsets intersect.IntIteratorintIterator()Iterate over the set bitsjava.util.Iterator<java.lang.Integer>iterator()intnextSetBit(int i)Usage: for(int i=bs.nextSetBit(0); i>=0; i=bs.nextSetBit(i+1)) { operate on index i here }intnextUnsetBit(int i)Usage: for(int i=bs.nextUnsetBit(0); i>=0; i=bs.nextUnsetBit(i+1)) { operate on index i here }intsize()Query the sizejava.lang.StringtoString()IntIteratorunsetIntIterator()Iterate over the unset bits
-
-
-
Constructor Detail
-
ImmutableBitSet
public ImmutableBitSet(java.nio.LongBuffer bs)
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 Detail
-
asBitSet
public BitSet 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
public ImmutableBitSet clone()
- Overrides:
clonein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
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)
- Parameters:
i- index- Returns:
- value of the bit
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
intIterator
public IntIterator intIterator()
Iterate over the set bits- Returns:
- an iterator
-
iterator
public java.util.Iterator<java.lang.Integer> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.Integer>
-
intersects
public boolean intersects(BitSet bs)
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
public IntIterator unsetIntIterator()
Iterate over the unset bits- Returns:
- an iterator
-
getNumberOfWords
public int getNumberOfWords()
Description copied from interface:WordArrayGet the total number of words contained in this data structure.- Specified by:
getNumberOfWordsin interfaceWordArray- Returns:
- the number
-
getWord
public long getWord(int index)
Description copied from interface:WordArrayGet the word at the given index
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-