/** * Fix the records into sorted order, swapping when the first record is * greater than the second record. * * @param s paged sortable * @param pN page number of first record * @param pO page offset of first record * @param rN page number of second record * @param rO page offset of second record */ private static void fix(IndexedSortable s, int pN, int pO, int rN, int rO) { if (s.compare(pN, pO, rN, rO) > 0) { s.swap(pN, pO, rN, rO); } }
/** * Sort the given range of items using quick sort. {@inheritDoc} If the recursion depth falls below * {@link #getMaxDepth}, then switch to {@link HeapSort}. */ public void sort(final IndexedSortable s, int p, int r) { int recordsPerSegment = s.recordsPerSegment(); int recordSize = s.recordSize(); int maxOffset = recordSize * (recordsPerSegment - 1); int pN = p / recordsPerSegment; int pO = (p % recordsPerSegment) * recordSize; int rN = r / recordsPerSegment; int rO = (r % recordsPerSegment) * recordSize; sortInternal(s, recordsPerSegment, recordSize, maxOffset, p, pN, pO, r, rN, rO, getMaxDepth(r - p)); }
@Override public void sort(IndexedSortable s) { sort(s, 0, s.size()); } }
public void sort(final IndexedSortable s, final int p, final int r) { final int N = r - p; // build heap w/ reverse comparator, then write in-place from end final int t = Integer.highestOneBit(N); for (int i = t; i > 1; i >>>= 1) { for (int j = i >>> 1; j < i; ++j) { downHeap(s, p - 1, j, N + 1); } } for (int i = r - 1; i > p; --i) { s.swap(p, i); downHeap(s, p - 1, 1, i - p + 1); } }
/** * Sort the given range of items using quick sort. {@inheritDoc} If the recursion depth falls below * {@link #getMaxDepth}, then switch to {@link HeapSort}. */ public void sort(final IndexedSortable s, int p, int r) { int recordsPerSegment = s.recordsPerSegment(); int recordSize = s.recordSize(); int maxOffset = recordSize * (recordsPerSegment - 1); int pN = p / recordsPerSegment; int pO = (p % recordsPerSegment) * recordSize; int rN = r / recordsPerSegment; int rO = (r % recordsPerSegment) * recordSize; sortInternal(s, recordsPerSegment, recordSize, maxOffset, p, pN, pO, r, rN, rO, getMaxDepth(r - p)); }
@Override public void sort(IndexedSortable s) { sort(s, 0, s.size()); } }
public void sort(final IndexedSortable s, final int p, final int r) { final int N = r - p; // build heap w/ reverse comparator, then write in-place from end final int t = Integer.highestOneBit(N); for (int i = t; i > 1; i >>>= 1) { for (int j = i >>> 1; j < i; ++j) { downHeap(s, p - 1, j, N + 1); } } for (int i = r - 1; i > p; --i) { s.swap(p, i); downHeap(s, p - 1, 1, i - p + 1); } }
/** * Fix the records into sorted order, swapping when the first record is * greater than the second record. * * @param s paged sortable * @param pN page number of first record * @param pO page offset of first record * @param rN page number of second record * @param rO page offset of second record */ private static void fix(IndexedSortable s, int pN, int pO, int rN, int rO) { if (s.compare(pN, pO, rN, rO) > 0) { s.swap(pN, pO, rN, rO); } }
/** * Sort the given range of items using quick sort. {@inheritDoc} If the recursion depth falls below * {@link #getMaxDepth}, then switch to {@link HeapSort}. */ public void sort(final IndexedSortable s, int p, int r) { int recordsPerSegment = s.recordsPerSegment(); int recordSize = s.recordSize(); int maxOffset = recordSize * (recordsPerSegment - 1); int pN = p / recordsPerSegment; int pO = (p % recordsPerSegment) * recordSize; int rN = r / recordsPerSegment; int rO = (r % recordsPerSegment) * recordSize; sortInternal(s, recordsPerSegment, recordSize, maxOffset, p, pN, pO, r, rN, rO, getMaxDepth(r - p)); }
@Override public void sort(IndexedSortable s) { sort(s, 0, s.size()); } }
public void sort(final IndexedSortable s, final int p, final int r) { final int N = r - p; // build heap w/ reverse comparator, then write in-place from end final int t = Integer.highestOneBit(N); for (int i = t; i > 1; i >>>= 1) { for (int j = i >>> 1; j < i; ++j) { downHeap(s, p - 1, j, N + 1); } } for (int i = r - 1; i > p; --i) { s.swap(p, i); downHeap(s, p - 1, 1, i - p + 1); } }
/** * Fix the records into sorted order, swapping when the first record is * greater than the second record. * * @param s paged sortable * @param pN page number of first record * @param pO page offset of first record * @param rN page number of second record * @param rO page offset of second record */ private static void fix(IndexedSortable s, int pN, int pO, int rN, int rO) { if (s.compare(pN, pO, rN, rO) > 0) { s.swap(pN, pO, rN, rO); } }
/** * Sort the given range of items using quick sort. {@inheritDoc} If the recursion depth falls below * {@link #getMaxDepth}, then switch to {@link HeapSort}. */ public void sort(final IndexedSortable s, int p, int r) { int recordsPerSegment = s.recordsPerSegment(); int recordSize = s.recordSize(); int maxOffset = recordSize * (recordsPerSegment - 1); int pN = p / recordsPerSegment; int pO = (p % recordsPerSegment) * recordSize; int rN = r / recordsPerSegment; int rO = (r % recordsPerSegment) * recordSize; sortInternal(s, recordsPerSegment, recordSize, maxOffset, p, pN, pO, r, rN, rO, getMaxDepth(r - p)); }
@Override public void sort(IndexedSortable s) { sort(s, 0, s.size()); } }
public void sort(final IndexedSortable s, final int p, final int r) { final int N = r - p; // build heap w/ reverse comparator, then write in-place from end final int t = Integer.highestOneBit(N); for (int i = t; i > 1; i >>>= 1) { for (int j = i >>> 1; j < i; ++j) { downHeap(s, p - 1, j, N + 1); } } for (int i = r - 1; i > p; --i) { s.swap(p, i); downHeap(s, p - 1, 1, i - p + 1); } }
private static void downHeap(final IndexedSortable s, final int b, int i, final int N) { for (int idx = i << 1; idx < N; idx = i << 1) { if (idx + 1 < N && s.compare(b + idx, b + idx + 1) < 0) { if (s.compare(b + i, b + idx + 1) < 0) { s.swap(b + i, b + idx + 1); } else { return; } i = idx + 1; } else if (s.compare(b + i, b + idx) < 0) { s.swap(b + i, b + idx); i = idx; } else { return; } } }
public void sort(IndexedSortable s) { sort(s, 0, s.size()); }
/** * Fix the records into sorted order, swapping when the first record is * greater than the second record. * * @param s paged sortable * @param pN page number of first record * @param pO page offset of first record * @param rN page number of second record * @param rO page offset of second record */ private static void fix(IndexedSortable s, int pN, int pO, int rN, int rO) { if (s.compare(pN, pO, rN, rO) > 0) { s.swap(pN, pO, rN, rO); } }
public void sort(IndexedSortable s) { sort(s, 0, s.size()); }
private static void downHeap(final IndexedSortable s, final int b, int i, final int N) { for (int idx = i << 1; idx < N; idx = i << 1) { if (idx + 1 < N && s.compare(b + idx, b + idx + 1) < 0) { if (s.compare(b + i, b + idx + 1) < 0) { s.swap(b + i, b + idx + 1); } else { return; } i = idx + 1; } else if (s.compare(b + i, b + idx) < 0) { s.swap(b + i, b + idx); i = idx; } else { return; } } }