Package com.aoindustries.util.sort
Class FastQSort
- java.lang.Object
-
- com.aoindustries.util.sort.FastQSort
-
- All Implemented Interfaces:
ComparisonSortAlgorithm<Object>,SortAlgorithm<Object>
public final class FastQSort extends Object
A quick sort demonstration algorithm SortAlgorithm.java- Version:
- \@(#)QSortAlgorithm.java 1.3, 29 Feb 1996
extended with TriMedian and InsertionSort by Denis Ahrens
with all the tips from Robert Sedgewick (Algorithms in C++).
It uses TriMedian and InsertionSort for lists shorts than 4.
<fuhrmann@cs.tu-berlin.de>
Adapted from Denis Ahrens' FastQSortAlgorithm, which was derived from Sun's example QSortAlgorithm.
2003-11-06 - Dan Armstrong - To avoid worst-case scenarios, if the quickSort recursion depth exceeds
(int)(10*Math.log(list.size())), the algorithm will quit and a HeapSort will be performed. - Author:
- James Gosling, Kevin A. Smith
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected static <T> intcompare(List<T> list, int i, int j, Comparator<? super T> comparator, SortStatistics stats)protected static <T> intcompare(T[] array, int i, int j, Comparator<? super T> comparator, SortStatistics stats)protected static <T> intcompare(T O1, T O2, Comparator<? super T> comparator, SortStatistics stats)protected static <T> Tget(List<T> list, int i, SortStatistics stats)protected static <T> Tget(T[] array, int i, SortStatistics stats)static FastQSortgetInstance()booleanisStable()Checks if this is a stable sort.protected static <T> voidset(List<T> list, int i, T O, SortStatistics stats)protected static <T> voidset(T[] array, int i, T O, SortStatistics stats)<T extends E>
voidsort(List<T> list)<T extends E>
voidsort(List<T> list, SortStatistics stats)<T extends E>
voidsort(List<T> list, Comparator<? super T> comparator)<T> voidsort(List<T> list, Comparator<? super T> comparator, SortStatistics stats)<T extends E>
voidsort(T[] array)<T extends E>
voidsort(T[] array, SortStatistics stats)<T extends E>
voidsort(T[] array, Comparator<? super T> comparator)<T> voidsort(T[] array, Comparator<? super T> comparator, SortStatistics stats)protected static <T> voidswap(List<T> list, int i, int j, SortStatistics stats)protected static <T> voidswap(T[] array, int i, int j, SortStatistics stats)
-
-
-
Method Detail
-
getInstance
public static FastQSort getInstance()
-
isStable
public boolean isStable()
Description copied from interface:SortAlgorithmChecks if this is a stable sort. A stable sort will keep elements with equal values in their same relative order.
-
sort
public <T> void sort(List<T> list, Comparator<? super T> comparator, SortStatistics stats)
- Specified by:
sortin interfaceComparisonSortAlgorithm<Object>
-
sort
public <T> void sort(T[] array, Comparator<? super T> comparator, SortStatistics stats)- Specified by:
sortin interfaceComparisonSortAlgorithm<Object>
-
sort
public <T extends E> void sort(List<T> list)
- Specified by:
sortin interfaceSortAlgorithm<E>
-
sort
public <T extends E> void sort(T[] array)
- Specified by:
sortin interfaceSortAlgorithm<E>
-
sort
public <T extends E> void sort(List<T> list, SortStatistics stats)
- Specified by:
sortin interfaceSortAlgorithm<E>
-
sort
public <T extends E> void sort(T[] array, SortStatistics stats)- Specified by:
sortin interfaceSortAlgorithm<E>
-
sort
public <T extends E> void sort(List<T> list, Comparator<? super T> comparator)
- Specified by:
sortin interfaceComparisonSortAlgorithm<E>
-
sort
public <T extends E> void sort(T[] array, Comparator<? super T> comparator)- Specified by:
sortin interfaceComparisonSortAlgorithm<E>
-
compare
protected static <T> int compare(List<T> list, int i, int j, Comparator<? super T> comparator, SortStatistics stats)
-
compare
protected static <T> int compare(T[] array, int i, int j, Comparator<? super T> comparator, SortStatistics stats)
-
compare
protected static <T> int compare(T O1, T O2, Comparator<? super T> comparator, SortStatistics stats)
-
get
protected static <T> T get(List<T> list, int i, SortStatistics stats)
-
get
protected static <T> T get(T[] array, int i, SortStatistics stats)
-
set
protected static <T> void set(List<T> list, int i, T O, SortStatistics stats)
-
set
protected static <T> void set(T[] array, int i, T O, SortStatistics stats)
-
swap
protected static <T> void swap(List<T> list, int i, int j, SortStatistics stats)
-
swap
protected static <T> void swap(T[] array, int i, int j, SortStatistics stats)
-
-