Class QuickSelect
- java.lang.Object
-
- org.ddogleg.sorting.QuickSelect
-
public class QuickSelect extends java.lang.ObjectQuickSelect searches for the k-th largest item in the list. While doing this search it will sort the list partially. all the items below k will have a value less than it and all the items more than k will have a value greater than it. However the values above and below can be unsorted. QuickSelect is faster than QuickSort of you don't need a fully sorted list.
An implementation of the quick select algorithm from Numerical Recipes Third Edition that is specified for arrays of doubles. See page 433.
DO NOT MODIFY. AUTOGENERATED CODE.
GenerateQuickSelect
-
-
Constructor Summary
Constructors Constructor and Description QuickSelect()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static byteselect(byte[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest.static java.lang.Comparableselect(java.lang.Comparable[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest.static java.lang.Comparableselect(java.lang.Comparable[] data, int k, int maxIndex, int[] indexes)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest.static doubleselect(double[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest.static floatselect(float[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest.static intselect(int[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest.static longselect(long[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest.static shortselect(short[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest.static intselectIndex(byte[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.static intselectIndex(double[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.static intselectIndex(float[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.static intselectIndex(int[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.static intselectIndex(long[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.static intselectIndex(short[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.
-
-
-
Method Detail
-
select
public static java.lang.Comparable select(java.lang.Comparable[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest. This implies that the array itself is modified. For convenience the 'k' element is returned.- Parameters:
data- The unsorted listk- The element of the sorted list that is to be foundmaxIndex- Only element up to this value are considered- Returns:
- the 'k'th largest element
-
select
public static java.lang.Comparable select(java.lang.Comparable[] data, int k, int maxIndex, int[] indexes)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest. This implies that the array itself is modified. For convenience the 'k' element is returned.- Parameters:
data- The unsorted list. Not modified.k- The element of the sorted list that is to be foundmaxIndex- Only element up to this value are consideredindexes- (output) Sorted list of indexes.- Returns:
- the 'k'th largest element
-
select
public static float select(float[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest. This implies that the array itself is modified. For convinience the 'k' element is returned.- Parameters:
data- The unsorted list. Is modified.k- The element of the sorted list that is to be foundmaxIndex- Only element up to this value are considered- Returns:
- the 'k'th largest element
-
selectIndex
public static int selectIndex(float[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.
Note: There is additional overhead since the values of indexes needs to be set
- Parameters:
indexes- Temporary storage and is overwritten
-
select
public static double select(double[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest. This implies that the array itself is modified. For convinience the 'k' element is returned.- Parameters:
data- The unsorted list. Is modified.k- The element of the sorted list that is to be foundmaxIndex- Only element up to this value are considered- Returns:
- the 'k'th largest element
-
selectIndex
public static int selectIndex(double[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.
Note: There is additional overhead since the values of indexes needs to be set
- Parameters:
indexes- Temporary storage and is overwritten
-
select
public static long select(long[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest. This implies that the array itself is modified. For convinience the 'k' element is returned.- Parameters:
data- The unsorted list. Is modified.k- The element of the sorted list that is to be foundmaxIndex- Only element up to this value are considered- Returns:
- the 'k'th largest element
-
selectIndex
public static int selectIndex(long[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.
Note: There is additional overhead since the values of indexes needs to be set
- Parameters:
indexes- Temporary storage and is overwritten
-
select
public static int select(int[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest. This implies that the array itself is modified. For convinience the 'k' element is returned.- Parameters:
data- The unsorted list. Is modified.k- The element of the sorted list that is to be foundmaxIndex- Only element up to this value are considered- Returns:
- the 'k'th largest element
-
selectIndex
public static int selectIndex(int[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.
Note: There is additional overhead since the values of indexes needs to be set
- Parameters:
indexes- Temporary storage and is overwritten
-
select
public static short select(short[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest. This implies that the array itself is modified. For convinience the 'k' element is returned.- Parameters:
data- The unsorted list. Is modified.k- The element of the sorted list that is to be foundmaxIndex- Only element up to this value are considered- Returns:
- the 'k'th largest element
-
selectIndex
public static int selectIndex(short[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.
Note: There is additional overhead since the values of indexes needs to be set
- Parameters:
indexes- Temporary storage and is overwritten
-
select
public static byte select(byte[] data, int k, int maxIndex)Sorts the array such that the values in the array up to and including 'k' are sorted the least to greatest. This implies that the array itself is modified. For convinience the 'k' element is returned.- Parameters:
data- The unsorted list. Is modified.k- The element of the sorted list that is to be foundmaxIndex- Only element up to this value are considered- Returns:
- the 'k'th largest element
-
selectIndex
public static int selectIndex(byte[] data, int k, int maxIndex, int[] indexes)Returns the original index of the 'k' largest element in the list.
Note: There is additional overhead since the values of indexes needs to be set
- Parameters:
indexes- Temporary storage and is overwritten
-
-
DataMelt 3.0 © DataMelt by jWork.ORG