Skip to content

Commit

Permalink
Merge bf0ffd1 into 5c0d441
Browse files Browse the repository at this point in the history
  • Loading branch information
richardstartin committed Oct 23, 2018
2 parents 5c0d441 + bf0ffd1 commit e42e5ce
Show file tree
Hide file tree
Showing 35 changed files with 1,074 additions and 565 deletions.
16 changes: 2 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,8 @@ branches:
only:
- master

################
## Note the "&&". We want the script to fail fast if there is a technical error (javadoc, style)
## which saves time both for travis but also for developers looking at the error logs.
## Moreover, if the script makes it to mvn -f ./jmh/pom.xm, then **all** previous
## tests must be green.
#################
script: >
mvn javadoc:test-javadoc &&
mvn animal-sniffer:check &&
mvn checkstyle:check &&
mvn -f ./roaringbitmap/pom.xml test jacoco:report -Dcheckstyle.skip=true -Dmaven.javadoc.skip=true -Dgpg.skip=true &&
mvn -f ./real-roaring-dataset/pom.xml test -Dcheckstyle.skip=true &&
mvn -f ./jmh/pom.xml test -Dcheckstyle.skip=true -DBITMAP_TYPES=ROARING_ONLY &&
mvn -f ./memory/pom.xml test -Dcheckstyle.skip=true
script: >
mvn test jacoco:report -Dgpg.skip=true -DBITMAP_TYPES=ROARING_ONLY
after_success:
- mvn coveralls:report
5 changes: 2 additions & 3 deletions jmh/src/main/java/org/roaringbitmap/RandomData.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public static RoaringBitmap randomContiguousBitmap(int startKey, int numKeys, do
}

public static RoaringBitmap randomBitmap(int maxKeys, double rleLimit, double denseLimit) {
int[] keys = createSorted16BitInts(maxKeys);
return forKeys(keys, rleLimit, denseLimit);
return forKeys(createSorted16BitInts(maxKeys), rleLimit, denseLimit);
}

public static IntStream rleRegion() {
Expand Down Expand Up @@ -63,7 +62,7 @@ private static int[] createSorted16BitInts(int howMany) {
}

private static RoaringBitmap forKeys(int[] keys, double rleLimit, double denseLimit) {
DenseOrderedWriter writer = new DenseOrderedWriter();
RoaringBitmapWriter<RoaringBitmap> writer = RoaringBitmapWriter.writer().optimiseForArrays().get();
IntStream.of(keys)
.forEach(key -> {
double choice = ThreadLocalRandom.current().nextDouble();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.BitSet;
import java.util.stream.IntStream;

import static org.roaringbitmap.RoaringBitmapWriter.writer;

@State(Scope.Benchmark)
@Fork(value = 1, jvmArgsPrepend =
{
Expand Down Expand Up @@ -101,7 +103,7 @@ public RoaringBitmap roaringOffset() {
@Benchmark
public RoaringBitmap roaringBatchOrderedWriter() {
int[] buffer = new int[256];
DenseOrderedWriter writer = new DenseOrderedWriter();
RoaringBitmapWriter<RoaringBitmap> writer = writer().constantMemory().get();
for(int i = 0; i < bitSets.length; ++i) {
BitSetWithOffset bit = bitSets[i];
RoaringBatchIterator iterator = bit.bitmap.getBatchIterator();
Expand Down
40 changes: 7 additions & 33 deletions jmh/src/main/java/org/roaringbitmap/writer/WriteSequential.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@ public class WriteSequential {
public enum Scenario {
DENSE {
@Override
OrderedWriter newWriter() {
return new DenseOrderedWriter();
RoaringBitmapWriter<RoaringBitmap> newWriter() {
return RoaringBitmapWriter.writer().constantMemory().get();
}
},
SPARSE {
@Override
OrderedWriter newWriter() {
return new SparseOrderedWriter();
}
},
UNOPTIMIZED {
@Override
OrderedWriter newWriter() {
return new UnoptimizedOrderedWriter();
RoaringBitmapWriter<RoaringBitmap> newWriter() {
return RoaringBitmapWriter.writer().optimiseForArrays().get();
}
}
;
abstract OrderedWriter newWriter();
abstract RoaringBitmapWriter newWriter();
}

@Param({"100", "1000", "10000", "100000", "1000000", "10000000"})
Expand All @@ -42,7 +36,7 @@ OrderedWriter newWriter() {
@Param({"0.1", "0.5", "0.9"})
double randomness;

@Param({"DENSE", "SPARSE", "UNOPTIMIZED"})
@Param({"DENSE", "SPARSE"})
Scenario scenario;

int[] data;
Expand Down Expand Up @@ -91,32 +85,12 @@ public RoaringBitmap incrementalNativeAdd() {

@Benchmark
public RoaringBitmap incrementalUseOrderedWriter() {
OrderedWriter writer = scenario.newWriter();
RoaringBitmapWriter<RoaringBitmap> writer = scenario.newWriter();
for (int i = 0; i < data.length; ++i) {
writer.add(data[i]);
}
writer.flush();
return writer.getUnderlying();
}

public static class UnoptimizedOrderedWriter implements OrderedWriter {

private final RoaringBitmap roaringBitmap = new RoaringBitmap();

@Override
public RoaringBitmap getUnderlying() {
return roaringBitmap;
}

@Override
public void add(int value) {
roaringBitmap.add(value);
}

@Override
public void flush() {

}

}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.8</version>
<version>0.8.2</version>
<executions>
<execution>
<id>prepare-agent</id>
Expand Down
1 change: 1 addition & 0 deletions real-roaring-dataset/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<!-- Only RoaringBitmap jar is deployed -->
<maven.deploy.skip>true</maven.deploy.skip>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
<checkstyle.skip>true</checkstyle.skip>

<checkstyle.configLocation>${basedir}/../roaringbitmap/style/roaring_google_checks.xml</checkstyle.configLocation>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.roaringbitmap;

/**
* Key-value storage of 16 bit containers
* @param <T> the type of stored container
*/
public interface AppendableStorage<T> {

/**
* Appends the key and container to the storage, throws if the key is less
* than the current mark.
* @param key the key to append
* @param container the data to append
*/
void append(short key, T container);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ public interface BitmapDataProvider extends ImmutableBitmapDataProvider {
*
* @param x integer value
*/
public void add(int x);
void add(int x);

/**
* Add a range of values to the bitmap
* @param min the inclusive minimum value
* @param sup the exclusive maximum value
*/
void add(long min, long sup);

/**
* If present remove the specified integers (effectively, sets its bit value to false)
*
* @param x integer value representing the index in a bitmap
*/
public void remove(int x);
void remove(int x);

/**
* Recover allocated but unused memory.
*/
public void trim();
void trim();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package org.roaringbitmap;

import java.util.Arrays;

import static org.roaringbitmap.Util.*;


/**
* This class can be used to write quickly values to a bitmap.
* The values are expected to be (increasing) sorted order.
* Values are first written to a temporary internal buffer, but
* the underlying bitmap can forcefully synchronize by calling "flush"
* (although calling flush to often would defeat the performance
* purpose of this class).
* The main use case for an ConstantMemoryContainerAppender is to get bitmaps quickly.
* You should benchmark your particular use case to see if it helps.
*
* <pre>
* {@code
*
* //...
*
*
* RoaringBitmapWriter<RoaringBitmap> writer =
* RoaringBitmapWriter.writer().constantMemory().get();
* for (int i :....) {
* writer.add(i);
* }
* writer.flush(); // important
* }
* </pre>
*/
public class ConstantMemoryContainerAppender<T extends BitmapDataProvider
& AppendableStorage<Container>> implements RoaringBitmapWriter<T> {

private boolean doPartialSort;
private static final int WORD_COUNT = 1 << 10;
private final long[] bitmap;
private final T underlying;
private boolean dirty = false;
private int currentKey;

/**
* Initialize an ConstantMemoryContainerAppender with a receiving bitmap
*
* @param underlying bitmap where the data gets written
*/
ConstantMemoryContainerAppender(boolean doPartialSort, T underlying) {
this.underlying = underlying;
this.doPartialSort = doPartialSort;
this.bitmap = new long[WORD_COUNT];
}

/**
* Grab a reference to the underlying bitmap
*
* @return the underlying bitmap
*/
@Override
public T getUnderlying() {
return underlying;
}

/**
* Adds the value to the underlying bitmap. The data might
* be added to a temporary buffer. You should call "flush"
* when you are done.
*
* @param value the value to add.
*/
@Override
public void add(int value) {
int key = toIntUnsigned(highbits(value));
if (key != currentKey) {
if (key < currentKey) {
underlying.add(value);
return;
} else {
appendToUnderlying();
currentKey = key;
}
}
int low = toIntUnsigned(lowbits(value));
bitmap[(low >>> 6)] |= (1L << low);
dirty = true;
}

@Override
public void addMany(int... values) {
if (doPartialSort) {
partialRadixSort(values);
}
for (int value : values) {
add(value);
}
}

@Override
public void add(long min, long max) {
appendToUnderlying();
underlying.add(min, max);
int mark = (int)((max >>> 16) + 1);
if (currentKey < mark) {
currentKey = mark;
}
}

/**
* Ensures that any buffered additions are flushed to the underlying bitmap.
*/
@Override
public void flush() {
currentKey += appendToUnderlying();
}

private Container chooseBestContainer() {
Container container = new BitmapContainer(bitmap, -1)
.repairAfterLazy().runOptimize();
return container instanceof BitmapContainer ? container.clone() : container;
}

private int appendToUnderlying() {
if (dirty) {
assert currentKey <= 0xFFFF;
underlying.append((short) currentKey, chooseBestContainer());
Arrays.fill(bitmap, 0L);
dirty = false;
return 1;
}
return 0;
}
}
3 changes: 2 additions & 1 deletion roaringbitmap/src/main/java/org/roaringbitmap/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
/**
* Base container class.
*/
public abstract class Container implements Iterable<Short>, Cloneable, Externalizable {
public abstract class Container implements Iterable<Short>, Cloneable, Externalizable,
WordStorage<Container> {

/**
* Create a container initialized with a range of consecutive values
Expand Down
Loading

0 comments on commit e42e5ce

Please sign in to comment.