Search in sources :

Example 1 with LongOpenHashSet

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()));
    }
}
Also used : LongSet(com.carrotsearch.hppc.LongSet) Token(org.apache.cassandra.index.sasi.disk.Token) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) LongOpenHashSet(com.carrotsearch.hppc.LongOpenHashSet)

Example 2 with LongOpenHashSet

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);
    }
}
Also used : LongSet(com.carrotsearch.hppc.LongSet) SequentialWriter(org.apache.cassandra.io.util.SequentialWriter) RandomAccessReader(org.apache.cassandra.io.util.RandomAccessReader) LongOpenHashSet(com.carrotsearch.hppc.LongOpenHashSet) File(java.io.File) MappedBuffer(org.apache.cassandra.index.sasi.utils.MappedBuffer)

Example 3 with LongOpenHashSet

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);
}
Also used : LongSet(com.carrotsearch.hppc.LongSet) LongOpenHashSet(com.carrotsearch.hppc.LongOpenHashSet)

Aggregations

LongOpenHashSet (com.carrotsearch.hppc.LongOpenHashSet)3 LongSet (com.carrotsearch.hppc.LongSet)3 File (java.io.File)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 Token (org.apache.cassandra.index.sasi.disk.Token)1 MappedBuffer (org.apache.cassandra.index.sasi.utils.MappedBuffer)1 RandomAccessReader (org.apache.cassandra.io.util.RandomAccessReader)1 SequentialWriter (org.apache.cassandra.io.util.SequentialWriter)1