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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations