#include <bheap.h>
Inheritance diagram for ABA_BHEAP< Type, Key >:
Public Member Functions | |
ABA_BHEAP (ABA_GLOBAL *glob, int size) | |
ABA_BHEAP (ABA_GLOBAL *glob, const ABA_BUFFER< Type > &elems, const ABA_BUFFER< Key > &keys) | |
void | insert (Type elem, Key key) |
Type | getMin () const |
Key | getMinKey () const |
Type | extractMin () |
void | clear () |
int | size () const |
int | number () const |
bool | empty () const |
void | realloc (int newSize) |
void | check () const |
Private Member Functions | |
int | leftSon (int i) const |
int | rightSon (int i) const |
int | father (int i) const |
void | heapify (int i) |
Private Attributes | |
ABA_GLOBAL * | glob_ |
ABA_ARRAY< Type > | heap_ |
ABA_ARRAY< Key > | keys_ |
int | n_ |
Friends | |
ostream & | operator<< (ostream &out, const ABA_BHEAP< Type, Key > &rhs) |
The output operator writes the elements of the heap together with their keys on an output stream. |
Definition at line 74 of file bheap.h.
ABA_BHEAP< Type, Key >::ABA_BHEAP | ( | ABA_GLOBAL * | glob, | |
int | size | |||
) |
A constructor.
glob | A pointer to the corresponding global object. | |
size | The maximal number of elements which can be stored. |
ABA_BHEAP< Type, Key >::ABA_BHEAP | ( | ABA_GLOBAL * | glob, | |
const ABA_BUFFER< Type > & | elems, | |||
const ABA_BUFFER< Key > & | keys | |||
) |
A constructor with initialization.
The heap is initialized from an ABA_BUFFER of elements and a corresponding ABA_BUFFER of keys. The running time is for
elements.
glob | A pointer to the corresponding global object. | |
elem | A ABA_BUFFER wich contains the elements. | |
elem | A ABA_BUFFER wich contains the keys. |
void ABA_BHEAP< Type, Key >::insert | ( | Type | elem, | |
Key | key | |||
) |
Inserts an item with a key into the heap.
It is a fatal error to perform this operation if the heap is full. If the precompiler flag -DABACUSSAFE is set, we check if the heap is not already full.
elem | The element being inserted into the heap. | |
key | The key of this element. |
Type ABA_BHEAP< Type, Key >::getMin | ( | ) | const |
Key ABA_BHEAP< Type, Key >::getMinKey | ( | ) | const |
Type ABA_BHEAP< Type, Key >::extractMin | ( | ) |
Accesses and removes the minimum element from the heap.
The minimum element is stored in the root of the tree, i.e., in heap_[0]. If the heap does not become empty by removing the minimal element, we move the last element stored in heap_ to the root (heap_[0]). Whereas this operation can destroy the heap property, the two subtrees rooted at nodes 1 and 2 still satisfy the heap property. Hence calling heapify(0) will restore the overall heap property.
void ABA_BHEAP< Type, Key >::clear | ( | ) |
Empties the heap.
int ABA_BHEAP< Type, Key >::size | ( | ) | const |
int ABA_BHEAP< Type, Key >::number | ( | ) | const |
bool ABA_BHEAP< Type, Key >::empty | ( | ) | const |
false otherwise.
void ABA_BHEAP< Type, Key >::realloc | ( | int | newSize | ) |
Changes the size of the heap.
newSize | The new maximal number of elements in the heap. |
void ABA_BHEAP< Type, Key >::check | ( | ) | const |
Stops with an error message if the heap properties are violated.
This function is used for debugging this class.
int ABA_BHEAP< Type, Key >::leftSon | ( | int | i | ) | const [private] |
Returns the index of the left son of node i.
int ABA_BHEAP< Type, Key >::rightSon | ( | int | i | ) | const [private] |
Returns the index of the right son of node i.
int ABA_BHEAP< Type, Key >::father | ( | int | i | ) | const [private] |
Returns the index of the father of element i.
void ABA_BHEAP< Type, Key >::heapify | ( | int | i | ) | [private] |
Is the central function to maintain the heap property.
The function assumes that the two trees rooted at left(i) and right(i) fulfil already the heap property and restores the heap property of the (sub-) tree rooted at i.
ostream& operator<< | ( | ostream & | out, | |
const ABA_BHEAP< Type, Key > & | rhs | |||
) | [friend] |
The output operator writes the elements of the heap together with their keys on an output stream.
out | The output stream. | |
rhs | The heap being output. |
ABA_GLOBAL* ABA_BHEAP< Type, Key >::glob_ [private] |