Class BloomFilterStrategies.LockFreeBitArray
- Enclosing class:
- BloomFilterStrategies
We use this instead of java.util.BitSet because we need access to the array of longs and we need compare-and-swap.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LongAddable(package private) final AtomicLongArrayprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) longbitCount()Number of set bits (1s).(package private) longbitSize()Number of bits(package private) BloomFilterStrategies.LockFreeBitArraycopy()(package private) intReturns the number oflongs in the underlyingAtomicLongArray.boolean(package private) booleanget(long bitIndex) inthashCode()(package private) voidCombines the two BitArrays using bitwise OR.(package private) voidputData(int i, long longValue) (package private) booleanset(long bitIndex) Returns true if the bit changed value.static long[]toPlainArray(AtomicLongArray atomicLongArray) Careful here: if threads are mutating the atomicLongArray while this method is executing, the final long[] will be a "rolling snapshot" of the state of the bit array.
-
Field Details
-
LONG_ADDRESSABLE_BITS
private static final int LONG_ADDRESSABLE_BITS- See Also:
-
data
-
bitCount
-
-
Constructor Details
-
LockFreeBitArray
LockFreeBitArray(long bits) -
LockFreeBitArray
LockFreeBitArray(long[] data)
-
-
Method Details
-
set
boolean set(long bitIndex) Returns true if the bit changed value. -
get
boolean get(long bitIndex) -
toPlainArray
Careful here: if threads are mutating the atomicLongArray while this method is executing, the final long[] will be a "rolling snapshot" of the state of the bit array. This is usually good enough, but should be kept in mind. -
bitSize
long bitSize()Number of bits -
bitCount
long bitCount()Number of set bits (1s).Note that because of concurrent set calls and uses of atomics, this bitCount is a (very) close *estimate* of the actual number of bits set. It's not possible to do better than an estimate without locking. Note that the number, if not exactly accurate, is *always* underestimating, never overestimating.
-
copy
-
putAll
Combines the two BitArrays using bitwise OR.NOTE: Because of the use of atomics, if the other LockFreeBitArray is being mutated while this operation is executing, not all of those new 1's may be set in the final state of this LockFreeBitArray. The ONLY guarantee provided is that all the bits that were set in the other LockFreeBitArray at the start of this method will be set in this LockFreeBitArray at the end of this method.
-
putData
void putData(int i, long longValue) -
dataLength
int dataLength()Returns the number oflongs in the underlyingAtomicLongArray. -
equals
-
hashCode
public int hashCode()
-