MinHeap

class m3sh.heap.MinHeap(items=None)[source]

Priority queue.

Smaller priority values signify higher priority. The top element of a priority queue is the object of highest priority.

Parameters:

items (iterable, optional) – A sequence of (object, priority) pairs. Generically, priority is a numeric data type.

Raises:

TypeError – If items is not iterable.

Note

Only hashable objects can be added to a heap. All user defined types are hashable.

Attributes

top

Access item of highest priority.

Methods

pop()

Remove item of highest priority.

push(data, priority)

Add data object.

remove(data)

Remove data object from heap.

update(data, priority)

Update priority of a data object.

Special methods

__contains__(item)

Containment check.

__iter__()

Item iterator.

__len__()

Return number of queued items.