Search in sources :

Example 6 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class PrimitiveLongSetTest method shouldContainReallyBigLongValue.

@Test
public void shouldContainReallyBigLongValue() throws Exception {
    // GIVEN
    PrimitiveLongSet set = newSet(10);
    set.add(7416509207113022571L);
    // WHEN/THEN
    boolean existedBefore = set.contains(7620037383187366331L);
    boolean added = set.add(7620037383187366331L);
    boolean existsAfter = set.contains(7620037383187366331L);
    assertFalse("7620037383187366331 should not exist before adding here", existedBefore);
    assertTrue("7620037383187366331 should be reported as added here", added);
    assertTrue("7620037383187366331 should exist", existsAfter);
}
Also used : PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) Test(org.junit.Test)

Example 7 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class HopScotchHashingAlgorithmTest method figureOutGrowthThreshold.

private int figureOutGrowthThreshold() {
    final AtomicBoolean grew = new AtomicBoolean();
    Monitor monitor = new Monitor.Adapter() {

        @Override
        public boolean tableGrew(int fromCapacity, int toCapacity, int currentSize) {
            grew.set(true);
            return true;
        }
    };
    try (PrimitiveLongSet set = new PrimitiveLongHashSet(new LongKeyTable<>(DEFAULT_H, VALUE_MARKER), VALUE_MARKER, monitor)) {
        int i = 0;
        for (i = 0; !grew.get(); i++) {
            set.add(i * 3);
        }
        return i;
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Monitor(org.neo4j.collection.primitive.hopscotch.HopScotchHashingAlgorithm.Monitor) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet)

Example 8 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class HopScotchHashingAlgorithmTest method shouldSupportIteratingThroughResize.

@Test
public void shouldSupportIteratingThroughResize() throws Exception {
    // GIVEN
    int threshold = figureOutGrowthThreshold();
    TableGrowthAwareMonitor monitor = new TableGrowthAwareMonitor();
    PrimitiveLongSet set = new PrimitiveLongHashSet(new LongKeyTable<>(DEFAULT_H, VALUE_MARKER), VALUE_MARKER, monitor);
    Set<Long> added = new HashSet<>();
    for (int i = 0; i < threshold - 1; i++) {
        long value = i * 3;
        set.add(value);
        added.add(value);
    }
    // WHEN
    PrimitiveLongIterator iterator = set.iterator();
    Set<Long> iterated = new HashSet<>();
    for (int i = 0; i < threshold / 2; i++) {
        iterated.add(iterator.next());
    }
    assertFalse(monitor.checkAndReset());
    // will push it over the edge, to grow the table
    set.add((threshold - 1) * 3);
    assertTrue(monitor.checkAndReset());
    while (iterator.hasNext()) {
        iterated.add(iterator.next());
    }
    // THEN
    assertEquals(added, iterated);
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class LuceneLegacyIndex method query.

protected LegacyIndexHits query(Query query, String keyForDirectLookup, Object valueForDirectLookup, QueryContext additionalParametersOrNull) {
    List<EntityId> simpleTransactionStateIds = new ArrayList<>();
    Collection<EntityId> removedIdsFromTransactionState = Collections.emptySet();
    IndexSearcher fulltextTransactionStateSearcher = null;
    if (transaction != null) {
        if (keyForDirectLookup != null) {
            simpleTransactionStateIds.addAll(transaction.getAddedIds(this, keyForDirectLookup, valueForDirectLookup));
        } else {
            fulltextTransactionStateSearcher = transaction.getAdditionsAsSearcher(this, additionalParametersOrNull);
        }
        removedIdsFromTransactionState = keyForDirectLookup != null ? transaction.getRemovedIds(this, keyForDirectLookup, valueForDirectLookup) : transaction.getRemovedIds(this, query);
    }
    LegacyIndexHits idIterator = null;
    IndexReference searcher = null;
    dataSource.getReadLock();
    try {
        searcher = dataSource.getIndexSearcher(identifier);
    } finally {
        dataSource.releaseReadLock();
    }
    if (searcher != null) {
        try {
            // Gather all added ids from fulltextTransactionStateSearcher and simpleTransactionStateIds.
            PrimitiveLongSet idsModifiedInTransactionState = gatherIdsModifiedInTransactionState(simpleTransactionStateIds, fulltextTransactionStateSearcher, query);
            // Do the combined search from store and fulltext tx state
            DocToIdIterator hits = new DocToIdIterator(search(searcher, fulltextTransactionStateSearcher, query, additionalParametersOrNull, removedIdsFromTransactionState), removedIdsFromTransactionState, searcher, idsModifiedInTransactionState);
            idIterator = simpleTransactionStateIds.isEmpty() ? hits : new CombinedIndexHits(Arrays.<LegacyIndexHits>asList(hits, new ConstantScoreIterator(simpleTransactionStateIds, Float.NaN)));
        } catch (IOException e) {
            throw new RuntimeException("Unable to query " + this + " with " + query, e);
        }
    }
    // We've only got transaction state
    idIterator = idIterator == null ? new ConstantScoreIterator(simpleTransactionStateIds, 0) : idIterator;
    return idIterator;
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) LegacyIndexHits(org.neo4j.kernel.api.LegacyIndexHits)

Example 10 with PrimitiveLongSet

use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.

the class LuceneLegacyIndex method gatherIdsModifiedInTransactionState.

private PrimitiveLongSet gatherIdsModifiedInTransactionState(List<EntityId> simpleTransactionStateIds, IndexSearcher fulltextTransactionStateSearcher, Query query) throws IOException {
    // If there's no state them don't bother gathering it
    if (simpleTransactionStateIds.isEmpty() && fulltextTransactionStateSearcher == null) {
        return PrimitiveLongCollections.emptySet();
    }
    // There's potentially some state
    DocValuesCollector docValuesCollector = null;
    int fulltextSize = 0;
    if (fulltextTransactionStateSearcher != null) {
        docValuesCollector = new DocValuesCollector();
        fulltextTransactionStateSearcher.search(query, docValuesCollector);
        fulltextSize = docValuesCollector.getTotalHits();
        // Nah, no state
        if (simpleTransactionStateIds.isEmpty() && fulltextSize == 0) {
            return PrimitiveLongCollections.emptySet();
        }
    }
    PrimitiveLongSet set = longSet(simpleTransactionStateIds.size() + fulltextSize);
    // Add from simple tx state
    for (EntityId id : simpleTransactionStateIds) {
        set.add(id.id());
    }
    if (docValuesCollector != null) {
        // Add from fulltext tx state
        PrimitiveLongIterator valuesIterator = docValuesCollector.getValuesIterator(LuceneLegacyIndex.KEY_DOC_ID);
        while (valuesIterator.hasNext()) {
            set.add(valuesIterator.next());
        }
    }
    return set;
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) DocValuesCollector(org.neo4j.kernel.api.impl.index.collector.DocValuesCollector)

Aggregations

PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)36 Test (org.junit.Test)27 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)5 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)5 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)4 ReadOperations (org.neo4j.kernel.api.ReadOperations)4 Statement (org.neo4j.kernel.api.Statement)4 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 IOException (java.io.IOException)3 CCVar (apoc.algo.wcc.CCVar)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CCResult (apoc.result.CCResult)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringReader (java.io.StringReader)1 java.util (java.util)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1