private int siftDownComparatorDesc(int index, final int value) { assert comparator != null; int half = size >>> 1; while (index < half) { // loop while a non-leaf int child = (index << 1) + 1; // assume left child is largest int c = array[child]; int right = child + 1; if (right < size && comparator.compare(c, array[right]) < 0) c = array[child = right]; if (comparator.compare(value, c) >= 0) break; array[index] = c; index = child; } array[index] = value; return index; }
private int siftUpComparatorDesc(int index, final int value) { assert comparator != null; while (index > 0) { int parent = (index - 1) >>> 1; int e = array[parent]; if (comparator.compare(value, e) <= 0) break; array[index] = e; index = parent; } array[index] = value; return index; }