Package org.roaringbitmap.buffer
Class ImmutableRoaringArray
java.lang.Object
org.roaringbitmap.buffer.ImmutableRoaringArray
- All Implemented Interfaces:
Cloneable
,PointableRoaringArray
This is the underlying data structure for an ImmutableRoaringBitmap. This class is not meant for
end-users.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) ByteBuffer
protected static final short
protected static final short
(package private) int
private static final int
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Create an array based on a previously serialized ByteBuffer. -
Method Summary
Modifier and TypeMethodDescriptionint
advanceUntil
(char x, int pos) Find the smallest integer index larger than pos such that getKeyAtIndex(index)>=x.private void
private int
branchyUnsignedBinarySearch
(char k) clone()
Create an independent copy of the underlying arrayprivate int
computeSerializedSizeInBytes
(boolean hasRunContainers) boolean
containsForContainerAtIndex
(int i, char x) This checks whether the container at index i has the value x.boolean
int
first()
Gets the first value in the arrayint
getCardinality
(int k) Returns the cardinality of the container at the given index.getContainerAtIndex
(int i) int
getContainerIndex
(char x) Returns either the index of the container corresponding to key x, or a negative value.getContainerPointer
(int startIndex) int
getIndex
(char x) private int
getKey
(int k) char
getKeyAtIndex
(int i) private int
getOffsetContainer
(int k, boolean hasRunCompression) private int
getOffsetContainerSlow
(int k, boolean hasRunCompression) private int
int
hashCode()
boolean
Check whether this bitmap has had its runs compressed.protected int
headerSize
(boolean hasrun) boolean
isEmpty()
Returns true if this bitmap is empty.private boolean
isRunContainer
(int i, boolean hasrun) int
last()
Gets the last value in the arrayvoid
serialize
(DataOutput out) Serialize.void
serialize
(ByteBuffer buffer) Serialize.int
int
size()
private int
unsignedBinarySearch
(char k)
-
Field Details
-
SERIAL_COOKIE
protected static final short SERIAL_COOKIE- See Also:
-
SERIAL_COOKIE_NO_RUNCONTAINER
protected static final short SERIAL_COOKIE_NO_RUNCONTAINER- See Also:
-
startofrunbitmap
private static final int startofrunbitmap- See Also:
-
buffer
ByteBuffer buffer -
size
int size
-
-
Constructor Details
-
ImmutableRoaringArray
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 Details
-
advanceUntil
public int advanceUntil(char x, int pos) Description copied from interface:PointableRoaringArray
Find the smallest integer index larger than pos such that getKeyAtIndex(index)>=x. If none can be found, return size.- Specified by:
advanceUntil
in 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.
-
branchyUnsignedBinarySearch
private int branchyUnsignedBinarySearch(char k) -
clone
Description copied from interface:PointableRoaringArray
Create an independent copy of the underlying array- Specified by:
clone
in interfacePointableRoaringArray
- Overrides:
clone
in classObject
- Returns:
- a copy
-
computeSerializedSizeInBytes
private int computeSerializedSizeInBytes(boolean hasRunContainers) -
getCardinality
public int getCardinality(int k) Description copied from interface:PointableRoaringArray
Returns the cardinality of the container at the given index. This method is expected to be fast.- Specified by:
getCardinality
in interfacePointableRoaringArray
- Parameters:
k
- index- Returns:
- the cardinality
-
getContainerIndex
public int getContainerIndex(char x) Description copied from interface:PointableRoaringArray
Returns either the index of the container corresponding to key x, or a negative value.- Specified by:
getContainerIndex
in interfacePointableRoaringArray
- Parameters:
x
- 16-bit key- Returns:
- index of container (negative value if no container found)
-
getContainerAtIndex
- Specified by:
getContainerAtIndex
in interfacePointableRoaringArray
- Parameters:
i
- index- Returns:
- matching container
-
containsForContainerAtIndex
public boolean containsForContainerAtIndex(int i, char x) Description copied from interface:PointableRoaringArray
This checks whether the container at index i has the value x. This can be faster than calling "getContainerAtIndex" and then calling contains.- Specified by:
containsForContainerAtIndex
in 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
- Specified by:
getContainerPointer
in interfacePointableRoaringArray
- Returns:
- a ContainerPointer to iterator over the array
-
getContainerPointer
- Specified by:
getContainerPointer
in interfacePointableRoaringArray
- Parameters:
startIndex
- starting index- Returns:
- a ContainerPointer to iterator over the array initially positioned at startIndex
-
getIndex
public int getIndex(char x) - Specified by:
getIndex
in interfacePointableRoaringArray
- Parameters:
x
- 16-bit key- Returns:
- corresponding index
-
getKey
private int getKey(int k) -
getKeyAtIndex
public char getKeyAtIndex(int i) - Specified by:
getKeyAtIndex
in interfacePointableRoaringArray
- Parameters:
i
- the index- Returns:
- 16-bit key at the index
-
getOffsetContainer
private int getOffsetContainer(int k, boolean hasRunCompression) -
getOffsetContainerSlow
private int getOffsetContainerSlow(int k, boolean hasRunCompression) -
getStartOfKeys
private int getStartOfKeys() -
equals
-
hashCode
public int hashCode() -
hasRunCompression
public boolean hasRunCompression()Description copied from interface:PointableRoaringArray
Check whether this bitmap has had its runs compressed.- Specified by:
hasRunCompression
in 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
-
isRunContainer
private boolean isRunContainer(int i, boolean hasrun) -
serialize
Serialize. The current bitmap is not modified.- Specified by:
serialize
in interfacePointableRoaringArray
- Parameters:
out
- the DataOutput stream- Throws:
IOException
- Signals that an I/O exception has occurred.
-
serialize
Description copied from interface:PointableRoaringArray
Serialize. The current bitmap is not modified.- Specified by:
serialize
in interfacePointableRoaringArray
- Parameters:
buffer
- the buffer to serialize to
-
serializedSizeInBytes
public int serializedSizeInBytes()- Specified by:
serializedSizeInBytes
in interfacePointableRoaringArray
- Returns:
- the size that the data structure occupies on disk
-
size
public int size()- Specified by:
size
in interfacePointableRoaringArray
- Returns:
- number of keys
-
unsignedBinarySearch
private int unsignedBinarySearch(char k) -
first
public int first()Description copied from interface:PointableRoaringArray
Gets the first value in the array- Specified by:
first
in interfacePointableRoaringArray
- Returns:
- te first value in the array
-
last
public int last()Description copied from interface:PointableRoaringArray
Gets the last value in the array- Specified by:
last
in interfacePointableRoaringArray
- Returns:
- te last value in the array
-
assertNonEmpty
private void assertNonEmpty()
-