Package org.roaringbitmap.buffer
Class MutableRoaringArray
- java.lang.Object
-
- org.roaringbitmap.buffer.MutableRoaringArray
-
- All Implemented Interfaces:
Externalizable,Serializable,Cloneable,AppendableStorage<MappeableContainer>,PointableRoaringArray
public final class MutableRoaringArray extends Object implements Cloneable, 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 intINITIAL_CAPACITYprotected static intNO_OFFSET_THRESHOLDprotected static shortSERIAL_COOKIEprotected static shortSERIAL_COOKIE_NO_RUNCONTAINER
-
Constructor Summary
Constructors Modifier Constructor Description protectedMutableRoaringArray()MutableRoaringArray(int initialCapacity)
-
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.voidappend(short key, MappeableContainer value)Appends the key and container to the storage, throws if the key is less than the current mark.protected voidappendCopiesAfter(PointableRoaringArray highLowContainer, short beforeStart)Append copies of the values AFTER a specified key (may or may not be present) to end.protected voidappendCopiesUntil(PointableRoaringArray highLowContainer, short stoppingKey)Append copies of the values from another array, from the startprotected voidappendCopy(short key, MappeableContainer value)protected voidappendCopy(PointableRoaringArray highLowContainer, int startingIndex, int end)Append copies of the values from another arrayprotected voidclear()MutableRoaringArrayclone()Create an independent copy of the underlying arraybooleancontainsForContainerAtIndex(int i, short x)This checks whether the container at index i has the value x.protected voidcopyRange(int begin, int end, int newBegin)voiddeserialize(DataInput in)Deserialize.protected voidextendArray(int k)intfirst()Gets the first value in the arrayintgetCardinality(int i)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()protected voidinsertNewKeyValueAt(int i, short key, MappeableContainer value)intlast()Gets the last value in the arrayvoidreadExternal(ObjectInput in)protected voidremoveAtIndex(int i)protected voidremoveIndexRange(int begin, int end)protected voidreplaceKeyAndContainerAtIndex(int i, short key, MappeableContainer c)protected voidresize(int newLength)voidserialize(DataOutput out)Serialize.intserializedSizeInBytes()Report the number of bytes required for serialization.protected voidsetContainerAtIndex(int i, MappeableContainer c)intsize()voidtrim()If possible, recover wasted memory.voidwriteExternal(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(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.
-
append
public void append(short key, MappeableContainer value)Description copied from interface:AppendableStorageAppends the key and container to the storage, throws if the key is less than the current mark.- Specified by:
appendin interfaceAppendableStorage<MappeableContainer>- Parameters:
key- the key to appendvalue- the data to append
-
appendCopiesAfter
protected void appendCopiesAfter(PointableRoaringArray highLowContainer, short 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, short 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(short key, MappeableContainer value)
-
clear
protected void clear()
-
trim
public void trim()
If possible, recover wasted memory.
-
clone
public MutableRoaringArray clone()
Description copied from interface:PointableRoaringArrayCreate an independent copy of the underlying array- Specified by:
clonein interfacePointableRoaringArray- Overrides:
clonein classObject- Returns:
- a copy
-
copyRange
protected void copyRange(int begin, int end, int newBegin)
-
deserialize
public void deserialize(DataInput in) throws IOException
Deserialize.- Parameters:
in- the DataInput stream- Throws:
IOException- Signals that an I/O exception has occurred.
-
extendArray
protected void extendArray(int k)
-
getCardinality
public int getCardinality(int i)
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:
i- 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
-
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()
-
insertNewKeyValueAt
protected void insertNewKeyValueAt(int i, short key, MappeableContainer value)
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
removeAtIndex
protected void removeAtIndex(int i)
-
removeIndexRange
protected void removeIndexRange(int begin, int end)
-
replaceKeyAndContainerAtIndex
protected void replaceKeyAndContainerAtIndex(int i, short key, MappeableContainer c)
-
resize
protected void resize(int newLength)
-
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()
Report the number of bytes required for serialization.- Specified by:
serializedSizeInBytesin interfacePointableRoaringArray- Returns:
- the size in bytes
-
setContainerAtIndex
protected void setContainerAtIndex(int i, MappeableContainer c)
-
size
public int size()
- Specified by:
sizein interfacePointableRoaringArray- Returns:
- number of keys
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
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
-
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
-
-