use of it.unimi.dsi.fastutil.ints.IntComparator 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;
}
use of it.unimi.dsi.fastutil.ints.IntComparator in project symja_android_library by axkr.
the class TableSlice method sortOn.
/**
* Sort this view in place without modifying or copying the underlying source table. Unlike {@link
* Table#sortOn(Sort)} which returns a copy of the table, this method sorts the view in place.
*
* @param key to sort on.
*/
public void sortOn(Sort key) {
Preconditions.checkArgument(!key.isEmpty());
if (key.size() == 1) {
IntComparator comparator = SortUtils.getComparator(table, key);
this.sortOrder = sortOn(comparator);
} else {
IntComparatorChain chain = SortUtils.getChain(table, key);
this.sortOrder = sortOn(chain);
}
}
use of it.unimi.dsi.fastutil.ints.IntComparator in project symja_android_library by axkr.
the class Table method sortOn.
/**
* Returns a copy of this table sorted using the given sort key.
*
* @param key to sort on.
* @return a sorted copy of this table.
*/
public Table sortOn(Sort key) {
Preconditions.checkArgument(!key.isEmpty());
if (key.size() == 1) {
IntComparator comparator = SortUtils.getComparator(this, key);
return sortOn(comparator);
}
IntComparatorChain chain = SortUtils.getChain(this, key);
return sortOn(chain);
}
use of it.unimi.dsi.fastutil.ints.IntComparator in project symja_android_library by axkr.
the class IntComparatorChain method compare.
public int compare(int o1, int o2) throws UnsupportedOperationException {
if (!this.isLocked) {
this.checkChainIntegrity();
this.isLocked = true;
}
Iterator<IntComparator> comparators = this.comparatorChain.iterator();
for (int comparatorIndex = 0; comparators.hasNext(); ++comparatorIndex) {
IntComparator comparator = comparators.next();
int retval = comparator.compare(o1, o2);
if (retval != 0) {
if (this.orderingBits.get(comparatorIndex)) {
if (retval > 0) {
retval = -1;
} else {
retval = 1;
}
}
return retval;
}
}
return 0;
}
use of it.unimi.dsi.fastutil.ints.IntComparator in project symja_android_library by axkr.
the class SortUtils method getChain.
/**
* Returns a comparator chain for sorting according to the given key
*/
public static IntComparatorChain getChain(Table table, Sort key) {
Iterator<Map.Entry<String, Sort.Order>> entries = key.iterator();
Map.Entry<String, Sort.Order> sort = entries.next();
Column<?> column = table.column(sort.getKey());
IntComparator comparator = rowComparator(column, sort.getValue());
IntComparatorChain chain = new IntComparatorChain(comparator);
while (entries.hasNext()) {
sort = entries.next();
chain.addComparator(rowComparator(table.column(sort.getKey()), sort.getValue()));
}
return chain;
}
Aggregations