com.alexkasko.unsafe.offheapstruct
class OffHeapStructSorterUnsignedLong 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 unsigned 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.
Constructor and Description |
---|
OffHeapStructSorterUnsignedLong() |
Modifier and Type | Method and Description |
---|---|
private static int |
compareUnsigned(long l1,
long l2) |
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 unsigned 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 unsigned long struct key.
|
private static boolean |
gt(long l1,
long l2) |
private static boolean |
lt(long l1,
long l2) |
(package private) static void |
sort(OffHeapStructCollection a,
int keyOffset)
Sorts the specified off-heap struct collection into ascending order using unsigned 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 unsigned long struct key.
|
OffHeapStructSorterUnsignedLong()
static 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 structsprivate static boolean gt(long l1, long l2)
private static boolean lt(long l1, long l2)
private static int compareUnsigned(long l1, long l2)
Copyright © 2014. All Rights Reserved.