Interfaces¶
AddressableHeap¶
The main interface of the library is the AddressableHeap
.
Addressable heaps support key-value pairs. After an insertion the user get a handle which she
can later use in order to increase the priority of the element (decrease-key), change the value
or delete the element completely from the heap.
-
class
jheaps.types.
AddressableHeap
[source]¶ Interface for an addressable heap.
-
abstract
delete_min
()[source]¶ Delete the minimum element and return a handle. The handle can be used to access the key or value but not to perform any other operation.
- Return type
-
abstract
-
class
jheaps.types.
AddressableHeapHandle
[source]¶ Interface for an addressable heap handle.
-
abstract
decrease_key
(key)[source]¶ Decrease the key of the element represented by this handle.
- Parameters
key – the new key
-
abstract property
key
¶ Get the key
- Returns
the key
-
abstract property
value
¶ Get the value
- Returns
the value
-
abstract
MergeableHeap¶
Most addressable heaps are also mergeable.
DoubleEndedAddressableHeap¶
The library also contains a few double ended addressable heaps which are also mergeable.
-
class
jheaps.types.
DoubleEndedAddressableHeap
[source]¶ Interface for an double ended addressable heap.
-
abstract
clear
()¶ Clear the heap
-
abstract
delete_max
()[source]¶ Delete the minimum element and return a handle. The handle can be used to access the key or value but not to perform any other operation.
- Return type
DoubledEndedAddressableHeapHandle
-
abstract
delete_min
()[source]¶ Delete the minimum element and return a handle. The handle can be used to access the key or value but not to perform any other operation.
- Return type
-
abstract
insert
(key, value)[source]¶ Insert a new element.
- Parameters
key – the key
value (long integer) – the value
- Returns
a handle for the new element
- Return type
-
abstract
is_empty
()¶ Check if the heap is empty.
- Returns
whether the heap is empty or not
- Return type
boolean
-
abstract
-
class
jheaps.types.
DoubleEndedAddressableHeapHandle
[source]¶ Interface for a double ended addressable heap handle.
-
abstract
decrease_key
(key)¶ Decrease the key of the element represented by this handle.
- Parameters
key – the new key
-
abstract
delete
()¶ Delete an element.
-
abstract
increase_key
(key)[source]¶ Increase the key of the element represented by this handle.
- Parameters
key – the new key
-
abstract property
key
¶ Get the key
- Returns
the key
-
abstract property
value
¶ Get the value
- Returns
the value
-
abstract
Heap¶
A simpler interface is also supported for heaps which are not addressable. In this simpler interface, values are not supported.
DoubleEndedHeap¶
Support is also provided for double ended heaps (minmax).
-
class
jheaps.types.
DoubleEndedHeap
[source]¶ Interface for a double ended heap.
-
abstract
clear
()¶ Clear the heap
-
abstract
delete_min
()¶ Delete the minimum element and return its key.
-
abstract
find_min
()¶ Return the minimum key.
-
abstract
insert
(key)¶ Insert a new element.
- Parameters
key – the key
-
abstract
is_empty
()¶ Check if the heap is empty.
- Returns
whether the heap is empty or not
- Return type
boolean
-
abstract