com.badlogic.gdx.utils
Class Select

java.lang.Object
  extended by com.badlogic.gdx.utils.Select

public class Select
extends 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.

Author:
Jon Renner

Constructor Summary
Select()
           
 
Method Summary
static Select instance()
          Provided for convenience
<T> T
select(T[] items, Comparator<T> comp, int kthLowest, int size)
           
<T> int
selectIndex(T[] items, Comparator<T> comp, int kthLowest, int size)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Select

public Select()
Method Detail

instance

public static Select instance()
Provided for convenience


select

public <T> T select(T[] items,
                    Comparator<T> comp,
                    int kthLowest,
                    int size)

selectIndex

public <T> int selectIndex(T[] items,
                           Comparator<T> comp,
                           int kthLowest,
                           int size)


Copyright © 2013. All Rights Reserved.