@Test public void addoffset() { final RoaringBitmap rb = new RoaringBitmap(); rb.add(10); rb.add(0xFFFF); rb.add(0x010101); for (int i = 100000; i < 200000; i += 4) { rb.add(i); } rb.add(400000L, 1400000L); for (int offset = 3; offset < 1000000; offset *= 3) { RoaringBitmap rboff = RoaringBitmap.addOffset(rb, offset); IntIterator i = rb.getIntIterator(); IntIterator j = rboff.getIntIterator(); while (i.hasNext() && j.hasNext()) { int val1 = i.next() + offset; int val2 = j.next(); assertEquals(val1, val2); } assertEquals(i.hasNext(), j.hasNext()); } for (int offset = 1024; offset < 1000000; offset *= 2) { RoaringBitmap rboff = RoaringBitmap.addOffset(rb, offset); IntIterator i = rb.getIntIterator(); IntIterator j = rboff.getIntIterator(); while (i.hasNext() && j.hasNext()) { assertEquals(i.next() + offset, j.next()); } assertEquals(i.hasNext(), j.hasNext()); } }
public static RoaringBitmap addOffset(final RoaringBitmap x, long offset) { long container_offset_long = offset < 0 ? (offset - (1<<16) + 1) / (1<<16) : offset / (1 << 16); if((container_offset_long < -(1<<16) ) || (container_offset_long >= (1<<16) )) { return new RoaringBitmap(); } int container_offset = (int) container_offset_long; int in_container_offset = (int)(offset - container_offset_long * (1L<<16)); if(in_container_offset == 0) { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; answer.highLowContainer.append((char)key, x.highLowContainer.getContainerAtIndex(pos).clone()); } return answer; } else { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; Container c = x.highLowContainer.getContainerAtIndex(pos); Container[] offsetted = Util.addOffset(c, (char)in_container_offset); boolean keyok = (key >= 0) && (key <= 0xFFFF); boolean keypok = (key + 1 >= 0) && (key + 1 <= 0xFFFF); if( !offsetted[0].isEmpty() && keyok) { int current_size = answer.highLowContainer.size(); int lastkey = 0; if(current_size > 0) { lastkey = (answer.highLowContainer.getKeyAtIndex( current_size - 1)); } if((current_size > 0) && (lastkey == key)) { Container prev = answer.highLowContainer .getContainerAtIndex(current_size - 1); Container orresult = prev.ior(offsetted[0]); answer.highLowContainer.setContainerAtIndex(current_size - 1, orresult); } else { answer.highLowContainer.append((char)key, offsetted[0]); } } if( !offsetted[1].isEmpty() && keypok) { answer.highLowContainer.append((char)(key + 1), offsetted[1]); } } answer.repairAfterLazy(); return answer; } }
RoaringBitmap implements Cloneable, Serializable, Iterable<Integer>, Externalizable,
    ImmutableBitmapDataProvider, BitmapDataProvider, AppendableStorage<Container> { public static RoaringBitmap addOffset(final RoaringBitmap x, long offset) { long container_offset_long = offset < 0 ? (offset - (1<<16) + 1) / (1<<16) : offset / (1 << 16); if((container_offset_long < -(1<<16) ) || (container_offset_long >= (1<<16) )) { return new RoaringBitmap(); } int container_offset = (int) container_offset_long; int in_container_offset = (int)(offset - container_offset_long * (1L<<16)); if(in_container_offset == 0) { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; answer.highLowContainer.append((char)key, x.highLowContainer.getContainerAtIndex(pos).clone()); } return answer; } else { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; Container c = x.highLowContainer.getContainerAtIndex(pos); Container[] offsetted = Util.addOffset(c, (char)in_container_offset); boolean keyok = (key >= 0) && (key <= 0xFFFF); boolean keypok = (key + 1 >= 0) && (key + 1 <= 0xFFFF); if( !offsetted[0].isEmpty() && keyok) { int current_size = answer.highLowContainer.size(); int lastkey = 0; if(current_size > 0) { lastkey = (answer.highLowContainer.getKeyAtIndex( current_size - 1)); } if((current_size > 0) && (lastkey == key)) { Container prev = answer.highLowContainer .getContainerAtIndex(current_size - 1); Container orresult = prev.ior(offsetted[0]); answer.highLowContainer.setContainerAtIndex(current_size - 1, orresult); } else { answer.highLowContainer.append((char)key, offsetted[0]); } } if( !offsetted[1].isEmpty() && keypok) { answer.highLowContainer.append((char)(key + 1), offsetted[1]); } } answer.repairAfterLazy(); return answer; } } }
RoaringBitmap implements Cloneable, Serializable, Iterable<Integer>, Externalizable,
    ImmutableBitmapDataProvider, BitmapDataProvider, AppendableStorage<Container> { public static RoaringBitmap addOffset(final RoaringBitmap x, long offset) { long container_offset_long = offset < 0 ? (offset - (1<<16) + 1) / (1<<16) : offset / (1 << 16); if((container_offset_long < -(1<<16) ) || (container_offset_long >= (1<<16) )) { return new RoaringBitmap(); } int container_offset = (int) container_offset_long; int in_container_offset = (int)(offset - container_offset_long * (1L<<16)); if(in_container_offset == 0) { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; answer.highLowContainer.append((char)key, x.highLowContainer.getContainerAtIndex(pos).clone()); } return answer; } else { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; Container c = x.highLowContainer.getContainerAtIndex(pos); Container[] offsetted = Util.addOffset(c, (char)in_container_offset); boolean keyok = (key >= 0) && (key <= 0xFFFF); boolean keypok = (key + 1 >= 0) && (key + 1 <= 0xFFFF); if( !offsetted[0].isEmpty() && keyok) { int current_size = answer.highLowContainer.size(); int lastkey = 0; if(current_size > 0) { lastkey = (answer.highLowContainer.getKeyAtIndex( current_size - 1)); } if((current_size > 0) && (lastkey == key)) { Container prev = answer.highLowContainer .getContainerAtIndex(current_size - 1); Container orresult = prev.ior(offsetted[0]); answer.highLowContainer.setContainerAtIndex(current_size - 1, orresult); } else { answer.highLowContainer.append((char)key, offsetted[0]); } } if( !offsetted[1].isEmpty() && keypok) { answer.highLowContainer.append((char)(key + 1), offsetted[1]); } } answer.repairAfterLazy(); return answer; } } RoaringBitmap();   RoaringBitmap(RoaringArray highLowContainer);  RoaringBitmap(ImmutableRoaringBitmap rb); }
RoaringBitmap implements Cloneable, Serializable, Iterable<Integer>, Externalizable,
    ImmutableBitmapDataProvider, BitmapDataProvider, AppendableStorage<Container> { public static RoaringBitmap addOffset(final RoaringBitmap x, long offset) { long container_offset_long = offset < 0 ? (offset - (1<<16) + 1) / (1<<16) : offset / (1 << 16); if((container_offset_long < -(1<<16) ) || (container_offset_long >= (1<<16) )) { return new RoaringBitmap(); } int container_offset = (int) container_offset_long; int in_container_offset = (int)(offset - container_offset_long * (1L<<16)); if(in_container_offset == 0) { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; answer.highLowContainer.append((char)key, x.highLowContainer.getContainerAtIndex(pos).clone()); } return answer; } else { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; Container c = x.highLowContainer.getContainerAtIndex(pos); Container[] offsetted = Util.addOffset(c, (char)in_container_offset); boolean keyok = (key >= 0) && (key <= 0xFFFF); boolean keypok = (key + 1 >= 0) && (key + 1 <= 0xFFFF); if( !offsetted[0].isEmpty() && keyok) { int current_size = answer.highLowContainer.size(); int lastkey = 0; if(current_size > 0) { lastkey = (answer.highLowContainer.getKeyAtIndex( current_size - 1)); } if((current_size > 0) && (lastkey == key)) { Container prev = answer.highLowContainer .getContainerAtIndex(current_size - 1); Container orresult = prev.ior(offsetted[0]); answer.highLowContainer.setContainerAtIndex(current_size - 1, orresult); } else { answer.highLowContainer.append((char)key, offsetted[0]); } } if( !offsetted[1].isEmpty() && keypok) { answer.highLowContainer.append((char)(key + 1), offsetted[1]); } } answer.repairAfterLazy(); return answer; } } RoaringBitmap();   RoaringBitmap(RoaringArray highLowContainer);  RoaringBitmap(ImmutableRoaringBitmap rb); static RoaringBitmap addOffset(final RoaringBitmap x, long offset); static RoaringBitmap add(RoaringBitmap rb, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap add(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static RoaringBitmap and(final RoaringBitmap x1, final RoaringBitmap x2); static int andCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2); void add(final int... dat); void addN(final int[] dat, final int offset, final int n); static RoaringBitmap bitmapOf(final int... dat); static RoaringBitmap bitmapOfUnordered(final int... data); static RoaringBitmap flip(RoaringBitmap bm, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap flip(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static boolean intersects(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap or(Iterator<? extends RoaringBitmap> bitmaps); static RoaringBitmap or(RoaringBitmap... bitmaps); static RoaringBitmap or(final RoaringBitmap x1, final RoaringBitmap x2); static int orCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static int xorCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static int andNotCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap remove(RoaringBitmap rb, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap remove(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static RoaringBitmap xor(final RoaringBitmap x1, final RoaringBitmap x2); @Override void add(final int x); void add(final long rangeStart, final long rangeEnd); @Deprecated void add(final int rangeStart, final int rangeEnd); boolean intersects(long minimum, long supremum); void and(final RoaringBitmap x2); static RoaringBitmap and(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap and(final Iterator<? extends RoaringBitmap> bitmaps,
      final int rangeStart, final int rangeEnd); void andNot(final RoaringBitmap x2); static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2,
      long rangeStart, long rangeEnd); @Deprecated static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2,
          final int rangeStart, final int rangeEnd); void orNot(final RoaringBitmap other, long rangeEnd); static RoaringBitmap orNot(
          final RoaringBitmap x1, final RoaringBitmap x2, long rangeEnd); boolean checkedAdd(final int x); boolean checkedRemove(final int x); void clear(); @Override RoaringBitmap clone(); @Override boolean contains(final int x); boolean contains(long minimum, long supremum); void deserialize(DataInput in, byte[] buffer); void deserialize(DataInput in); void deserialize(ByteBuffer bbf); @Override boolean equals(Object o); boolean isHammingSimilar(RoaringBitmap other, int tolerance); void flip(final int x); void flip(final long rangeStart, final long rangeEnd); @Deprecated void flip(final int rangeStart, final int rangeEnd); @Override long getLongCardinality(); @Override int getCardinality(); @Override void forEach(IntConsumer ic); ContainerPointer getContainerPointer(); @Override PeekableIntIterator getIntIterator(); @Override IntIterator getReverseIntIterator(); @Override RoaringBatchIterator getBatchIterator(); @Override long getLongSizeInBytes(); @Override int getSizeInBytes(); @Override int hashCode(); boolean hasRunCompression(); @Override boolean isEmpty(); @Override Iterator<Integer> iterator(); @Override RoaringBitmap limit(int maxcardinality); void or(final RoaringBitmap x2); static RoaringBitmap or(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap or(final Iterator<? extends RoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); @Override long rankLong(int x); @Override long rangeCardinality(long start, long end); @Override int rank(int x); @Override void readExternal(ObjectInput in); @Override void remove(final int x); void remove(final long rangeStart, final long rangeEnd); @Deprecated void remove(final int rangeStart, final int rangeEnd); boolean removeRunCompression(); boolean runOptimize(); boolean contains(RoaringBitmap subset); @Override int select(int j); @Override long nextValue(int fromValue); @Override long previousValue(int fromValue); @Override long nextAbsentValue(int fromValue); @Override long previousAbsentValue(int fromValue); @Override int first(); @Override int last(); @Override void serialize(DataOutput out); @Override void serialize(ByteBuffer buffer); static long maximumSerializedSize(long cardinality, long universe_size); @Override int serializedSizeInBytes(); @Override int[] toArray(); @Override void append(char key, Container container); MutableRoaringBitmap toMutableRoaringBitmap(); @Override String toString(); @Override void trim(); @Override void writeExternal(ObjectOutput out); void xor(final RoaringBitmap x2); static RoaringBitmap xor(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap xor(final Iterator<? extends RoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); }
RoaringBitmap implements Cloneable, Serializable, Iterable<Integer>, Externalizable,
    ImmutableBitmapDataProvider, BitmapDataProvider, AppendableStorage<Container> { public static RoaringBitmap addOffset(final RoaringBitmap x, long offset) { long container_offset_long = offset < 0 ? (offset - (1<<16) + 1) / (1<<16) : offset / (1 << 16); if((container_offset_long < -(1<<16) ) || (container_offset_long >= (1<<16) )) { return new RoaringBitmap(); } int container_offset = (int) container_offset_long; int in_container_offset = (int)(offset - container_offset_long * (1L<<16)); if(in_container_offset == 0) { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; answer.highLowContainer.append((char)key, x.highLowContainer.getContainerAtIndex(pos).clone()); } return answer; } else { RoaringBitmap answer = new RoaringBitmap(); for(int pos = 0; pos < x.highLowContainer.size(); pos++) { int key = (x.highLowContainer.getKeyAtIndex(pos)); key += container_offset; Container c = x.highLowContainer.getContainerAtIndex(pos); Container[] offsetted = Util.addOffset(c, (char)in_container_offset); boolean keyok = (key >= 0) && (key <= 0xFFFF); boolean keypok = (key + 1 >= 0) && (key + 1 <= 0xFFFF); if( !offsetted[0].isEmpty() && keyok) { int current_size = answer.highLowContainer.size(); int lastkey = 0; if(current_size > 0) { lastkey = (answer.highLowContainer.getKeyAtIndex( current_size - 1)); } if((current_size > 0) && (lastkey == key)) { Container prev = answer.highLowContainer .getContainerAtIndex(current_size - 1); Container orresult = prev.ior(offsetted[0]); answer.highLowContainer.setContainerAtIndex(current_size - 1, orresult); } else { answer.highLowContainer.append((char)key, offsetted[0]); } } if( !offsetted[1].isEmpty() && keypok) { answer.highLowContainer.append((char)(key + 1), offsetted[1]); } } answer.repairAfterLazy(); return answer; } } RoaringBitmap();   RoaringBitmap(RoaringArray highLowContainer);  RoaringBitmap(ImmutableRoaringBitmap rb); static RoaringBitmap addOffset(final RoaringBitmap x, long offset); static RoaringBitmap add(RoaringBitmap rb, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap add(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static RoaringBitmap and(final RoaringBitmap x1, final RoaringBitmap x2); static int andCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2); void add(final int... dat); void addN(final int[] dat, final int offset, final int n); static RoaringBitmap bitmapOf(final int... dat); static RoaringBitmap bitmapOfUnordered(final int... data); static RoaringBitmap flip(RoaringBitmap bm, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap flip(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static boolean intersects(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap or(Iterator<? extends RoaringBitmap> bitmaps); static RoaringBitmap or(RoaringBitmap... bitmaps); static RoaringBitmap or(final RoaringBitmap x1, final RoaringBitmap x2); static int orCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static int xorCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static int andNotCardinality(final RoaringBitmap x1, final RoaringBitmap x2); static RoaringBitmap remove(RoaringBitmap rb, final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap remove(RoaringBitmap rb, final int rangeStart, final int rangeEnd); static RoaringBitmap xor(final RoaringBitmap x1, final RoaringBitmap x2); @Override void add(final int x); void add(final long rangeStart, final long rangeEnd); @Deprecated void add(final int rangeStart, final int rangeEnd); boolean intersects(long minimum, long supremum); void and(final RoaringBitmap x2); static RoaringBitmap and(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap and(final Iterator<? extends RoaringBitmap> bitmaps,
      final int rangeStart, final int rangeEnd); void andNot(final RoaringBitmap x2); static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2,
      long rangeStart, long rangeEnd); @Deprecated static RoaringBitmap andNot(final RoaringBitmap x1, final RoaringBitmap x2,
          final int rangeStart, final int rangeEnd); void orNot(final RoaringBitmap other, long rangeEnd); static RoaringBitmap orNot(
          final RoaringBitmap x1, final RoaringBitmap x2, long rangeEnd); boolean checkedAdd(final int x); boolean checkedRemove(final int x); void clear(); @Override RoaringBitmap clone(); @Override boolean contains(final int x); boolean contains(long minimum, long supremum); void deserialize(DataInput in, byte[] buffer); void deserialize(DataInput in); void deserialize(ByteBuffer bbf); @Override boolean equals(Object o); boolean isHammingSimilar(RoaringBitmap other, int tolerance); void flip(final int x); void flip(final long rangeStart, final long rangeEnd); @Deprecated void flip(final int rangeStart, final int rangeEnd); @Override long getLongCardinality(); @Override int getCardinality(); @Override void forEach(IntConsumer ic); ContainerPointer getContainerPointer(); @Override PeekableIntIterator getIntIterator(); @Override IntIterator getReverseIntIterator(); @Override RoaringBatchIterator getBatchIterator(); @Override long getLongSizeInBytes(); @Override int getSizeInBytes(); @Override int hashCode(); boolean hasRunCompression(); @Override boolean isEmpty(); @Override Iterator<Integer> iterator(); @Override RoaringBitmap limit(int maxcardinality); void or(final RoaringBitmap x2); static RoaringBitmap or(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap or(final Iterator<? extends RoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd); @Override long rankLong(int x); @Override long rangeCardinality(long start, long end); @Override int rank(int x); @Override void readExternal(ObjectInput in); @Override void remove(final int x); void remove(final long rangeStart, final long rangeEnd); @Deprecated void remove(final int rangeStart, final int rangeEnd); boolean removeRunCompression(); boolean runOptimize(); boolean contains(RoaringBitmap subset); @Override int select(int j); @Override long nextValue(int fromValue); @Override long previousValue(int fromValue); @Override long nextAbsentValue(int fromValue); @Override long previousAbsentValue(int fromValue); @Override int first(); @Override int last(); @Override void serialize(DataOutput out); @Override void serialize(ByteBuffer buffer); static long maximumSerializedSize(long cardinality, long universe_size); @Override int serializedSizeInBytes(); @Override int[] toArray(); @Override void append(char key, Container container); MutableRoaringBitmap toMutableRoaringBitmap(); @Override String toString(); @Override void trim(); @Override void writeExternal(ObjectOutput out); void xor(final RoaringBitmap x2); static RoaringBitmap xor(final Iterator<? extends RoaringBitmap> bitmaps,
      final long rangeStart, final long rangeEnd); @Deprecated static RoaringBitmap xor(final Iterator<? extends RoaringBitmap> bitmaps,
          final int rangeStart, final int rangeEnd);  }