use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class CompressionResults method testSuperDense.
public static void testSuperDense() {
System.out.println("Sparse case... universe = [0," + universe_size + ")");
RoaringBitmap r = new RoaringBitmap();
int howmany = 100;
int gap = universe_size / howmany;
for (int i = 1; i < howmany; i++) {
r.add(i * gap + 1, ((i + 1) * gap));
}
System.out.println("Adding " + r.getCardinality() + " values partionned by " + howmany + " gaps of 1 ...");
System.out.println("As a bitmap it would look like 01111...11011111... ");
System.out.println("Bits used per value = " + F.format(r.getSizeInBytes() * 8.0 / r.getCardinality()));
r.runOptimize();
System.out.println("Bits used per value after run optimize = " + F.format(r.getSizeInBytes() * 8.0 / r.getCardinality()));
System.out.println("Bits used per gap after run optimize = " + F.format(r.getSizeInBytes() * 8.0 / howmany));
System.out.println("An uncompressed bitset might use " + F.format(universe_size * 1.0 / r.getCardinality()) + " bits per value set");
System.out.println();
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class CompressionResults method testSuperSparse.
public static void testSuperSparse() {
System.out.println("Sparse case... universe = [0," + universe_size + ")");
RoaringBitmap r = new RoaringBitmap();
int howmany = 100;
int gap = universe_size / howmany;
System.out.println("Adding " + howmany + " values separated by gaps of " + gap + "...");
System.out.println("As a bitmap it would look like 1000...001000... ");
for (int i = 1; i < howmany; i++) {
r.add(i * gap);
}
System.out.println("Bits used per value = " + F.format(r.getSizeInBytes() * 8.0 / howmany));
r.runOptimize();
System.out.println("Bits used per value after run optimize = " + F.format(r.getSizeInBytes() * 8.0 / howmany));
System.out.println("An uncompressed bitset might use " + F.format(universe_size * 1.0 / howmany) + " bits per value set");
System.out.println();
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class IntervalCheck method main.
public static void main(String[] args) {
// some bitmap
RoaringBitmap rr = RoaringBitmap.bitmapOf(1, 2, 3, 1000);
// we want to check if it intersects a given range [10,1000]
int low = 10;
int high = 1000;
RoaringBitmap range = new RoaringBitmap();
range.add((long) low, (long) high + 1);
//
//
// prints true if they intersect
System.out.println(RoaringBitmap.intersects(rr, range));
}
use of org.roaringbitmap.RoaringBitmap in project RoaringBitmap by RoaringBitmap.
the class SerializeToByteArrayExample method main.
public static void main(String[] args) {
RoaringBitmap mrb = RoaringBitmap.bitmapOf(1, 2, 3, 1000);
System.out.println("starting with bitmap " + mrb);
// to improve compression
mrb.runOptimize();
byte[] array = new byte[mrb.serializedSizeInBytes()];
try {
mrb.serialize(new java.io.DataOutputStream(new java.io.OutputStream() {
int c = 0;
@Override
public void close() {
}
@Override
public void flush() {
}
@Override
public void write(int b) {
array[c++] = (byte) b;
}
@Override
public void write(byte[] b) {
write(b, 0, b.length);
}
@Override
public void write(byte[] b, int off, int l) {
System.arraycopy(b, off, array, c, l);
c += l;
}
}));
} catch (IOException ioe) {
// should never happen because we write to a byte array
throw new RuntimeException("unexpected error while serializing to a byte array");
}
RoaringBitmap ret = new RoaringBitmap();
try {
ret.deserialize(new java.io.DataInputStream(new java.io.InputStream() {
int c = 0;
@Override
public int read() {
return array[c++] & 0xff;
}
@Override
public int read(byte[] b) {
return read(b, 0, b.length);
}
@Override
public int read(byte[] b, int off, int l) {
System.arraycopy(array, c, b, off, l);
c += l;
return l;
}
}));
} catch (IOException ioe) {
// should never happen because we read from a byte array
throw new RuntimeException("unexpected error while deserializing from a byte array");
}
if (!ret.equals(mrb))
throw new RuntimeException("bug");
System.out.println("decoded from byte array : " + ret);
}
use of org.roaringbitmap.RoaringBitmap in project presto by prestodb.
the class HiveManifestUtils method decompressFileNames.
static List<String> decompressFileNames(String compressedFileNames) {
// Check if the compressed fileNames string is a number
if (compressedFileNames.matches("\\d+")) {
long end = Long.parseLong(compressedFileNames);
if (end == 0) {
return ImmutableList.of("0");
}
return LongStream.range(0, end + 1).mapToObj(String::valueOf).collect(toImmutableList());
}
try {
RoaringBitmap roaringBitmap = new RoaringBitmap();
ByteBuffer byteBuffer = ByteBuffer.wrap(compressedFileNames.getBytes(ISO_8859_1));
roaringBitmap.deserialize(byteBuffer);
return Arrays.stream(roaringBitmap.toArray()).mapToObj(Integer::toString).collect(toImmutableList());
} catch (IOException e) {
throw new PrestoException(MALFORMED_HIVE_FILE_STATISTICS, "Failed de-compressing the file names in manifest");
}
}
Aggregations