Package one.nio.mem

Class OffheapBitSet

java.lang.Object
one.nio.mem.OffheapBitSet
All Implemented Interfaces:
Closeable, AutoCloseable

public class OffheapBitSet extends Object implements Closeable
An offheap implementation of a bit set. Especially useful for large bloom filters, e.g. in Cassandra. This implementation is not meant to be modified concurrently. However it can be read concurrently. Current implementation supports only reversed byte order (i.e. Big endian on x86).
See Also:
  • Field Details

    • baseAddr

      protected long baseAddr
    • size

      protected long size
  • Constructor Details

    • OffheapBitSet

      public OffheapBitSet(long numBits)
    • OffheapBitSet

      public OffheapBitSet(long address, long sizeBytes)
  • Method Details

    • bits2words

      public static long bits2words(long numBits)
      Parameters:
      numBits - a number of bits to hold
      Returns:
      the number of 64 bit words it would take to hold numBits
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • capacity

      public long capacity()
    • get

      public boolean get(long index)
      Returns true or false for the specified bit index. The index should be less than the capacity.
      Parameters:
      index - the bit index
      Returns:
      the value of the bit with the specified index
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • unsafeGet

      public boolean unsafeGet(long index)
      Same as get(long) but does not check for index within capacity bounds. This allows to make it few ticks faster in exchange to seg fault possibility. Use when going out of capacity is ensured by other means outside of this method
      Parameters:
      index - a bit index
      Returns:
      the value of the bit with the specified index
    • set

      public void set(long index)
      Sets the bit at the specified index. The index should be less than the capacity.
      Parameters:
      index - a bit index
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • unsafeSet

      public void unsafeSet(long index)
    • clear

      public void clear(long index)
      clears the bit. The index should be less than the capacity.
      Parameters:
      index - a bit index
    • unsafeClear

      public void unsafeClear(long index)
    • clear

      public void clear()
    • checkBounds

      protected long checkBounds(long index)