private void downHeap(int idx) {
        Reference<E> e = entries.array[idx];

        int iter = idx;
        while (hasChildren(iter)) {
            int cidx = leftChild(iter);
            Reference<E> c = entries.array[cidx];

            if (hasRightChild(iter)) {
                int rcidx = rightChild(iter);
                Reference<E> rc = entries.array[rcidx];
                if (compare(rc, c) < 0) {
                    cidx = rcidx;
                    c = rc;
                }
            }

            if (compare(e, c) <= 0) {
                break;
            }

            entries.array[cidx] = e;
            entries.array[iter] = c;
            c.index = iter;
            iter = cidx;
        }

        e.index = iter;
    }
private void downHeap ( int idx ) { Reference < E > e = entries . array [ idx ] ; int iter = idx ; while ( hasChildren ( iter ) ) { int cidx = leftChild ( iter ) ; Reference < E > c = entries . array [ cidx ] ; if ( hasRightChild ( iter ) ) { int rcidx = rightChild ( iter ) ; Reference < E > rc = entries . array [ rcidx ] ; if ( compare ( rc , c ) < 0 ) { cidx = rcidx ; c = rc ; } } if ( compare ( e , c ) <= 0 ) { break ; } entries . array [ cidx ] = e ; entries . array [ iter ] = c ; c . index = iter ; iter = cidx ; } e . index = iter ; }
Move an element downwards inside the heap, until all of its children have a key greater or equal to its own.