#include <tlarrayheap.h>
Inheritance diagram for TLArrayHeap< T, _OP >:
Public Member Functions | |
TLArrayHeap (const _OP &op=_OP()) | |
Create empty heap. | |
~TLArrayHeap () | |
Destroy heap clearing it. | |
T & | operator[] (size_t idx) |
Get number of elements in heap: Get element with passed index as reference. | |
const T & | operator[] (size_t idx) const |
See non-const version. | |
void | clear (bool keep_memory=0) |
Clear the whole heap. | |
T * | first () |
const T * | first () const |
void | DownHeapFirst () |
See first(). | |
void | ReHeap (size_t idx, int size_change=0) |
Re-order heap after change of specified element. | |
void | insert (const T &e) |
Insert element into the heap. . | |
int | ReplaceFirst (const T &e) |
Replace first (=largest) element by new one. | |
int | PopFirst (T *e=NULL) |
Remove first (=largest) element. | |
template<typename K> ssize_t | LinSearch (const K &key) |
Linearly search element in heap. | |
template<typename K> ssize_t | RecSearch (const K &key) |
Recursively search element in heap. | |
template<typename K> int | remove (const K &key, T *e=NULL) |
Remove element with passed key. | |
int | RemoveIdx (size_t idx, T *e=NULL) |
Like remove() but with index instead of key. | |
template<typename K> int | replace (const K &key, const T &new_ent) |
Find element and replace it. | |
int | ReplaceIdx (size_t idx, const T &new_ent) |
Like replace() but with index instead of key. | |
size_t | CheckHeap () |
Debugging: check heap condition for all entries. | |
Private Member Functions | |
T & | heap (size_t idx) |
T * | heapP (size_t idx) |
void | _realloc (size_t new_asize) |
Perform reallocation operation to change array size. | |
void | _clearall () |
Clear all elements in the array using OP.clr(). | |
void | _UpHeap (size_t idx) |
void | _DownHeap (size_t idx) |
template<typename K> size_t | _RecSearch (const K &key, size_t idx) |
template<typename K> size_t | _LinSearch (const K &key) |
void | _ReHeap (size_t idx, int size_change=0) |
void | _RemoveIdx (size_t idx, T *e=NULL) |
TLArrayHeap (const TLArrayHeap &) | |
Do not use these:. | |
void | operator= (const TLArrayHeap &) |
This heap implementation uses an array to store the elements. The array is resized as needed using reallocation (OP.realloc()). Note that there is nothing which hinders you to store several identical elements in this heap (i.e. several equally large elements).
WHAT TO USE FOR <T>: (Standard text from tlbtree.h:) This class is probably most useful for T being a simple type (integer, unique pointers to a class or small data-only structures). You may use any POD type or any struct/class which is a "plain data type" (PDT; see defop.h) and even for "complex data types" as long as you can provide the required operator plugin OP and it has a working default constructor and a working copy constructor (both for temporaries).
Thread safety: The complete heap must be protected by a mutex for all "write" operations.
This class is NOT "C++-safe", i.e. do not use the assignment operator or the copy constructor (these are private).
Definition at line 62 of file tlarrayheap.h.
|
Do not use these:.
|
|
Create empty heap.
Definition at line 173 of file tlarrayheap.h. |
|
Destroy heap clearing it.
Definition at line 175 of file tlarrayheap.h. |
|
Clear all elements in the array using OP.clr().
Reimplemented from TLArray< T, _OP >. Definition at line 94 of file tlarrayheap.h. Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::clear(), and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::~TLArrayHeap(). |
|
For internal use only. Move element with internal index [idx] down in heap. Definition at line 112 of file tlarrayheap.h. Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::_ReHeap(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::DownHeapFirst(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::PopFirst(), and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::ReplaceFirst(). |
|
For internal use only. Linearly find element in heap; internal idx with value 0 if not found. Definition at line 142 of file tlarrayheap.h. Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::LinSearch(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::remove(), and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::replace(). |
|
Perform reallocation operation to change array size.
Reimplemented from TLArray< T, _OP >. Definition at line 86 of file tlarrayheap.h. |
|
For internal use only. Recursively find element in heap; internal idx with value 0 if not found. Definition at line 129 of file tlarrayheap.h. Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::_RecSearch(), and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::RecSearch(). |
|
For internal use only. Move element with internal index [idx] up or down in heap.
Definition at line 151 of file tlarrayheap.h. Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::_RemoveIdx(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::ReHeap(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::replace(), and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::ReplaceIdx(). |
|
For internal use only. Remove element with internal index [idx]. Definition at line 160 of file tlarrayheap.h. Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::remove(), and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::RemoveIdx(). |
|
For internal use only. Move element with internal index [idx] up in heap. Definition at line 102 of file tlarrayheap.h. Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::_ReHeap(), and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::insert(). |
|
Debugging: check heap condition for all entries.
Definition at line 370 of file tlarrayheap.h. Referenced by main(). |
|
Clear the whole heap.
Reimplemented from TLArray< T, _OP >. Definition at line 211 of file tlarrayheap.h. |
|
See first().
Definition at line 221 of file tlarrayheap.h. |
|
Definition at line 218 of file tlarrayheap.h. |
|
Get first (=largest) element in the heap (or NULL): Do not modify; if you did, call DownHeapFirst(). Runtime is O(1). Definition at line 217 of file tlarrayheap.h. |
|
Use this for array subscript: NOTE about indices: All user-visible indices are in range 0..NElem()-1. Internally, indices 1..NElem() are used with 0 being special. Definition at line 80 of file tlarrayheap.h. Referenced by TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::_DownHeap(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::_LinSearch(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::_RecSearch(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::_RemoveIdx(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::_UpHeap(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::CheckHeap(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::operator[](), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::PopFirst(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::replace(), TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::ReplaceFirst(), and TLArrayHeap< RJumpEntry, RJumpEntry_Operators >::ReplaceIdx(). |
|
|
Insert element into the heap. Runtime is O(log(n)). Definition at line 244 of file tlarrayheap.h. Referenced by main(). |
|
Linearly search element in heap.
Return index of element or -1 if not found. If there are more than one identical entries, the first one which is found, is returned. This implements linear serach in the array. Definition at line 287 of file tlarrayheap.h. Referenced by main(). |
|
|
|
See non-const version.
Reimplemented from TLArray< T, _OP >. Definition at line 207 of file tlarrayheap.h. |
|
Get number of elements in heap: Get element with passed index as reference.
NO RANGE CHECK! Range: 0..NElem()-1. Runtime is O(1). Note: Probably only useful if you need to iterate through the elements or obtained an index via some function. Reimplemented from TLArray< T, _OP >. Definition at line 205 of file tlarrayheap.h. |
|
Remove first (=largest) element. If e is non-NULL, store that element there (using OP::ass()) before removing it.
Definition at line 269 of file tlarrayheap.h. Referenced by main(). |
|
Recursively search element in heap.
Return index of element or -1 if not found. If there are more than one identical entries, the first one which is found, is returned. This function will not descend into sub-trees where the element can surely not be found, hence the smaller the element the longer the operation will take.
NOTE that this function uses TWO as much compare operations per processed element and cannot be inlined as it is recursive, so LinSearch() IS faster in most of the cases. Definition at line 307 of file tlarrayheap.h. Referenced by main(). |
|
Re-order heap after change of specified element. See operator[]: Make sure element with passed index is at the correct position in the heap (Re-order). Runtime is O(log(n)).
Definition at line 236 of file tlarrayheap.h. |
|
Remove element with passed key.
If e is non-NULL, store that element there (using OP::ass()) before removing it. IF there is more than one element matching the key, only the first one which is found, is removed.
Definition at line 322 of file tlarrayheap.h. Referenced by main(). |
|
Like remove() but with index instead of key.
Runtime is O(log(n))
Definition at line 336 of file tlarrayheap.h. Referenced by main(). |
|
Find element and replace it.
Just like remove() but instead of removing the element, replace it with new_ent. Same behavior and return value. Definition at line 346 of file tlarrayheap.h. |
|
Replace first (=largest) element by new one.
Definition at line 254 of file tlarrayheap.h. |
|
Like replace() but with index instead of key.
Runtime is O(log(n))
Definition at line 360 of file tlarrayheap.h. Referenced by main(). |