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).
Author:
Oleg Anastasyev
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected long
     
    protected long
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    OffheapBitSet(long numBits)
     
    OffheapBitSet(long address, long sizeBytes)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    bits2words(long numBits)
    returns the number of 64 bit words it would take to hold numBits
    long
     
    protected long
    checkBounds(long index)
     
    void
     
    void
    clear(long index)
    clears the bit.
    void
     
    boolean
    get(long index)
    Returns true or false for the specified bit index.
    void
    set(long index)
    Sets the bit at the specified index.
    void
    unsafeClear(long index)
     
    boolean
    unsafeGet(long index)
    Same as get(long) but does not check for index within capacity bounds.
    void
    unsafeSet(long index)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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)
      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.
      Throws:
      IndexOutOfBoundsException
    • 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
    • set

      public void set(long index)
      Sets the bit at the specified index. The index should be less than the capacity.
    • unsafeSet

      public void unsafeSet(long index)
    • clear

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

      public void unsafeClear(long index)
    • clear

      public void clear()
    • checkBounds

      protected long checkBounds(long index)