/** * Sorts the specified range of the receiver into ascending order, according to the <i>natural * ordering</i> of its elements. All elements in this range must implement the <tt>Comparable</tt> * interface. Furthermore, all elements in this range must be <i>mutually comparable</i> (that is, * <tt>e1.compareTo(e2)</tt> must not throw a <tt>ClassCastException</tt> for any elements * <tt>e1</tt> and <tt>e2</tt> in the array). * * <p>The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas * McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. * 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that * cause other quicksorts to degrade to quadratic performance. * * <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. * * @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()>0 && (from<0 || * from>to || to>=size())</tt>). */ public void quickSortFromTo(int from, int to) { if (size == 0) return; checkRangeFromTo(from, to, size); org.ihtsdo.cern.colt.Sorting.quickSort(elements, from, to + 1); }
/** * Sorts the receiver according to the order induced by the specified comparator. All elements in * the range must be <i>mutually comparable</i> by the specified comparator (that is, * <tt>c.compare(e1, e2)</tt> must not throw a <tt>ClassCastException</tt> for any elements * <tt>e1</tt> and <tt>e2</tt> in the range). * * <p>The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas * McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. * 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that * cause other quicksorts to degrade to quadratic performance. * * @param from the index of the first element (inclusive) to be sorted. * @param to the index of the last element (inclusive) to be sorted. * @param c the comparator to determine the order of the receiver. * @throws ClassCastException if the array contains elements that are not <i>mutually * comparable</i> using the specified comparator. * @throws IllegalArgumentException if <tt>fromIndex > toIndex</tt> * @throws ArrayIndexOutOfBoundsException if <tt>fromIndex < 0</tt> or <tt>toIndex > * a.length</tt> * @see Comparator * @exception IndexOutOfBoundsException index is out of range (<tt>size()>0 && (from<0 || * from>to || to>=size())</tt>). */ public void quickSortFromTo(int from, int to, java.util.Comparator c) { if (size == 0) return; checkRangeFromTo(from, to, size); org.ihtsdo.cern.colt.Sorting.quickSort(elements, from, to + 1, c); }
/** * Searches the receiver for the specified value using the binary search algorithm. The receiver * must be sorted into ascending order according to the specified comparator. All elements in the * range must be <i>mutually comparable</i> by the specified comparator (that is, * <tt>c.compare(e1, e2)</tt> must not throw a <tt>ClassCastException</tt> for any elements * <tt>e1</tt> and <tt>e2</tt> in the range). * * <p>If the receiver is not sorted, the results are undefined: in particular, the call may enter * an infinite loop. If the receiver contains multiple elements equal to the specified object, * there is no guarantee which instance will be found. * * @param key the value to be searched for. * @param from the leftmost search position, inclusive. * @param to the rightmost search position, inclusive. * @param comparator the comparator by which the receiver is sorted. * @throws ClassCastException if the receiver contains elements that are not <i>mutually * comparable</i> using the specified comparator. * @return index of the search key, if it is contained in the receiver; otherwise, * <tt>(-(<i>insertion point</i>) - 1)</tt>. The <i>insertion point</i> is defined as the the * point at which the value would be inserted into the receiver: the index of the first * element greater than the key, or <tt>receiver.size()</tt>, if all elements in the receiver * are less than the specified key. Note that this guarantees that the return value will be * >= 0 if and only if the key is found. * @see org.ihtsdo.cern.colt.Sorting * @see java.util.Arrays * @see java.util.Comparator */ public int binarySearchFromTo(Object key, int from, int to, java.util.Comparator comparator) { return org.ihtsdo.cern.colt.Sorting.binarySearchFromTo( this.elements, key, from, to, comparator); }