当前位置: 首页>>代码示例>>Java>>正文


Java IntArrays.swap方法代码示例

本文整理汇总了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 ) );
}
 
开发者ID:aikar,项目名称:fastutil-lite,代码行数:48,代码来源:ObjectArrays.java

示例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 ) );
 }
 
开发者ID:aikar,项目名称:fastutil-lite,代码行数:48,代码来源:LongArrays.java


注:本文中的it.unimi.dsi.fastutil.ints.IntArrays.swap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。