com.netflix.zeno.fastblob.state
Class ThreadSafeBitSet

java.lang.Object
  extended by com.netflix.zeno.fastblob.state.ThreadSafeBitSet

public class ThreadSafeBitSet
extends java.lang.Object

This is a lock-free, thread-safe version of a BitSet.

Instead of a long array to hold the bits, this implementation uses an AtomicLongArray, then does the appropriate compare-and-swap operations when setting the bits.


Constructor Summary
ThreadSafeBitSet()
           
ThreadSafeBitSet(int log2SegmentSizeInBits)
           
 
Method Summary
 ThreadSafeBitSet andNot(ThreadSafeBitSet other)
          Return a new bit set which contains all bits which are contained in this bit set, and which are NOT contained in the other bit set.

In other words, return a new bit set, which is a bitwise and with the bitwise not of the other bit set.

 int cardinality()
           
 void clearAll()
          Clear all bits to 0.
 int currentCapacity()
           
static ThreadSafeBitSet deserializeFrom(java.io.DataInputStream dis)
          Deserialize a ThreadSafeBitSet from an InputStream
 boolean get(int position)
           
static ThreadSafeBitSet orAll(ThreadSafeBitSet... bitSets)
          Return a new bit set which contains all bits which are contained in *any* of the specified bit sets.
 void serializeTo(java.io.DataOutputStream os)
          Serialize this ThreadSafeBitSet to an OutputStream
 void set(int position)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadSafeBitSet

public ThreadSafeBitSet()

ThreadSafeBitSet

public ThreadSafeBitSet(int log2SegmentSizeInBits)
Method Detail

set

public void set(int position)

get

public boolean get(int position)

cardinality

public int cardinality()
Returns:
the number of bits which are set in this bit set.

currentCapacity

public int currentCapacity()
Returns:
the number of bits which are current specified by this bit set. This is the maximum value to which you might need to iterate, if you were to iterate over all bits in this set.

clearAll

public void clearAll()
Clear all bits to 0.


andNot

public ThreadSafeBitSet andNot(ThreadSafeBitSet other)
Return a new bit set which contains all bits which are contained in this bit set, and which are NOT contained in the other bit set.

In other words, return a new bit set, which is a bitwise and with the bitwise not of the other bit set.

Parameters:
other -
Returns:

orAll

public static ThreadSafeBitSet orAll(ThreadSafeBitSet... bitSets)
Return a new bit set which contains all bits which are contained in *any* of the specified bit sets.

Parameters:
bitSets -
Returns:

serializeTo

public void serializeTo(java.io.DataOutputStream os)
                 throws java.io.IOException
Serialize this ThreadSafeBitSet to an OutputStream

Throws:
java.io.IOException

deserializeFrom

public static ThreadSafeBitSet deserializeFrom(java.io.DataInputStream dis)
                                        throws java.io.IOException
Deserialize a ThreadSafeBitSet from an InputStream

Throws:
java.io.IOException