Package org.roaringbitmap
Class RoaringArray
java.lang.Object
org.roaringbitmap.RoaringArray
- All Implemented Interfaces:
Externalizable,Serializable,Cloneable,AppendableStorage<Container>
public final class RoaringArray
extends Object
implements Cloneable, 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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intadvanceUntil(char x, int pos)Find the smallest integer index larger than pos such that array[index].key>=x.voidAppends 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 voidclear()clone()voiddeserialize(DataInput in)Deserialize.voiddeserialize(DataInput in, byte[] buffer)Deserialize.voiddeserialize(ByteBuffer bbf)Deserialize (retrieve) this bitmap.booleanintfirst()Gets the first value in the arrayprotected ContainergetContainer(char x)protected ContainergetContainerAtIndex(int i)protected intgetContainerIndex(char x)Create a ContainerPointer for this RoaringArraygetContainerPointer(int startIndex)Create a ContainerPointer for this RoaringArrayprotected chargetKeyAtIndex(int i)inthashCode()intlast()Gets the last value in the arrayvoidreadExternal(ObjectInput in)voidserialize(DataOutput out)Serialize.voidserialize(ByteBuffer buffer)Serialize.intReport the number of bytes required for serialization.protected intsize()voidtrim()If possible, recover wasted memory.voidwriteExternal(ObjectOutput out)
-
Constructor Details
-
RoaringArray
protected RoaringArray()
-
-
Method Details
-
advanceUntil
protected int advanceUntil(char 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
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
-
append
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
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
deserialize
Deserialize. 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:
IOException- Signals that an I/O exception has occurred.InvalidRoaringFormat- if a Roaring Bitmap cookie is missing.
-
deserialize
Deserialize.- 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:
IOException- Signals that an I/O exception has occurred.InvalidRoaringFormat- if a Roaring Bitmap cookie is missing.
-
deserialize
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
-
getContainer
-
getContainerIndex
protected int getContainerIndex(char x) -
getContainerAtIndex
-
getContainerPointer
Create a ContainerPointer for this RoaringArray- Returns:
- a ContainerPointer
-
getContainerPointer
Create a ContainerPointer for this RoaringArray- Parameters:
startIndex- starting index in the container list- Returns:
- a ContainerPointer
-
getKeyAtIndex
protected char getKeyAtIndex(int i) -
hashCode
public int hashCode() -
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOException
-
serialize
Serialize. The current bitmap is not modified.- Parameters:
out- the DataOutput stream- Throws:
IOException- Signals that an I/O exception has occurred.
-
serialize
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
-
size
protected int size() -
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
first
public int first()Gets the first value in the array- Returns:
- the first value in the array
- Throws:
NoSuchElementException- if empty
-
last
public int last()Gets the last value in the array- Returns:
- the last value in the array
- Throws:
NoSuchElementException- if empty
-