Top Description Inners Fields Constructors Methods
org.springframework.cglib.util

public abstract Class ParallelSorter

extends SorterTemplate
Class Inheritance
Annotations
@SuppressWarnings:rawtypes, unchecked
Imports
java.util.Comparator, org.springframework.asm.ClassVisitor, org.springframework.cglib.core.AbstractClassGenerator, .ClassesKey, .ReflectUtils

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.

Author
Chris Nokleberg

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
pack-priv static interface
pack-priv static class
pack-priv static class
public static class
pack-priv static class
pack-priv static class
pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
protected Object[]
a

private ParallelSorter.Comparer

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private void
chooseComparer(int index, Comparator<T> cmp)

protected int
public static ParallelSorter
create(Object[]
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.
arrays
)

Create a new ParallelSorter object for a set of arrays.

private int
len()

public void
mergeSort(int
array (column) to sort by
index
)

public void
mergeSort(int
array (column) to sort by
index
,
int
starting array index (row), inclusive
lo
,
int
ending array index (row), exclusive
hi
)

Sort the arrays using an in-place merge sort.

public void
mergeSort(int
array (column) to sort by
index
,
Comparator<T>
Comparator to use if the specified column is non-primitive
cmp
)

Sort the arrays using an in-place merge sort.

public void
mergeSort(int
array (column) to sort by
index
,
int
starting array index (row), inclusive
lo
,
int
ending array index (row), exclusive
hi
,
Comparator<T>
Comparator to use if the specified column is non-primitive
cmp
)

Sort the arrays using an in-place merge sort.

public abstract ParallelSorter
newInstance(Object[] arrays)

public void
quickSort(int
array (column) to sort by
index
)

Sort the arrays using the quicksort algorithm.

public void
quickSort(int
array (column) to sort by
index
,
int
starting array index (row), inclusive
lo
,
int
ending array index (row), exclusive
hi
)

Sort the arrays using the quicksort algorithm.

public void
quickSort(int
array (column) to sort by
index
,
Comparator<T>
Comparator to use if the specified column is non-primitive
cmp
)

Sort the arrays using the quicksort algorithm.

public void
quickSort(int
array (column) to sort by
index
,
int
starting array index (row), inclusive
lo
,
int
ending array index (row), exclusive
hi
,
Comparator<T>
Comparator to use if the specified column is non-primitive
cmp
)

Sort the arrays using the quicksort algorithm.

Inherited from org.springframework.cglib.util.SorterTemplate:
mergeSortquickSortswap

Field Detail

aback to summary
protected Object[] a
comparerback to summary
private ParallelSorter.Comparer comparer

Constructor Detail

ParallelSorterback to summary
protected ParallelSorter()

Method Detail

chooseComparerback to summary
private void chooseComparer(int index, Comparator<T> cmp)
compareback to summary
protected int compare(int i, int j)

Implements abstract org.springframework.cglib.util.SorterTemplate.compare.

Annotations
@Override
createback to summary
public static ParallelSorter create(Object[] arrays)

Create a new ParallelSorter object for a set of arrays. You may sort the arrays multiple times via the same ParallelSorter object.

Parameters
arrays:Object[]

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.

lenback to summary
private int len()
mergeSortback to summary
public void mergeSort(int index)
Parameters
index:int

array (column) to sort by

mergeSortback to summary
public void mergeSort(int index, int lo, int hi)

Sort the arrays using an in-place merge sort.

Parameters
index:int

array (column) to sort by

lo:int

starting array index (row), inclusive

hi:int

ending array index (row), exclusive

mergeSortback to summary
public void mergeSort(int index, Comparator<T> cmp)

Sort the arrays using an in-place merge sort.

Parameters
index:int

array (column) to sort by

cmp:Comparator<T>

Comparator to use if the specified column is non-primitive

mergeSortback to summary
public void mergeSort(int index, int lo, int hi, Comparator<T> cmp)

Sort the arrays using an in-place merge sort.

Parameters
index:int

array (column) to sort by

lo:int

starting array index (row), inclusive

hi:int

ending array index (row), exclusive

cmp:Comparator<T>

Comparator to use if the specified column is non-primitive

newInstanceback to summary
public abstract ParallelSorter newInstance(Object[] arrays)
quickSortback to summary
public void quickSort(int index)

Sort the arrays using the quicksort algorithm.

Parameters
index:int

array (column) to sort by

quickSortback to summary
public void quickSort(int index, int lo, int hi)

Sort the arrays using the quicksort algorithm.

Parameters
index:int

array (column) to sort by

lo:int

starting array index (row), inclusive

hi:int

ending array index (row), exclusive

quickSortback to summary
public void quickSort(int index, Comparator<T> cmp)

Sort the arrays using the quicksort algorithm.

Parameters
index:int

array (column) to sort by

cmp:Comparator<T>

Comparator to use if the specified column is non-primitive

quickSortback to summary
public void quickSort(int index, int lo, int hi, Comparator<T> cmp)

Sort the arrays using the quicksort algorithm.

Parameters
index:int

array (column) to sort by

lo:int

starting array index (row), inclusive

hi:int

ending array index (row), exclusive

cmp:Comparator<T>

Comparator to use if the specified column is non-primitive

org.springframework.cglib.util back to summary

pack-priv Class ParallelSorter.ByteComparer

extends Object
implements Comparer
Class Inheritance
All Implemented Interfaces
org.springframework.cglib.util.ParallelSorter.Comparer

Field Summary

Modifier and TypeField and Description
private final byte[]
a

Constructor Summary

AccessConstructor and Description
public
ByteComparer(byte[] a)

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final byte[] a

Constructor Detail

ByteComparerback to summary
public ByteComparer(byte[] a)

Method Detail

compareback to summary
public int compare(int i, int j)

Implements org.springframework.cglib.util.ParallelSorter.Comparer.compare.

Annotations
@Override
org.springframework.cglib.util back to summary

pack-priv Class ParallelSorter.ComparatorComparer

extends Object
implements Comparer
Class Inheritance
  • java.lang.Object
  • org.springframework.cglib.util.ParallelSorter.ComparatorComparer
All Implemented Interfaces
org.springframework.cglib.util.ParallelSorter.Comparer

Field Summary

Modifier and TypeField and Description
private final Object[]
a

private final Comparator<T>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final Object[] a
cmpback to summary
private final Comparator<T> cmp

Constructor Detail

ComparatorComparerback to summary
public ComparatorComparer(Object[] a, Comparator<T> cmp)

Method Detail

compareback to summary
public int compare(int i, int j)

Implements org.springframework.cglib.util.ParallelSorter.Comparer.compare.

Annotations
@Override
org.springframework.cglib.util back to summary

pack-priv Interface ParallelSorter.Comparer

Known Direct Implementers
org.springframework.cglib.util.ParallelSorter.ComparatorComparer, org.springframework.cglib.util.ParallelSorter.ObjectComparer, org.springframework.cglib.util.ParallelSorter.IntComparer, org.springframework.cglib.util.ParallelSorter.LongComparer, org.springframework.cglib.util.ParallelSorter.FloatComparer, org.springframework.cglib.util.ParallelSorter.DoubleComparer, org.springframework.cglib.util.ParallelSorter.ShortComparer, org.springframework.cglib.util.ParallelSorter.ByteComparer

Method Summary

Modifier and TypeMethod and Description
public int
compare(int i, int j)

Method Detail

compareback to summary
public int compare(int i, int j)
org.springframework.cglib.util back to summary

pack-priv Class ParallelSorter.DoubleComparer

extends Object
implements Comparer
Class Inheritance
All Implemented Interfaces
org.springframework.cglib.util.ParallelSorter.Comparer

Field Summary

Modifier and TypeField and Description
private final double[]
a

Constructor Summary

AccessConstructor and Description
public
DoubleComparer(double[] a)

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final double[] a

Constructor Detail

DoubleComparerback to summary
public DoubleComparer(double[] a)

Method Detail

compareback to summary
public int compare(int i, int j)

Implements org.springframework.cglib.util.ParallelSorter.Comparer.compare.

Annotations
@Override
org.springframework.cglib.util back to summary

pack-priv Class ParallelSorter.FloatComparer

extends Object
implements Comparer
Class Inheritance
All Implemented Interfaces
org.springframework.cglib.util.ParallelSorter.Comparer

Field Summary

Modifier and TypeField and Description
private final float[]
a

Constructor Summary

AccessConstructor and Description
public
FloatComparer(float[] a)

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final float[] a

Constructor Detail

FloatComparerback to summary
public FloatComparer(float[] a)

Method Detail

compareback to summary
public int compare(int i, int j)

Implements org.springframework.cglib.util.ParallelSorter.Comparer.compare.

Annotations
@Override
org.springframework.cglib.util back to summary

public Class ParallelSorter.Generator

extends AbstractClassGenerator
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Object[]
private static final AbstractClassGenerator.Source

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ParallelSorter
protected Object
public void
protected ClassLoader
protected Object
public void
setArrays(Object[] arrays)

Inherited from org.springframework.cglib.core.AbstractClassGenerator:
creategenerategetAttemptLoadgetClassLoadergetClassNamegetCurrentgetNamingPolicygetProtectionDomaingetStrategygetUseCachesetAttemptLoadsetClassLoadersetContextClasssetNamePrefixsetNamingPolicysetStrategysetUseCacheunwrapCachedValuewrapCachedClass

Field Detail

arraysback to summary
private Object[] arrays
SOURCEback to summary
private static final AbstractClassGenerator.Source SOURCE

Constructor Detail

Generatorback to summary
public Generator()

Method Detail

createback to summary
public ParallelSorter create()
firstInstanceback to summary
protected Object firstInstance(Class<T> type)

Implements abstract org.springframework.cglib.core.AbstractClassGenerator.firstInstance.

Annotations
@Override
generateClassback to summary
public void generateClass(ClassVisitor v) throws Exception

Implements org.springframework.cglib.core.ClassGenerator.generateClass.

Annotations
@Override
getDefaultClassLoaderback to summary
protected ClassLoader getDefaultClassLoader()

Implements abstract org.springframework.cglib.core.AbstractClassGenerator.getDefaultClassLoader.

Annotations
@Override
nextInstanceback to summary
protected Object nextInstance(Object instance)

Implements abstract org.springframework.cglib.core.AbstractClassGenerator.nextInstance.

Annotations
@Override
setArraysback to summary
public void setArrays(Object[] arrays)
org.springframework.cglib.util back to summary

pack-priv Class ParallelSorter.IntComparer

extends Object
implements Comparer
Class Inheritance
All Implemented Interfaces
org.springframework.cglib.util.ParallelSorter.Comparer

Field Summary

Modifier and TypeField and Description
private final int[]
a

Constructor Summary

AccessConstructor and Description
public
IntComparer(int[] a)

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final int[] a

Constructor Detail

IntComparerback to summary
public IntComparer(int[] a)

Method Detail

compareback to summary
public int compare(int i, int j)

Implements org.springframework.cglib.util.ParallelSorter.Comparer.compare.

Annotations
@Override
org.springframework.cglib.util back to summary

pack-priv Class ParallelSorter.LongComparer

extends Object
implements Comparer
Class Inheritance
All Implemented Interfaces
org.springframework.cglib.util.ParallelSorter.Comparer

Field Summary

Modifier and TypeField and Description
private final long[]
a

Constructor Summary

AccessConstructor and Description
public
LongComparer(long[] a)

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final long[] a

Constructor Detail

LongComparerback to summary
public LongComparer(long[] a)

Method Detail

compareback to summary
public int compare(int i, int j)

Implements org.springframework.cglib.util.ParallelSorter.Comparer.compare.

Annotations
@Override
org.springframework.cglib.util back to summary

pack-priv Class ParallelSorter.ObjectComparer

extends Object
implements Comparer
Class Inheritance
All Implemented Interfaces
org.springframework.cglib.util.ParallelSorter.Comparer

Field Summary

Modifier and TypeField and Description
private final Object[]
a

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final Object[] a

Constructor Detail

ObjectComparerback to summary
public ObjectComparer(Object[] a)

Method Detail

compareback to summary
public int compare(int i, int j)

Implements org.springframework.cglib.util.ParallelSorter.Comparer.compare.

Annotations
@Override
org.springframework.cglib.util back to summary

pack-priv Class ParallelSorter.ShortComparer

extends Object
implements Comparer
Class Inheritance
All Implemented Interfaces
org.springframework.cglib.util.ParallelSorter.Comparer

Field Summary

Modifier and TypeField and Description
private final short[]
a

Constructor Summary

AccessConstructor and Description
public
ShortComparer(short[] a)

Method Summary

Modifier and TypeMethod and Description
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aback to summary
private final short[] a

Constructor Detail

ShortComparerback to summary
public ShortComparer(short[] a)

Method Detail

compareback to summary
public int compare(int i, int j)

Implements org.springframework.cglib.util.ParallelSorter.Comparer.compare.

Annotations
@Override