Search in sources :

Example 1 with IntList

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

the class PersonAndPetKataTest method getAgeStatisticsOfPets.

@Test
public void getAgeStatisticsOfPets() {
    IntList ages = this.people.asLazy().flatCollect(Person::getPets).collectInt(Pet::getAge).toList();
    IntSet uniqueAges = ages.toSet();
    IntSummaryStatistics stats = ages.summaryStatistics();
    Assert.assertEquals(IntHashSet.newSetWith(1, 2, 3, 4), uniqueAges);
    Assert.assertEquals(stats.getMin(), ages.min());
    Assert.assertEquals(stats.getMax(), ages.max());
    Assert.assertEquals(stats.getSum(), ages.sum());
    Assert.assertEquals(stats.getAverage(), ages.average(), 0.0);
    Assert.assertEquals(stats.getCount(), ages.size());
    Assert.assertTrue(ages.allSatisfy(IntPredicates.greaterThan(0)));
    Assert.assertTrue(ages.allSatisfy(i -> i > 0));
    Assert.assertFalse(ages.anySatisfy(IntPredicates.equal(0)));
    Assert.assertFalse(ages.anySatisfy(i -> i == 0));
    Assert.assertTrue(ages.noneSatisfy(IntPredicates.lessThan(0)));
    Assert.assertTrue(ages.noneSatisfy(i -> i < 0));
    Assert.assertEquals(2.0d, ages.median(), 0.0);
}
Also used : Arrays(java.util.Arrays) Multimap(org.eclipse.collections.api.multimap.Multimap) HashMap(java.util.HashMap) ObjectIntPair(org.eclipse.collections.api.tuple.primitive.ObjectIntPair) Verify(org.eclipse.collections.impl.test.Verify) MutableBag(org.eclipse.collections.api.bag.MutableBag) MutableList(org.eclipse.collections.api.list.MutableList) Multimaps(org.eclipse.collections.impl.factory.Multimaps) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MutableSet(org.eclipse.collections.api.set.MutableSet) IntHashSet(org.eclipse.collections.impl.set.mutable.primitive.IntHashSet) RichIterable(org.eclipse.collections.api.RichIterable) HashBag(org.eclipse.collections.impl.bag.mutable.HashBag) Map(java.util.Map) PrimitiveTuples(org.eclipse.collections.impl.tuple.primitive.PrimitiveTuples) ImmutableBag(org.eclipse.collections.api.bag.ImmutableBag) PartitionMutableList(org.eclipse.collections.api.partition.list.PartitionMutableList) StringIterate(org.eclipse.collections.impl.utility.StringIterate) ImmutableIntBag(org.eclipse.collections.api.bag.primitive.ImmutableIntBag) Before(org.junit.Before) Predicates2(org.eclipse.collections.impl.block.factory.Predicates2) MutableListMultimap(org.eclipse.collections.api.multimap.list.MutableListMultimap) IntList(org.eclipse.collections.api.list.primitive.IntList) Set(java.util.Set) Bags(org.eclipse.collections.impl.factory.Bags) IntPredicates(org.eclipse.collections.impl.block.factory.primitive.IntPredicates) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MutableBagMultimap(org.eclipse.collections.api.multimap.bag.MutableBagMultimap) IntSet(org.eclipse.collections.api.set.primitive.IntSet) AbstractMap(java.util.AbstractMap) List(java.util.List) Lists(org.eclipse.collections.impl.factory.Lists) Sets(org.eclipse.collections.impl.factory.Sets) PartitionIterable(org.eclipse.collections.api.partition.PartitionIterable) IntSummaryStatistics(java.util.IntSummaryStatistics) Comparator(java.util.Comparator) Assert(org.junit.Assert) Collections(java.util.Collections) UnifiedSet(org.eclipse.collections.impl.set.mutable.UnifiedSet) IntSet(org.eclipse.collections.api.set.primitive.IntSet) IntSummaryStatistics(java.util.IntSummaryStatistics) IntList(org.eclipse.collections.api.list.primitive.IntList) Test(org.junit.Test)

Example 2 with IntList

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

the class PartitionedSeekTest method shouldCreateReasonablePartitionsWhenFromInclusiveMatchKeyInRoot.

@Test
void shouldCreateReasonablePartitionsWhenFromInclusiveMatchKeyInRoot() throws IOException {
    try (GBPTree<MutableLong, MutableLong> tree = instantiateTree()) {
        // given
        int numberOfRootChildren = random.nextInt(1, 10);
        int numberOfDesiredLevels = numberOfRootChildren == 0 ? 1 : random.nextInt(2, 4);
        int high = insertEntriesUntil(tree, numberOfDesiredLevels, numberOfRootChildren);
        List<MutableLong> rootKeys = getKeysOnLevel(tree, 0);
        int numberOfDesiredPartitions = random.nextInt(1, rootKeys.size());
        long from = layout.keySeed(rootKeys.get(0));
        long to = random.nextLong(from, high);
        // when
        Collection<Seeker<MutableLong, MutableLong>> seekers = tree.partitionedSeek(layout.key(from), layout.key(to), numberOfDesiredPartitions, NULL);
        // then
        IntList entryCountPerPartition = assertEntries(from, to, seekers);
        verifyEntryCountPerPartition(entryCountPerPartition);
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) IntList(org.eclipse.collections.api.list.primitive.IntList) Test(org.junit.jupiter.api.Test)

Example 3 with IntList

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

the class PartitionedSeekTest method shouldCreateReasonablePartitionsWhenToExclusiveMatchKeyInRoot.

@Test
void shouldCreateReasonablePartitionsWhenToExclusiveMatchKeyInRoot() throws IOException {
    try (GBPTree<MutableLong, MutableLong> tree = instantiateTree()) {
        // given
        int numberOfRootChildren = random.nextInt(1, 10);
        int numberOfDesiredLevels = numberOfRootChildren == 0 ? 1 : random.nextInt(2, 4);
        int high = insertEntriesUntil(tree, numberOfDesiredLevels, numberOfRootChildren);
        List<MutableLong> rootKeys = getKeysOnLevel(tree, 0);
        int numberOfDesiredPartitions = random.nextInt(1, rootKeys.size());
        long to = layout.keySeed(rootKeys.get(rootKeys.size() - 1));
        long from = random.nextLong(0, to);
        // when
        Collection<Seeker<MutableLong, MutableLong>> seekers = tree.partitionedSeek(layout.key(from), layout.key(to), numberOfDesiredPartitions, NULL);
        // then
        IntList entryCountPerSeeker = assertEntries(from, to, seekers);
        verifyEntryCountPerPartition(entryCountPerSeeker);
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) IntList(org.eclipse.collections.api.list.primitive.IntList) Test(org.junit.jupiter.api.Test)

Example 4 with IntList

use of org.eclipse.collections.api.list.primitive.IntList in project narchy by automenta.

the class TinyCountingTable method storeChain.

/**
 * stores the following chain of items, in TinyTable.
 *
 * @param bucketId
 * @param chainId
 * @param items
 */
private void storeChain(int bucketId, int chainId, LongList items) {
    // we change the chain in the table to be the same size as the new chain.
    IntList chainIndexes = adjustChainToItems(bucketId, chainId, items);
    // at this point we are sure that they are the same size.
    // System.out.println(Items[bucketId]);
    // assertTrue(chainIndexes.size() == items.length);
    // then we put the items in the appropriate indices.
    int is = Math.min(chainIndexes.size(), items.size());
    for (int i = 0; i < is; i++) {
        int itemOffset = chainIndexes.get(i);
        if (itemOffset < 0)
            return;
        this.set(bucketId, itemOffset, items.get(i));
    }
}
Also used : FingerPrint(il.technion.tinytable.hash.FingerPrint) IntList(org.eclipse.collections.api.list.primitive.IntList)

Example 5 with IntList

use of org.eclipse.collections.api.list.primitive.IntList in project narchy by automenta.

the class TinyTable method getChain.

long[] getChain(int bucketId, int chainId) {
    IntList chain = RankIndexing.getChain(chainId, I0[bucketId], IStar[bucketId], bucketCapacity);
    int s = chain.size();
    long[] result = new long[s];
    for (int i = 0; i < s; i++) {
        int itemOffset = chain.get(i);
        if (itemOffset < 0)
            return null;
        result[i] = this.get(bucketId, itemOffset);
    }
    return result;
}
Also used : FingerPrint(il.technion.tinytable.hash.FingerPrint) IntList(org.eclipse.collections.api.list.primitive.IntList)

Aggregations

IntList (org.eclipse.collections.api.list.primitive.IntList)10 MutableList (org.eclipse.collections.api.list.MutableList)5 Lists (org.eclipse.collections.impl.factory.Lists)5 Verify (org.eclipse.collections.impl.test.Verify)5 CharList (org.eclipse.collections.api.list.primitive.CharList)4 Functions (org.eclipse.collections.impl.block.factory.Functions)4 Assert (org.junit.Assert)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 MutableBag (org.eclipse.collections.api.bag.MutableBag)3 PartitionMutableList (org.eclipse.collections.api.partition.list.PartitionMutableList)3 MutableSet (org.eclipse.collections.api.set.MutableSet)3 Predicates2 (org.eclipse.collections.impl.block.factory.Predicates2)3 FingerPrint (il.technion.tinytable.hash.FingerPrint)2 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 MutableLong (org.apache.commons.lang3.mutable.MutableLong)2