Class SortUtil

java.lang.Object
com.ardor3d.util.SortUtil

public abstract class SortUtil extends Object
Shell and merge sort implementations with the goal of reducing garbage and allowing tuning.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static int
    The size at or below which we will use shell sort instead of the system sort.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static <T> void
    merge(T[] source, T[] destination, int left, int mid, int right, Comparator<? super T> comp)
    Performs a merge on two sets of data stored in source, represented by the ranges formed by [left, mid] and [mid+1, right].
    static <T> void
    msort(T[] source, int left, int right, Comparator<? super T> comp)
    Merge sorts the supplied data, in the given range, using the given comparator.
    static <T> void
    msort(T[] source, T[] copy, int left, int right, Comparator<? super T> comp)
    Merge sorts the supplied data, in the given range, using the given comparator.
    static <T extends Comparable<T>>
    void
    shellSort(T[] array, int left, int right)
    Performs an in-place shell sort (extension of insertion sort) of the provided data.
    static <T> void
    shellSort(T[] array, int left, int right, Comparator<? super T> comp)
    Performs an in-place shell sort (extension of insertion sort) of the provided data.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SHELL_SORT_THRESHOLD

      public static int SHELL_SORT_THRESHOLD
      The size at or below which we will use shell sort instead of the system sort.
  • Constructor Details

    • SortUtil

      public SortUtil()
  • Method Details

    • msort

      public static <T> void msort(T[] source, int left, int right, Comparator<? super T> comp)
      Merge sorts the supplied data, in the given range, using the given comparator. Note: this internally creates a temporary copy of the array to use as work space during sort.
      Type Parameters:
      T - the type of data to sort
      Parameters:
      source - the array to sort. Will hold the sorted array on completion.
      left - the left-most index of our sort range.
      right - the right-most index of our sort range.
      comp - our object Comparator
    • msort

      public static <T> void msort(T[] source, T[] copy, int left, int right, Comparator<? super T> comp)
      Merge sorts the supplied data, in the given range, using the given comparator.
      Type Parameters:
      T - the type of data to sort
      Parameters:
      source - contains the elements to be sorted and acts as a work space for the sort.
      copy - contains the elements to be sorted and will hold the fully sorted array when complete.
      left - the left-most index of our sort range.
      right - the right-most index of our sort range.
      comp - our object Comparator
    • merge

      protected static <T> void merge(T[] source, T[] destination, int left, int mid, int right, Comparator<? super T> comp)
      Performs a merge on two sets of data stored in source, represented by the ranges formed by [left, mid] and [mid+1, right]. Stores the result in destination.
      Type Parameters:
      T - the type of data to sort
      Parameters:
      source - our source data
      destination - the array to store our result in
      left - the left index of the range to sort
      mid - the middle index of the range to sort
      right - the right index of the range to sort
      comp - our object Comparator
    • shellSort

      public static <T> void shellSort(T[] array, int left, int right, Comparator<? super T> comp)
      Performs an in-place shell sort (extension of insertion sort) of the provided data.
      Type Parameters:
      T - the type of data to sort
      Parameters:
      array - our source data
      left - the left index of the range to sort
      right - the right index (inclusive) of the range to sort
      comp - our object Comparator
    • shellSort

      public static <T extends Comparable<T>> void shellSort(T[] array, int left, int right)
      Performs an in-place shell sort (extension of insertion sort) of the provided data.
      Type Parameters:
      T - the type of data to sort
      Parameters:
      array - our source data
      left - the left index of the range to sort
      right - the right index (inclusive) of the range to sort