Package arc.util

Class Select

java.lang.Object
arc.util.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 ArcRuntimeException

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 Details

    • Select

      public Select()
  • Method Details

    • 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)