Example usage for org.apache.mahout.math Sorting mergeSort

List of usage examples for org.apache.mahout.math Sorting mergeSort

Introduction

In this page you can find the example usage for org.apache.mahout.math Sorting mergeSort.

Prototype

public static void mergeSort(double[] array, int start, int end) 

Source Link

Document

Perform a merge sort on a range of a double array using a Double.compare as an ordering.

Usage

From source file:gov.vha.isaac.ochre.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Sorts the specified range of the receiver into ascending order.
 *
 * The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in
 * the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed
 * n*log(n) performance, and can approach linear performance on nearly sorted lists.
 *
 * <p> <b>You should never call this method unless you are sure that this particular sorting algorithm is
 * the right one for your data set.</b> It is generally better to call {@code sort()} or
 * {@code sortFromTo(...)} instead, because those methods automatically choose the best sorting
 * algorithm./*from w  ww.  j av  a  2s  .  co m*/
 *
 * @param from the index of the first element (inclusive) to be sorted.
 * @param to the index of the last element (inclusive) to be sorted.
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
@Override
public void mergeSortFromTo(int from, int to) {
    int mySize = size();
    AbstractList.checkRangeFromTo(from, to, mySize);

    long[] myElements = elements();
    Sorting.mergeSort(myElements, from, to + 1);
    elements(myElements);
    setSizeRaw(mySize);
}

From source file:org.ihtsdo.otf.tcc.datastore.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Sorts the specified range of the receiver into ascending order.
 *
 * The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in
 * the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed
 * n*log(n) performance, and can approach linear performance on nearly sorted lists.
 *
 * <p> <b>You should never call this method unless you are sure that this particular sorting algorithm is
 * the right one for your data set.</b> It is generally better to call <tt>sort()</tt> or
 * <tt>sortFromTo(...)</tt> instead, because those methods automatically choose the best sorting
 * algorithm./*from w  ww .j av  a  2  s. co m*/
 *
 * @param from the index of the first element (inclusive) to be sorted.
 * @param to the index of the last element (inclusive) to be sorted.
 * @exception IndexOutOfBoundsException index is out of range ( <tt>size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())</tt> ).
 */
@Override
public void mergeSortFromTo(int from, int to) {
    int mySize = size();
    checkRangeFromTo(from, to, mySize);

    long[] myElements = elements();
    Sorting.mergeSort(myElements, from, to + 1);
    elements(myElements);
    setSizeRaw(mySize);
}

From source file:sh.isaac.api.collections.uuidnidmap.AbstractUuidList.java

License:Apache License

/**
 * Sorts the specified range of the receiver into ascending order.
 *
 * The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in
 * the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed
 * n*log(n) performance, and can approach linear performance on nearly sorted lists.
 *
 * <p> <b>You should never call this method unless you are sure that this particular sorting algorithm is
 * the right one for your data set.</b> It is generally better to call {@code sort()} or
 * {@code sortFromTo(...)} instead, because those methods automatically choose the best sorting
 * algorithm.//from   w w w. ja  va  2  s. c o  m
 *
 * @param from the index of the first element (inclusive) to be sorted.
 * @param to the index of the last element (inclusive) to be sorted.
 * @exception IndexOutOfBoundsException index is out of range ( {@code size()&gt;0 && (from&lt;0 ||
 * from&gt;to || to&gt;=size())} ).
 */
@Override
public void mergeSortFromTo(int from, int to) {
    final int mySize = size();

    AbstractList.checkRangeFromTo(from, to, mySize);

    final long[] myElements = elements();

    Sorting.mergeSort(myElements, from, to + 1);
    elements(myElements);
    setSizeRaw(mySize);
}