use of com.linkedin.pinot.core.util.IntDoubleIndexedPriorityQueue in project pinot by linkedin.
the class DoubleGroupByResultHolder method switchToMapMode.
/**
* Helper method to switch the storage from array mode to map mode.
*
* @param initialPriorityQueueSize Initial size of priority queue
*/
private void switchToMapMode(int initialPriorityQueueSize) {
_storageMode = StorageMode.MAP_STORAGE;
_resultMap = new Int2DoubleOpenHashMap(_resultHolderCapacity);
_priorityQueue = new IntDoubleIndexedPriorityQueue(initialPriorityQueueSize, _minHeap);
for (int id = 0; id < _resultHolderCapacity; id++) {
_resultMap.put(id, _resultArray[id]);
_priorityQueue.put(id, _resultArray[id]);
}
}
use of com.linkedin.pinot.core.util.IntDoubleIndexedPriorityQueue in project pinot by linkedin.
the class IntDoubleIndexedPriorityQueueTest method test.
/**
* Helper method builds the priority queue, randomly updates elements and
* then asserts the following:
* <ul>
* <li> Elements are popped from the priority queue in the expected order. </li>
* <li> Size of the priority queue is as expected (after elements are updated). </li>
* </ul>
* @param minHeap Min or max mode
*/
public void test(boolean minHeap) {
Random random = new Random(0);
IntDoubleIndexedPriorityQueue pq = new IntDoubleIndexedPriorityQueue(NUM_RECORDS, minHeap);
Int2DoubleOpenHashMap map = new Int2DoubleOpenHashMap(NUM_RECORDS);
// Initialize the priority queue.
for (int i = 0; i < NUM_RECORDS; i++) {
double value = random.nextDouble();
pq.put(i, value);
map.put(i, value);
}
// Update some records randomly
for (int i = 0; i < NUM_RECORDS; i++) {
int key = random.nextInt(NUM_RECORDS);
double value = random.nextDouble();
pq.put(key, value);
map.put(key, value);
}
// Transfer the map into list so it can be sorted.
List<Pairs.IntDoublePair> list = new ArrayList<>(NUM_RECORDS);
for (Int2DoubleMap.Entry entry : map.int2DoubleEntrySet()) {
list.add(new Pairs.IntDoublePair(entry.getKey(), entry.getValue()));
}
// Comparison for min heap is the same as that for ascending order.
boolean descendingOrder = !minHeap;
Collections.sort(list, new Pairs.IntDoubleComparator(descendingOrder));
// Ensure that elements are popped from priority queue in the expected order.
int i = 0;
while (!pq.isEmpty()) {
Pairs.IntDoublePair actual = pq.poll();
Pairs.IntDoublePair expected = list.get(i++);
Assert.assertEquals(actual.getIntValue(), expected.getIntValue());
Assert.assertEquals(actual.getDoubleValue(), expected.getDoubleValue());
}
// Assert that priority queue had expected number of elements.
Assert.assertEquals(i, list.size());
}
Aggregations