Package com.badlogic.gdx.utils
Class Select
- java.lang.Object
-
- com.badlogic.gdx.utils.Select
-
public class Select extends java.lang.Object
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
GdxRuntimeException
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.
-
-
Constructor Summary
Constructors Constructor Description Select()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Select
instance()
Provided for convenience<T> T
select(T[] items, java.util.Comparator<T> comp, int kthLowest, int size)
<T> int
selectIndex(T[] items, java.util.Comparator<T> comp, int kthLowest, int size)
-
-
-
Method Detail
-
instance
public static Select instance()
Provided for convenience
-
select
public <T> T select(T[] items, java.util.Comparator<T> comp, int kthLowest, int size)
-
selectIndex
public <T> int selectIndex(T[] items, java.util.Comparator<T> comp, int kthLowest, int size)
-
-