Package org.roaringbitmap.buffer
Class ImmutableRoaringArray
- java.lang.Object
-
- org.roaringbitmap.buffer.ImmutableRoaringArray
-
- All Implemented Interfaces:
Cloneable,PointableRoaringArray
public final class ImmutableRoaringArray extends Object implements PointableRoaringArray
This is the underlying data structure for an ImmutableRoaringBitmap. This class is not meant for end-users.
-
-
Field Summary
Fields Modifier and Type Field Description protected static shortSERIAL_COOKIEprotected static shortSERIAL_COOKIE_NO_RUNCONTAINER
-
Constructor Summary
Constructors Modifier Constructor Description protectedImmutableRoaringArray(ByteBuffer bbf)Create an array based on a previously serialized ByteBuffer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intadvanceUntil(short x, int pos)Find the smallest integer index larger than pos such that getKeyAtIndex(index)>=x.ImmutableRoaringArrayclone()Create an independent copy of the underlying arraybooleancontainsForContainerAtIndex(int i, short x)This checks whether the container at index i has the value x.intfirst()Gets the first value in the arrayintgetCardinality(int k)Returns the cardinality of the container at the given index.MappeableContainergetContainerAtIndex(int i)intgetContainerIndex(short x)Returns either the index of the container corresponding to key x, or a negative value.MappeableContainerPointergetContainerPointer()MappeableContainerPointergetContainerPointer(int startIndex)intgetIndex(short x)shortgetKeyAtIndex(int i)inthashCode()booleanhasRunCompression()Check whether this bitmap has had its runs compressed.protected intheaderSize(boolean hasrun)booleanisEmpty()Returns true if this bitmap is empty.intlast()Gets the last value in the arrayvoidserialize(DataOutput out)Serialize.intserializedSizeInBytes()intsize()
-
-
-
Field Detail
-
SERIAL_COOKIE
protected static final short SERIAL_COOKIE
- See Also:
- Constant Field Values
-
SERIAL_COOKIE_NO_RUNCONTAINER
protected static final short SERIAL_COOKIE_NO_RUNCONTAINER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ImmutableRoaringArray
protected ImmutableRoaringArray(ByteBuffer bbf)
Create an array based on a previously serialized ByteBuffer. The input ByteBuffer is effectively copied (with the slice operation) so you should expect the provided ByteBuffer position/mark/limit/order to remain unchanged.- Parameters:
bbf- The source ByteBuffer
-
-
Method Detail
-
advanceUntil
public int advanceUntil(short x, int pos)Description copied from interface:PointableRoaringArrayFind the smallest integer index larger than pos such that getKeyAtIndex(index)>=x. If none can be found, return size.- Specified by:
advanceUntilin interfacePointableRoaringArray- Parameters:
x- minimal valuepos- index to exceed- Returns:
- the smallest index greater than pos such that getKeyAtIndex(index) is at least as large as min, or size if it is not possible.
-
clone
public ImmutableRoaringArray clone()
Description copied from interface:PointableRoaringArrayCreate an independent copy of the underlying array- Specified by:
clonein interfacePointableRoaringArray- Overrides:
clonein classObject- Returns:
- a copy
-
getCardinality
public int getCardinality(int k)
Description copied from interface:PointableRoaringArrayReturns the cardinality of the container at the given index. This method is expected to be fast.- Specified by:
getCardinalityin interfacePointableRoaringArray- Parameters:
k- index- Returns:
- the cardinality
-
getContainerIndex
public int getContainerIndex(short x)
Description copied from interface:PointableRoaringArrayReturns either the index of the container corresponding to key x, or a negative value.- Specified by:
getContainerIndexin interfacePointableRoaringArray- Parameters:
x- 16-bit key- Returns:
- index of container (negative value if no container found)
-
getContainerAtIndex
public MappeableContainer getContainerAtIndex(int i)
- Specified by:
getContainerAtIndexin interfacePointableRoaringArray- Parameters:
i- index- Returns:
- matching container
-
containsForContainerAtIndex
public boolean containsForContainerAtIndex(int i, short x)Description copied from interface:PointableRoaringArrayThis checks whether the container at index i has the value x. This can be faster than calling "getContainerAtIndex" and then calling contains.- Specified by:
containsForContainerAtIndexin interfacePointableRoaringArray- Parameters:
i- container index (assumed to be non-negative)x- 16-bit value to check- Returns:
- whether the container contains at index i contains x
-
getContainerPointer
public MappeableContainerPointer getContainerPointer()
- Specified by:
getContainerPointerin interfacePointableRoaringArray- Returns:
- a ContainerPointer to iterator over the array
-
getContainerPointer
public MappeableContainerPointer getContainerPointer(int startIndex)
- Specified by:
getContainerPointerin interfacePointableRoaringArray- Parameters:
startIndex- starting index- Returns:
- a ContainerPointer to iterator over the array initially positioned at startIndex
-
getIndex
public int getIndex(short x)
- Specified by:
getIndexin interfacePointableRoaringArray- Parameters:
x- 16-bit key- Returns:
- corresponding index
-
getKeyAtIndex
public short getKeyAtIndex(int i)
- Specified by:
getKeyAtIndexin interfacePointableRoaringArray- Parameters:
i- the index- Returns:
- 16-bit key at the index
-
hasRunCompression
public boolean hasRunCompression()
Description copied from interface:PointableRoaringArrayCheck whether this bitmap has had its runs compressed.- Specified by:
hasRunCompressionin interfacePointableRoaringArray- Returns:
- whether this bitmap has run compression
-
headerSize
protected int headerSize(boolean hasrun)
-
isEmpty
public boolean isEmpty()
Returns true if this bitmap is empty.- Returns:
- true if empty
-
serialize
public void serialize(DataOutput out) throws IOException
Serialize. The current bitmap is not modified.- Specified by:
serializein interfacePointableRoaringArray- Parameters:
out- the DataOutput stream- Throws:
IOException- Signals that an I/O exception has occurred.
-
serializedSizeInBytes
public int serializedSizeInBytes()
- Specified by:
serializedSizeInBytesin interfacePointableRoaringArray- Returns:
- the size that the data structure occupies on disk
-
size
public int size()
- Specified by:
sizein interfacePointableRoaringArray- Returns:
- number of keys
-
first
public int first()
Description copied from interface:PointableRoaringArrayGets the first value in the array- Specified by:
firstin interfacePointableRoaringArray- Returns:
- te first value in the array
-
last
public int last()
Description copied from interface:PointableRoaringArrayGets the last value in the array- Specified by:
lastin interfacePointableRoaringArray- Returns:
- te last value in the array
-
-