Class 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.

    • 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.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • data

        final java.util.concurrent.atomic.AtomicLongArray data
    • Constructor Detail

      • LockFreeBitArray

        LockFreeBitArray​(long bits)
      • LockFreeBitArray

        LockFreeBitArray​(long[] data)
    • 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.

      • 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​(@CheckForNull
                              java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object