Search in sources :

Example 11 with MutableLongList

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

the class RelationshipModifier method checkAndLockRelationshipsIfNodeIsGoingToBeDense.

private boolean checkAndLockRelationshipsIfNodeIsGoingToBeDense(NodeRecord node, RelationshipModifications.NodeRelationshipIds byNode, RecordAccess<RelationshipRecord, Void> relRecords, ResourceLocker locks, LockTracer lockTracer) {
    // We have an exclusively locked sparse not that may turn dense
    long nextRel = node.getNextRel();
    if (!isNull(nextRel)) {
        RelationshipRecord rel = relRecords.getOrLoad(nextRel, null, cursorContext).forReadingData();
        long nodeId = node.getId();
        if (!rel.isFirstInChain(nodeId)) {
            throw new IllegalStateException("Expected node " + rel + " to be first in chain for node " + nodeId);
        }
        int currentDegree = relCount(nodeId, rel);
        if (currentDegree + byNode.creations().size() >= denseNodeThreshold) {
            // The current length plus our additions in this transaction is above threshold, it will be converted so we need to lock all the relationships
            // Since it is sparse and locked we can trust this chain read to be stable
            // find all id's and lock them as we will create new chains based on type and direction
            MutableLongList ids = LongLists.mutable.withInitialCapacity(currentDegree);
            do {
                ids.add(nextRel);
                nextRel = relRecords.getOrLoad(nextRel, null, cursorContext).forReadingData().getNextRel(nodeId);
            } while (!isNull(nextRel));
            locks.acquireExclusive(lockTracer, RELATIONSHIP, ids.toSortedArray());
            return true;
        }
    }
    return false;
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) RelationshipLockHelper.findAndLockInsertionPoint(org.neo4j.internal.recordstorage.RelationshipLockHelper.findAndLockInsertionPoint)

Example 12 with MutableLongList

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

the class ArrayListIterateTest method collectLongOverOptimizeLimit.

@Test
public void collectLongOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableLongList actual = ArrayListIterate.collectLong(list, PrimitiveFunctions.unboxIntegerToLong());
    LongArrayList expected = new LongArrayList(list.size());
    for (int i = 0; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add((long) i);
    }
    Assert.assertEquals(expected, actual);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) Test(org.junit.Test)

Example 13 with MutableLongList

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

the class ArrayListIterateTest method collectLongWithTargetOverOptimizeLimit.

@Test
public void collectLongWithTargetOverOptimizeLimit() {
    ArrayList<Integer> list = new ArrayList<>(Interval.zeroTo(OVER_OPTIMIZED_LIMIT));
    MutableLongList target = new LongArrayList();
    MutableLongList actual = ArrayListIterate.collectLong(list, PrimitiveFunctions.unboxIntegerToLong(), target);
    LongArrayList expected = new LongArrayList(list.size());
    for (int i = 0; i <= OVER_OPTIMIZED_LIMIT; i++) {
        expected.add((long) i);
    }
    Assert.assertEquals(expected, actual);
    Assert.assertSame("Target sent as parameter was not returned as result", target, actual);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) DoubleArrayList(org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList) ShortArrayList(org.eclipse.collections.impl.list.mutable.primitive.ShortArrayList) IntArrayList(org.eclipse.collections.impl.list.mutable.primitive.IntArrayList) ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) CharArrayList(org.eclipse.collections.impl.list.mutable.primitive.CharArrayList) FloatArrayList(org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) BooleanArrayList(org.eclipse.collections.impl.list.mutable.primitive.BooleanArrayList) Test(org.junit.Test)

Example 14 with MutableLongList

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

the class ArrayListIterateTest method collectLongWithTarget.

@Test
public void collectLongWithTarget() {
    ArrayList<Integer> list = this.createIntegerList();
    MutableLongList target = new LongArrayList();
    MutableLongList actual = ArrayListIterate.collectLong(list, PrimitiveFunctions.unboxIntegerToLong(), target);
    Assert.assertSame("Target list sent as parameter not returned", target, actual);
    Assert.assertEquals(LongArrayList.newListWith(-1L, 0L, 4L), actual);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Test(org.junit.Test)

Example 15 with MutableLongList

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

the class ArrayListIterateTest method collectLong.

@Test
public void collectLong() {
    ArrayList<Integer> list = this.createIntegerList();
    MutableLongList actual = ArrayListIterate.collectLong(list, PrimitiveFunctions.unboxIntegerToLong());
    Assert.assertEquals(LongArrayList.newListWith(-1L, 0L, 4L), actual);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Test(org.junit.Test)

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