Package org.roaringbitmap
Class RoaringArray
- java.lang.Object
-
- org.roaringbitmap.RoaringArray
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable,java.lang.Cloneable,AppendableStorage<Container>
public final class RoaringArray extends java.lang.Object implements java.lang.Cloneable, java.io.Externalizable, AppendableStorage<Container>
Specialized array to store the containers used by a RoaringBitmap. This is not meant to be used by end users.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected static intNO_OFFSET_THRESHOLDprotected static shortSERIAL_COOKIEprotected static shortSERIAL_COOKIE_NO_RUNCONTAINER
-
Constructor Summary
Constructors Modifier Constructor Description protectedRoaringArray()
-
Method Summary
Modifier and Type Method Description protected intadvanceUntil(short x, int pos)Find the smallest integer index larger than pos such that array[index].key>=x.voidappend(short key, Container value)Appends the key and container to the storage, throws if the key is less than the current mark.protected voidappend(RoaringArray sa, int startingIndex, int end)Append the values from another array, no copy is made (use with care)protected voidappendCopiesAfter(RoaringArray sa, short beforeStart)Append copies of the values AFTER a specified key (may or may not be present) to end.protected voidappendCopiesUntil(RoaringArray sourceArray, short stoppingKey)Append copies of the values from another array, from the startprotected voidappendCopy(RoaringArray sa, int index)Append copy of the one value from another arrayprotected voidappendCopy(RoaringArray sa, int startingIndex, int end)Append copies of the values from another arrayprotected voidclear()RoaringArrayclone()protected voidcopyRange(int begin, int end, int newBegin)voiddeserialize(java.io.DataInput in)Deserialize.voiddeserialize(java.io.DataInput in, byte[] buffer)Deserialize.voiddeserialize(java.nio.ByteBuffer bbf)Deserialize (retrieve) this bitmap.booleanequals(java.lang.Object o)protected voidextendArray(int k)intfirst()Gets the first value in the arrayprotected ContainergetContainer(short x)protected ContainergetContainerAtIndex(int i)ContainerPointergetContainerPointer()Create a ContainerPointer for this RoaringArrayContainerPointergetContainerPointer(int startIndex)Create a ContainerPointer for this RoaringArrayprotected intgetIndex(short x)protected shortgetKeyAtIndex(int i)inthashCode()protected intheaderSize()protected voidinsertNewKeyValueAt(int i, short key, Container value)intlast()Gets the last value in the arrayvoidreadExternal(java.io.ObjectInput in)protected voidremoveAtIndex(int i)protected voidremoveIndexRange(int begin, int end)protected voidreplaceKeyAndContainerAtIndex(int i, short key, Container c)protected voidresize(int newLength)voidserialize(java.io.DataOutput out)Serialize.voidserialize(java.nio.ByteBuffer buffer)Serialize.intserializedSizeInBytes()Report the number of bytes required for serialization.protected voidsetContainerAtIndex(int i, Container c)protected intsize()voidtrim()If possible, recover wasted memory.voidwriteExternal(java.io.ObjectOutput out)
-
-
-
Field Detail
-
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
protected int advanceUntil(short x, int pos)Find the smallest integer index larger than pos such that array[index].key>=x. If none can be found, return size. Based on code by O. Kaser.- Parameters:
x- minimal valuepos- index to exceed- Returns:
- the smallest index greater than pos such that array[index].key is at least as large as min, or size if it is not possible.
-
append
public void append(short key, Container 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<Container>- Parameters:
key- the key to appendvalue- the data to append
-
appendCopiesAfter
protected void appendCopiesAfter(RoaringArray sa, short beforeStart)
Append copies of the values AFTER a specified key (may or may not be present) to end.- Parameters:
sa- other arraybeforeStart- given key is the largest key that we won't copy
-
appendCopiesUntil
protected void appendCopiesUntil(RoaringArray sourceArray, short stoppingKey)
Append copies of the values from another array, from the start- Parameters:
sourceArray- The array to copy fromstoppingKey- any equal or larger key in other array will terminate copying
-
appendCopy
protected void appendCopy(RoaringArray sa, int index)
Append copy of the one value from another array- Parameters:
sa- other arrayindex- index in the other array
-
appendCopy
protected void appendCopy(RoaringArray sa, int startingIndex, int end)
Append copies of the values from another array- Parameters:
sa- other arraystartingIndex- starting index in the other arrayend- endingIndex (exclusive) in the other array
-
append
protected void append(RoaringArray sa, int startingIndex, int end)
Append the values from another array, no copy is made (use with care)- Parameters:
sa- other arraystartingIndex- starting index in the other arrayend- endingIndex (exclusive) in the other array
-
clear
protected void clear()
-
trim
public void trim()
If possible, recover wasted memory.
-
clone
public RoaringArray clone() throws java.lang.CloneNotSupportedException
- Overrides:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException
-
copyRange
protected void copyRange(int begin, int end, int newBegin)
-
deserialize
public void deserialize(java.io.DataInput in) throws java.io.IOExceptionDeserialize. If the DataInput is available as a byte[] or a ByteBuffer, you could prefer relying ondeserialize(ByteBuffer). If the InputStream is >= 8kB, you could prefer relying ondeserialize(DataInput, byte[]);- Parameters:
in- the DataInput stream- Throws:
java.io.IOException- Signals that an I/O exception has occurred.InvalidRoaringFormat- if a Roaring Bitmap cookie is missing.
-
deserialize
public void deserialize(java.io.DataInput in, byte[] buffer) throws java.io.IOExceptionDeserialize.- Parameters:
in- the DataInput streambuffer- The buffer gets overwritten with data during deserialization. You can pass a NULL reference as a buffer. A buffer containing at least 8192 bytes might be ideal for performance. It is recommended to reuse the buffer between calls to deserialize (in a single-threaded context) for best performance.- Throws:
java.io.IOException- Signals that an I/O exception has occurred.InvalidRoaringFormat- if a Roaring Bitmap cookie is missing.
-
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.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
extendArray
protected void extendArray(int k)
-
getContainer
protected Container getContainer(short x)
-
getContainerAtIndex
protected Container getContainerAtIndex(int i)
-
getContainerPointer
public ContainerPointer getContainerPointer()
Create a ContainerPointer for this RoaringArray- Returns:
- a ContainerPointer
-
getContainerPointer
public ContainerPointer getContainerPointer(int startIndex)
Create a ContainerPointer for this RoaringArray- Parameters:
startIndex- starting index in the container list- Returns:
- a ContainerPointer
-
getIndex
protected int getIndex(short x)
-
getKeyAtIndex
protected short getKeyAtIndex(int i)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
headerSize
protected int headerSize()
-
insertNewKeyValueAt
protected void insertNewKeyValueAt(int i, short key, Container value)
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
removeAtIndex
protected void removeAtIndex(int i)
-
removeIndexRange
protected void removeIndexRange(int begin, int end)
-
replaceKeyAndContainerAtIndex
protected void replaceKeyAndContainerAtIndex(int i, short key, Container c)
-
resize
protected void resize(int newLength)
-
serialize
public void serialize(java.io.DataOutput out) throws java.io.IOExceptionSerialize. The current bitmap is not modified.- 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.- Parameters:
buffer- the ByteBuffer to write to
-
serializedSizeInBytes
public int serializedSizeInBytes()
Report the number of bytes required for serialization.- Returns:
- the size in bytes
-
setContainerAtIndex
protected void setContainerAtIndex(int i, Container c)
-
size
protected int size()
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
first
public int first()
Gets the first value in the array- Returns:
- the first value in the array
- Throws:
java.util.NoSuchElementException- if empty
-
last
public int last()
Gets the last value in the array- Returns:
- the last value in the array
- Throws:
java.util.NoSuchElementException- if empty
-
-