Package com.pnfsoftware.jeb.util.collect
Class Bitmap
java.lang.Object
com.pnfsoftware.jeb.util.collect.Bitmap
A fast, efficient bitmap making optimal use of memory.
Implementation note: this bitmap works optimally on 64-bit systems.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllFrom(Bitmap other) Add the values of a source bitmap into this bitmap.voidclear()Clear the bitmap to all false.clone()intCount the number of true values in the bitmap.intCount the number of false values in the bitmap.booleanFormat set bits as inclusive/exclusive ranges.formatAsRanges(boolean useExcludedEnds) Format set bits as ranges.booleanget(int i) Retrieve the value of a bit.inthashCode()booleanisEmpty()Determine whether all entries in the bitmap are set to false.booleanisFull()Determine whether all entries in the bitmap are set to true.ones()Generate a list of zero-based indices for the bitmap entry is true.voidremoveAllFrom(Bitmap other) Remove the values of a source bitmap into this bitmap.voidreset(int i) Fast reset a bit to false.voidset(int i) Fast set a bit to true.booleanset(int i, boolean v) Set a bit to the provided value.voidsetRange(int from, int to) Fast set multiple bits to true.intsize()Retrieve the map size.toString()
-
Constructor Details
-
Bitmap
public Bitmap(int bitsize) Create a bitmap.- Parameters:
bitsize- number of bits
-
-
Method Details
-
clone
-
hashCode
public int hashCode() -
equals
-
size
public int size()Retrieve the map size.- Returns:
- number of bits
-
countOnes
public int countOnes()Count the number of true values in the bitmap.- Returns:
- number of set bits
-
countZeros
public int countZeros()Count the number of false values in the bitmap.- Returns:
- number of unset bits
-
clear
public void clear()Clear the bitmap to all false. -
set
public boolean set(int i, boolean v) Set a bit to the provided value.- Parameters:
i- zero-based indexv- value- Returns:
- true if the value was updated; false if it was unchanged
-
set
public void set(int i) Fast set a bit to true.- Parameters:
i- zero-based index
-
setRange
public void setRange(int from, int to) Fast set multiple bits to true.- Parameters:
from- start zero-based index (inclusive)to- end zero-based index (exclusive)
-
reset
public void reset(int i) Fast reset a bit to false.- Parameters:
i- zero-based index
-
get
public boolean get(int i) Retrieve the value of a bit.- Parameters:
i- zero-based index- Returns:
- the current bit value
-
addAllFrom
Add the values of a source bitmap into this bitmap. Both bitmaps must have the same size.- Parameters:
other- source bitmap
-
removeAllFrom
Remove the values of a source bitmap into this bitmap. Both bitmaps must have the same size.- Parameters:
other- source bitmap
-
isFull
public boolean isFull()Determine whether all entries in the bitmap are set to true.- Returns:
- true if all bits are set
-
isEmpty
public boolean isEmpty()Determine whether all entries in the bitmap are set to false.- Returns:
- true if all bits are unset
-
ones
Generate a list of zero-based indices for the bitmap entry is true.- Returns:
- a list of integers
-
toString
-
formatAsRanges
Format set bits as inclusive/exclusive ranges.- Returns:
- formatted ranges
-
formatAsRanges
Format set bits as ranges.- Parameters:
useExcludedEnds- true to format ranges as[begin,end); false to use inclusive end indices- Returns:
- formatted ranges
-