java.lang.Object
org.bitlap.roaringbitmap.buffer.ImmutableRoaringBitmap
org.bitlap.roaringbitmap.buffer.MutableRoaringBitmap
- 所有已实现的接口:
Externalizable,Serializable,Cloneable,Iterable<Integer>,AppendableStorage<MappeableContainer>,BitmapDataProvider,ImmutableBitmapDataProvider
public class MutableRoaringBitmap
extends ImmutableRoaringBitmap
implements Cloneable, Serializable, Iterable<Integer>, Externalizable, BitmapDataProvider, AppendableStorage<MappeableContainer>
MutableRoaringBitmap, a compressed alternative to the BitSet. It is similar to
org.bitlap.roaringbitmap.RoaringBitmap, but it differs in that it can interact with
ImmutableRoaringBitmap objects in the sense that MutableRoaringBitmap is
derived from ImmutableRoaringBitmap.
A MutableRoaringBitmap is an instance of an ImmutableRoaringBitmap (where methods like
"serialize" are implemented). That is, they both share the same core (immutable) methods, but a
MutableRoaringBitmap adds methods that allow you to modify the object. This design allows us to
use MutableRoaringBitmap as ImmutableRoaringBitmap instances when needed.
MutableRoaringBitmap instances can be casted to an ImmutableRoaringBitmap instance
in constant time which means that code written for ImmutableRoaringBitmap instances
run at full speed (without copies) on MutableRoaringBitmap
instances.
A MutableRoaringBitmap can be used much like an org.roaringbitmap.RoaringBitmap instance, and
they serialize to the same output. The RoaringBitmap instance will be faster since it does not
carry the overhead of a ByteBuffer back-end, but the MutableRoaringBitmap can be used as an
ImmutableRoaringBitmap instance. Thus, if you use ImmutableRoaringBitmap, you probably need to
use MutableRoaringBitmap instances as well; if you do not use ImmutableRoaringBitmap, you
probably want to use only RoaringBitmap instances.
import org.bitlap.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.-
嵌套类概要
从接口继承的嵌套类/接口 org.bitlap.roaringbitmap.ImmutableBitmapDataProvider
ImmutableBitmapDataProvider.RoaringOfInt -
构造器概要
构造器构造器说明Create an empty bitmapMutableRoaringBitmap(MutableRoaringArray highLowContainer) Create a MutableRoaringBitmap from a RoaringBitmap. -
方法概要
修饰符和类型方法说明voidadd(int x) Add the value to the container (set the value to "true"), whether it already appears or not.voidadd(int... dat) Set all the specified values to true.voidadd(int rangeStart, int rangeEnd) 已过时。use the version where longs specify the rangevoidadd(long rangeStart, long rangeEnd) Add to the current bitmap all integers in [rangeStart,rangeEnd).static MutableRoaringBitmapadd(MutableRoaringBitmap rb, int rangeStart, int rangeEnd) 已过时。use the version where longs specify the rangestatic MutableRoaringBitmapadd(MutableRoaringBitmap rb, long rangeStart, long rangeEnd) Generate a new bitmap with all integers in [rangeStart,rangeEnd) added.voidaddN(int[] dat, int offset, int n) Set the specified values to true, within given boundaries.static MutableRoaringBitmapaddOffset(ImmutableRoaringBitmap x, long offset) Generate a copy of the provided bitmap, but with all its values incremented by offset.voidand(ImmutableRoaringBitmap array) In-place bitwise AND (intersection) operation.static MutableRoaringBitmapBitwise AND (intersection) operation.voidIn-place bitwise ANDNOT (difference) operation.static MutableRoaringBitmapBitwise ANDNOT (difference) operation.voidappend(char key, MappeableContainer container) Appends the key and container to the storage, throws if the key is less than the current mark.static MutableRoaringBitmapbitmapOf(int... dat) Generate a bitmap with the specified values set to true.booleancheckedAdd(int x) Add the value to the container (set the value to "true"), whether it already appears or not.booleancheckedRemove(int x) If present remove the specified integer (effectively, sets its bit value to false)voidclear()reset to an empty bitmap; result occupies as much space a newly created bitmap.clone()voiddeserialize(DataInput in) Deserialize the bitmap (retrieve from the input stream).voiddeserialize(ByteBuffer buffer) Deserialize (retrieve) this bitmap.voidflip(int x) Add the value if it is not already present, otherwise remove it.voidflip(int rangeStart, int rangeEnd) 已过时。use the version where longs specify the rangevoidflip(long rangeStart, long rangeEnd) Modifies the current bitmap by complementing the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive).static MutableRoaringBitmapflip(MutableRoaringBitmap rb, int rangeStart, int rangeEnd) 已过时。use the version where longs specify the rangestatic MutableRoaringBitmapflip(MutableRoaringBitmap bm, long rangeStart, long rangeEnd) Complements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive).iterator()iterate over the positions of the true values.protected voidprotected static MutableRoaringBitmapstatic longmaximumSerializedSize(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 voidvoidIn-place bitwise OR (union) operation.static MutableRoaringBitmapor(ImmutableRoaringBitmap... bitmaps) Compute overall OR between bitmaps.static MutableRoaringBitmapBitwise OR (union) operation.voidorNot(ImmutableRoaringBitmap other, long rangeEnd) In-place bitwise ORNOT operation.protected static voidrangeSanityCheck(long rangeStart, long rangeEnd) voidvoidremove(int x) If present remove the specified integers (effectively, sets its bit value to false)voidremove(int rangeStart, int rangeEnd) 已过时。use the version where longs specify the rangevoidremove(long rangeStart, long rangeEnd) Remove from the current bitmap all integers in [rangeStart,rangeEnd).static MutableRoaringBitmapremove(MutableRoaringBitmap rb, int rangeStart, int rangeEnd) 已过时。use the version where longs specify the rangestatic MutableRoaringBitmapremove(MutableRoaringBitmap rb, long rangeStart, long rangeEnd) Generate a new bitmap with all integers in [rangeStart,rangeEnd) removed.booleanRemove run-length encoding even when it is more space efficientprotected voidbooleanUse a run-length encoding where it is estimated as more space efficientConvenience method, effectively casts the object to an object of class ImmutableRoaringBitmap.voidtrim()Recover allocated but unused memory.voidvoidIn-place bitwise XOR (symmetric difference) operation.static MutableRoaringBitmapBitwise XOR (symmetric difference) operation.从类继承的方法 org.bitlap.roaringbitmap.buffer.ImmutableRoaringBitmap
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, xorCardinality从接口继承的方法 org.bitlap.roaringbitmap.ImmutableBitmapDataProvider
contains, 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, toArray从接口继承的方法 java.lang.Iterable
forEach, spliterator
-
构造器详细资料
-
MutableRoaringBitmap
public MutableRoaringBitmap()Create an empty bitmap -
MutableRoaringBitmap
-
MutableRoaringBitmap
Create a MutableRoaringBitmap from a RoaringBitmap. The RoaringBitmap is not modified.- 参数:
rb- the original bitmap
-
-
方法详细资料
-
addOffset
Generate a copy of the provided bitmap, but with all its values incremented by offset. The parameter offset can be negative. Values that would fall outside of the valid 32-bit range are discarded so that the result can have lower cardinality. This method can be relatively expensive when offset is not divisible by 65536. Use sparingly.- 参数:
x- source bitmapoffset- increment (can be negative)- 返回:
- a new bitmap
-
add
Generate a new bitmap with all integers in [rangeStart,rangeEnd) added.- 参数:
rb- initial bitmap (will not be modified)rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range- 返回:
- new bitmap
-
add
@Deprecated public static MutableRoaringBitmap add(MutableRoaringBitmap rb, int rangeStart, int rangeEnd) 已过时。use the version where longs specify the rangeGenerate a new bitmap with all integers in [rangeStart,rangeEnd) added.- 参数:
rb- initial bitmap (will not be modified)rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range- 返回:
- new bitmap
-
and
Bitwise AND (intersection) operation. The provided bitmaps are *not* modified. This operation is thread-safe as long as the provided bitmaps remain unchanged.- 参数:
x1- first bitmapx2- other bitmap- 返回:
- result of the operation
-
andNot
Bitwise ANDNOT (difference) operation. The provided bitmaps are *not* modified. This operation is thread-safe as long as the provided bitmaps remain unchanged.- 参数:
x1- first bitmapx2- other bitmap- 返回:
- result of the operation
-
add
public void add(int... dat) Set all the specified values to true. This can be expected to be slightly faster than calling "add" repeatedly. The provided integers values don't have to be in sorted order, but it may be preferable to sort them from a performance point of view.- 参数:
dat- set values
-
addN
public void addN(int[] dat, int offset, int n) Set the specified values to true, within given boundaries. This can be expected to be slightly faster than calling "add" repeatedly on the values dat[offset], dat[offset+1],..., dat[offset+n-1]. The provided integers values don't have to be in sorted order, but it may be preferable to sort them from a performance point of view.- 参数:
dat- set valuesoffset- from which index the values should be set to truen- how many values should be set to true
-
bitmapOf
Generate a bitmap with the specified values set to true. The provided integers values don't have to be in sorted order, but it may be preferable to sort them from a performance point of view.- 参数:
dat- set values- 返回:
- a new bitmap
-
rangeSanityCheck
protected static void rangeSanityCheck(long rangeStart, long rangeEnd) -
flip
Complements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive). The given bitmap is unchanged.- 参数:
bm- bitmap being negatedrangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range- 返回:
- a new Bitmap
-
flip
@Deprecated public static MutableRoaringBitmap flip(MutableRoaringBitmap rb, int rangeStart, int rangeEnd) 已过时。use the version where longs specify the rangeComplements the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive). The given bitmap is unchanged.- 参数:
rb- bitmap being negatedrangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range- 返回:
- a new Bitmap
-
lazyorfromlazyinputs
protected static MutableRoaringBitmap lazyorfromlazyinputs(MutableRoaringBitmap x1, MutableRoaringBitmap x2) -
or
Compute overall OR between bitmaps. (Effectively callsBufferFastAggregation.or(org.bitlap.roaringbitmap.buffer.ImmutableRoaringBitmap...))- 参数:
bitmaps- input bitmaps- 返回:
- aggregated bitmap
-
or
Bitwise OR (union) operation. The provided bitmaps are *not* modified. This operation is thread-safe as long as the provided bitmaps remain unchanged.- 参数:
x1- first bitmapx2- other bitmap- 返回:
- result of the operation
-
remove
Generate a new bitmap with all integers in [rangeStart,rangeEnd) removed.- 参数:
rb- initial bitmap (will not be modified)rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range- 返回:
- new bitmap
-
remove
@Deprecated public static MutableRoaringBitmap remove(MutableRoaringBitmap rb, int rangeStart, int rangeEnd) 已过时。use the version where longs specify the rangeGenerate a new bitmap with all integers in [rangeStart,rangeEnd) removed.- 参数:
rb- initial bitmap (will not be modified)rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range- 返回:
- new bitmap
-
xor
Bitwise XOR (symmetric difference) operation. The provided bitmaps are *not* modified. This operation is thread-safe as long as the provided bitmaps remain unchanged.- 参数:
x1- first bitmapx2- other bitmap- 返回:
- result of the operation
-
add
public void add(int x) Add the value to the container (set the value to "true"), whether it already appears or not. Java lacks native unsigned integers but the x argument is considered to be unsigned. Within bitmaps, numbers are ordered according toInteger.compareUnsigned(int, int). We order the numbers like 0, 1, ..., 2147483647, -2147483648, -2147483647,..., -1.- 指定者:
add在接口中BitmapDataProvider- 参数:
x- integer value
-
add
public void add(long rangeStart, long rangeEnd) Add to the current bitmap all integers in [rangeStart,rangeEnd).- 指定者:
add在接口中BitmapDataProvider- 参数:
rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range
-
add
已过时。use the version where longs specify the rangeAdd to the current bitmap all integers in [rangeStart,rangeEnd).- 参数:
rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range
-
and
In-place bitwise AND (intersection) operation. The current bitmap is modified.- 参数:
array- other bitmap
-
andNot
In-place bitwise ANDNOT (difference) operation. The current bitmap is modified.- 参数:
x2- other bitmap
-
orNot
In-place bitwise ORNOT operation. The current bitmap is modified.- 参数:
other- the other bitmaprangeEnd- end point of the range (exclusive).
-
checkedAdd
public boolean checkedAdd(int x) Add the value to the container (set the value to "true"), whether it already appears or not.- 参数:
x- integer value- 返回:
- true if the added int wasn't already contained in the bitmap. False otherwise.
-
checkedRemove
public boolean checkedRemove(int x) If present remove the specified integer (effectively, sets its bit value to false)- 参数:
x- integer value representing the index in a bitmap- 返回:
- true if the unset bit was already in the bitmap
-
clear
public void clear()reset to an empty bitmap; result occupies as much space a newly created bitmap. -
clone
- 覆盖:
clone在类中ImmutableRoaringBitmap
-
deserialize
Deserialize the bitmap (retrieve from the input stream). The current bitmap is overwritten. See format specification at https://github.com/RoaringBitmap/RoaringFormatSpec- 参数:
in- the DataInput stream- 抛出:
IOException- Signals that an I/O exception has occurred.
-
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 to remain unchanged.- 参数:
buffer- the byte buffer (can be mapped, direct, array backed etc.- 抛出:
IOException- Signals that an I/O exception has occurred.
-
flip
public void flip(int x) Add the value if it is not already present, otherwise remove it.- 参数:
x- integer value
-
flip
public void flip(long rangeStart, long rangeEnd) Modifies the current bitmap by complementing the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive).- 参数:
rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range
-
flip
已过时。use the version where longs specify the rangeModifies the current bitmap by complementing the bits in the given range, from rangeStart (inclusive) rangeEnd (exclusive).- 参数:
rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range
-
getMappeableRoaringArray
- 返回:
- a mutable copy of this bitmap
-
iterator
iterate over the positions of the true values.- 指定者:
iterator在接口中Iterable<Integer>- 覆盖:
iterator在类中ImmutableRoaringBitmap- 返回:
- the iterator
-
lazyor
-
naivelazyor
-
or
In-place bitwise OR (union) operation. The current bitmap is modified.- 参数:
x2- other bitmap
-
readExternal
- 指定者:
readExternal在接口中Externalizable- 抛出:
IOExceptionClassNotFoundException
-
remove
public void remove(int x) If present remove the specified integers (effectively, sets its bit value to false)- 指定者:
remove在接口中BitmapDataProvider- 参数:
x- integer value representing the index in a bitmap
-
remove
public void remove(long rangeStart, long rangeEnd) Remove from the current bitmap all integers in [rangeStart,rangeEnd).- 参数:
rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range
-
remove
已过时。use the version where longs specify the rangeRemove from the current bitmap all integers in [rangeStart,rangeEnd).- 参数:
rangeStart- inclusive beginning of rangerangeEnd- exclusive ending of range
-
removeRunCompression
public boolean removeRunCompression()Remove run-length encoding even when it is more space efficient- 返回:
- whether a change was applied
-
repairAfterLazy
protected void repairAfterLazy() -
runOptimize
public boolean runOptimize()Use a run-length encoding where it is estimated as more space efficient- 返回:
- whether a change was applied
-
toImmutableRoaringBitmap
Convenience method, effectively casts the object to an object of class ImmutableRoaringBitmap. This function is equivalent to :
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.(ImmutableRoaringBitmap) 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.bitlap.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);- 返回:
- a cast of this object
-
trim
public void trim()Recover allocated but unused memory.- 指定者:
trim在接口中BitmapDataProvider
-
writeExternal
- 指定者:
writeExternal在接口中Externalizable- 抛出:
IOException
-
xor
In-place bitwise XOR (symmetric difference) operation. The current bitmap is modified.- 参数:
x2- other bitmap
-
maximumSerializedSize
public 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. This function is identical to RoaringBitmap.maximumSerializedSize.- 参数:
cardinality- maximal cardinalityuniverse_size- maximal value- 返回:
- upper bound on the serialized size in bytes of the bitmap
-
append
从接口复制的说明:AppendableStorageAppends the key and container to the storage, throws if the key is less than the current mark.- 指定者:
append在接口中AppendableStorage<MappeableContainer>- 参数:
key- the key to appendcontainer- the data to append
-