Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Dec 8, 2023
2 parents 6605ea0 + f4b4440 commit 2d6c4ca
Show file tree
Hide file tree
Showing 141 changed files with 7,750 additions and 1,201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public interface AddSnapshotDeltaBitmap extends Bitmap, AutoCloseable {
* @return the roaring bitmap associated with this snapshot, can be null
* for empty value
*/
RoaringBitmap roaringBitmap();
RoaringBitmap64 roaringBitmap();
}

private class DeltaBitmap implements SimpleBitmap, AddSnapshotDeltaBitmap {
private boolean closed;
/**
* compressed memory bitmap storing the delta
*/
final RoaringBitmap snapshot = new RoaringBitmap();
final RoaringBitmap64 snapshot = new RoaringBitmap64();
/**
* next snapshot created after this one
*/
Expand All @@ -94,7 +94,7 @@ private class DeltaBitmap implements SimpleBitmap, AddSnapshotDeltaBitmap {
}

@Override
public RoaringBitmap roaringBitmap() {
public RoaringBitmap64 roaringBitmap() {
return snapshot;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,24 @@ public boolean access(long bitIndex) {

@Override
public long rank1(long pos) {
throw new NotImplementedException();
long c = 0;
for (int i = 0; i < pos; i++) {
if (access(i)) {
c++;
}
}
return c;
}

@Override
public long rank0(long pos) {
throw new NotImplementedException();
long c = 0;
for (int i = 0; i < pos; i++) {
if (!access(i)) {
c++;
}
}
return c;
}

@Override
Expand Down Expand Up @@ -264,7 +276,7 @@ public String getType() {
}

public long selectPrev1(long start) {
throw new NotImplementedException();
return select1(rank1(start));
}

public long getNumBits() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class BitmapFactoryImpl extends BitmapFactory {
protected ModifiableBitmap doCreateModifiableBitmap(String type) {
return switch (Objects.requireNonNullElse(type, HDTVocabulary.BITMAP_TYPE_PLAIN)) {
case HDTVocabulary.BITMAP_TYPE_PLAIN -> Bitmap375Big.memory(0);
case HDTVocabulary.BITMAP_TYPE_ROAR -> new RoaringBitmap();
case HDTVocabulary.BITMAP_TYPE_ROARING -> new RoaringBitmap64();
default -> throw new IllegalArgumentException("Implementation not found for Bitmap with type " + type);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,34 @@
* in memory, will throw a {@link NotImplementedException} if we try to add a
* non 0 value
*/
public class EmptyBitmap implements ModifiableBitmap {
public class EmptyBitmap implements ModifiableBitmap, ModifiableMultiLayerBitmap {
/**
* create empty bitmap simulating a bitmap of a particular size
*
* @param size the size
* @return bitmap
*/
public static ModifiableBitmap of(long size) {
return new EmptyBitmap(size);
public static EmptyBitmap of(long size) {
return new EmptyBitmap(size, 0);
}

/**
* create empty bitmap simulating a bitmap of a particular size
*
* @param size the size
* @param layers layers
* @return bitmap
*/
public static EmptyBitmap of(long size, long layers) {
return new EmptyBitmap(size, layers);
}

private long size;
private final long layers;

private EmptyBitmap(long size) {
private EmptyBitmap(long size, long layers) {
this.size = size;
this.layers = layers;
}

@Override
Expand Down Expand Up @@ -84,11 +97,56 @@ public long select1(long n) {
return -1;
}

@Override
public boolean access(long layer, long position) {
return false;
}

@Override
public long rank1(long layer, long position) {
return rank1(position);
}

@Override
public long rank0(long layer, long position) {
return rank0(position);
}

@Override
public long selectPrev1(long layer, long start) {
return selectPrev1(start);
}

@Override
public long selectNext1(long layer, long start) {
return selectNext1(start);
}

@Override
public long select0(long layer, long n) {
return select0(n);
}

@Override
public long select1(long layer, long n) {
return select1(n);
}

@Override
public long getNumBits() {
return size;
}

@Override
public long countOnes(long layer) {
return countOnes();
}

@Override
public long countZeros(long layer) {
return countZeros();
}

@Override
public long countOnes() {
return 0;
Expand Down Expand Up @@ -129,6 +187,16 @@ public void load(InputStream input, ProgressListener listener) {

@Override
public String getType() {
return HDTVocabulary.BITMAP_TYPE_PLAIN;
return layers == 0 ? HDTVocabulary.BITMAP_TYPE_PLAIN : HDTVocabulary.BITMAP_TYPE_ROARING_MULTI;
}

@Override
public long getLayersCount() {
return layers;
}

@Override
public void set(long layer, long position, boolean value) {
set(position, value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.the_qa_company.qendpoint.core.compact.bitmap;

import com.the_qa_company.qendpoint.core.hdt.HDTVocabulary;
import com.the_qa_company.qendpoint.core.listener.ProgressListener;
import com.the_qa_company.qendpoint.core.util.io.CloseMappedByteBuffer;
import com.the_qa_company.qendpoint.core.util.io.IOUtil;
import org.roaringbitmap.buffer.ImmutableRoaringBitmap;

import java.io.Closeable;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
* Mapped {@link Bitmap} wrapper for the {@link ImmutableRoaringBitmap}, not
* compatible with {@link RoaringBitmap64}
*
* @author Antoine Willerval
*/
public class MappedRoaringBitmap implements SimpleBitmap, Closeable {
private final CloseMappedByteBuffer buffer;
private final ImmutableRoaringBitmap rbm;

public MappedRoaringBitmap(CloseMappedByteBuffer buffer) {
this.buffer = buffer;
this.rbm = new ImmutableRoaringBitmap(buffer.getInternalBuffer());
}

public ImmutableRoaringBitmap getHandle() {
return rbm;
}

@Override
public boolean access(long position) {
return rbm.contains((int) position);
}

@Override
public long getNumBits() {
return rbm.last();
}

@Override
public long getSizeBytes() {
return rbm.serializedSizeInBytes() + 8;
}

@Override
public void save(OutputStream output, ProgressListener listener) throws IOException {
long size = rbm.serializedSizeInBytes();
IOUtil.writeLong(output, size);
rbm.serialize(new DataOutputStream(output));
}

@Override
public String getType() {
return HDTVocabulary.BITMAP_TYPE_ROARING;
}

@Override
public long select1(long n) {
long position = n - 1;
if (position == -1)
return -1;
if (position < rbm.getLongCardinality()) {
return rbm.select((int) position);
} else {
return rbm.select((int) rbm.getLongCardinality() - 1) + 1;
}
}

@Override
public long rank1(long position) {
if (position >= 0)
return rbm.rankLong((int) position);
return 0;
}

@Override
public long countOnes() {
return rbm.getLongCardinality();
}

@Override
public long selectPrev1(long start) {
return select1(rank1(start));
}

@Override
public long selectNext1(long start) {
long pos = rank1(start - 1);
if (pos < rbm.getLongCardinality())
return select1(pos + 1);
return -1;
}

@Override
public void close() throws IOException {
buffer.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.the_qa_company.qendpoint.core.compact.bitmap;

public interface ModifiableMultiLayerBitmap extends MultiLayerBitmap {
/**
* Set the value of the bit at position pos
*
* @param layer layer
* @param position pos
* @param value value
*/
void set(long layer, long position, boolean value);
}
Loading

0 comments on commit 2d6c4ca

Please sign in to comment.