use of com.linkedin.pinot.common.utils.Pairs.IntDoubleComparator in project pinot by linkedin.
the class DoubleGroupByResultHolderTest method testTrimResults.
/**
* Helper method for testing trim results.
* Sets a max size on the result holder and adds more values than the max size of the result holder.
* Then asserts that the right results survive after trimming.
*
* @param minOrder
*/
void testTrimResults(final boolean minOrder) {
GroupByResultHolder resultHolder = new DoubleGroupByResultHolder(INITIAL_CAPACITY, MAX_CAPACITY, INITIAL_CAPACITY, DEFAULT_VALUE, minOrder);
List<IntDoublePair> expected = new ArrayList<>(MAX_CAPACITY);
for (int i = 0; i < INITIAL_CAPACITY; i++) {
resultHolder.setValueForKey(i, _expected[i]);
expected.add(new IntDoublePair(i, _expected[i]));
}
// This will trigger the transition from array based to map based storage within the result holder.
resultHolder.ensureCapacity(MAX_CAPACITY);
for (int i = INITIAL_CAPACITY; i < MAX_CAPACITY; i++) {
resultHolder.setValueForKey(i, _expected[i]);
expected.add(new IntDoublePair(i, _expected[i]));
}
// Trim the results.
resultHolder.trimResults();
// Sort the input
Collections.sort(expected, new IntDoubleComparator(!minOrder));
// Ensure that all the correct group keys survive after trimming.
for (int i = 0; i < INITIAL_CAPACITY; i++) {
IntDoublePair pair = expected.get(i);
Assert.assertEquals(resultHolder.getDoubleResult(pair.getIntValue()), pair.getDoubleValue());
}
}
Aggregations