Package one.nio.mem

Class OffheapBitSet

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class OffheapBitSet
    extends java.lang.Object
    implements java.io.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:
    BitSet
    • Field Summary

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

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static long bits2words​(long numBits)  
      long capacity()  
      protected long checkBounds​(long index)  
      void clear()  
      void clear​(long index)
      clears the bit.
      void close()  
      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 Detail

      • baseAddr

        protected long baseAddr
      • size

        protected long size
    • Constructor Detail

      • OffheapBitSet

        public OffheapBitSet​(long numBits)
      • OffheapBitSet

        public OffheapBitSet​(long address,
                             long sizeBytes)
    • Method Detail

      • 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 java.lang.AutoCloseable
        Specified by:
        close in interface java.io.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:
        java.lang.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:
        java.lang.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)