Binary heap sort in Python, based on Timothy J Fontaine's node.js implementation