Skip to content

Commit 2d6c4ca

Browse files
committed
Merge remote-tracking branch 'origin/dev'
2 parents 6605ea0 + f4b4440 commit 2d6c4ca

File tree

141 files changed

+7750
-1201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+7750
-1201
lines changed

qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/AddSnapshotBitmap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ public interface AddSnapshotDeltaBitmap extends Bitmap, AutoCloseable {
6464
* @return the roaring bitmap associated with this snapshot, can be null
6565
* for empty value
6666
*/
67-
RoaringBitmap roaringBitmap();
67+
RoaringBitmap64 roaringBitmap();
6868
}
6969

7070
private class DeltaBitmap implements SimpleBitmap, AddSnapshotDeltaBitmap {
7171
private boolean closed;
7272
/**
7373
* compressed memory bitmap storing the delta
7474
*/
75-
final RoaringBitmap snapshot = new RoaringBitmap();
75+
final RoaringBitmap64 snapshot = new RoaringBitmap64();
7676
/**
7777
* next snapshot created after this one
7878
*/
@@ -94,7 +94,7 @@ private class DeltaBitmap implements SimpleBitmap, AddSnapshotDeltaBitmap {
9494
}
9595

9696
@Override
97-
public RoaringBitmap roaringBitmap() {
97+
public RoaringBitmap64 roaringBitmap() {
9898
return snapshot;
9999
}
100100

qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/Bitmap64Big.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,24 @@ public boolean access(long bitIndex) {
162162

163163
@Override
164164
public long rank1(long pos) {
165-
throw new NotImplementedException();
165+
long c = 0;
166+
for (int i = 0; i < pos; i++) {
167+
if (access(i)) {
168+
c++;
169+
}
170+
}
171+
return c;
166172
}
167173

168174
@Override
169175
public long rank0(long pos) {
170-
throw new NotImplementedException();
176+
long c = 0;
177+
for (int i = 0; i < pos; i++) {
178+
if (!access(i)) {
179+
c++;
180+
}
181+
}
182+
return c;
171183
}
172184

173185
@Override
@@ -264,7 +276,7 @@ public String getType() {
264276
}
265277

266278
public long selectPrev1(long start) {
267-
throw new NotImplementedException();
279+
return select1(rank1(start));
268280
}
269281

270282
public long getNumBits() {

qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/BitmapFactoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class BitmapFactoryImpl extends BitmapFactory {
3636
protected ModifiableBitmap doCreateModifiableBitmap(String type) {
3737
return switch (Objects.requireNonNullElse(type, HDTVocabulary.BITMAP_TYPE_PLAIN)) {
3838
case HDTVocabulary.BITMAP_TYPE_PLAIN -> Bitmap375Big.memory(0);
39-
case HDTVocabulary.BITMAP_TYPE_ROAR -> new RoaringBitmap();
39+
case HDTVocabulary.BITMAP_TYPE_ROARING -> new RoaringBitmap64();
4040
default -> throw new IllegalArgumentException("Implementation not found for Bitmap with type " + type);
4141
};
4242
}

qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/EmptyBitmap.java

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,34 @@
1818
* in memory, will throw a {@link NotImplementedException} if we try to add a
1919
* non 0 value
2020
*/
21-
public class EmptyBitmap implements ModifiableBitmap {
21+
public class EmptyBitmap implements ModifiableBitmap, ModifiableMultiLayerBitmap {
2222
/**
2323
* create empty bitmap simulating a bitmap of a particular size
2424
*
2525
* @param size the size
2626
* @return bitmap
2727
*/
28-
public static ModifiableBitmap of(long size) {
29-
return new EmptyBitmap(size);
28+
public static EmptyBitmap of(long size) {
29+
return new EmptyBitmap(size, 0);
30+
}
31+
32+
/**
33+
* create empty bitmap simulating a bitmap of a particular size
34+
*
35+
* @param size the size
36+
* @param layers layers
37+
* @return bitmap
38+
*/
39+
public static EmptyBitmap of(long size, long layers) {
40+
return new EmptyBitmap(size, layers);
3041
}
3142

3243
private long size;
44+
private final long layers;
3345

34-
private EmptyBitmap(long size) {
46+
private EmptyBitmap(long size, long layers) {
3547
this.size = size;
48+
this.layers = layers;
3649
}
3750

3851
@Override
@@ -84,11 +97,56 @@ public long select1(long n) {
8497
return -1;
8598
}
8699

100+
@Override
101+
public boolean access(long layer, long position) {
102+
return false;
103+
}
104+
105+
@Override
106+
public long rank1(long layer, long position) {
107+
return rank1(position);
108+
}
109+
110+
@Override
111+
public long rank0(long layer, long position) {
112+
return rank0(position);
113+
}
114+
115+
@Override
116+
public long selectPrev1(long layer, long start) {
117+
return selectPrev1(start);
118+
}
119+
120+
@Override
121+
public long selectNext1(long layer, long start) {
122+
return selectNext1(start);
123+
}
124+
125+
@Override
126+
public long select0(long layer, long n) {
127+
return select0(n);
128+
}
129+
130+
@Override
131+
public long select1(long layer, long n) {
132+
return select1(n);
133+
}
134+
87135
@Override
88136
public long getNumBits() {
89137
return size;
90138
}
91139

140+
@Override
141+
public long countOnes(long layer) {
142+
return countOnes();
143+
}
144+
145+
@Override
146+
public long countZeros(long layer) {
147+
return countZeros();
148+
}
149+
92150
@Override
93151
public long countOnes() {
94152
return 0;
@@ -129,6 +187,16 @@ public void load(InputStream input, ProgressListener listener) {
129187

130188
@Override
131189
public String getType() {
132-
return HDTVocabulary.BITMAP_TYPE_PLAIN;
190+
return layers == 0 ? HDTVocabulary.BITMAP_TYPE_PLAIN : HDTVocabulary.BITMAP_TYPE_ROARING_MULTI;
191+
}
192+
193+
@Override
194+
public long getLayersCount() {
195+
return layers;
196+
}
197+
198+
@Override
199+
public void set(long layer, long position, boolean value) {
200+
set(position, value);
133201
}
134202
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.the_qa_company.qendpoint.core.compact.bitmap;
2+
3+
import com.the_qa_company.qendpoint.core.hdt.HDTVocabulary;
4+
import com.the_qa_company.qendpoint.core.listener.ProgressListener;
5+
import com.the_qa_company.qendpoint.core.util.io.CloseMappedByteBuffer;
6+
import com.the_qa_company.qendpoint.core.util.io.IOUtil;
7+
import org.roaringbitmap.buffer.ImmutableRoaringBitmap;
8+
9+
import java.io.Closeable;
10+
import java.io.DataOutputStream;
11+
import java.io.IOException;
12+
import java.io.OutputStream;
13+
14+
/**
15+
* Mapped {@link Bitmap} wrapper for the {@link ImmutableRoaringBitmap}, not
16+
* compatible with {@link RoaringBitmap64}
17+
*
18+
* @author Antoine Willerval
19+
*/
20+
public class MappedRoaringBitmap implements SimpleBitmap, Closeable {
21+
private final CloseMappedByteBuffer buffer;
22+
private final ImmutableRoaringBitmap rbm;
23+
24+
public MappedRoaringBitmap(CloseMappedByteBuffer buffer) {
25+
this.buffer = buffer;
26+
this.rbm = new ImmutableRoaringBitmap(buffer.getInternalBuffer());
27+
}
28+
29+
public ImmutableRoaringBitmap getHandle() {
30+
return rbm;
31+
}
32+
33+
@Override
34+
public boolean access(long position) {
35+
return rbm.contains((int) position);
36+
}
37+
38+
@Override
39+
public long getNumBits() {
40+
return rbm.last();
41+
}
42+
43+
@Override
44+
public long getSizeBytes() {
45+
return rbm.serializedSizeInBytes() + 8;
46+
}
47+
48+
@Override
49+
public void save(OutputStream output, ProgressListener listener) throws IOException {
50+
long size = rbm.serializedSizeInBytes();
51+
IOUtil.writeLong(output, size);
52+
rbm.serialize(new DataOutputStream(output));
53+
}
54+
55+
@Override
56+
public String getType() {
57+
return HDTVocabulary.BITMAP_TYPE_ROARING;
58+
}
59+
60+
@Override
61+
public long select1(long n) {
62+
long position = n - 1;
63+
if (position == -1)
64+
return -1;
65+
if (position < rbm.getLongCardinality()) {
66+
return rbm.select((int) position);
67+
} else {
68+
return rbm.select((int) rbm.getLongCardinality() - 1) + 1;
69+
}
70+
}
71+
72+
@Override
73+
public long rank1(long position) {
74+
if (position >= 0)
75+
return rbm.rankLong((int) position);
76+
return 0;
77+
}
78+
79+
@Override
80+
public long countOnes() {
81+
return rbm.getLongCardinality();
82+
}
83+
84+
@Override
85+
public long selectPrev1(long start) {
86+
return select1(rank1(start));
87+
}
88+
89+
@Override
90+
public long selectNext1(long start) {
91+
long pos = rank1(start - 1);
92+
if (pos < rbm.getLongCardinality())
93+
return select1(pos + 1);
94+
return -1;
95+
}
96+
97+
@Override
98+
public void close() throws IOException {
99+
buffer.close();
100+
}
101+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.the_qa_company.qendpoint.core.compact.bitmap;
2+
3+
public interface ModifiableMultiLayerBitmap extends MultiLayerBitmap {
4+
/**
5+
* Set the value of the bit at position pos
6+
*
7+
* @param layer layer
8+
* @param position pos
9+
* @param value value
10+
*/
11+
void set(long layer, long position, boolean value);
12+
}

0 commit comments

Comments
 (0)