Search in sources :

Example 26 with MutableLongList

use of org.eclipse.collections.api.list.primitive.MutableLongList in project neo4j by neo4j.

the class TxStateIndexChanges method indexUpdatesForRangeSeek.

// RANGE SEEK
static AddedAndRemoved indexUpdatesForRangeSeek(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, PropertyIndexQuery.RangePredicate<?> predicate, IndexOrder indexOrder) {
    NavigableMap<ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return EMPTY_ADDED_AND_REMOVED;
    }
    int size = descriptor.schema().getPropertyIds().length;
    RangeFilterValues rangeFilter = predicate == null ? RangeFilterValues.fromExists(size, equalityPrefix) : RangeFilterValues.fromRange(size, equalityPrefix, predicate);
    MutableLongList added = LongLists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    Map<ValueTuple, ? extends LongDiffSets> inRange = sortedUpdates.subMap(rangeFilter.lower, true, rangeFilter.upper, true);
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : inRange.entrySet()) {
        ValueTuple values = entry.getKey();
        Value rangeKey = values.valueAt(equalityPrefix.length);
        LongDiffSets diffForSpecificValue = entry.getValue();
        // Needs to manually filter for if lower or upper should be included
        // since we only wants to compare the first value of the key and not all of them for composite indexes
        boolean allowed = rangeFilter.allowedEntry(rangeKey, equalityPrefix.length);
        // The TreeMap cannot perfectly order multi-dimensional types (spatial) and need additional filtering out false positives
        if (allowed && (predicate == null || predicate.isRegularOrder() || predicate.acceptsValue(rangeKey))) {
            added.addAll(diffForSpecificValue.getAdded());
            removed.addAll(diffForSpecificValue.getRemoved());
        }
    }
    return new AddedAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) NavigableMap(java.util.NavigableMap) Map(java.util.Map) UnmodifiableMap(org.eclipse.collections.impl.UnmodifiableMap) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

Example 27 with MutableLongList

use of org.eclipse.collections.api.list.primitive.MutableLongList in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method createTestGraph.

@Override
public void createTestGraph(GraphDatabaseService graphDb) {
    try (Transaction tx = graphDb.beginTx()) {
        entityParams.createEntityIndex(tx, DEFAULT_ENTITY_TOKEN, PROP_NAME, PROP_INDEX_NAME);
        entityParams.createEntityIndex(tx, DEFAULT_ENTITY_TOKEN, PROP_2_NAME, PROP_2_INDEX_NAME);
        entityParams.createEntityIndex(tx, DEFAULT_ENTITY_TOKEN, PROP_3_NAME, PROP_3_INDEX_NAME);
        tx.commit();
    }
    try (Transaction tx = graphDb.beginTx()) {
        entityParams.createEntityIndex(tx, WHAT_TOKEN, EVER_PROP_NAME, WHAT_EVER_INDEX_NAME);
        tx.commit();
    }
    try (Transaction tx = graphDb.beginTx()) {
        entityParams.createCompositeEntityIndex(tx, PERSON_TOKEN, FIRSTNAME_PROP_NAME, SURNAME_PROP_NAME, COMPOSITE_INDEX_NAME);
        tx.commit();
    } catch (Exception e) {
        throw new AssertionError(e);
    }
    try (Transaction tx = graphDb.beginTx()) {
        tx.schema().awaitIndexesOnline(5, MINUTES);
        tx.commit();
    }
    try (Transaction tx = graphDb.beginTx()) {
        strOne = entityWithProp(tx, "one");
        strTwo1 = entityWithProp(tx, "two");
        strTwo2 = entityWithProp(tx, "two");
        strThree1 = entityWithProp(tx, "three");
        strThree2 = entityWithProp(tx, "three");
        strThree3 = entityWithProp(tx, "three");
        entityWithProp(tx, false);
        boolTrue = entityWithProp(tx, true);
        // Purposely mix ordering
        entityWithProp(tx, 3);
        entityWithProp(tx, 3);
        entityWithProp(tx, 3);
        entityWithProp(tx, 2);
        entityWithProp(tx, 2);
        entityWithProp(tx, 1);
        entityWithProp(tx, 4);
        num5 = entityWithProp(tx, 5);
        num6 = entityWithProp(tx, 6);
        num12a = entityWithProp(tx, 12.0);
        num12b = entityWithProp(tx, 12.0);
        entityWithProp(tx, 18);
        entityWithProp(tx, 24);
        entityWithProp(tx, 30);
        entityWithProp(tx, 36);
        entityWithProp(tx, 42);
        if (entityParams.tokenlessEntitySupported()) {
            strOneNoLabel = entityWithNoLabel(tx, "one");
        } else {
            strOneNoLabel = -1;
        }
        joeDalton = person(tx, "Joe", "Dalton");
        williamDalton = person(tx, "William", "Dalton");
        jackDalton = person(tx, "Jack", "Dalton");
        averellDalton = person(tx, "Averell", "Dalton");
        // Purposely mix order
        entityWithProp(tx, Values.pointValue(Cartesian, 1, 0));
        entityWithProp(tx, Values.pointValue(Cartesian, 0, 0));
        entityWithProp(tx, Values.pointValue(Cartesian, 0, 0));
        entityWithProp(tx, Values.pointValue(Cartesian, 0, 0));
        entityWithProp(tx, Values.pointValue(Cartesian, 0, 1));
        entityWithProp(tx, Values.pointValue(Cartesian_3D, 0, 0, 0));
        entityWithProp(tx, Values.pointValue(WGS84, 0, 0));
        entityWithProp(tx, Values.pointValue(WGS84_3D, 0, 0, 0));
        // Purposely mix order
        date891 = entityWithProp(tx, DateValue.date(1989, 3, 24));
        date86 = entityWithProp(tx, DateValue.date(1986, 11, 18));
        date892 = entityWithProp(tx, DateValue.date(1989, 3, 24));
        entityWithProp(tx, new String[] { "first", "second", "third" });
        entityWithProp(tx, new String[] { "fourth", "fifth", "sixth", "seventh" });
        MutableLongList listOfIds = LongLists.mutable.empty();
        listOfIds.add(entityWithWhatever(tx, "string"));
        listOfIds.add(entityWithWhatever(tx, false));
        listOfIds.add(entityWithWhatever(tx, 3));
        listOfIds.add(entityWithWhatever(tx, 13.0));
        whateverPoint = entityWithWhatever(tx, Values.pointValue(Cartesian, 1, 0));
        listOfIds.add(whateverPoint);
        listOfIds.add(entityWithWhatever(tx, DateValue.date(1989, 3, 24)));
        listOfIds.add(entityWithWhatever(tx, new String[] { "first", "second", "third" }));
        entitiesOfAllPropertyTypes = listOfIds.toArray();
        assertSameDerivedValue(POINT_1, POINT_2);
        entityWithProp(tx, "prop3", POINT_1.asObjectCopy());
        entityWithProp(tx, "prop3", POINT_2.asObjectCopy());
        entityWithProp(tx, "prop3", POINT_2.asObjectCopy());
        tx.commit();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) KernelException(org.neo4j.exceptions.KernelException)

Example 28 with MutableLongList

use of org.eclipse.collections.api.list.primitive.MutableLongList in project neo4j by neo4j.

the class IndexSamplingController method indexesToSample.

private LongList indexesToSample(IndexSamplingMode mode, IndexMap indexMap) {
    MutableLongList indexesToSample = LongLists.mutable.of();
    LongIterator allIndexes = indexMap.indexIds();
    while (allIndexes.hasNext()) {
        long indexId = allIndexes.next();
        if (shouldSampleIndex(mode, indexId)) {
            indexesToSample.add(indexId);
        }
    }
    return indexesToSample;
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongIterator(org.eclipse.collections.api.iterator.LongIterator)

Example 29 with MutableLongList

use of org.eclipse.collections.api.list.primitive.MutableLongList in project neo4j by neo4j.

the class TokenIndexAccessorTest method convertToExpectedEntitiesPerToken.

private static MutableLongObjectMap<MutableLongList> convertToExpectedEntitiesPerToken(MutableLongObjectMap<long[]> trackingStructure) {
    MutableLongObjectMap<MutableLongList> entitiesPerToken = LongObjectMaps.mutable.empty();
    trackingStructure.forEachKeyValue((entityId, tokens) -> {
        for (long token : tokens) {
            MutableLongList entities = entitiesPerToken.getIfAbsentPut(token, LongLists.mutable.empty());
            entities.add(entityId);
        }
    });
    return entitiesPerToken;
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList)

Example 30 with MutableLongList

use of org.eclipse.collections.api.list.primitive.MutableLongList in project neo4j by neo4j.

the class RelationshipLockHelperTest method shouldKeepListSorted.

@Test
void shouldKeepListSorted() {
    MutableLongList shuffle = LongLists.mutable.empty();
    int numIds = 1000;
    SortedLockList sortedListIterator = new SortedLockList(random.nextInt(numIds));
    for (int i = 0; i < numIds; i++) {
        int value = random.nextInt(numIds);
        sortedListIterator.add(value);
        shuffle.add(value);
        assertThat(sortedListIterator.underlyingList().toArray()).isSorted();
    }
    shuffle.shuffleThis();
    shuffle.forEach(value -> {
        sortedListIterator.remove(value);
        assertThat(sortedListIterator.underlyingList().toArray()).isSorted();
    });
    assertThat(sortedListIterator.underlyingList().toArray()).isEmpty();
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) SortedLockList(org.neo4j.internal.recordstorage.RelationshipLockHelper.SortedLockList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)30 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)8 Test (org.junit.jupiter.api.Test)8 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 ArrayList (java.util.ArrayList)5 LongLists (org.eclipse.collections.impl.factory.primitive.LongLists)5 Supplier (java.util.function.Supplier)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 LongList (org.eclipse.collections.api.list.primitive.LongList)4 Test (org.junit.Test)4 KernelException (org.neo4j.exceptions.KernelException)4 Transaction (org.neo4j.graphdb.Transaction)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 List (java.util.List)3 Map (java.util.Map)3 NavigableMap (java.util.NavigableMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 ExecutorService (java.util.concurrent.ExecutorService)3 Executors (java.util.concurrent.Executors)3 Future (java.util.concurrent.Future)3