本文整理汇总了Java中cern.colt.Sorting类的典型用法代码示例。如果您正苦于以下问题:Java Sorting类的具体用法?Java Sorting怎么用?Java Sorting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sorting类属于cern.colt包,在下文中一共展示了Sorting类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: report
import cern.colt.Sorting; //导入依赖的package包/类
@Override
public Object report(Argument args[], Context context)
throws ExtensionException, LogoException {
LogoStatsTbl tbl = StatsExtension.getTblFromArgument(args[0]);
int varNumber = ExtnUtils.getVarNumberFromArg(tbl, args[1]);
double pcnt;
try {
pcnt = args[2].getDoubleValue();
} catch (LogoException e) {
throw new ExtensionException(e.getMessage());
}
pcnt /= 100.0;
if (pcnt < 0.0 || pcnt > 100.0) {
throw new ExtensionException("The percent must be between"
+ " 0.0 and 100.0, inclusive.");
}
double[] X = tbl.getColumn(varNumber, true);
Sorting.mergeSort(X, 0, X.length);
return Descriptive.quantile(new DoubleArrayList(X), pcnt);
}
示例2: get
import cern.colt.Sorting; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public ImmutableSparseVector get( final Object o ) {
final T summary = (T)o;
final int nTerms = summary.size();
double[] scores = new double[ nTerms ];
final double[] scores2 = new double[ nTerms ];
int[] terms = new int[ nTerms ];
//final int totalOccourrences = summary.length();
for ( int i = 0; i < nTerms; i++ ) {
final int term = summary.term( i );
final int count = summary.count( i );
terms[ i ] = term;
scores[ i ] = scores2[ i ] = (double)count;// / (double)totalOccourrences;
}
double threshold = 0.0;
if ( cutAt > nTerms && cutAt < Integer.MAX_VALUE ) {
Sorting.mergeSort( scores2, 0, scores2.length );
threshold = scores2[ scores2.length - cutAt + 1 ];
}
return ImmutableSparseVector.getInstance( terms, scores, totalTerms, threshold, summary.id() );
}
示例3: getOrder
import cern.colt.Sorting; //导入依赖的package包/类
/**
* Returns the order of the given sensitive attribute in the original dataset.
* Required for t-closeness.
*
* @param attribute
* @return distribution
*/
public int[] getOrder(String attribute) {
// Check
if (!indexesSensitive.containsKey(attribute)) {
throw new IllegalArgumentException("Attribute " + attribute + " is not sensitive");
}
// Prepare
final String[] dictionary = dataAnalyzed.getDictionary().getMapping()[indexesSensitive.get(attribute)];
final DataType<?> type = this.dataTypesSensitive.get(attribute);
// Init
int[] order = new int[dictionary.length];
for (int i = 0; i < order.length; i++) {
order[i] = i;
}
// Sort
Sorting.mergeSort(order, 0, order.length, new IntComparator() {
@Override public int compare(int arg0, int arg1) {
String value1 = dictionary[arg0];
String value2 = dictionary[arg1];
try {
return type.compare(value1, value2);
} catch (NumberFormatException | ParseException e) {
throw new IllegalStateException(e);
}
}
});
// Return
return order;
}
示例4: run
import cern.colt.Sorting; //导入依赖的package包/类
/**
* Run the benchmark
* @param size
*/
private static void run(int size) {
// Prepare
int[][] arrays = new int[REPETITIONS*3+3][];
for (int j=0; j<arrays.length; j++){
arrays[j] = new int[size];
}
Random random = new Random();
for (int j=0; j<arrays.length; j++){
for (int i=0; i<size; i++){
arrays[j][i] = random.nextInt();
}
}
int index = 0;
// Run colt merge sort
BENCHMARK.addRun(size, "ColtMergeSort");
Sorting.mergeSort(arrays[index++], 0, size); // Warm up
for (int i = 0; i < REPETITIONS; i++) {
BENCHMARK.startTimer(TIME);
Sorting.mergeSort(arrays[index++], 0, size);
BENCHMARK.addStopTimer(TIME);
}
// Run colt quick sort
IntComparator c = new IntComparator(){
public int compare(int arg0, int arg1) {
int result = arg0 < arg1 ? -1 : 0;
result = arg0 > arg1 ? +1 : 0;
return result;
}
};
BENCHMARK.addRun(size, "ColtQuickSort");
Sorting.quickSort(arrays[index++], 0, size, c); // Warm up
for (int i = 0; i < REPETITIONS; i++) {
BENCHMARK.startTimer(TIME);
Sorting.quickSort(arrays[index++], 0, size, c);
BENCHMARK.addStopTimer(TIME);
}
// Run java quick sort
BENCHMARK.addRun(size, "JavaQuickSort");
Sorting.mergeSort(arrays[index++], 0, size); // Warm up
for (int i = 0; i < REPETITIONS; i++) {
BENCHMARK.startTimer(TIME);
Arrays.sort(arrays[index++]);
BENCHMARK.addStopTimer(TIME);
}
}