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