Transcribed an implementation of heap as accumulation (beware, the datatype index has changed)