use of it.unimi.dsi.fastutil.Swapper in project pinot by linkedin.
the class StarTreeDataTable method getSortedDocIds.
/**
* Helper method that returns an array of docIds sorted as per dimension sort order.
*
* @param mappedByteBuffer Mmap buffer containing docs to sort
* @param recordSizeInBytes Size of one record in bytes
* @param dimensionSizeInBytes Size of dimension columns in bytes
* @param numRecords Number of records
* @return DocId array in sorted order
*/
private int[] getSortedDocIds(final MMapBuffer mappedByteBuffer, final long recordSizeInBytes, final long dimensionSizeInBytes, int numRecords) {
final int[] ids = new int[numRecords];
for (int i = 0; i < ids.length; i++) {
ids[i] = i;
}
IntComparator comparator = new IntComparator() {
@Override
public int compare(int i1, int i2) {
long pos1 = (ids[i1]) * recordSizeInBytes;
long pos2 = (ids[i2]) * recordSizeInBytes;
mappedByteBuffer.copyTo(pos1, dimLbuf1, 0, dimensionSizeInBytes);
mappedByteBuffer.copyTo(pos2, dimLbuf2, 0, dimensionSizeInBytes);
for (int dimIndex : sortOrder) {
int v1 = flipEndiannessIfNeeded(dimLbuf1.getInt(dimIndex * V1Constants.Numbers.INTEGER_SIZE));
int v2 = flipEndiannessIfNeeded(dimLbuf2.getInt(dimIndex * V1Constants.Numbers.INTEGER_SIZE));
if (v1 != v2) {
return v1 - v2;
}
}
return 0;
}
@Override
public int compare(Integer o1, Integer o2) {
return compare(o1.intValue(), o2.intValue());
}
};
Swapper swapper = new Swapper() {
@Override
public void swap(int i, int j) {
int tmp = ids[i];
ids[i] = ids[j];
ids[j] = tmp;
}
};
Arrays.quickSort(0, numRecords, comparator, swapper);
return ids;
}
Aggregations