Package com.ardor3d.util
Class SortUtil
java.lang.Object
com.ardor3d.util.SortUtil
Shell and merge sort implementations with the goal of reducing garbage and allowing tuning.
-
Field Summary
Modifier and TypeFieldDescriptionstatic int
The size at or below which we will use shell sort instead of the system sort. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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>>
voidshellSort
(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.
-
Field Details
-
SHELL_SORT_THRESHOLD
public static int SHELL_SORT_THRESHOLDThe size at or below which we will use shell sort instead of the system sort.
-
-
Constructor Details
-
SortUtil
public SortUtil()
-
-
Method Details
-
msort
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
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 datadestination
- the array to store our result inleft
- the left index of the range to sortmid
- the middle index of the range to sortright
- the right index of the range to sortcomp
- our object Comparator
-
shellSort
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 dataleft
- the left index of the range to sortright
- the right index (inclusive) of the range to sortcomp
- our object Comparator
-
shellSort
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 dataleft
- the left index of the range to sortright
- the right index (inclusive) of the range to sort
-