Package one.nio.mem

Class 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:
    BitSet
    • 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)
        returns the number of 64 bit words it would take to hold numBits
      • 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)