mate_common.datastructures.priority_queue module

This module provides a max-heap wrapper over Python’s min-heap.

class mate_common.datastructures.priority_queue.PriorityQueue

Bases: Generic[mate_common.datastructures.priority_queue.T]

Wrapper to enforce heap invariants by hiding underlying list.

Unfortunately python provides a standard min-heap but not a max-heap; this class ranks by maximum priority by inverting the priority before pushing to the standard min-heap. This makes me sad but seems to be the goto solution.

Elements of the priority queue are a 3-tuple of

(priority, insertion counter index, data)

empty() bool

Reports whether the PQ is empty.

Return type

bool

pop() mate_common.datastructures.priority_queue.T

Returns just the data of the tuple with the highest priority.

Return type

mate_common.datastructures.priority_queue.T

pop_all() List[mate_common.datastructures.priority_queue.T]

Removes and returns all data in priority order.

Return type

List[mate_common.datastructures.priority_queue.T]

push(elem: mate_common.datastructures.priority_queue.T, priority: float) None

Push the negation of the priority to max-heapify our min-heap.

Parameters
  • elem (mate_common.datastructures.priority_queue.T) –

  • priority (float) –

Return type

None