Search in sources :

Example 1 with MutableLongList

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

the class PrimitiveStreamsTest method toLongList.

@Test
public void toLongList() {
    MutableLongList list = PrimitiveStreams.mLongList(LongStream.rangeClosed(1, 10));
    Assert.assertEquals(IntInterval.oneTo(10).collectLong(i -> (long) i, LongLists.mutable.empty()), list);
    Assert.assertEquals(LongLists.immutable.ofAll(LongStream.rangeClosed(1, 10)), list);
}
Also used : IntStream(java.util.stream.IntStream) ImmutableLongList(org.eclipse.collections.api.list.primitive.ImmutableLongList) LongLists(org.eclipse.collections.impl.factory.primitive.LongLists) ImmutableIntStack(org.eclipse.collections.api.stack.primitive.ImmutableIntStack) MutableIntBag(org.eclipse.collections.api.bag.primitive.MutableIntBag) ImmutableDoubleList(org.eclipse.collections.api.list.primitive.ImmutableDoubleList) DoubleLists(org.eclipse.collections.impl.factory.primitive.DoubleLists) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) MutableDoubleStack(org.eclipse.collections.api.stack.primitive.MutableDoubleStack) IntSets(org.eclipse.collections.impl.factory.primitive.IntSets) ImmutableDoubleBag(org.eclipse.collections.api.bag.primitive.ImmutableDoubleBag) DoubleSets(org.eclipse.collections.impl.factory.primitive.DoubleSets) MutableIntSet(org.eclipse.collections.api.set.primitive.MutableIntSet) ImmutableLongSet(org.eclipse.collections.api.set.primitive.ImmutableLongSet) IntStacks(org.eclipse.collections.impl.factory.primitive.IntStacks) ImmutableDoubleStack(org.eclipse.collections.api.stack.primitive.ImmutableDoubleStack) ImmutableIntBag(org.eclipse.collections.api.bag.primitive.ImmutableIntBag) LongStream(java.util.stream.LongStream) MutableLongBag(org.eclipse.collections.api.bag.primitive.MutableLongBag) MutableDoubleSet(org.eclipse.collections.api.set.primitive.MutableDoubleSet) LongStacks(org.eclipse.collections.impl.factory.primitive.LongStacks) DoubleStacks(org.eclipse.collections.impl.factory.primitive.DoubleStacks) ImmutableDoubleSet(org.eclipse.collections.api.set.primitive.ImmutableDoubleSet) MutableIntStack(org.eclipse.collections.api.stack.primitive.MutableIntStack) Test(org.junit.Test) ImmutableIntList(org.eclipse.collections.api.list.primitive.ImmutableIntList) LongBags(org.eclipse.collections.impl.factory.primitive.LongBags) DoubleStream(java.util.stream.DoubleStream) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IntLists(org.eclipse.collections.impl.factory.primitive.IntLists) MutableDoubleList(org.eclipse.collections.api.list.primitive.MutableDoubleList) MutableLongStack(org.eclipse.collections.api.stack.primitive.MutableLongStack) IntInterval(org.eclipse.collections.impl.list.primitive.IntInterval) ImmutableLongBag(org.eclipse.collections.api.bag.primitive.ImmutableLongBag) LongSets(org.eclipse.collections.impl.factory.primitive.LongSets) ImmutableLongStack(org.eclipse.collections.api.stack.primitive.ImmutableLongStack) ImmutableIntSet(org.eclipse.collections.api.set.primitive.ImmutableIntSet) DoubleBags(org.eclipse.collections.impl.factory.primitive.DoubleBags) Assert(org.junit.Assert) IntBags(org.eclipse.collections.impl.factory.primitive.IntBags) MutableDoubleBag(org.eclipse.collections.api.bag.primitive.MutableDoubleBag) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) Test(org.junit.Test)

Example 2 with MutableLongList

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

the class AbstractListTestCase method collectLong.

@Override
public void collectLong() {
    super.collectLong();
    MutableLongList result = this.newWith(1, 2, 3, 4).collectLong(PrimitiveFunctions.unboxIntegerToLong());
    Assert.assertEquals(LongLists.mutable.of(1L, 2L, 3L, 4L), result);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList)

Example 3 with MutableLongList

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

the class TxStateIndexChanges method indexUpdatesForRangeSeekByPrefix.

// PREFIX
static AddedAndRemoved indexUpdatesForRangeSeekByPrefix(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, TextValue prefix, 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;
    ValueTuple floor = getCompositeValueTuple(size, equalityPrefix, prefix, true);
    ValueTuple maxString = getCompositeValueTuple(size, equalityPrefix, Values.MAX_STRING, false);
    MutableLongList added = LongLists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : sortedUpdates.subMap(floor, maxString).entrySet()) {
        Value key = entry.getKey().valueAt(equalityPrefix.length);
        // Needs to check type since the subMap might include non-TextValue for composite index
        if (key.valueGroup() == ValueGroup.TEXT && ((TextValue) key).startsWith(prefix)) {
            LongDiffSets diffSets = entry.getValue();
            added.addAll(diffSets.getAdded());
            removed.addAll(diffSets.getRemoved());
        } else {
            break;
        }
    }
    return new AddedAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) 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 4 with MutableLongList

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

the class IndexedIdGenerator method nextIdBatch.

@Override
public org.neo4j.internal.id.IdRange nextIdBatch(int size, boolean forceConsecutiveAllocation, CursorContext cursorContext) {
    assertNotReadOnly();
    if (forceConsecutiveAllocation) {
        long startId;
        do {
            startId = highId.getAndAdd(size);
        } while (IdValidator.hasReservedIdInRange(startId, startId + size));
        return new org.neo4j.internal.id.IdRange(EMPTY_LONG_ARRAY, startId, size);
    }
    long prev = -1;
    long startOfRange = -1;
    int rangeLength = 0;
    MutableLongList other = null;
    for (int i = 0; i < size; i++) {
        long id = nextId(cursorContext);
        if (other != null) {
            other.add(id);
        } else {
            if (i == 0) {
                prev = id;
                startOfRange = id;
                rangeLength = 1;
            } else {
                if (id == prev + 1) {
                    prev = id;
                    rangeLength++;
                } else {
                    other = LongLists.mutable.empty();
                    other.add(id);
                }
            }
        }
    }
    return new org.neo4j.internal.id.IdRange(other != null ? other.toArray() : EMPTY_LONG_ARRAY, startOfRange, rangeLength);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList)

Example 5 with MutableLongList

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

the class TokenIndexAccessorTest method verifyReaderSeesAllUpdates.

private void verifyReaderSeesAllUpdates(MutableLongObjectMap<MutableLongList> entitiesPerToken) throws Exception {
    for (long token : TOKENS) {
        MutableLongList expectedEntities = entitiesPerToken.getIfAbsent(token, LongLists.mutable::empty);
        assertReaderFindsExpected(token, expectedEntities);
    }
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList)

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