Sorts the given array using the Bitonic Sort algorithm. @param the type of elements in the array, which must implement the Comparable interface @param array the array to be sorted @return the sorted array
(T[] array)
| 20 | * @return the sorted array |
| 21 | */ |
| 22 | @Override |
| 23 | public <T extends Comparable<T>> T[] sort(T[] array) { |
| 24 | if (array.length == 0) { |
| 25 | return array; |
| 26 | } |
| 27 | |
| 28 | final int paddedSize = nextPowerOfTwo(array.length); |
| 29 | T[] paddedArray = Arrays.copyOf(array, paddedSize); |
| 30 | |
| 31 | // Fill the padded part with a maximum value |
| 32 | final T maxValue = max(array); |
| 33 | Arrays.fill(paddedArray, array.length, paddedSize, maxValue); |
| 34 | |
| 35 | bitonicSort(paddedArray, 0, paddedSize, Direction.ASCENDING); |
| 36 | return Arrays.copyOf(paddedArray, array.length); |
| 37 | } |
| 38 | |
| 39 | private <T extends Comparable<T>> void bitonicSort(final T[] array, final int low, final int cnt, final Direction direction) { |
| 40 | if (cnt > 1) { |
nothing calls this directly
no test coverage detected