A heap is an implementation of a priority queue, which is a structure that maintains a sorted set of elements. The key property is that insertion of an arbitrary element and removal of the first element (determined by order) is performed in O(log n) time.
Heap elements are key/value pairs and are compared using the <=> generic word on the first element of the pair.
There are two classes of heaps. Min-heaps sort their elements so that the minimum element is first: