m3sh.heap.
Heap#
- class Heap(items=None)#
Heap data structure.
A heap stores (obj, key) tuples, called heap items. Stored objects have to be hashable. Keys are compared using the < operator. Custom classes used as keys have to implement
__lt__().- Parameters:
- itemsiterable, optional
A sequence of (obj, key) tuples. If not provided, an empty heap is created.
See also
Examples
Given two iterables objs and keys, one holding objects the other holding keys, a heap can be initialized using
zip():>>> heap = Heap(zip(objs, keys))
Attributes
Access top item.
Methods