|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.logicalcobwebs.cglib.util.SorterTemplate org.logicalcobwebs.cglib.util.ParallelSorter
public abstract class ParallelSorter
For the efficient sorting of multiple arrays in parallel.
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.
Nested Class Summary | |
---|---|
(package private) static class |
ParallelSorter.ByteComparer
|
(package private) static class |
ParallelSorter.ComparatorComparer
|
(package private) static interface |
ParallelSorter.Comparer
|
(package private) static class |
ParallelSorter.DoubleComparer
|
(package private) static class |
ParallelSorter.FloatComparer
|
static class |
ParallelSorter.Generator
|
(package private) static class |
ParallelSorter.IntComparer
|
(package private) static class |
ParallelSorter.LongComparer
|
(package private) static class |
ParallelSorter.ObjectComparer
|
(package private) static class |
ParallelSorter.ShortComparer
|
Field Summary | |
---|---|
protected java.lang.Object[] |
a
|
private ParallelSorter.Comparer |
comparer
|
Constructor Summary | |
---|---|
protected |
ParallelSorter()
|
Method Summary | |
---|---|
private void |
chooseComparer(int index,
java.util.Comparator cmp)
|
protected int |
compare(int i,
int j)
|
static ParallelSorter |
create(java.lang.Object[] arrays)
Create a new ParallelSorter object for a set of arrays. |
private int |
len()
|
void |
mergeSort(int index)
|
void |
mergeSort(int index,
java.util.Comparator cmp)
Sort the arrays using an in-place merge sort. |
void |
mergeSort(int index,
int lo,
int hi)
Sort the arrays using an in-place merge sort. |
void |
mergeSort(int index,
int lo,
int hi,
java.util.Comparator cmp)
Sort the arrays using an in-place merge sort. |
abstract ParallelSorter |
newInstance(java.lang.Object[] arrays)
|
void |
quickSort(int index)
Sort the arrays using the quicksort algorithm. |
void |
quickSort(int index,
java.util.Comparator cmp)
Sort the arrays using the quicksort algorithm. |
void |
quickSort(int index,
int lo,
int hi)
Sort the arrays using the quicksort algorithm. |
void |
quickSort(int index,
int lo,
int hi,
java.util.Comparator cmp)
Sort the arrays using the quicksort algorithm. |
Methods inherited from class org.logicalcobwebs.cglib.util.SorterTemplate |
---|
mergeSort, quickSort, swap |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.Object[] a
private ParallelSorter.Comparer comparer
Constructor Detail |
---|
protected ParallelSorter()
Method Detail |
---|
public abstract ParallelSorter newInstance(java.lang.Object[] arrays)
public static ParallelSorter create(java.lang.Object[] arrays)
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.loader
- ClassLoader for generated class, uses "current" if nullprivate int len()
public void quickSort(int index)
index
- array (column) to sort bypublic void quickSort(int index, int lo, int hi)
index
- array (column) to sort bylo
- starting array index (row), inclusivehi
- ending array index (row), exclusivepublic void quickSort(int index, java.util.Comparator cmp)
index
- array (column) to sort bycmp
- Comparator to use if the specified column is non-primitivepublic void quickSort(int index, int lo, int hi, java.util.Comparator cmp)
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-primitivepublic void mergeSort(int index)
index
- array (column) to sort bypublic void mergeSort(int index, int lo, int hi)
index
- array (column) to sort bylo
- starting array index (row), inclusivehi
- ending array index (row), exclusivepublic void mergeSort(int index, java.util.Comparator cmp)
index
- array (column) to sort bylo
- starting array index (row), inclusivehi
- ending array index (row), exclusivepublic void mergeSort(int index, int lo, int hi, java.util.Comparator cmp)
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-primitiveprivate void chooseComparer(int index, java.util.Comparator cmp)
protected int compare(int i, int j)
compare
in class SorterTemplate
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |