it.unimi.dsi.fastutil.Arrays.quickSort()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中it.unimi.dsi.fastutil.Arrays.quickSort()方法的一些代码示例,展示了Arrays.quickSort()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Arrays.quickSort()方法的具体详情如下:
包路径:it.unimi.dsi.fastutil.Arrays
类名称:Arrays
方法名:quickSort

Arrays.quickSort介绍

[英]Sorts the specified range of elements using the specified swapper and according to the order induced by the specified comparator using quicksort.

The sorting algorithm is a tuned quicksort adapted from Jon L. Bentley and M. Douglas McIlroy, “Engineering a Sort Function”, Software: Practice and Experience, 23(11), pages 1249−1265, 1993.
[中]使用指定的交换程序并根据使用快速排序的指定比较器产生的顺序对指定范围的元素进行排序。
排序算法是根据Jon L.Bentley和M.Douglas McIlroy的《设计排序功能》改编的优化快速排序,软件:实践与经验,23(11),第1249页−1265, 1993.

代码示例

代码示例来源:origin: prestodb/presto

private static void sort(final double[] values, final double[] weights, int nextIndex)
{
  // sort x and y value arrays based on the x values
  Arrays.quickSort(0, nextIndex, new AbstractIntComparator()
  {
    @Override
    public int compare(int a, int b)
    {
      return Doubles.compare(values[a], values[b]);
    }
  }, new Swapper()
  {
    @Override
    public void swap(int a, int b)
    {
      double temp = values[a];
      values[a] = values[b];
      values[b] = temp;
      temp = weights[a];
      weights[a] = weights[b];
      weights[b] = temp;
    }
  });
}

代码示例来源:origin: apache/incubator-pinot

Arrays.quickSort(0, _numDocs, comparator, swapper);

代码示例来源:origin: apache/incubator-pinot

sortedDocIds[i] = startDocId + i;
it.unimi.dsi.fastutil.Arrays.quickSort(0, numDocs, new IntComparator() {
 @Override
 public int compare(int i1, int i2) {

代码示例来源:origin: apache/incubator-pinot

sortedDocIds[j] = temp;
};
Arrays.quickSort(0, numDocs, comparator, swapper);

代码示例来源:origin: lenskit/lenskit

@Override
public EntityCollection build() {
  if (!isSorted) {
    Arrays.quickSort(0, size, this::compareIds, new SortSwap());
  }
  AttrStore[] stores = new AttrStore[storeBuilders.length];
  PackIndex[] indexes = new PackIndex[needIndex.length];
  for (int i = 0; i < stores.length; i++) {
    stores[i] = storeBuilders[i].build();
    if (needIndex[i]) {
      indexes[i] = buildIndex(i);
    }
  }
  return new PackedEntityCollection(entityType, attributes, stores, indexes, entityBuilderClass);
}

代码示例来源:origin: lenskit/lenskit

/**
 * Create a new {@link Long2DoubleSortedArrayMap} from unsorted key and value
 * arrays. The provided arrays will be modified and should not be used
 * by the client after this operation has completed. The key domain of
 * the new {@link Long2DoubleSortedArrayMap} will be the same as {@code keys}.
 *
 * @param keys Array of entry keys. This should be duplicate-free.
 * @param values The values of the vector, in key order.
 * @return A sparse vector backed by the provided arrays.
 * @throws IllegalArgumentException if there is a problem with the provided
 *                                  arrays (length mismatch, etc.).
 */
public static Long2DoubleSortedArrayMap wrapUnsorted(long[] keys, double[] values) {
  IdComparator comparator = new IdComparator(keys);
  ParallelSwapper swapper = new ParallelSwapper(keys, values);
  quickSort(0, keys.length, comparator, swapper);
  int n = keys.length;
  for (int i = 1; i < n; i++) {
    if (keys[i-1] == keys[i]) {
      throw new IllegalArgumentException("duplicate keys");
    }
  }
  SortedKeyIndex index = SortedKeyIndex.wrap(keys, keys.length);
  return wrap(index, values);
}

代码示例来源:origin: prestosql/presto

private static void sort(final double[] values, final double[] weights, int nextIndex)
{
  // sort x and y value arrays based on the x values
  Arrays.quickSort(0, nextIndex, new AbstractIntComparator()
  {
    @Override
    public int compare(int a, int b)
    {
      return Doubles.compare(values[a], values[b]);
    }
  }, new Swapper()
  {
    @Override
    public void swap(int a, int b)
    {
      double temp = values[a];
      values[a] = values[b];
      values[b] = temp;
      temp = weights[a];
      weights[a] = weights[b];
      weights[b] = temp;
    }
  });
}

代码示例来源:origin: io.prestosql/presto-main

private static void sort(final double[] values, final double[] weights, int nextIndex)
{
  // sort x and y value arrays based on the x values
  Arrays.quickSort(0, nextIndex, new AbstractIntComparator()
  {
    @Override
    public int compare(int a, int b)
    {
      return Doubles.compare(values[a], values[b]);
    }
  }, new Swapper()
  {
    @Override
    public void swap(int a, int b)
    {
      double temp = values[a];
      values[a] = values[b];
      values[b] = temp;
      temp = weights[a];
      weights[a] = weights[b];
      weights[b] = temp;
    }
  });
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

private static void sort(final double[] values, final double[] weights, int nextIndex)
{
  // sort x and y value arrays based on the x values
  Arrays.quickSort(0, nextIndex, new AbstractIntComparator()
  {
    @Override
    public int compare(int a, int b)
    {
      return Doubles.compare(values[a], values[b]);
    }
  }, new Swapper()
  {
    @Override
    public void swap(int a, int b)
    {
      double temp = values[a];
      values[a] = values[b];
      values[b] = temp;
      temp = weights[a];
      weights[a] = weights[b];
      weights[b] = temp;
    }
  });
}

代码示例来源:origin: twitter/GraphJet

Arrays.quickSort(0, size, new IntComparator() {
 @Override

代码示例来源:origin: uk.ac.gate.mimir/mimir-core

/**
 * Sorts the arrays inside a {@link TermsResultSet} using the termString for
 * comparison.
 * @param trs
 */
public static void sortTermsResultSetByTermString(final TermsResultSet trs) {
 Arrays.quickSort(0, trs.termStrings.length, new AbstractIntComparator() {
  @Override
  public int compare(int k1, int k2) {
   return trs.termStrings[k1].compareTo(trs.termStrings[k2]);
  }
 }, new Swapper(trs));
}

代码示例来源:origin: org.grouplens.lenskit/lenskit-data-structures

/**
 * Sort the list-in-progress by the specified comparator.
 * @param order The comparator.
 * @return The buidler (for chaining).
 */
public ScoredIdListBuilder sort(Comparator<ScoredId> order) {
  Preconditions.checkState(ids != null, "builder has been finished");
  quickSort(0, size(), new SortComp(order), new SortSwap());
  return this;
}

代码示例来源:origin: uk.ac.gate.mimir/mimir-core

getClass().getName() + " can only combine arrays of length 1.");
final TermsResultSet trs = resSets[0];
Arrays.quickSort(0, trs.termStrings.length, new IntComparator() {
 @Override
 public int compare(Integer o1, Integer o2) {

代码示例来源:origin: org.grouplens.lenskit/lenskit-data-structures

/**
 * Create a new {@code MutableSparseVector} from unsorted key and value
 * arrays. The provided arrays will be modified and should not be used
 * by the client after this operation has completed. The key domain of
 * the new {@code MutableSparseVector} will be the same as {@code keys}.
 *
 * @param keys Array of entry keys. This should be duplicate-free.
 * @param values The values of the vector, in key order.
 * @return A sparse vector backed by the provided arrays.
 * @throws IllegalArgumentException if there is a problem with the provided
 *                                  arrays (length mismatch, etc.).
 */
public static MutableSparseVector wrapUnsorted(long[] keys, double[] values) {
  IdComparator comparator = new IdComparator(keys);
  ParallelSwapper swapper = new ParallelSwapper(keys, values);
  quickSort(0, keys.length, comparator, swapper);
  return MutableSparseVector.wrap(keys, values);
}

代码示例来源:origin: org.lenskit/lenskit-core

/**
 * Create a new {@link Long2DoubleSortedArrayMap} from unsorted key and value
 * arrays. The provided arrays will be modified and should not be used
 * by the client after this operation has completed. The key domain of
 * the new {@link Long2DoubleSortedArrayMap} will be the same as {@code keys}.
 *
 * @param keys Array of entry keys. This should be duplicate-free.
 * @param values The values of the vector, in key order.
 * @return A sparse vector backed by the provided arrays.
 * @throws IllegalArgumentException if there is a problem with the provided
 *                                  arrays (length mismatch, etc.).
 */
public static Long2DoubleSortedArrayMap wrapUnsorted(long[] keys, double[] values) {
  IdComparator comparator = new IdComparator(keys);
  ParallelSwapper swapper = new ParallelSwapper(keys, values);
  quickSort(0, keys.length, comparator, swapper);
  // FIXME Verify that the keys have no duplicates
  SortedKeyIndex index = SortedKeyIndex.wrap(keys, keys.length);
  return wrap(index, values);
}

代码示例来源:origin: org.lenskit/lenskit-core

@Override
public EntityCollection build() {
  if (!isSorted) {
    Arrays.quickSort(0, size, new IdComparator(), new SortSwap());
  }
  AttrStore[] stores = new AttrStore[storeBuilders.length];
  PackIndex[] indexes = new PackIndex[needIndex.length];
  for (int i = 0; i < stores.length; i++) {
    stores[i] = storeBuilders[i].build();
    if (needIndex[i]) {
      indexes[i] = buildIndex(i);
    }
  }
  return new PackedEntityCollection(entityType, attributes, stores, indexes, entityBuilderClass);
}

代码示例来源:origin: it.unimi.dsi/webgraph

final InputBitStream labelBitStream, final File tempDir, final List<File> batches, final List<File> labelBatches,
  final Label prototype) throws IOException {
it.unimi.dsi.fastutil.Arrays.quickSort(0, n, (x,y) -> {
    final int t = source[x] - source[y];
    if (t != 0) return t;

代码示例来源:origin: it.unimi.dsi/fastutil

if ((s = b - a) > 1) quickSort(from, from + s, comp, swapper);
if ((s = d - c) > 1) quickSort(to - s, to, comp, swapper);

代码示例来源:origin: uk.ac.gate.mimir/mimir-core

it.unimi.dsi.fastutil.Arrays.quickSort(0, hitsOnCurrentDocument.size(),
    new AbstractIntComparator() {
     @Override

代码示例来源:origin: it.unimi.dsi/fastutil

final int len = to - from;
if (len < PARALLEL_QUICKSORT_NO_FORK) {
  quickSort(from, to, comp, swapper);
  return;

相关文章