public class MutableRoaringBitmap extends ImmutableRoaringBitmap implements java.lang.Cloneable, java.io.Serializable, java.lang.Iterable<java.lang.Integer>, java.io.Externalizable, BitmapDataProvider, AppendableStorage<MappeableContainer>
import org.roaringbitmap.buffer.*;
//...
MutableRoaringBitmap rr = MutableRoaringBitmap.bitmapOf(1,2,3,1000);
MutableRoaringBitmap rr2 = new MutableRoaringBitmap();
for(int k = 4000; k<4255;++k) rr2.add(k);
RoaringBitmap rror = RoaringBitmap.or(rr, rr2);
//...
DataOutputStream wheretoserialize = ...
rr.runOptimize(); // can help compression
rr.serialize(wheretoserialize);
Integers are added in unsigned sorted order. That is, they
are treated as unsigned integers (see
Java 8's Integer.toUnsignedLong function). Up to 4294967296 integers
can be stored.ImmutableRoaringBitmap,
RoaringBitmap,
序列化表格ImmutableBitmapDataProvider.RoaringOfInt| 构造器和说明 |
|---|
MutableRoaringBitmap()
Create an empty bitmap
|
MutableRoaringBitmap(MutableRoaringArray highLowContainer) |
MutableRoaringBitmap(RoaringBitmap rb)
Create a MutableRoaringBitmap from a RoaringBitmap.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
add(int... dat)
Set all the specified values to true.
|
void |
add(int x)
Add the value to the container (set the value to "true"), whether it already appears or not.
|
void |
add(int rangeStart,
int rangeEnd)
已过时。
use the version where longs specify the range
|
void |
add(long rangeStart,
long rangeEnd)
Add to the current bitmap all integers in [rangeStart,rangeEnd).
|
static MutableRoaringBitmap |
add(MutableRoaringBitmap rb,
int rangeStart,
int rangeEnd)
已过时。
use the version where longs specify the range
|
static MutableRoaringBitmap |
add(MutableRoaringBitmap rb,
long rangeStart,
long rangeEnd)
Generate a new bitmap with all integers in [rangeStart,rangeEnd) added.
|
void |
addN(int[] dat,
int offset,
int n)
Set the specified values to true, within given boundaries.
|
static MutableRoaringBitmap |
addOffset(ImmutableRoaringBitmap x,
long offset)
Generate a copy of the provided bitmap, but with
all its values incremented by offset.
|
void |
and(ImmutableRoaringBitmap array)
In-place bitwise AND (intersection) operation.
|
static MutableRoaringBitmap |
and(MutableRoaringBitmap x1,
MutableRoaringBitmap x2)
Bitwise AND (intersection) operation.
|
void |
andNot(ImmutableRoaringBitmap x2)
In-place bitwise ANDNOT (difference) operation.
|
static MutableRoaringBitmap |
andNot(MutableRoaringBitmap x1,
MutableRoaringBitmap x2)
Bitwise ANDNOT (difference) operation.
|
void |
append(char key,
MappeableContainer container)
Appends the key and container to the storage, throws if the key is less
than the current mark.
|
static MutableRoaringBitmap |
bitmapOf(int... dat)
Generate a bitmap with the specified values set to true.
|
boolean |
checkedAdd(int x)
Add the value to the container (set the value to "true"), whether it already appears or not.
|
boolean |
checkedRemove(int x)
If present remove the specified integer (effectively, sets its bit value to false)
|
void |
clear()
reset to an empty bitmap; result occupies as much space a newly created bitmap.
|
MutableRoaringBitmap |
clone() |
void |
deserialize(java.nio.ByteBuffer buffer)
Deserialize (retrieve) this bitmap.
|
void |
deserialize(java.io.DataInput in)
Deserialize the bitmap (retrieve from the input stream).
|
void |
flip(int x)
Add the value if it is not already present, otherwise remove it.
|
void |
flip(int rangeStart,
int rangeEnd)
已过时。
use the version where longs specify the range
|
void |
flip(long rangeStart,
long rangeEnd)
Modifies the current bitmap by complementing the bits in the given range, from rangeStart
(inclusive) rangeEnd (exclusive).
|
static MutableRoaringBitmap |
flip(MutableRoaringBitmap rb,
int rangeStart,
int rangeEnd)
已过时。
use the version where longs specify the range
|
static MutableRoaringBitmap |
flip(MutableRoaringBitmap bm,
long rangeStart,
long rangeEnd)
Complements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive).
|
MutableRoaringArray |
getMappeableRoaringArray() |
java.util.Iterator<java.lang.Integer> |
iterator()
iterate over the positions of the true values.
|
protected void |
lazyor(ImmutableRoaringBitmap x2) |
protected static MutableRoaringBitmap |
lazyorfromlazyinputs(MutableRoaringBitmap x1,
MutableRoaringBitmap x2) |
static long |
maximumSerializedSize(int cardinality,
int universe_size)
Assume that one wants to store "cardinality" integers in [0, universe_size),
this function returns an upper bound on the serialized size in bytes.
|
protected void |
naivelazyor(ImmutableRoaringBitmap x2) |
static MutableRoaringBitmap |
or(ImmutableRoaringBitmap... bitmaps)
Compute overall OR between bitmaps.
|
void |
or(ImmutableRoaringBitmap x2)
In-place bitwise OR (union) operation.
|
static MutableRoaringBitmap |
or(MutableRoaringBitmap x1,
MutableRoaringBitmap x2)
Bitwise OR (union) operation.
|
void |
orNot(ImmutableRoaringBitmap other,
long rangeEnd)
In-place bitwise ORNOT operation.
|
protected static void |
rangeSanityCheck(long rangeStart,
long rangeEnd) |
void |
readExternal(java.io.ObjectInput in) |
void |
remove(int x)
If present remove the specified integers (effectively, sets its bit value to false)
|
void |
remove(int rangeStart,
int rangeEnd)
已过时。
use the version where longs specify the range
|
void |
remove(long rangeStart,
long rangeEnd)
Remove from the current bitmap all integers in [rangeStart,rangeEnd).
|
static MutableRoaringBitmap |
remove(MutableRoaringBitmap rb,
int rangeStart,
int rangeEnd)
已过时。
use the version where longs specify the range
|
static MutableRoaringBitmap |
remove(MutableRoaringBitmap rb,
long rangeStart,
long rangeEnd)
Generate a new bitmap with all integers in [rangeStart,rangeEnd) removed.
|
boolean |
removeRunCompression()
Remove run-length encoding even when it is more space efficient
|
protected void |
repairAfterLazy() |
boolean |
runOptimize()
Use a run-length encoding where it is estimated as more space efficient
|
ImmutableRoaringBitmap |
toImmutableRoaringBitmap()
Convenience method, effectively casts the object to an object of class ImmutableRoaringBitmap.
|
void |
trim()
Recover allocated but unused memory.
|
void |
writeExternal(java.io.ObjectOutput out) |
void |
xor(ImmutableRoaringBitmap x2)
In-place bitwise XOR (symmetric difference) operation.
|
static MutableRoaringBitmap |
xor(MutableRoaringBitmap x1,
MutableRoaringBitmap x2)
Bitwise XOR (symmetric difference) operation.
|
and, and, and, andCardinality, andNot, andNot, andNot, andNotCardinality, cardinalityExceeds, contains, contains, contains, equals, first, flip, flip, forEach, getBatchIterator, getCardinality, getContainerPointer, getIntIterator, getLongCardinality, getLongSizeInBytes, getReverseIntIterator, getSizeInBytes, hashCode, hasRunCompression, intersects, intersects, isEmpty, isHammingSimilar, last, lazyor, limit, nextAbsentValue, nextValue, or, or, or, or, orCardinality, orNot, previousAbsentValue, previousValue, rangeCardinality, rank, rankLong, select, serialize, serialize, serializedSizeInBytes, toArray, toMutableRoaringBitmap, toRoaringBitmap, toString, xor, xor, xor, xorCardinalitycontains, first, forEach, getBatchIterator, getCardinality, getIntIterator, getLongCardinality, getLongSizeInBytes, getReverseIntIterator, getSizeInBytes, isEmpty, last, limit, nextAbsentValue, nextValue, previousAbsentValue, previousValue, rangeCardinality, rank, rankLong, reverseStream, select, serialize, serialize, serializedSizeInBytes, stream, toArraypublic MutableRoaringBitmap()
public MutableRoaringBitmap(MutableRoaringArray highLowContainer)
public MutableRoaringBitmap(RoaringBitmap rb)
rb - the original bitmappublic static MutableRoaringBitmap addOffset(ImmutableRoaringBitmap x, long offset)
x - source bitmapoffset - increment (can be negative)public static MutableRoaringBitmap add(MutableRoaringBitmap rb, long rangeStart, long rangeEnd)
rb - initial bitmap (will not be modified)rangeStart - inclusive beginning of rangerangeEnd - exclusive ending of range@Deprecated public static MutableRoaringBitmap add(MutableRoaringBitmap rb, int rangeStart, int rangeEnd)
rb - initial bitmap (will not be modified)rangeStart - inclusive beginning of rangerangeEnd - exclusive ending of rangepublic static MutableRoaringBitmap and(MutableRoaringBitmap x1, MutableRoaringBitmap x2)
x1 - first bitmapx2 - other bitmappublic static MutableRoaringBitmap andNot(MutableRoaringBitmap x1, MutableRoaringBitmap x2)
x1 - first bitmapx2 - other bitmappublic void add(int... dat)
dat - set valuespublic void addN(int[] dat,
int offset,
int n)
dat - set valuesoffset - from which index the values should be set to truen - how many values should be set to truepublic static MutableRoaringBitmap bitmapOf(int... dat)
dat - set valuesprotected static void rangeSanityCheck(long rangeStart,
long rangeEnd)
public static MutableRoaringBitmap flip(MutableRoaringBitmap bm, long rangeStart, long rangeEnd)
bm - bitmap being negatedrangeStart - inclusive beginning of rangerangeEnd - exclusive ending of range@Deprecated public static MutableRoaringBitmap flip(MutableRoaringBitmap rb, int rangeStart, int rangeEnd)
rb - bitmap being negatedrangeStart - inclusive beginning of rangerangeEnd - exclusive ending of rangeprotected static MutableRoaringBitmap lazyorfromlazyinputs(MutableRoaringBitmap x1, MutableRoaringBitmap x2)
public static MutableRoaringBitmap or(ImmutableRoaringBitmap... bitmaps)
BufferFastAggregation.or(org.bitlap.roaringbitmap.buffer.ImmutableRoaringBitmap...))bitmaps - input bitmapspublic static MutableRoaringBitmap or(MutableRoaringBitmap x1, MutableRoaringBitmap x2)
x1 - first bitmapx2 - other bitmappublic static MutableRoaringBitmap remove(MutableRoaringBitmap rb, long rangeStart, long rangeEnd)
rb - initial bitmap (will not be modified)rangeStart - inclusive beginning of rangerangeEnd - exclusive ending of range@Deprecated public static MutableRoaringBitmap remove(MutableRoaringBitmap rb, int rangeStart, int rangeEnd)
rb - initial bitmap (will not be modified)rangeStart - inclusive beginning of rangerangeEnd - exclusive ending of rangepublic static MutableRoaringBitmap xor(MutableRoaringBitmap x1, MutableRoaringBitmap x2)
x1 - first bitmapx2 - other bitmappublic void add(int x)
Integer.compareUnsigned(int, int).
We order the numbers like 0, 1, ..., 2147483647, -2147483648, -2147483647,..., -1.add 在接口中 BitmapDataProviderx - integer valuepublic void add(long rangeStart,
long rangeEnd)
add 在接口中 BitmapDataProviderrangeStart - inclusive beginning of rangerangeEnd - exclusive ending of range@Deprecated
public void add(int rangeStart,
int rangeEnd)
rangeStart - inclusive beginning of rangerangeEnd - exclusive ending of rangepublic void and(ImmutableRoaringBitmap array)
array - other bitmappublic void andNot(ImmutableRoaringBitmap x2)
x2 - other bitmappublic void orNot(ImmutableRoaringBitmap other, long rangeEnd)
other - the other bitmaprangeEnd - end point of the range (exclusive).public boolean checkedAdd(int x)
x - integer valuepublic boolean checkedRemove(int x)
x - integer value representing the index in a bitmappublic void clear()
public MutableRoaringBitmap clone()
clone 在类中 ImmutableRoaringBitmappublic void deserialize(java.io.DataInput in)
throws java.io.IOException
in - the DataInput streamjava.io.IOException - Signals that an I/O exception has occurred.public void deserialize(java.nio.ByteBuffer buffer)
throws java.io.IOException
buffer - the byte buffer (can be mapped, direct, array backed etc.java.io.IOException - Signals that an I/O exception has occurred.public void flip(int x)
x - integer valuepublic void flip(long rangeStart,
long rangeEnd)
rangeStart - inclusive beginning of rangerangeEnd - exclusive ending of range@Deprecated
public void flip(int rangeStart,
int rangeEnd)
rangeStart - inclusive beginning of rangerangeEnd - exclusive ending of rangepublic MutableRoaringArray getMappeableRoaringArray()
public java.util.Iterator<java.lang.Integer> iterator()
iterator 在接口中 java.lang.Iterable<java.lang.Integer>iterator 在类中 ImmutableRoaringBitmapprotected void lazyor(ImmutableRoaringBitmap x2)
protected void naivelazyor(ImmutableRoaringBitmap x2)
public void or(ImmutableRoaringBitmap x2)
x2 - other bitmappublic void readExternal(java.io.ObjectInput in)
throws java.io.IOException,
java.lang.ClassNotFoundException
readExternal 在接口中 java.io.Externalizablejava.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic void remove(int x)
remove 在接口中 BitmapDataProviderx - integer value representing the index in a bitmappublic void remove(long rangeStart,
long rangeEnd)
rangeStart - inclusive beginning of rangerangeEnd - exclusive ending of range@Deprecated
public void remove(int rangeStart,
int rangeEnd)
rangeStart - inclusive beginning of rangerangeEnd - exclusive ending of rangepublic boolean removeRunCompression()
protected void repairAfterLazy()
public boolean runOptimize()
public ImmutableRoaringBitmap toImmutableRoaringBitmap()
(ImmutableRoaringBitmap) bitmap
Some users would prefer to generate a hard copy of the data. The following
code illustrates how to proceed, but note that the resulting copy can be
expected to perform significantly worse than the original: the toImmutableRoaringBitmap
method is almost free, it uses less memory and it produces a much faster bitmap.
/////////////
// Code to create a hard copy of MutableRoaringBitmap to an
// ImmutableRoaringBitmap.
// Usage of this code is discouraged because it is expensive
// and it creates a copy that
// suffers from more performance overhead than the original.
/////////////
import org.roaringbitmap.buffer.*;
//...
MutableRoaringBitmap rr = ... // some bitmap
rr.runOptimize(); // can help compression
// we are going to create an immutable copy of rr
ByteBuffer outbb = ByteBuffer.allocate(mrb.serializedSizeInBytes());
mrb.serialize(outbb);
outbb.flip();
ImmutableRoaringBitmap irb = new ImmutableRoaringBitmap(outbb);
public void trim()
trim 在接口中 BitmapDataProviderpublic void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
writeExternal 在接口中 java.io.Externalizablejava.io.IOExceptionpublic void xor(ImmutableRoaringBitmap x2)
x2 - other bitmappublic static long maximumSerializedSize(int cardinality,
int universe_size)
cardinality - maximal cardinalityuniverse_size - maximal valuepublic void append(char key,
MappeableContainer container)
AppendableStorageappend 在接口中 AppendableStorage<MappeableContainer>key - the key to appendcontainer - the data to append