pypdevsbbl.extra.heap module¶
This file is a python-implementation for a heap.
This file allows for both a min-heap and a max-heap by making
use of the MIN_HEAP() and MAX_HEAP() comparator
functions listed below.
-
pypdevsbbl.extra.heap.MIN_HEAP(x, l)¶ Comparator function, indicating to use a min-heap as the heap.
See also
-
pypdevsbbl.extra.heap.MAX_HEAP(x, l)¶ Comparator function, indicating to use a max-heap as the heap.
See also
-
class
pypdevsbbl.extra.heap.heap(comparator=<function <lambda>>)[source]¶ Bases:
objectThe heap class is a simple heap implementation.
Note
The comparator function takes two arguments (
xandl, as described below) and should returnTrueifxshould be swapped withl.x: The value of a node in the heap.l: The root to comparexto.
Warning
You shouldn’t need any other than
MIN_HEAP()orMAX_HEAP()for the comparison function. If you do, you’re probably doing strange things and you should consider using another datastructure.Parameters: comparator (def) – The comparison function. Defaults to MAX_HEAP().-
_heapify(i)[source]¶ Fix the heap, making sure the heap condition remains satisfied.
Warning
This function should not be called from an external source.
Parameters: i (int) – Index of the root node to heapify.
-
insert(node)[source]¶ Insert a new node into the heap.
Parameters: node (object) – A comparable object to insert.
-
pop(i=0)[source]¶ Remove the ith item of the heap.
Parameters: i (int) – The index of the node to pop. Defaults to 0 (the top). Returns: The item that was removed.