public class QuickBitVector extends Object
WARNING: Methods of this class do not check preconditions. Provided with invalid parameters these method may return (or set) invalid values without throwing any exception. You should only use this class when performance is critical and you are absolutely sure that indexes are within bounds.
A bitvector is modelled as a long array, i.e. long[] bits holds bits of a bitvector. Each long value holds 64 bits. The i-th bit is stored in bits[i/64] at bit position i % 64 (where bit position 0 refers to the least significant bit and 63 refers to the most significant bit).
Modifier and Type | Method and Description |
---|---|
static long |
bitMaskWithBitsSetFromTo(int from,
int to)
Returns a bit mask with bits in the specified range set to 1, all the
rest set to 0.
|
static void |
clear(long[] bits,
int bitIndex)
Changes the bit with index bitIndex in the bitvector
bits to the "clear" (false) state.
|
static boolean |
get(long[] bits,
int bitIndex)
Returns from the bitvector the value of the bit with the specified index.
|
static long |
getLongFromTo(long[] bits,
int from,
int to)
Returns a long value representing bits of a bitvector from index
from to index to.
|
static int |
leastSignificantBit(int value)
Returns the index of the least significant bit in state "true".
|
static long[] |
makeBitVector(int size,
int bitsPerElement)
Constructs a low level bitvector that holds size elements, with
each element taking bitsPerElement bits.
|
static int |
mostSignificantBit(int value)
Returns the index of the most significant bit in state "true".
|
static void |
put(long[] bits,
int bitIndex,
boolean value)
Sets the bit with index bitIndex in the bitvector bits
to the state specified by value.
|
static void |
putLongFromTo(long[] bits,
long value,
int from,
int to)
Sets bits of a bitvector from index
from to index
to to the bits of value . |
static void |
set(long[] bits,
int bitIndex)
Changes the bit with index bitIndex in the bitvector
bits to the "set" (true) state.
|
public static final long bitMaskWithBitsSetFromTo(int from, int to)
from
- index of start bit (inclusive)to
- index of end bit (inclusive).public static void clear(long[] bits, int bitIndex)
bits
- the bitvector.bitIndex
- the index of the bit to be cleared.public static boolean get(long[] bits, int bitIndex)
bits
- the bitvector.bitIndex
- the bit index.public static long getLongFromTo(long[] bits, int from, int to)
from
, ..., bit
to-from
set to bit to
. All other bits of return
value are set to 0. If from > to then returns zero (
0L). Precondition (not checked): to-from+1 <= 64.bits
- the bitvector.from
- index of start bit (inclusive).to
- index of end bit (inclusive).public static int leastSignificantBit(int value)
0x80000000 --> 31 0x7fffffff --> 0 0x00000001 --> 0 0x00000000 --> 32
public static long[] makeBitVector(int size, int bitsPerElement)
size
- the number of elements to be stored in the bitvector (must be
>= 0).bitsPerElement
- the number of bits one single element takes.public static int mostSignificantBit(int value)
0x80000000 --> 31 0x7fffffff --> 30 0x00000001 --> 0 0x00000000 --> -1
public static void put(long[] bits, int bitIndex, boolean value)
bits
- the bitvector.bitIndex
- the index of the bit to be changed.value
- the value to be stored in the bit.public static void putLongFromTo(long[] bits, long value, int from, int to)
from
to index
to
to the bits of value
. Bit from
is set to bit 0 of value
, ..., bit to
is set to
bit to-from
of value
. All other bits stay
unaffected. If from > to then does nothing. Precondition (not
checked): to-from+1 <= 64.bits
- the bitvector.value
- the value to be copied into the bitvector.from
- index of start bit (inclusive).to
- index of end bit (inclusive).public static void set(long[] bits, int bitIndex)
bits
- the bitvector.bitIndex
- the index of the bit to be set.Jump to the Parallel Colt Homepage