Class BloomFilterStrategies.LockFreeBitArray

java.lang.Object
com.google.common.hash.BloomFilterStrategies.LockFreeBitArray
Enclosing class:
BloomFilterStrategies

static final class BloomFilterStrategies.LockFreeBitArray extends 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 Details

  • 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

      public 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. 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)
      ORs the bits encoded in the ith long in the underlying AtomicLongArray with the given value.
    • dataLength

      int dataLength()
      Returns the number of longs in the underlying AtomicLongArray.
    • equals

      public boolean equals(@CheckForNull Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object