Search in sources :

Example 26 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project neo4j by neo4j.

the class BaseCursorScan method reserveBatch.

@Override
public boolean reserveBatch(C cursor, int sizeHint) {
    requirePositive(sizeHint);
    LongIterator addedItems = ImmutableEmptyLongIterator.INSTANCE;
    if (hasChanges && !addedItemsConsumed) {
        // the idea here is to give each batch an exclusive range of the underlying
        // memory so that each thread can read in parallel without contention.
        int addedStart = addedChunk.getAndAdd(sizeHint);
        if (addedStart < addedItemsArray.length) {
            int batchSize = min(sizeHint, addedItemsArray.length - addedStart);
            sizeHint -= batchSize;
            addedItems = new RangeLongIterator(addedItemsArray, addedStart, batchSize);
        } else {
            addedItemsConsumed = true;
        }
    }
    return scanStore(cursor, sizeHint, addedItems);
}
Also used : RangeLongIterator(org.neo4j.collection.RangeLongIterator) LongIterator(org.eclipse.collections.api.iterator.LongIterator) ImmutableEmptyLongIterator(org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator) RangeLongIterator(org.neo4j.collection.RangeLongIterator)

Example 27 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project neo4j by neo4j.

the class RelationshipModifications method idsAsBatch.

static RelationshipBatch idsAsBatch(LongSet ids, IdDataDecorator idDataDecorator) {
    return new RelationshipBatch() {

        @Override
        public int size() {
            return ids.size();
        }

        @Override
        public boolean isEmpty() {
            return ids.isEmpty();
        }

        @Override
        public boolean contains(long id) {
            return ids.contains(id);
        }

        @Override
        public long first() {
            return ids.longIterator().next();
        }

        @Override
        public <E extends Exception> void forEach(RelationshipVisitor<E> relationship) throws E {
            LongIterator iterator = ids.longIterator();
            while (iterator.hasNext()) {
                long id = iterator.next();
                idDataDecorator.accept(id, relationship);
            }
        }
    };
}
Also used : RelationshipVisitor(org.neo4j.storageengine.api.RelationshipVisitor) LongIterator(org.eclipse.collections.api.iterator.LongIterator)

Example 28 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project mapdb by jankotek.

the class AbstractLongLongMapTestCase method longIterator.

@Test
public void longIterator() {
    MutableLongSet expected = LongHashSet.newSetWith(0L, 31L, 32L);
    MutableLongSet actual = LongHashSet.newSetWith();
    LongIterator iterator = this.map.longIterator();
    Assert.assertTrue(iterator.hasNext());
    actual.add(iterator.next());
    Assert.assertTrue(iterator.hasNext());
    actual.add(iterator.next());
    Assert.assertTrue(iterator.hasNext());
    actual.add(iterator.next());
    Assert.assertFalse(iterator.hasNext());
    Assert.assertEquals(expected, actual);
    Verify.assertThrows(NoSuchElementException.class, iterator::next);
    Verify.assertThrows(NoSuchElementException.class, () -> this.getEmptyMap().longIterator().next());
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) LongIterator(org.eclipse.collections.api.iterator.LongIterator) Test(org.junit.Test)

Example 29 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project mapdb by jankotek.

the class AbstractMutableLongCollectionTestCase method longIterator_throws_non_empty_collection.

@Override
@Test(expected = NoSuchElementException.class)
public void longIterator_throws_non_empty_collection() {
    super.longIterator_throws_non_empty_collection();
    MutableLongCollection collection = this.newWith();
    collection.add(1L);
    collection.add(2L);
    collection.add(3L);
    LongIterator iterator = collection.longIterator();
    while (iterator.hasNext()) {
        iterator.next();
    }
    iterator.next();
}
Also used : MutableLongCollection(org.eclipse.collections.api.collection.primitive.MutableLongCollection) LongIterator(org.eclipse.collections.api.iterator.LongIterator) MutableLongIterator(org.eclipse.collections.api.iterator.MutableLongIterator) Test(org.junit.Test)

Example 30 with LongIterator

use of org.eclipse.collections.api.iterator.LongIterator in project mapdb by jankotek.

the class AbstractLazyLongIterableTestCase method longIterator_throws.

@Test(expected = NoSuchElementException.class)
public void longIterator_throws() {
    LongIterator iterator = this.classUnderTest().longIterator();
    while (iterator.hasNext()) {
        iterator.next();
    }
    iterator.next();
}
Also used : LongIterator(org.eclipse.collections.api.iterator.LongIterator) Test(org.junit.Test)

Aggregations

LongIterator (org.eclipse.collections.api.iterator.LongIterator)45 Test (org.junit.Test)16 Test (org.junit.jupiter.api.Test)15 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)9 MutableLongIterator (org.eclipse.collections.api.iterator.MutableLongIterator)5 MutableLongCollection (org.eclipse.collections.api.collection.primitive.MutableLongCollection)4 LongSet (org.eclipse.collections.api.set.primitive.LongSet)3 IndexReaderStub (org.neo4j.kernel.api.impl.index.IndexReaderStub)3 LazyLongIterable (org.eclipse.collections.api.LazyLongIterable)2 LongIterable (org.eclipse.collections.api.LongIterable)2 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 RelationshipChangesForNode.createRelationshipChangesForNode (org.neo4j.kernel.impl.api.state.RelationshipChangesForNode.createRelationshipChangesForNode)2 IOException (java.io.IOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)1 ImmutableEmptyLongIterator (org.eclipse.collections.impl.iterator.ImmutableEmptyLongIterator)1 AbstractPrimitiveLongBaseIterator (org.neo4j.collection.PrimitiveLongCollections.AbstractPrimitiveLongBaseIterator)1 RangeLongIterator (org.neo4j.collection.RangeLongIterator)1