heap implementation based on Python's heapq