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 clear()[source]

Clear the 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

AddressableHeapHandle

abstract find_min()[source]

Return a handle for the minimum element.

Return type

AddressableHeapHandle

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

AddressableHeapHandle

abstract is_empty()[source]

Check if the heap is empty.

Returns

whether the heap is empty or not

Return type

boolean

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 delete()[source]

Delete an element.

abstract property key

Get the key

Returns

the key

abstract property value

Get the value

Returns

the value

MergeableHeap

Most addressable heaps are also mergeable.

class jheaps.types.MergeableHeap[source]

Interface for a mergeable heap.

abstract meld(other)[source]

Meld heap other into the current heap. After the meld operation the heap other is not usable.

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

DoubleEndedAddressableHeapHandle

abstract find_max()[source]

Return a handle for the maximum element.

Return type

DoubleEndedAddressableHeapHandle

abstract find_min()[source]

Return a handle for the minimum element.

Return type

DoubleEndedAddressableHeapHandle

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

DoubleEndedAddressableHeapHandle

abstract is_empty()

Check if the heap is empty.

Returns

whether the heap is empty or not

Return type

boolean

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

Heap

A simpler interface is also supported for heaps which are not addressable. In this simpler interface, values are not supported.

class jheaps.types.Heap[source]

Interface for a heap.

abstract clear()[source]

Clear the heap

abstract delete_min()[source]

Delete the minimum element and return its key.

abstract find_min()[source]

Return the minimum key.

abstract insert(key)[source]

Insert a new element.

Parameters

key – the key

abstract is_empty()[source]

Check if the heap is empty.

Returns

whether the heap is empty or not

Return type

boolean

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_max()[source]

Delete the maximum element and return its key.

abstract delete_min()

Delete the minimum element and return its key.

abstract find_max()[source]

Return the maximum 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