use of com.carrotsearch.hppc.LongHashSet in project janusgraph by JanusGraph.
the class IDAuthorityTest method testSimpleIDAcquisition.
@Test
public void testSimpleIDAcquisition() throws BackendException {
final IDBlockSizer blockSizer = new InnerIDBlockSizer();
idAuthorities[0].setIDBlockSizer(blockSizer);
int numTrials = 100;
LongSet ids = new LongHashSet((int) blockSize * numTrials);
long previous = 0;
for (int i = 0; i < numTrials; i++) {
IDBlock block = idAuthorities[0].getIDBlock(0, 0, GET_ID_BLOCK_TIMEOUT);
checkBlock(block, ids);
if (hasEmptyUid) {
if (previous != 0)
assertEquals(previous + 1, block.getId(0));
previous = block.getId(block.numIds() - 1);
}
}
}
use of com.carrotsearch.hppc.LongHashSet in project janusgraph by JanusGraph.
the class VertexIDAssignerTest method testCustomIdAssignment.
private void testCustomIdAssignment(CustomIdStrategy idStrategy) {
LongSet vertexIds = new LongHashSet();
final long maxCount = idAssigner.getIDManager().getVertexCountBound();
long count = 1;
for (int trial = 0; trial < 10; trial++) {
final JanusGraph graph = getInMemoryGraph(true, true);
int numVertices = 1000;
final List<JanusGraphVertex> vertices = new ArrayList<>(numVertices);
try {
for (int i = 0; i < numVertices; i++, count++) {
final long userVertexId;
switch(idStrategy) {
case LOW:
userVertexId = count;
break;
case HIGH:
userVertexId = maxCount - count;
break;
default:
throw new RuntimeException("Unsupported custom id strategy: " + idStrategy);
}
final long id = idAssigner.getIDManager().toVertexId(userVertexId);
JanusGraphVertex next = graph.addVertex(T.id, id, "user_id", userVertexId);
vertices.add(next);
}
// Verify that ids are set, unique and consistent with user id basis
for (JanusGraphVertex v : vertices) {
assertTrue(v.hasId());
long id = v.longId();
assertTrue(id > 0 && id < Long.MAX_VALUE);
assertTrue(vertexIds.add(id));
assertEquals((long) v.value("user_id"), idAssigner.getIDManager().fromVertexId(id));
}
} finally {
graph.tx().rollback();
graph.close();
}
}
}
use of com.carrotsearch.hppc.LongHashSet in project cassandra by apache.
the class RangeIntersectionIteratorTest method testIntersectionOfRandomRanges.
private void testIntersectionOfRandomRanges(Strategy strategy) {
for (int attempt = 0; attempt < 16; attempt++) {
final ThreadLocalRandom random = ThreadLocalRandom.current();
final int maxRanges = random.nextInt(2, 16);
// generate randomize ranges
long[][] ranges = new long[maxRanges][];
for (int i = 0; i < ranges.length; i++) {
int rangeSize = random.nextInt(16, 512);
LongSet range = new LongHashSet(rangeSize);
for (int j = 0; j < rangeSize; j++) range.add(random.nextLong(0, 100));
ranges[i] = range.toArray();
Arrays.sort(ranges[i]);
}
List<Long> expected = new ArrayList<>();
// determine unique tokens which intersect every range
for (long token : ranges[0]) {
boolean intersectsAll = true;
for (int i = 1; i < ranges.length; i++) {
if (Arrays.binarySearch(ranges[i], token) < 0) {
intersectsAll = false;
break;
}
}
if (intersectsAll)
expected.add(token);
}
RangeIterator.Builder<Long, Token> builder = RangeIntersectionIterator.builder(strategy);
for (long[] range : ranges) builder.add(new LongIterator(range));
Assert.assertEquals(expected, convert(builder.build()));
}
}
use of com.carrotsearch.hppc.LongHashSet in project elasticsearch by elastic.
the class BinaryRangeAggregatorTests method doTestSortedSetRangeLeafCollector.
private void doTestSortedSetRangeLeafCollector(int maxNumValuesPerDoc) throws Exception {
final Set<BytesRef> termSet = new HashSet<>();
final int numTerms = TestUtil.nextInt(random(), maxNumValuesPerDoc, 100);
while (termSet.size() < numTerms) {
termSet.add(new BytesRef(TestUtil.randomSimpleString(random(), randomInt(2))));
}
final BytesRef[] terms = termSet.toArray(new BytesRef[0]);
Arrays.sort(terms);
final int numRanges = randomIntBetween(1, 10);
BinaryRangeAggregator.Range[] ranges = new BinaryRangeAggregator.Range[numRanges];
for (int i = 0; i < numRanges; ++i) {
ranges[i] = new BinaryRangeAggregator.Range(Integer.toString(i), randomBoolean() ? null : new BytesRef(TestUtil.randomSimpleString(random(), randomInt(2))), randomBoolean() ? null : new BytesRef(TestUtil.randomSimpleString(random(), randomInt(2))));
}
Arrays.sort(ranges, BinaryRangeAggregator.RANGE_COMPARATOR);
FakeSortedSetDocValues values = new FakeSortedSetDocValues(terms);
final int[] counts = new int[ranges.length];
SortedSetRangeLeafCollector collector = new SortedSetRangeLeafCollector(values, ranges, null) {
@Override
protected void doCollect(LeafBucketCollector sub, int doc, long bucket) throws IOException {
counts[(int) bucket]++;
}
};
final int[] expectedCounts = new int[ranges.length];
final int maxDoc = randomIntBetween(5, 10);
for (int doc = 0; doc < maxDoc; ++doc) {
LongHashSet ordinalSet = new LongHashSet();
final int numValues = randomInt(maxNumValuesPerDoc);
while (ordinalSet.size() < numValues) {
ordinalSet.add(random().nextInt(terms.length));
}
final long[] ords = ordinalSet.toArray();
Arrays.sort(ords);
values.ords = ords;
// simulate aggregation
collector.collect(doc);
// now do it the naive way
for (int i = 0; i < ranges.length; ++i) {
for (long ord : ords) {
BytesRef term = terms[(int) ord];
if ((ranges[i].from == null || ranges[i].from.compareTo(term) <= 0) && (ranges[i].to == null || ranges[i].to.compareTo(term) > 0)) {
expectedCounts[i]++;
break;
}
}
}
}
assertArrayEquals(expectedCounts, counts);
}
use of com.carrotsearch.hppc.LongHashSet in project elasticsearch by elastic.
the class HistogramIT method testSingleValuedFieldOrderedBySubAggregationDesc.
public void testSingleValuedFieldOrderedBySubAggregationDesc() throws Exception {
SearchResponse response = client().prepareSearch("idx").addAggregation(histogram("histo").field(SINGLE_VALUED_FIELD_NAME).interval(interval).order(Histogram.Order.aggregation("sum", false)).subAggregation(sum("sum").field(SINGLE_VALUED_FIELD_NAME))).execute().actionGet();
assertSearchResponse(response);
Histogram histo = response.getAggregations().get("histo");
assertThat(histo, notNullValue());
assertThat(histo.getName(), equalTo("histo"));
assertThat(histo.getBuckets().size(), equalTo(numValueBuckets));
LongHashSet visited = new LongHashSet();
double previousSum = Double.POSITIVE_INFINITY;
// TODO: use diamond once JI-9019884 is fixed
List<Histogram.Bucket> buckets = new ArrayList<>(histo.getBuckets());
for (int i = 0; i < numValueBuckets; ++i) {
Histogram.Bucket bucket = buckets.get(i);
assertThat(bucket, notNullValue());
long key = ((Number) bucket.getKey()).longValue();
assertTrue(visited.add(key));
int b = (int) (key / interval);
assertThat(bucket.getDocCount(), equalTo(valueCounts[b]));
assertThat(bucket.getAggregations().asList().isEmpty(), is(false));
Sum sum = bucket.getAggregations().get("sum");
assertThat(sum, notNullValue());
long s = 0;
for (int j = 0; j < numDocs; ++j) {
if ((j + 1) / interval == b) {
s += j + 1;
}
}
assertThat(sum.getValue(), equalTo((double) s));
assertThat(sum.getValue(), lessThanOrEqualTo(previousSum));
previousSum = s;
}
}
Aggregations