本文整理汇总了Java中it.unimi.dsi.fastutil.ints.IntArrays.swap方法的典型用法代码示例。如果您正苦于以下问题:Java IntArrays.swap方法的具体用法?Java IntArrays.swap怎么用?Java IntArrays.swap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.ints.IntArrays
的用法示例。
在下文中一共展示了IntArrays.swap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compute
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected void compute() {
final K[] x = this.x;
final int len = to - from;
if ( len < PARALLEL_QUICKSORT_NO_FORK ) {
quickSortIndirect( perm, x, from, to );
return;
}
// Choose a partition element, v
int m = from + len / 2;
int l = from;
int n = to - 1;
int s = len / 8;
l = med3Indirect( perm, x, l, l + s, l + 2 * s );
m = med3Indirect( perm, x, m - s, m, m + s );
n = med3Indirect( perm, x, n - 2 * s, n - s, n );
m = med3Indirect( perm, x, l, m, n );
final K v = x[ perm[ m ] ];
// Establish Invariant: v* (<v)* (>v)* v*
int a = from, b = a, c = to - 1, d = c;
while ( true ) {
int comparison;
while ( b <= c && ( comparison = ( ((Comparable<K>)(x[ perm[ b ] ])).compareTo(v) ) ) <= 0 ) {
if ( comparison == 0 ) IntArrays.swap( perm, a++, b );
b++;
}
while ( c >= b && ( comparison = ( ((Comparable<K>)(x[ perm[ c ] ])).compareTo(v) ) ) >= 0 ) {
if ( comparison == 0 ) IntArrays.swap( perm, c, d-- );
c--;
}
if ( b > c ) break;
IntArrays.swap( perm, b++, c-- );
}
// Swap partition elements back to middle
int t;
s = Math.min( a - from, b - a );
IntArrays.swap( perm, from, b - s, s );
s = Math.min( d - c, to - d - 1 );
IntArrays.swap( perm, b, to - s, s );
// Recursively sort non-partition-elements
s = b - a;
t = d - c;
if ( s > 1 && t > 1 ) invokeAll( new ForkJoinQuickSortIndirect <K>( perm, x, from, from + s ), new ForkJoinQuickSortIndirect <K>( perm, x, to - t, to ) );
else if ( s > 1 ) invokeAll( new ForkJoinQuickSortIndirect <K>( perm, x, from, from + s ) );
else invokeAll( new ForkJoinQuickSortIndirect <K>( perm, x, to - t, to ) );
}
示例2: compute
import it.unimi.dsi.fastutil.ints.IntArrays; //导入方法依赖的package包/类
@Override
protected void compute() {
final long[] x = this.x;
final int len = to - from;
if ( len < PARALLEL_QUICKSORT_NO_FORK ) {
quickSortIndirect( perm, x, from, to );
return;
}
// Choose a partition element, v
int m = from + len / 2;
int l = from;
int n = to - 1;
int s = len / 8;
l = med3Indirect( perm, x, l, l + s, l + 2 * s );
m = med3Indirect( perm, x, m - s, m, m + s );
n = med3Indirect( perm, x, n - 2 * s, n - s, n );
m = med3Indirect( perm, x, l, m, n );
final long v = x[ perm[ m ] ];
// Establish Invariant: v* (<v)* (>v)* v*
int a = from, b = a, c = to - 1, d = c;
while ( true ) {
int comparison;
while ( b <= c && ( comparison = ( Long.compare((x[ perm[ b ] ]),(v)) ) ) <= 0 ) {
if ( comparison == 0 ) IntArrays.swap( perm, a++, b );
b++;
}
while ( c >= b && ( comparison = ( Long.compare((x[ perm[ c ] ]),(v)) ) ) >= 0 ) {
if ( comparison == 0 ) IntArrays.swap( perm, c, d-- );
c--;
}
if ( b > c ) break;
IntArrays.swap( perm, b++, c-- );
}
// Swap partition elements back to middle
int t;
s = Math.min( a - from, b - a );
IntArrays.swap( perm, from, b - s, s );
s = Math.min( d - c, to - d - 1 );
IntArrays.swap( perm, b, to - s, s );
// Recursively sort non-partition-elements
s = b - a;
t = d - c;
if ( s > 1 && t > 1 ) invokeAll( new ForkJoinQuickSortIndirect ( perm, x, from, from + s ), new ForkJoinQuickSortIndirect ( perm, x, to - t, to ) );
else if ( s > 1 ) invokeAll( new ForkJoinQuickSortIndirect ( perm, x, from, from + s ) );
else invokeAll( new ForkJoinQuickSortIndirect ( perm, x, to - t, to ) );
}