Binary heap implementation from:

http://eloquentjavascript.net/appendix2.html