com.alexkasko.unsafe.offheapstruct
class OffHeapStructSorterLong extends Object
alexkasko: borrowed from https://android.googlesource.com/platform/libcore/+/android-4.2.2_r1/luni/src/main/java/java/util/DualPivotQuicksort.java
and adapted to OffHeapStructCollection
with signed long keys.
This class implements the Dual-Pivot Quicksort algorithm by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. The algorithm offers O(n log(n)) performance on many data sets that cause other quicksorts to degrade to quadratic performance, and is typically faster than traditional (one-pivot) Quicksort implementations.
Modifier and Type | Class and Description |
---|---|
private static class |
OffHeapStructSorterLong.KeyWorker
Worker for two long keys sort
|
private static class |
OffHeapStructSorterLong.MergeIter
Merge-sort iterator over partly sorted collection
|
private static class |
OffHeapStructSorterLong.Worker
Worker, sorts part of the collection
|
Constructor and Description |
---|
OffHeapStructSorterLong() |
Modifier and Type | Method and Description |
---|---|
private static void |
doSort(OffHeapStructCollection a,
long left,
long right,
int keyOffset,
byte[] pi,
byte[] pj,
byte[] pe1,
byte[] pe2,
byte[] pe3,
byte[] pe4,
byte[] pe5)
Sorts the specified range of the off-heap struct collection into ascending order using signed long struct key.
|
private static void |
dualPivotQuicksort(OffHeapStructCollection a,
long left,
long right,
int keyOffset,
byte[] pi,
byte[] pj,
byte[] pe1,
byte[] pe2,
byte[] pe3,
byte[] pe4,
byte[] pe5)
Sorts the specified range of the off-heap struct collection into ascending order by the
Dual-Pivot Quicksort algorithm using signed long struct key.
|
(package private) static void |
sort(OffHeapStructCollection a,
int keyOffset)
Sorts the specified off-heap struct collection into ascending order using signed long struct key.
|
(package private) static void |
sort(OffHeapStructCollection a,
long fromIndex,
long toIndex,
int keyOffset)
Sorts the specified range of the off-heap struct collection into ascending order using signed long struct key.
|
(package private) static OffHeapDisposableIterator<byte[]> |
sortedIterator(ExecutorService executor,
int threads,
OffHeapStructCollection a,
int keyOffset)
Partially sorts collection and returns fully sorted iterator over it
|
(package private) static OffHeapDisposableIterator<byte[]> |
sortedIterator(ExecutorService executor,
int threads,
OffHeapStructCollection a,
long fromIndex,
long toIndex,
int keyOffset)
Partially sorts part of the collection and returns fully sorted iterator over it
|
(package private) static void |
sortTwoKeysParallel(Executor executor,
int threads,
OffHeapStructCollection a,
int key1Offset,
int key2Offset)
Sorts collection by two long keys.
|
OffHeapStructSorterLong()
static OffHeapDisposableIterator<byte[]> sortedIterator(ExecutorService executor, int threads, OffHeapStructCollection a, int keyOffset)
executor
- executor service for parallel sortingthreads
- number of worker threads to usea
- the off-heap struct collection to be sortedkeyOffset
- key offsetIllegalArgumentException
- if (fromIndex < 0 || fromIndex > toIndex || toIndex > a.size())
RuntimeException
- on worker thread errorstatic OffHeapDisposableIterator<byte[]> sortedIterator(ExecutorService executor, int threads, OffHeapStructCollection a, long fromIndex, long toIndex, int keyOffset)
executor
- executor service for parallel sortingthreads
- number of worker threads to usea
- the off-heap struct collection to be sortedfromIndex
- the index of the first element, inclusive, to be sortedtoIndex
- the index of the last element, exclusive, to be sortedkeyOffset
- key offsetIllegalArgumentException
- if (fromIndex < 0 || fromIndex > toIndex || toIndex > a.size())
RuntimeException
- on worker thread errorstatic void sortTwoKeysParallel(Executor executor, int threads, OffHeapStructCollection a, int key1Offset, int key2Offset)
executor
- executor for parallel sortingthreads
- number of worker threads to usea
- the off-heap struct collection to be sortedkey1Offset
- first key offsetkey2Offset
- second key offsetstatic void sort(OffHeapStructCollection a, int keyOffset)
a
- the off-heap struct collection to be sortedkeyOffset
- long key field offset within stuct boundsstatic void sort(OffHeapStructCollection a, long fromIndex, long toIndex, int keyOffset)
fromIndex
, inclusive, to
the index toIndex
, exclusive. If fromIndex == toIndex
,
the range to be sorted is empty (and the call is a no-op).a
- the off-heap struct collection to be sortedfromIndex
- the index of the first element, inclusive, to be sortedtoIndex
- the index of the last element, exclusive, to be sortedkeyOffset
- long sort key field offset within stuct boundsIllegalArgumentException
- if (fromIndex < 0 || fromIndex > toIndex || toIndex > a.size())
private static void doSort(OffHeapStructCollection a, long left, long right, int keyOffset, byte[] pi, byte[] pj, byte[] pe1, byte[] pe2, byte[] pe3, byte[] pe4, byte[] pe5)
sort
method in that the
right
index is inclusive, and it does no range checking on
left
or right
.a
- the off-heap header-payload collection to be sortedleft
- the index of the first element, inclusive, to be sortedright
- the index of the last element, inclusive, to be sorted* @param keyOffsetkeyOffset
- long sort key field offset within stuct boundspi
- temporary buffer for structspj
- temporary buffer for structspe1
- temporary buffer for structspe2
- temporary buffer for structspe3
- temporary buffer for structspe4
- temporary buffer for structspe5
- temporary buffer for structsprivate static void dualPivotQuicksort(OffHeapStructCollection a, long left, long right, int keyOffset, byte[] pi, byte[] pj, byte[] pe1, byte[] pe2, byte[] pe3, byte[] pe4, byte[] pe5)
a
- the off-heap header-payload collection to be sortedleft
- the index of the first element, inclusive, to be sortedright
- the index of the last element, inclusive, to be sortedkeyOffset
- long sort key field offset within stuct boundspi
- temporary buffer for structspj
- temporary buffer for structspe1
- temporary buffer for structspe2
- temporary buffer for structspe3
- temporary buffer for structspe4
- temporary buffer for structspe5
- temporary buffer for structsCopyright © 2014. All Rights Reserved.