Grafalgo
Library of useful data structures and algorithms
|
This class implements a heap data structure. More...
Public Member Functions | |
DiffHeap (int, int) | |
Constructor for DiffHeap class. | |
~DiffHeap () | |
Destructor for DiffHeap class. | |
void | clear () |
Remove all elements from heap. | |
void | resize (int) |
Resize a DiffHeap object. | |
void | expand (int) |
Expand the space available for this DiffHeap. | |
void | copyFrom (const DiffHeap &) |
Copy into DiffHeap from source. | |
index | findmin () const |
Find an item in the heap with the smallest key. | |
keytyp | key (index) const |
Get the key of item. | |
bool | member (index) const |
Determine if an item is in the heap. | |
bool | empty () const |
Determine if the heap is empty. | |
void | insert (index, keytyp) |
Add item to the heap. | |
void | remove (index) |
Remove an item from the heap. | |
index | deletemin () |
Delete a minimum key item from the heap and return it. | |
void | changekey (index, keytyp) |
Change the key of an item in the heap. | |
void | addtokeys (keytyp) |
void | clearStats () |
Clear the statistics counters. | |
string & | stats2string (string &) const |
Return a string representation of the statistics counters. | |
string & | toString (string &) const |
Private Member Functions | |
index | minchild (index) |
Find the position of the child withthe smallest key. | |
void | siftup (index, int) |
void | siftdown (index, int) |
Perform siftdown operation to restore heap order. | |
void | makeSpace (int) |
Allocate and initialize space for DiffHeap. | |
void | freeSpace () |
Free dynamic storage used by DiffHeap. | |
Private Attributes | |
int | hn |
number of items in the heap | |
index * | h |
{h[1],...,h[hn]} is set of items | |
int * | pos |
pos[i] gives position of i in h | |
keytyp * | dkey |
dkey[i] is delta-key of item i |
This class implements a heap data structure.
The heap elements are identified by index values in 1..n where n is specified when an object is constructed. This version uses a differential representation of the keys. This allows it to implement a constant time addtokeys() operation.
Definition at line 24 of file DiffHeap.cpp.
grafalgo::DiffHeap::DiffHeap | ( | int | , |
int | |||
) |
Constructor for DiffHeap class.
size | is the number of items in the contructed object |
D1 | is the degree of the underlying heap-ordered tree |
Definition at line 21 of file DiffHeap.cpp.
grafalgo::DiffHeap::~DiffHeap | ( | ) |
Destructor for DiffHeap class.
Definition at line 26 of file DiffHeap.cpp.
void grafalgo::DiffHeap::changekey | ( | index | i, |
keytyp | k | ||
) |
Change the key of an item in the heap.
i | is the index of an item in the heap |
k | is a new key value for item i |
Definition at line 174 of file DiffHeap.cpp.
void grafalgo::DiffHeap::clear | ( | ) | [virtual] |
Remove all elements from heap.
Implements grafalgo::Adt.
Definition at line 84 of file DiffHeap.cpp.
void grafalgo::DiffHeap::copyFrom | ( | const DiffHeap & | source | ) |
Copy into DiffHeap from source.
Definition at line 51 of file DiffHeap.cpp.
int grafalgo::DiffHeap::deletemin | ( | ) | [inline] |
Delete a minimum key item from the heap and return it.
Definition at line 78 of file DiffHeap.cpp.
bool grafalgo::DiffHeap::empty | ( | ) | const [inline] |
Determine if the heap is empty.
Definition at line 93 of file DiffHeap.cpp.
void grafalgo::DiffHeap::expand | ( | int | size | ) | [virtual] |
Expand the space available for this DiffHeap.
Rebuilds old value in new space.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Definition at line 77 of file DiffHeap.cpp.
int grafalgo::DiffHeap::findmin | ( | ) | const [inline] |
Find an item in the heap with the smallest key.
Definition at line 72 of file DiffHeap.cpp.
void grafalgo::DiffHeap::freeSpace | ( | ) | [private] |
Free dynamic storage used by DiffHeap.
Definition at line 48 of file DiffHeap.cpp.
void grafalgo::DiffHeap::insert | ( | index | i, |
keytyp | k | ||
) |
Add item to the heap.
i | is the index of an item that is not in the heap |
k | is the key value under which i is to be inserted |
Definition at line 103 of file DiffHeap.cpp.
keytyp grafalgo::DiffHeap::key | ( | index | i | ) | const [inline] |
Get the key of item.
i | is the index of an item in the heap |
Definition at line 93 of file DiffHeap.cpp.
void grafalgo::DiffHeap::makeSpace | ( | int | size | ) | [private] |
Allocate and initialize space for DiffHeap.
size | is number of index values to provide space for |
Definition at line 31 of file DiffHeap.cpp.
bool grafalgo::DiffHeap::member | ( | index | i | ) | const [inline] |
Determine if an item is in the heap.
i | is the index of an item in the heap |
Definition at line 88 of file DiffHeap.cpp.
int grafalgo::DiffHeap::minchild | ( | index | ) | [private] |
Find the position of the child withthe smallest key.
This is a private helper function, used by siftdown.
x | is a position of an item in the heap |
Definition at line 144 of file Dheap.cpp.
void grafalgo::DiffHeap::remove | ( | index | i | ) |
Remove an item from the heap.
i | is an item in the heap |
Definition at line 110 of file DiffHeap.cpp.
void grafalgo::DiffHeap::resize | ( | int | size | ) | [virtual] |
Resize a DiffHeap object.
The old value is discarded.
size | is the size of the resize |
Implements grafalgo::Adt.
Definition at line 65 of file DiffHeap.cpp.
void grafalgo::DiffHeap::siftdown | ( | index | i, |
int | x | ||
) | [private] |
Perform siftdown operation to restore heap order.
This is a private helper function.
i | is an index to be positioned in the heap |
x | is a tentative position for i in the heap |
Definition at line 145 of file DiffHeap.cpp.
string & grafalgo::DiffHeap::stats2string | ( | string & | ) | const |
Return a string representation of the statistics counters.
s | is a string in which the result is returned |
Definition at line 207 of file DiffHeap.cpp.