Java Code Examples for com.carrotsearch.hppc.LongSet#add()

The following examples show how to use com.carrotsearch.hppc.LongSet#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IDAuthorityTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
private void checkBlock(IDBlock block, LongSet ids) {
    assertEquals(blockSize,block.numIds());
    for (int i=0;i<blockSize;i++) {
        long id = block.getId(i);
        assertEquals(id,block.getId(i));
        assertFalse(ids.contains(id));
        assertTrue(id<idUpperBound);
        assertTrue(id>0);
        ids.add(id);
    }
    if (hasEmptyUid) {
        assertEquals(blockSize-1,block.getId(block.numIds()-1)-block.getId(0));
    }
    try {
        block.getId(blockSize);
        fail();
    } catch (ArrayIndexOutOfBoundsException e) {}
}
 
Example 2
Source File: CombinedTerm.java    From sasi with Apache License 2.0 6 votes vote down vote up
public CombinedTerm(AbstractType<?> comparator, DataTerm term)
{
    this.comparator = comparator;
    this.term = term;
    this.tokens = new TreeMap<>();

    RangeIterator<Long, Token> tokens = term.getTokens();
    while (tokens.hasNext())
    {
        Token current = tokens.next();
        LongSet offsets = this.tokens.get(current.get());
        if (offsets == null)
            this.tokens.put(current.get(), (offsets = new LongOpenHashSet()));

        for (Long offset : ((TokenTree.OnDiskToken) current).getOffsets())
            offsets.add(offset);
    }
}
 
Example 3
Source File: SnapshotMatchers.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean matchesSafely(Translog.Snapshot snapshot) {
    try {
        final LongSet seqNoList = new LongHashSet();
        Translog.Operation op;
        while ((op = snapshot.next()) != null) {
            seqNoList.add(op.seqNo());
        }
        for (long i = minSeqNo; i <= maxSeqNo; i++) {
            if (seqNoList.contains(i) == false) {
                notFoundSeqNo.add(i);
            }
        }
        return notFoundSeqNo.isEmpty();
    } catch (IOException ex) {
        throw new ElasticsearchException("failed to read snapshot content", ex);
    }
}
 
Example 4
Source File: TokenTreeBuilder.java    From sasi with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 5
Source File: TokenTreeBuilder.java    From sasi with Apache License 2.0 5 votes vote down vote up
public void add(SortedMap<Long, LongSet> data)
{
    for (Map.Entry<Long, LongSet> newEntry : data.entrySet())
    {
        LongSet found = tokens.get(newEntry.getKey());
        if (found == null)
            tokens.put(newEntry.getKey(), (found = new LongOpenHashSet(4)));

        for (LongCursor offset : newEntry.getValue())
            found.add(offset.value);
    }
}
 
Example 6
Source File: TokenTreeTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
private static LongSet convert(long... values)
{
    LongSet result = new LongOpenHashSet(values.length);
    for (long v : values)
        result.add(v);

    return result;
}
 
Example 7
Source File: TokenTreeTest.java    From sasi with Apache License 2.0 5 votes vote down vote up
private static TokenTree generateTree(final long minToken, final long maxToken) 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 = new TokenTreeBuilder(toks).finish();
    final File treeFile = File.createTempFile("token-tree-get-test", "tt");
    treeFile.deleteOnExit();

    final SequentialWriter writer = new SequentialWriter(treeFile, 4096, false);
    builder.write(writer);
    writer.close();

    RandomAccessReader reader = null;

    try
    {
        reader = RandomAccessReader.open(treeFile);
        return new TokenTree(new MappedBuffer(reader));
    }
    finally
    {
        FileUtils.closeQuietly(reader);
    }
}
 
Example 8
Source File: TokenTreeTest.java    From sasi with Apache License 2.0 4 votes vote down vote up
@Test
public void buildWithMultipleMapsAndIterate() throws Exception
{
    final SortedMap<Long, LongSet> merged = new TreeMap<>();
    final TokenTreeBuilder builder = new TokenTreeBuilder(simpleTokenMap).finish();
    builder.add(collidingTokensMap);

    merged.putAll(collidingTokensMap);
    for (Map.Entry<Long, LongSet> entry : simpleTokenMap.entrySet())
    {
        if (merged.containsKey(entry.getKey()))
        {
            LongSet mergingOffsets  = entry.getValue();
            LongSet existingOffsets = merged.get(entry.getKey());

            if (mergingOffsets.equals(existingOffsets))
                continue;

            Set<Long> mergeSet = new HashSet<>();
            for (LongCursor merging : mergingOffsets)
                mergeSet.add(merging.value);

            for (LongCursor existing : existingOffsets)
                mergeSet.add(existing.value);

            LongSet mergedResults = new LongOpenHashSet();
            for (Long result : mergeSet)
                mergedResults.add(result);

            merged.put(entry.getKey(), mergedResults);
        }
        else
        {
            merged.put(entry.getKey(), entry.getValue());
        }
    }

    final Iterator<Pair<Long, LongSet>> tokenIterator = builder.iterator();
    final Iterator<Map.Entry<Long, LongSet>> listIterator = merged.entrySet().iterator();
    while (tokenIterator.hasNext() && listIterator.hasNext())
    {
        Pair<Long, LongSet> tokenNext = tokenIterator.next();
        Map.Entry<Long, LongSet> listNext = listIterator.next();

        Assert.assertEquals(listNext.getKey(), tokenNext.left);
        Assert.assertEquals(listNext.getValue(), tokenNext.right);
    }

    Assert.assertFalse("token iterator not finished", tokenIterator.hasNext());
    Assert.assertFalse("list iterator not finished", listIterator.hasNext());

}