Top Description Fields Constructors Methods
com.sun.marlin

public final Class DualPivotQuicksort20191112Ext

extends Object
Class Inheritance
Imports
java.util.Arrays

This class implements powerful and fully optimized versions, both sequential and parallel, of the Dual-Pivot Quicksort algorithm by Vladimir Yaroslavskiy, Jon Bentley and Josh Bloch. This algorithm offers O(n log(n)) performance on all data sets, and is typically faster than traditional (one-pivot) Quicksort implementations. There are also additional algorithms, invoked from the Dual-Pivot Quicksort, such as mixed insertion sort, merging of runs and heap sort, counting sort and parallel merge sort.
Authors
Vladimir Yaroslavskiy, Jon Bentley, Josh Bloch, Doug Lea
Since
1.7 * 14
Version
2018.08.18

Field Summary

Modifier and TypeField and Description
private static final int
DELTA

Threshold of mixed insertion sort is incremented by this value.

private static final boolean
private static final int
MAX_INSERTION_SORT_SIZE

Max array size to use insertion sort.

private static final int
MAX_MIXED_INSERTION_SORT_SIZE

Max array size to use mixed insertion sort.

private static final int
MAX_RECURSION_DEPTH

Max recursive partitioning depth before using heap sort.

pack-priv static final int
MAX_RUN_CAPACITY

Max capacity of the index array for tracking runs.

private static final int
MIN_FIRST_RUN_SIZE

Min size of the first run to continue with scanning.

private static final int
MIN_FIRST_RUNS_FACTOR

Min factor for the first runs to continue scanning.

private static final int
MIN_TRY_MERGE_SIZE

Min array size to try merging of runs.

Constructor Summary

AccessConstructor and Description
private
DualPivotQuicksort20191112Ext()

Prevents instantiation.

Method Summary

Modifier and TypeMethod and Description
private static void
heapSort(int[]
the array to be sorted
a
,
int[]
the secondary array to be ordered
b
,
int
the index of the first element, inclusive, to be sorted
low
,
int
the index of the last element, exclusive, to be sorted
high
)

Sorts the specified range of the array using heap sort.

pack-priv static void
insertionSort(int[]
the array to be sorted
a
,
int[]
the secondary array to be ordered
b
,
int
the index of the first element, inclusive, to be sorted
low
,
int
the index of the last element, exclusive, to be sorted
high
)

Sorts the specified range of the array using insertion sort.

private static void
mergeParts(int[]
the destination where parts are merged (a)
dstA
,
int[]
the destination where parts are merged (b)
dstB
,
int
the start index of the destination, inclusive
k
,
int[]
the first part (a)
a1
,
int[]
the first part (b)
b1
,
int
the start index of the first part, inclusive
lo1
,
int
the end index of the first part, exclusive
hi1
,
int[]
the second part (a)
a2
,
int[]
the second part (b)
b2
,
int
the start index of the second part, inclusive
lo2
,
int
the end index of the second part, exclusive
hi2
)

Merges the sorted parts.

private static int[]

Returns:

the destination where runs are merged
mergeRuns
(int[]
the source array for the array to be sorted (a)
srcA
,
int[]
the temporary buffer used in merging (a)
dstA
,
int[]
the source array for the secondary array to be ordered (b)
srcB
,
int[]
the temporary buffer used in merging (b)
dstB
,
int
the start index in the source, inclusive
offset
,
int
specifies merging: to source ( > 0), buffer ( < 0) or any ( == 0)
aim
,
int[]
the start indexes of the runs, inclusive
run
,
int
the start index of the first run, inclusive
lo
,
int
the start index of the last run, inclusive
hi
)

Merges the specified runs.

private static void
mixedInsertionSort(int[]
the array to be sorted
a
,
int[]
the secondary array to be ordered
b
,
int
the index of the first element, inclusive, to be sorted
low
,
int
the index of the last element for simple insertion sort
end
,
int
the index of the last element, exclusive, to be sorted
high
)

Sorts the specified range of the array using mixed insertion sort.

private static void
pushDown(int[]
the array to be sorted
a
,
int[]
the secondary array to be ordered
b
,
int
the start index
p
,
int
the given element in a
valueA
,
int
the given element in b
valueB
,
int
the index of the first element, inclusive, to be sorted
low
,
int
the index of the last element, exclusive, to be sorted
high
)

Pushes specified element down during heap sort.

pack-priv static void
sort(DPQSSorterContext
sorter context
sorter
,
int[]
the array to be sorted
a
,
int[]
auxiliary storage for the array to be sorted
auxA
,
int[]
the secondary array to be ordered
b
,
int[]
auxiliary storage for the permutation array to be handled
auxB
,
int
the index of the first element, inclusive, to be sorted
low
,
int
the index of the last element, exclusive, to be sorted
high
)

Sorts the specified range of the array.

private static void
sort(DPQSSorterContext
sorter context
sorter
,
int[]
the array to be sorted
a
,
int[]
the secondary array to be ordered
b
,
int
the combination of recursion depth and bit flag, where the right bit "0" indicates that array is the leftmost part
bits
,
int
the index of the first element, inclusive, to be sorted
low
,
int
the index of the last element, exclusive, to be sorted
high
)

Sorts the specified array using the Dual-Pivot Quicksort and/or other sorts in special-cases, possibly with parallel partitions.

private static boolean

Returns:

true if finally sorted, false otherwise
tryMergeRuns
(DPQSSorterContext
sorter context
sorter
,
int[]
the array to be sorted
a
,
int[]
the secondary array to be ordered
b
,
int
the index of the first element to be sorted
low
,
int
the array size
size
)

Tries to sort the specified range of the array.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DELTAback to summary
private static final int DELTA

Threshold of mixed insertion sort is incremented by this value.

FAST_ISORTback to summary
private static final boolean FAST_ISORT
MAX_INSERTION_SORT_SIZEback to summary
private static final int MAX_INSERTION_SORT_SIZE

Max array size to use insertion sort.

MAX_MIXED_INSERTION_SORT_SIZEback to summary
private static final int MAX_MIXED_INSERTION_SORT_SIZE

Max array size to use mixed insertion sort.

MAX_RECURSION_DEPTHback to summary
private static final int MAX_RECURSION_DEPTH

Max recursive partitioning depth before using heap sort.

MAX_RUN_CAPACITYback to summary
pack-priv static final int MAX_RUN_CAPACITY

Max capacity of the index array for tracking runs.

MIN_FIRST_RUN_SIZEback to summary
private static final int MIN_FIRST_RUN_SIZE

Min size of the first run to continue with scanning.

MIN_FIRST_RUNS_FACTORback to summary
private static final int MIN_FIRST_RUNS_FACTOR

Min factor for the first runs to continue scanning.

MIN_TRY_MERGE_SIZEback to summary
private static final int MIN_TRY_MERGE_SIZE

Min array size to try merging of runs.

Constructor Detail

DualPivotQuicksort20191112Extback to summary
private DualPivotQuicksort20191112Ext()

Prevents instantiation.

Method Detail

heapSortback to summary
private static void heapSort(int[] a, int[] b, int low, int high)

Sorts the specified range of the array using heap sort.

Parameters
a:int[]

the array to be sorted

b:int[]

the secondary array to be ordered

low:int

the index of the first element, inclusive, to be sorted

high:int

the index of the last element, exclusive, to be sorted

insertionSortback to summary
pack-priv static void insertionSort(int[] a, int[] b, int low, int high)

Sorts the specified range of the array using insertion sort.

Parameters
a:int[]

the array to be sorted

b:int[]

the secondary array to be ordered

low:int

the index of the first element, inclusive, to be sorted

high:int

the index of the last element, exclusive, to be sorted

mergePartsback to summary
private static void mergeParts(int[] dstA, int[] dstB, int k, int[] a1, int[] b1, int lo1, int hi1, int[] a2, int[] b2, int lo2, int hi2)

Merges the sorted parts.

Parameters
dstA:int[]

the destination where parts are merged (a)

dstB:int[]

the destination where parts are merged (b)

k:int

the start index of the destination, inclusive

a1:int[]

the first part (a)

b1:int[]

the first part (b)

lo1:int

the start index of the first part, inclusive

hi1:int

the end index of the first part, exclusive

a2:int[]

the second part (a)

b2:int[]

the second part (b)

lo2:int

the start index of the second part, inclusive

hi2:int

the end index of the second part, exclusive

mergeRunsback to summary
private static int[] mergeRuns(int[] srcA, int[] dstA, int[] srcB, int[] dstB, int offset, int aim, int[] run, int lo, int hi)

Merges the specified runs.

Parameters
srcA:int[]

the source array for the array to be sorted (a)

dstA:int[]

the temporary buffer used in merging (a)

srcB:int[]

the source array for the secondary array to be ordered (b)

dstB:int[]

the temporary buffer used in merging (b)

offset:int

the start index in the source, inclusive

aim:int

specifies merging: to source ( > 0), buffer ( < 0) or any ( == 0)

run:int[]

the start indexes of the runs, inclusive

lo:int

the start index of the first run, inclusive

hi:int

the start index of the last run, inclusive

Returns:int[]

the destination where runs are merged

mixedInsertionSortback to summary
private static void mixedInsertionSort(int[] a, int[] b, int low, int end, int high)

Sorts the specified range of the array using mixed insertion sort. Mixed insertion sort is combination of simple insertion sort, pin insertion sort and pair insertion sort. In the context of Dual-Pivot Quicksort, the pivot element from the left part plays the role of sentinel, because it is less than any elements from the given part. Therefore, expensive check of the left range can be skipped on each iteration unless it is the leftmost call.

Parameters
a:int[]

the array to be sorted

b:int[]

the secondary array to be ordered

low:int

the index of the first element, inclusive, to be sorted

end:int

the index of the last element for simple insertion sort

high:int

the index of the last element, exclusive, to be sorted

pushDownback to summary
private static void pushDown(int[] a, int[] b, int p, int valueA, int valueB, int low, int high)

Pushes specified element down during heap sort.

Parameters
a:int[]

the array to be sorted

b:int[]

the secondary array to be ordered

p:int

the start index

valueA:int

the given element in a

valueB:int

the given element in b

low:int

the index of the first element, inclusive, to be sorted

high:int

the index of the last element, exclusive, to be sorted

sortback to summary
pack-priv static void sort(DPQSSorterContext sorter, int[] a, int[] auxA, int[] b, int[] auxB, int low, int high)

Sorts the specified range of the array.

Parameters
sorter:DPQSSorterContext

sorter context

a:int[]

the array to be sorted

auxA:int[]

auxiliary storage for the array to be sorted

b:int[]

the secondary array to be ordered

auxB:int[]

auxiliary storage for the permutation array to be handled

low:int

the index of the first element, inclusive, to be sorted

high:int

the index of the last element, exclusive, to be sorted

sortback to summary
private static void sort(DPQSSorterContext sorter, int[] a, int[] b, int bits, int low, int high)

Sorts the specified array using the Dual-Pivot Quicksort and/or other sorts in special-cases, possibly with parallel partitions.

Parameters
sorter:DPQSSorterContext

sorter context

a:int[]

the array to be sorted

b:int[]

the secondary array to be ordered

bits:int

the combination of recursion depth and bit flag, where the right bit "0" indicates that array is the leftmost part

low:int

the index of the first element, inclusive, to be sorted

high:int

the index of the last element, exclusive, to be sorted

tryMergeRunsback to summary
private static boolean tryMergeRuns(DPQSSorterContext sorter, int[] a, int[] b, int low, int size)

Tries to sort the specified range of the array.

Parameters
sorter:DPQSSorterContext

sorter context

a:int[]

the array to be sorted

b:int[]

the secondary array to be ordered

low:int

the index of the first element to be sorted

size:int

the array size

Returns:boolean

true if finally sorted, false otherwise