Class MutableRoaringBitmap

java.lang.Object
org.roaringbitmap.buffer.ImmutableRoaringBitmap
org.roaringbitmap.buffer.MutableRoaringBitmap
All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Iterable<Integer>, AppendableStorage<MappeableContainer>, BitmapDataProvider, ImmutableBitmapDataProvider

MutableRoaringBitmap, a compressed alternative to the BitSet. It is similar to org.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.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.
See Also: