| 117 | } |
| 118 | |
| 119 | private static <T> void siftDown(List<T> list, Comparator<? super T> comparator, |
| 120 | int i, int count, int offset) |
| 121 | { |
| 122 | T value = list.get(offset + i); |
| 123 | while (i < count / 2) { |
| 124 | int child = 2 * i + 1; |
| 125 | if (child + 1 < count && |
| 126 | comparator.compare(list.get(child), list.get(child + 1)) < 0) { |
| 127 | ++child; |
| 128 | } |
| 129 | if (comparator.compare(value, list.get(child)) >= 0) { |
| 130 | break; |
| 131 | } |
| 132 | list.set(offset + i, list.get(offset + child)); |
| 133 | i = child; |
| 134 | } |
| 135 | list.set(offset + i, value); |
| 136 | } |
| 137 | |
| 138 | private static <T> void insertionSort(List<T> list, |
| 139 | Comparator<? super T> comparator) |