Class BloomFilterStrategies.LockFreeBitArray
- java.lang.Object
-
- com.google.common.hash.BloomFilterStrategies.LockFreeBitArray
-
- Enclosing class:
- BloomFilterStrategies
static final class BloomFilterStrategies.LockFreeBitArray extends java.lang.Object
Models a lock-free array of bits.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
Fields Modifier and Type Field Description private LongAddable
bitCount
(package private) java.util.concurrent.atomic.AtomicLongArray
data
private static int
LONG_ADDRESSABLE_BITS
-
Constructor Summary
Constructors Constructor Description LockFreeBitArray(long bits)
LockFreeBitArray(long[] data)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) long
bitCount()
Number of set bits (1s).(package private) long
bitSize()
Number of bits(package private) BloomFilterStrategies.LockFreeBitArray
copy()
boolean
equals(java.lang.Object o)
(package private) boolean
get(long bitIndex)
int
hashCode()
(package private) void
putAll(BloomFilterStrategies.LockFreeBitArray other)
Combines the two BitArrays using bitwise OR.(package private) boolean
set(long bitIndex)
Returns true if the bit changed value.static long[]
toPlainArray(java.util.concurrent.atomic.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 Detail
-
LONG_ADDRESSABLE_BITS
private static final int LONG_ADDRESSABLE_BITS
- See Also:
- Constant Field Values
-
data
final java.util.concurrent.atomic.AtomicLongArray data
-
bitCount
private final LongAddable bitCount
-
-
Method Detail
-
set
boolean set(long bitIndex)
Returns true if the bit changed value.
-
get
boolean get(long bitIndex)
-
toPlainArray
public static long[] toPlainArray(java.util.concurrent.atomic.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. 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
BloomFilterStrategies.LockFreeBitArray copy()
-
putAll
void putAll(BloomFilterStrategies.LockFreeBitArray other)
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.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-