Heaps¶
New in version 0.2.0.
Orders¶
-
class
Order
()¶ Abstract class: Classes who implement a heap order must inherit from this class.
-
class
MinOrder
()¶ Min Heap order
-
class
MaxOrder
()¶ Max Heap order
Heap¶
-
class
ArrayHeap
(array, order)¶ Heap class backed by an array
Creates a heap
Arguments: Warning
don’t use internal methods if you want the heap to behave stable.
-
ArrayHeap.
insert
(key, value)¶ Insert a new node
Arguments: - key (int) – key of the new node
- value (any) – value of the new node
-
ArrayHeap.
extract
()¶ Extracts the greatest or smallest element of the heap depending on
Order()
Returns: node – The corrospending {key: *, value: *} node See also
-
ArrayHeap.
buildHeap
(array)¶ builds a new heap with the given {key: *, value: *} array.
Arguments: - array (Array) – The {key: *, value: *} array
-
Helpers¶
If you want to create a new heap, you can use this two helper functions, which automatically create new Order()
instances for the new heap.
-
createMinHeap
()¶ Creates a new minHeap
Returns: a new ArrayHeap with min first order Return type: ArrayHeap()
-
createMaxHeap
()¶ Creates a new maxHeap
Returns: a new ArrayHeap with max first order Return type: ArrayHeap()