public class MutableRoaringBitmap extends ImmutableRoaringBitmap implements Cloneable, Serializable, Iterable<Integer>, Externalizable, BitmapDataProvider
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,
Serialized Form| Constructor and Description |
|---|
MutableRoaringBitmap()
Create an empty bitmap
|
MutableRoaringBitmap(RoaringBitmap rb)
Create a MutableRoaringBitmap from a RoaringBitmap.
|
| Modifier and Type | Method and Description |
|---|---|
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)
Deprecated.
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)
Deprecated.
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 |
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.
|
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(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)
Deprecated.
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)
Deprecated.
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() |
int |
hashCode() |
Iterator<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.
|
protected static void |
rangeSanityCheck(long rangeStart,
long rangeEnd) |
void |
readExternal(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)
Deprecated.
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)
Deprecated.
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(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, contains, contains, equals, first, flip, flip, forEach, getCardinality, getContainerPointer, getIntIterator, getLongCardinality, getLongSizeInBytes, getReverseIntIterator, getSizeInBytes, hasRunCompression, intersects, isEmpty, isHammingSimilar, last, lazyor, limit, or, or, or, or, orCardinality, rank, rankLong, select, serialize, serializedSizeInBytes, toArray, toMutableRoaringBitmap, toRoaringBitmap, toString, xor, xor, xor, xorCardinalityfinalize, getClass, notify, notifyAll, wait, wait, waitforEach, spliteratorcontains, first, forEach, getCardinality, getIntIterator, getLongCardinality, getLongSizeInBytes, getReverseIntIterator, getSizeInBytes, isEmpty, last, limit, rank, rankLong, select, serialize, serializedSizeInBytes, toArraypublic MutableRoaringBitmap()
public MutableRoaringBitmap(RoaringBitmap rb)
rb - the original bitmappublic 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 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.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 in interface BitmapDataProviderx - integer valuepublic void add(long rangeStart,
long rangeEnd)
rangeStart - 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 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 in class ImmutableRoaringBitmappublic void deserialize(DataInput in) throws IOException
in - the DataInput streamIOException - 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 int hashCode()
hashCode in class ImmutableRoaringBitmappublic Iterator<Integer> iterator()
iterator in interface Iterable<Integer>iterator in class ImmutableRoaringBitmapprotected void lazyor(ImmutableRoaringBitmap x2)
protected void naivelazyor(ImmutableRoaringBitmap x2)
public void or(ImmutableRoaringBitmap x2)
x2 - other bitmappublic void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal in interface ExternalizableIOExceptionClassNotFoundExceptionpublic void remove(int x)
remove in interface 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(new DataOutputStream(new OutputStream(){
ByteBuffer mBB;
OutputStream init(ByteBuffer mbb) {mBB=mbb; return this;}
public void close() {}
public void flush() {}
public void write(int b) {
mBB.put((byte) b);}
public void write(byte[] b) {mBB.put(b);}
public void write(byte[] b, int off, int l) {mBB.put(b,off,l);}
}.init(outbb)));
outbb.flip();
ImmutableRoaringBitmap irb = new ImmutableRoaringBitmap(outbb);
public void trim()
trim in interface BitmapDataProviderpublic void writeExternal(ObjectOutput out) throws IOException
writeExternal in interface ExternalizableIOExceptionpublic void xor(ImmutableRoaringBitmap x2)
x2 - other bitmappublic static long maximumSerializedSize(int cardinality,
int universe_size)
cardinality - maximal cardinalityuniverse_size - maximal valueCopyright © 2017. All rights reserved.