Package org.basex.util
Class BitArray
- java.lang.Object
-
- org.basex.util.BitArray
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
cardinality()
Returns the number of bits set totrue
.void
clear(int i)
Sets the ith bit to 0.boolean
get(int i)
Gets the value of the ith bit.int
nextFree()
Gets the index of the first clear bit.int
nextSet(int i)
Gets the next bit set to 1, starting from the ith bit.void
set(int i)
Sets the ith bit to 1.long[]
toArray()
The word array used to store the bits.String
toString()
-
-
-
Constructor Detail
-
BitArray
public BitArray(long[] array, int nr)
Constructs a new bit array with the specified backing array.- Parameters:
array
- array with bitsnr
- number of used bits
-
BitArray
public BitArray()
Constructs a new bit array.
-
BitArray
public BitArray(int capacity, boolean set)
Constructs a new bit array and an initial value.- Parameters:
capacity
- initial number of bitsset
- sets or clears all values
-
-
Method Detail
-
toArray
public long[] toArray()
The word array used to store the bits. The array is shrunk to the last word, where a bit is set.- Returns:
- array of longs
-
cardinality
public int cardinality()
Returns the number of bits set totrue
.- Returns:
- number of bits set to
true
-
get
public boolean get(int i)
Gets the value of the ith bit.- Parameters:
i
- index of the bit- Returns:
true
if the ith bit is set
-
set
public void set(int i)
Sets the ith bit to 1.- Parameters:
i
- index of the bit
-
clear
public void clear(int i)
Sets the ith bit to 0.- Parameters:
i
- index of the bit
-
nextFree
public int nextFree()
Gets the index of the first clear bit.- Returns:
- index
-
nextSet
public int nextSet(int i)
Gets the next bit set to 1, starting from the ith bit.- Parameters:
i
- index from which to start the search (inclusive)- Returns:
- index of the next set bit after the ith bit
-
-