| 224 | } |
| 225 | |
| 226 | private static <T> void siftDown(T[] array, Comparator<? super T> comparator, |
| 227 | int i, int count, int offset) |
| 228 | { |
| 229 | T value = array[offset + i]; |
| 230 | while (i < count / 2) { |
| 231 | int child = 2 * i + 1; |
| 232 | if (child + 1 < count && |
| 233 | comparator.compare(array[child], array[child + 1]) < 0) { |
| 234 | ++child; |
| 235 | } |
| 236 | if (comparator.compare(value, array[child]) >= 0) { |
| 237 | break; |
| 238 | } |
| 239 | array[offset + i] = array[offset + child]; |
| 240 | i = child; |
| 241 | } |
| 242 | array[offset + i] = value; |
| 243 | } |
| 244 | |
| 245 | private static <T> void insertionSort(T[] array, |
| 246 | Comparator<? super T> comparator) |