Class BufferSort

java.lang.Object
tech.bitey.bufferstuff.BufferSort

public class BufferSort extends Object
Sorting algorithms for nio buffers.
Author:
biteytech@protonmail.com, heap-sort adapted from programiz.com
  • Constructor Details

    • BufferSort

      public BufferSort()
  • Method Details

    • heapSort

      public static void heapSort(IntBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified IntBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(IntBuffer b, IntBinaryOperator comparator, int fromIndex, int toIndex)
      Sorts a range of the specified IntBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      comparator - used to compare values from b. useful when the integers are identifiers or indices referencing some external data structure.
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(LongBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified LongBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(ShortBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified ShortBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(ByteBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified ByteBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(FloatBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified FloatBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(DoubleBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified DoubleBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • radixSort

      public static void radixSort(IntBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified IntBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n) in the worst case. However, radix sort has more overhead than heat sort, and is only faster for large ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • radixSort

      public static void radixSort(LongBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified LongBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n) in the worst case. However, radix sort has more overhead than heat sort, and is only faster for large ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • countingSort

      public static void countingSort(ShortBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified ShortBuffer in ascending order (lowest first). This sort is O(n) in the worst case, but it creates and iterates over an int array of length 2^16.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • countingSort

      public static void countingSort(ByteBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified ByteBuffer in ascending order (lowest first). This sort is O(n) in the worst case, but it creates and iterates over an int array of length 2^8.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(IntBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified IntBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(LongBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified LongBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(ShortBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified ShortBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(ByteBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified ByteBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(FloatBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified FloatBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(DoubleBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified DoubleBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(IntBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified IntBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      [100 - 10^7) heapSort
      10^7+ radixSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(LongBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified LongBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      [100 - 10^7) heapSort
      10^7+ radixSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(ShortBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified ShortBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      [100 - 10^7) heapSort
      10^7+ countingSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(ByteBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified ByteBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      [100 - 10^5) heapSort
      10^5+ countingSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(FloatBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified FloatBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      100+ heapSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(DoubleBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified DoubleBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      100+ heapSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(SmallIntBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallIntBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(SmallIntBuffer b, IntBinaryOperator comparator, int fromIndex, int toIndex)
      Sorts a range of the specified SmallIntBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      comparator - used to compare values from b. useful when the integers are identifiers or indices referencing some external data structure.
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(SmallLongBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallLongBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(SmallShortBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallShortBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(SmallByteBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallByteBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(SmallFloatBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallFloatBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • heapSort

      public static void heapSort(SmallDoubleBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallDoubleBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n*log(n)) in the worst case
      • a good general-purpose sorting algorithm
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • radixSort

      public static void radixSort(SmallIntBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallIntBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n) in the worst case. However, radix sort has more overhead than heat sort, and is only faster for large ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • radixSort

      public static void radixSort(SmallLongBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallLongBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n) in the worst case. However, radix sort has more overhead than heat sort, and is only faster for large ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • countingSort

      public static void countingSort(SmallShortBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallShortBuffer in ascending order (lowest first). This sort is O(n) in the worst case, but it creates and iterates over an int array of length 2^16.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • countingSort

      public static void countingSort(SmallByteBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallByteBuffer in ascending order (lowest first). This sort is O(n) in the worst case, but it creates and iterates over an int array of length 2^8.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(SmallIntBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallIntBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(SmallLongBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallLongBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(SmallShortBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallShortBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(SmallByteBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallByteBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(SmallFloatBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallFloatBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • insertionSort

      public static void insertionSort(SmallDoubleBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallDoubleBuffer in ascending order (lowest first). The sort is:
      • in-place
      • O(n^2) in the worst case. However, insertion sort has less overhead than heat sort, and is faster for small ranges.
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(SmallIntBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallIntBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      [100 - 10^7) heapSort
      10^7+ radixSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(SmallLongBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallLongBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      [100 - 10^7) heapSort
      10^7+ radixSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(SmallShortBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallShortBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      [100 - 10^7) heapSort
      10^7+ countingSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(SmallByteBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallByteBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      [100 - 10^5) heapSort
      10^5+ countingSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(SmallFloatBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallFloatBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      100+ heapSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • sort

      public static void sort(SmallDoubleBuffer b, int fromIndex, int toIndex)
      Sorts a range of the specified SmallDoubleBuffer in ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:
      Length Algorithm
      [0 - 100) insertionSort
      100+ heapSort
      Parameters:
      b - the buffer to be sorted
      fromIndex - the index of the first element (inclusive) to be sorted
      toIndex - the index of the last element (exclusive) to be sorted
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()