Package org.roaringbitmap.buffer
Class MutableRoaringArray
- java.lang.Object
-
- org.roaringbitmap.buffer.MutableRoaringArray
-
- All Implemented Interfaces:
java.io.Externalizable
,java.io.Serializable
,java.lang.Cloneable
,AppendableStorage<MappeableContainer>
,PointableRoaringArray
public final class MutableRoaringArray extends java.lang.Object implements java.lang.Cloneable, java.io.Externalizable, PointableRoaringArray, AppendableStorage<MappeableContainer>
Specialized array to store the containers used by a RoaringBitmap. This class is similar to org.roaringbitmap.RoaringArray but meant to be used with memory mapping. This is not meant to be used by end users. Objects of this class reside in RAM.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
INITIAL_CAPACITY
protected static int
NO_OFFSET_THRESHOLD
protected static short
SERIAL_COOKIE
protected static short
SERIAL_COOKIE_NO_RUNCONTAINER
-
Constructor Summary
Constructors Modifier Constructor Description protected
MutableRoaringArray()
MutableRoaringArray(int initialCapacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
advanceUntil(char x, int pos)
Find the smallest integer index larger than pos such that getKeyAtIndex(index)>=x.void
append(char key, MappeableContainer value)
Appends the key and container to the storage, throws if the key is less than the current mark.protected void
appendCopiesAfter(PointableRoaringArray highLowContainer, char beforeStart)
Append copies of the values AFTER a specified key (may or may not be present) to end.protected void
appendCopiesUntil(PointableRoaringArray highLowContainer, char stoppingKey)
Append copies of the values from another array, from the startprotected void
appendCopy(char key, MappeableContainer value)
protected void
appendCopy(PointableRoaringArray highLowContainer, int startingIndex, int end)
Append copies of the values from another arrayprotected void
clear()
MutableRoaringArray
clone()
Create an independent copy of the underlying arrayboolean
containsForContainerAtIndex(int i, char x)
This checks whether the container at index i has the value x.protected void
copyRange(int begin, int end, int newBegin)
void
deserialize(java.io.DataInput in)
Deserialize.void
deserialize(java.nio.ByteBuffer bbf)
Deserialize (retrieve) this bitmap.boolean
equals(java.lang.Object o)
protected void
extendArray(int k)
int
first()
Gets the first value in the arrayint
getCardinality(int i)
Returns the cardinality of the container at the given index.MappeableContainer
getContainerAtIndex(int i)
int
getContainerIndex(char x)
Returns either the index of the container corresponding to key x, or a negative value.MappeableContainerPointer
getContainerPointer()
MappeableContainerPointer
getContainerPointer(int startIndex)
int
getIndex(char x)
char
getKeyAtIndex(int i)
int
hashCode()
boolean
hasRunCompression()
Check whether this bitmap has had its runs compressed.protected int
headerSize()
protected void
insertNewKeyValueAt(int i, char key, MappeableContainer value)
int
last()
Gets the last value in the arrayvoid
readExternal(java.io.ObjectInput in)
protected void
removeAtIndex(int i)
protected void
removeIndexRange(int begin, int end)
protected void
replaceKeyAndContainerAtIndex(int i, char key, MappeableContainer c)
protected void
resize(int newLength)
void
serialize(java.io.DataOutput out)
Serialize.void
serialize(java.nio.ByteBuffer buffer)
Serialize.int
serializedSizeInBytes()
Report the number of bytes required for serialization.protected void
setContainerAtIndex(int i, MappeableContainer c)
int
size()
void
trim()
If possible, recover wasted memory.void
writeExternal(java.io.ObjectOutput out)
-
-
-
Field Detail
-
INITIAL_CAPACITY
protected static final int INITIAL_CAPACITY
- See Also:
- Constant Field Values
-
SERIAL_COOKIE_NO_RUNCONTAINER
protected static final short SERIAL_COOKIE_NO_RUNCONTAINER
- See Also:
- Constant Field Values
-
SERIAL_COOKIE
protected static final short SERIAL_COOKIE
- See Also:
- Constant Field Values
-
NO_OFFSET_THRESHOLD
protected static final int NO_OFFSET_THRESHOLD
- See Also:
- Constant Field Values
-
-
Method Detail
-
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.
-
append
public void append(char key, MappeableContainer value)
Description copied from interface:AppendableStorage
Appends the key and container to the storage, throws if the key is less than the current mark.- Specified by:
append
in interfaceAppendableStorage<MappeableContainer>
- Parameters:
key
- the key to appendvalue
- the data to append
-
appendCopiesAfter
protected void appendCopiesAfter(PointableRoaringArray highLowContainer, char beforeStart)
Append copies of the values AFTER a specified key (may or may not be present) to end.- Parameters:
highLowContainer
- the other arraybeforeStart
- given key is the largest key that we won't copy
-
appendCopiesUntil
protected void appendCopiesUntil(PointableRoaringArray highLowContainer, char stoppingKey)
Append copies of the values from another array, from the start- Parameters:
highLowContainer
- the other arraystoppingKey
- any equal or larger key in other array will terminate copying
-
appendCopy
protected void appendCopy(PointableRoaringArray highLowContainer, int startingIndex, int end)
Append copies of the values from another array- Parameters:
highLowContainer
- other arraystartingIndex
- starting index in the other arrayend
- last index array in the other array
-
appendCopy
protected void appendCopy(char key, MappeableContainer value)
-
clear
protected void clear()
-
trim
public void trim()
If possible, recover wasted memory.
-
clone
public MutableRoaringArray clone()
Description copied from interface:PointableRoaringArray
Create an independent copy of the underlying array- Specified by:
clone
in interfacePointableRoaringArray
- Overrides:
clone
in classjava.lang.Object
- Returns:
- a copy
-
copyRange
protected void copyRange(int begin, int end, int newBegin)
-
deserialize
public void deserialize(java.io.DataInput in) throws java.io.IOException
Deserialize.- Parameters:
in
- the DataInput stream- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
deserialize
public void deserialize(java.nio.ByteBuffer bbf)
Deserialize (retrieve) this bitmap. See format specification at https://github.com/RoaringBitmap/RoaringFormatSpec The current bitmap is overwritten. It is not necessary that limit() on the input ByteBuffer indicates the end of the serialized data. After loading this RoaringBitmap, you can advance to the rest of the data (if there is more) by setting bbf.position(bbf.position() + bitmap.serializedSizeInBytes()); Note that 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 byte buffer (can be mapped, direct, array backed etc.
-
extendArray
protected void extendArray(int k)
-
getCardinality
public int getCardinality(int i)
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:
i
- 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
public MappeableContainer getContainerAtIndex(int i)
- Specified by:
getContainerAtIndex
in interfacePointableRoaringArray
- Parameters:
i
- index- Returns:
- matching container
-
getContainerPointer
public MappeableContainerPointer getContainerPointer()
- Specified by:
getContainerPointer
in interfacePointableRoaringArray
- Returns:
- a ContainerPointer to iterator over the array
-
getContainerPointer
public MappeableContainerPointer getContainerPointer(int startIndex)
- 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
-
getKeyAtIndex
public char getKeyAtIndex(int i)
- Specified by:
getKeyAtIndex
in interfacePointableRoaringArray
- Parameters:
i
- the index- Returns:
- 16-bit key at the index
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
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()
-
insertNewKeyValueAt
protected void insertNewKeyValueAt(int i, char key, MappeableContainer value)
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
- Specified by:
readExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
removeAtIndex
protected void removeAtIndex(int i)
-
removeIndexRange
protected void removeIndexRange(int begin, int end)
-
replaceKeyAndContainerAtIndex
protected void replaceKeyAndContainerAtIndex(int i, char key, MappeableContainer c)
-
resize
protected void resize(int newLength)
-
serialize
public void serialize(java.io.DataOutput out) throws java.io.IOException
Serialize. The current bitmap is not modified.- Specified by:
serialize
in interfacePointableRoaringArray
- Parameters:
out
- the DataOutput stream- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
serialize
public void serialize(java.nio.ByteBuffer buffer)
Serialize. The current bitmap is not modified.- Specified by:
serialize
in interfacePointableRoaringArray
- Parameters:
buffer
- the ByteBuffer to write to
-
serializedSizeInBytes
public int serializedSizeInBytes()
Report the number of bytes required for serialization.- Specified by:
serializedSizeInBytes
in interfacePointableRoaringArray
- Returns:
- the size in bytes
-
setContainerAtIndex
protected void setContainerAtIndex(int i, MappeableContainer c)
-
size
public int size()
- Specified by:
size
in interfacePointableRoaringArray
- Returns:
- number of keys
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
- Specified by:
writeExternal
in interfacejava.io.Externalizable
- Throws:
java.io.IOException
-
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
-
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
-
-