use of com.carrotsearch.hppc.LongOpenHashSet 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 LongOpenHashSet(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.LongOpenHashSet in project cassandra by apache.
the class TokenTreeTest method generateTree.
private static TokenTree generateTree(final long minToken, final long maxToken, boolean isStatic) throws IOException {
final SortedMap<Long, LongSet> toks = new TreeMap<Long, LongSet>() {
{
for (long i = minToken; i <= maxToken; i++) {
LongSet offsetSet = new LongOpenHashSet();
offsetSet.add(i);
put(i, offsetSet);
}
}
};
final TokenTreeBuilder builder = isStatic ? new StaticTokenTreeBuilder(new FakeCombinedTerm(toks)) : new DynamicTokenTreeBuilder(toks);
builder.finish();
final File treeFile = File.createTempFile("token-tree-get-test", "tt");
treeFile.deleteOnExit();
try (SequentialWriter writer = new SequentialWriter(treeFile, DEFAULT_OPT)) {
builder.write(writer);
writer.sync();
}
RandomAccessReader reader = null;
try {
reader = RandomAccessReader.open(treeFile);
return new TokenTree(new MappedBuffer(reader));
} finally {
FileUtils.closeQuietly(reader);
}
}
use of com.carrotsearch.hppc.LongOpenHashSet in project cassandra by apache.
the class DynamicTokenTreeBuilder method add.
public void add(Long token, long keyPosition) {
LongSet found = tokens.get(token);
if (found == null)
tokens.put(token, (found = new LongOpenHashSet(2)));
found.add(keyPosition);
}
Aggregations