类 ParallelSorter
Given two arrays of equal length and varying types, the standard technique for sorting them in parallel is to create a new temporary object for each row, store the objects in a temporary array, sort the array using a custom comparator, and the extract the original values back into their respective arrays. This is wasteful in both time and memory.
This class generates bytecode customized to the particular set of arrays you need to sort, in such a way that both arrays are sorted in-place, simultaneously.
Two sorting algorithms are provided. Quicksort is best when you only need to sort by a single column, as it requires very few comparisons and swaps. Mergesort is best used when sorting multiple columns, as it is a "stable" sort--that is, it does not affect the relative order of equal objects from previous sorts.
The mergesort algorithm here is an "in-place" variant, which while slower, does not require a temporary array.
- 作者:
- Chris Nokleberg
-
嵌套类概要
嵌套类修饰符和类型类说明(专用程序包) static class(专用程序包) static class(专用程序包) static interface(专用程序包) static class(专用程序包) static classstatic class(专用程序包) static class(专用程序包) static class(专用程序包) static class(专用程序包) static class -
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private voidchooseComparer(int index, Comparator cmp) protected intcompare(int i, int j) static ParallelSorterCreate a new ParallelSorter object for a set of arrays.private intlen()voidmergeSort(int index) voidmergeSort(int index, int lo, int hi) Sort the arrays using an in-place merge sort.voidmergeSort(int index, int lo, int hi, Comparator cmp) Sort the arrays using an in-place merge sort.voidmergeSort(int index, Comparator cmp) Sort the arrays using an in-place merge sort.abstract ParallelSorternewInstance(Object[] arrays) voidquickSort(int index) Sort the arrays using the quicksort algorithm.voidquickSort(int index, int lo, int hi) Sort the arrays using the quicksort algorithm.voidquickSort(int index, int lo, int hi, Comparator cmp) Sort the arrays using the quicksort algorithm.voidquickSort(int index, Comparator cmp) Sort the arrays using the quicksort algorithm.从类继承的方法 cn.taketoday.bytecode.util.SorterTemplate
mergeSort, quickSort, swap
-
字段详细资料
-
a
-
comparer
-
-
构造器详细资料
-
ParallelSorter
protected ParallelSorter()
-
-
方法详细资料
-
newInstance
-
create
Create a new ParallelSorter object for a set of arrays. You may sort the arrays multiple times via the same ParallelSorter object.- 参数:
arrays- An array of arrays to sort. The arrays may be a mix of primitive and non-primitive types, but should all be the same length.
-
len
private int len() -
quickSort
public void quickSort(int index) Sort the arrays using the quicksort algorithm.- 参数:
index- array (column) to sort by
-
quickSort
public void quickSort(int index, int lo, int hi) Sort the arrays using the quicksort algorithm.- 参数:
index- array (column) to sort bylo- starting array index (row), inclusivehi- ending array index (row), exclusive
-
quickSort
Sort the arrays using the quicksort algorithm.- 参数:
index- array (column) to sort bycmp- Comparator to use if the specified column is non-primitive
-
quickSort
Sort the arrays using the quicksort algorithm.- 参数:
index- array (column) to sort bylo- starting array index (row), inclusivehi- ending array index (row), exclusivecmp- Comparator to use if the specified column is non-primitive
-
mergeSort
public void mergeSort(int index) - 参数:
index- array (column) to sort by
-
mergeSort
public void mergeSort(int index, int lo, int hi) Sort the arrays using an in-place merge sort.- 参数:
index- array (column) to sort bylo- starting array index (row), inclusivehi- ending array index (row), exclusive
-
mergeSort
Sort the arrays using an in-place merge sort.- 参数:
index- array (column) to sort by
-
mergeSort
Sort the arrays using an in-place merge sort.- 参数:
index- array (column) to sort bylo- starting array index (row), inclusivehi- ending array index (row), exclusivecmp- Comparator to use if the specified column is non-primitive
-
chooseComparer
-
compare
protected int compare(int i, int j) - 指定者:
compare在类中SorterTemplate
-