Package com.github.tommyettinger.ds
Class Select
java.lang.Object
com.github.tommyettinger.ds.Select
This class is for selecting a ranked element (kth ordered statistic) from an unordered list in faster time than sorting the
whole array. Typical applications include finding the nearest enemy unit(s), and other operations which are likely to run as
often as every x frames. Certain values of k will result in a partial sorting of the array.
The lowest ranking element starts at 1, not 0. 1 = first, 2 = second, 3 = third, etc. calling with a value of zero will result
in a RuntimeException
This class uses very minimal extra memory, as it makes no copies of the array. The underlying algorithms used are a naive single-pass for k=min and k=max, and Hoare's quickselect for values in between.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tselect(Arrangeable.ArrangeableList<T> items, Comparator<T> comp, int kthLowest, int size) static booleanselect(BooleanList items, BooleanComparator comp, int kthLowest, int size) static byteselect(ByteList items, ByteComparator comp, int kthLowest, int size) static charselect(CharList items, CharComparator comp, int kthLowest, int size) static doubleselect(DoubleList items, DoubleComparator comp, int kthLowest, int size) static floatselect(FloatList items, FloatComparator comp, int kthLowest, int size) static intselect(IntList items, IntComparator comp, int kthLowest, int size) static longselect(LongList items, LongComparator comp, int kthLowest, int size) static shortselect(ShortList items, ShortComparator comp, int kthLowest, int size) static <T> Tselect(T[] items, Comparator<T> comp, int kthLowest, int size) static <T> intselectIndex(Arrangeable.ArrangeableList<T> items, Comparator<T> comp, int kthLowest, int size) static intselectIndex(BooleanList items, BooleanComparator comp, int kthLowest, int size) static intselectIndex(ByteList items, ByteComparator comp, int kthLowest, int size) static intselectIndex(CharList items, CharComparator comp, int kthLowest, int size) static intselectIndex(DoubleList items, DoubleComparator comp, int kthLowest, int size) static intselectIndex(FloatList items, FloatComparator comp, int kthLowest, int size) static intselectIndex(IntList items, IntComparator comp, int kthLowest, int size) static intselectIndex(LongList items, LongComparator comp, int kthLowest, int size) static intselectIndex(ShortList items, ShortComparator comp, int kthLowest, int size) static <T> intselectIndex(T[] items, Comparator<T> comp, int kthLowest, int size)
-
Method Details
-
select
-
selectIndex
-
select
public static <T> T select(Arrangeable.ArrangeableList<T> items, Comparator<T> comp, int kthLowest, int size) -
selectIndex
public static <T> int selectIndex(Arrangeable.ArrangeableList<T> items, Comparator<T> comp, int kthLowest, int size) -
select
-
selectIndex
-
select
-
selectIndex
-
select
-
selectIndex
-
select
-
selectIndex
-
select
-
selectIndex
-
select
-
selectIndex
-
select
-
selectIndex
-
select
-
selectIndex
-