Package tech.bitey.bufferstuff
Class BufferSort
- java.lang.Object
-
- tech.bitey.bufferstuff.BufferSort
-
public class BufferSort extends java.lang.ObjectSorting algorithms for nio buffers.- Author:
- biteytech@protonmail.com, heap-sort adapted from programiz.com
-
-
Constructor Summary
Constructors Constructor Description BufferSort()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcountingSort(java.nio.ByteBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedByteBufferin ascending order (lowest first).static voidcountingSort(java.nio.ShortBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedShortBufferin ascending order (lowest first).static voidheapSort(java.nio.ByteBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedByteBufferin ascending order (lowest first).static voidheapSort(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedDoubleBufferin ascending order (lowest first).static voidheapSort(java.nio.FloatBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedFloatBufferin ascending order (lowest first).static voidheapSort(java.nio.IntBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin ascending order (lowest first).static voidheapSort(java.nio.IntBuffer b, java.util.function.IntBinaryOperator comparator, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin ascending order (lowest first).static voidheapSort(java.nio.LongBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedLongBufferin ascending order (lowest first).static voidheapSort(java.nio.ShortBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedShortBufferin ascending order (lowest first).static voidinsertionSort(java.nio.ByteBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedByteBufferin ascending order (lowest first).static voidinsertionSort(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedDoubleBufferin ascending order (lowest first).static voidinsertionSort(java.nio.FloatBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedFloatBufferin ascending order (lowest first).static voidinsertionSort(java.nio.IntBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin ascending order (lowest first).static voidinsertionSort(java.nio.LongBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedLongBufferin ascending order (lowest first).static voidinsertionSort(java.nio.ShortBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedShortBufferin ascending order (lowest first).static voidradixSort(java.nio.IntBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin ascending order (lowest first).static voidradixSort(java.nio.LongBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedLongBufferin ascending order (lowest first).static voidsort(java.nio.ByteBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedByteBufferin ascending order (lowest first).static voidsort(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedDoubleBufferin ascending order (lowest first).static voidsort(java.nio.FloatBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedFloatBufferin ascending order (lowest first).static voidsort(java.nio.IntBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin ascending order (lowest first).static voidsort(java.nio.LongBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedLongBufferin ascending order (lowest first).static voidsort(java.nio.ShortBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedShortBufferin ascending order (lowest first).
-
-
-
Method Detail
-
heapSort
public static void heapSort(java.nio.IntBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
heapSort
public static void heapSort(java.nio.IntBuffer b, java.util.function.IntBinaryOperator comparator, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin 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 sortedcomparator- used to compare values fromb. useful when the integers are identifiers or indices referencing some external data structure.fromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
heapSort
public static void heapSort(java.nio.LongBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedLongBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
heapSort
public static void heapSort(java.nio.ShortBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedShortBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
heapSort
public static void heapSort(java.nio.ByteBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedByteBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
heapSort
public static void heapSort(java.nio.FloatBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedFloatBufferin ascending order (lowest first). The sort is:- in-place
O(n*log(n))in the worst case- a good general-purpose sorting algorithm
Float.POSITIVE_INFINITY).- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
heapSort
public static void heapSort(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedDoubleBufferin ascending order (lowest first). The sort is:- in-place
O(n*log(n))in the worst case- a good general-purpose sorting algorithm
Double.POSITIVE_INFINITY).- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
radixSort
public static void radixSort(java.nio.IntBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
radixSort
public static void radixSort(java.nio.LongBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedLongBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
countingSort
public static void countingSort(java.nio.ShortBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedShortBufferin ascending order (lowest first). This sort isO(n)in the worst case, but it creates and iterates over anintarray of length 2^16.- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
countingSort
public static void countingSort(java.nio.ByteBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedByteBufferin ascending order (lowest first). This sort isO(n)in the worst case, but it creates and iterates over anintarray of length 2^8.- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
insertionSort
public static void insertionSort(java.nio.IntBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
insertionSort
public static void insertionSort(java.nio.LongBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedLongBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
insertionSort
public static void insertionSort(java.nio.ShortBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedShortBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
insertionSort
public static void insertionSort(java.nio.ByteBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedByteBufferin 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 sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
insertionSort
public static void insertionSort(java.nio.FloatBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedFloatBufferin 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.
Float.POSITIVE_INFINITY).- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
insertionSort
public static void insertionSort(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedDoubleBufferin 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.
Double.POSITIVE_INFINITY).- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
sort
public static void sort(java.nio.IntBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedIntBufferin ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:Length Algorithm [0 - 100)insertionSort[100 - 10^7)heapSort10^7+radixSort- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
sort
public static void sort(java.nio.LongBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedLongBufferin ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:Length Algorithm [0 - 100)insertionSort[100 - 10^7)heapSort10^7+radixSort- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
sort
public static void sort(java.nio.ShortBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedShortBufferin ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:Length Algorithm [0 - 100)insertionSort[100 - 10^7)heapSort10^7+countingSort- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
sort
public static void sort(java.nio.ByteBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedByteBufferin ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:Length Algorithm [0 - 100)insertionSort[100 - 10^5)heapSort10^5+countingSort- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
sort
public static void sort(java.nio.FloatBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedFloatBufferin ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:Length Algorithm [0 - 100)insertionSort100+heapSort- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
sort
public static void sort(java.nio.DoubleBuffer b, int fromIndex, int toIndex)Sorts a range of the specifiedDoubleBufferin ascending order (lowest first). The actual sorting algorithm used depends on the length of the range:Length Algorithm [0 - 100)insertionSort100+heapSort- Parameters:
b- the buffer to be sortedfromIndex- the index of the first element (inclusive) to be sortedtoIndex- the index of the last element (exclusive) to be sorted- Throws:
java.lang.IllegalArgumentException- iffromIndex > toIndexjava.lang.IndexOutOfBoundsException- iffromIndex < 0 or toIndex > b.capacity()
-
-