Heap implementation. For details see the comment in Heap.java