Package org.klomp.snark
Class BitField
java.lang.Object
org.klomp.snark.BitField
Container of a byte array representing set and unset bits.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear
(int bit) Sets the given bit to false.boolean
complete()
Return true if all bits are set.int
count()
Return the number of set bits.boolean
boolean
get
(int bit) Return true if the bit is set or false if it is not.byte[]
This returns the actual byte array used.int
hashCode()
void
set
(int bit) Sets the given bit to true.void
setAll()
Sets all bits to true.int
size()
Return the size of the BitField.toString()
-
Constructor Details
-
BitField
public BitField(int size) Creates a new BitField that representssize
unset bits. -
BitField
public BitField(byte[] bitfield, int size) Creates a new BitField that representssize
bits as set by the given byte array. This will make a copy of the array. Extra bytes will be ignored.- Throws:
IndexOutOfBoundsException
- if give byte array is not large enough.
-
-
Method Details
-
getFieldBytes
public byte[] getFieldBytes()This returns the actual byte array used. Changes to this array affect this BitField. Note that some bits at the end of the byte array are supposed to be always unset if they represent bits bigger then the size of the bitfield. Caller should synch on this and copy! -
size
public int size()Return the size of the BitField. The returned value is one bigger then the last valid bit number (since bit numbers are counted from zero). -
set
public void set(int bit) Sets the given bit to true.- Throws:
IndexOutOfBoundsException
- if bit is smaller then zero bigger then size (inclusive).
-
clear
public void clear(int bit) Sets the given bit to false.- Throws:
IndexOutOfBoundsException
- if bit is smaller then zero bigger then size (inclusive).- Since:
- 0.9.22
-
setAll
public void setAll()Sets all bits to true.- Since:
- 0.9.21
-
get
public boolean get(int bit) Return true if the bit is set or false if it is not.- Throws:
IndexOutOfBoundsException
- if bit is smaller then zero bigger then size (inclusive).
-
count
public int count()Return the number of set bits. -
complete
public boolean complete()Return true if all bits are set. -
hashCode
public int hashCode() -
equals
-
toString
-