Package org.basex.util
Class BitArray
java.lang.Object
org.basex.util.BitArray
Bit array that grows when needed. The implementation is similar to
BitSet.- Author:
- BaseX Team 2005-21, BSD License, Dimitar Popov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of bits set totrue.voidclear(int i) Sets the ith bit to 0.booleanget(int i) Gets the value of the ith bit.intnextFree()Gets the index of the first clear bit.intnextSet(int i) Gets the next bit set to 1, starting from the ith bit.voidset(int i) Sets the ith bit to 1.long[]toArray()The word array used to store the bits.toString()
-
Constructor Details
-
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 Details
-
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:
trueif 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
-
toString
-