Package one.nio.mem
Class OffheapBitSet
java.lang.Object
one.nio.mem.OffheapBitSet
- All Implemented Interfaces:
Closeable,AutoCloseable
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longbits2words(long numBits) returns the number of 64 bit words it would take to hold numBitslongcapacity()protected longcheckBounds(long index) voidclear()voidclear(long index) clears the bit.voidclose()booleanget(long index) Returns true or false for the specified bit index.voidset(long index) Sets the bit at the specified index.voidunsafeClear(long index) booleanunsafeGet(long index) Same asget(long)but does not check for index within capacity bounds.voidunsafeSet(long index)
-
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
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 asget(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)
-