ug4
|
updateable priority queue class. this priority queue works on an external array of elements T. More...
#include <boxsort2.h>
Public Member Functions | |
size_t | arr_size () const |
returns size of external array More... | |
BoxPriorityQueue2 () | |
BoxPriorityQueue2 (const std::vector< T > &v) | |
BoxPriorityQueue2 (size_t n, const T *arr_) | |
void | create (const std::vector< T > &v) |
void | create (size_t n, const T *arr_) |
creates the queue on a external array arr_[0]..arr_[n-1] More... | |
size_t | get_max () const |
returns the index in m_arr of maximal element of the heap More... | |
size_t | height () const |
returns nr of elements in the heap. More... | |
void | insert_item (size_t i) |
bool | is_in (size_t i) |
void | remove (size_t i) |
removes index i in arr More... | |
size_t | remove_max () |
returns the index in arr of maximal element of the heap More... | |
void | reset () |
void | update (size_t i) |
~BoxPriorityQueue2 () | |
deconstructor More... | |
Private Member Functions | |
BoxPriorityQueue2 (const BoxPriorityQueue2< T > &other) | |
void | size_check (size_t i) |
Private Attributes | |
const T * | arr |
stdvector< stdvector< size_t > > | m_box |
stdvector< int > | m_boxBegin |
stdvector< int > | m_boxEnd |
size_t | m_height |
stdvector< int > | m_next |
stdvector< int > | m_prev |
size_t | m_size |
stdvector< size_t > | m_values |
updateable priority queue class. this priority queue works on an external array of elements T.
T | type of elements in the maxheap. Has to support size_t T::get_val() const, and get_val() has to be between 0 and and small number (for example, 500). |
Elements are put in "boxes" depending on their get_val()-value - this makes sorting extremely easy: sorting and accessing is O(1), and inserting is maximal a) creation of enough boxes, and b) inserting into a box, so it is O(maximal get_val()). This algorithm is like a "radical" radix exchange sort.
|
private |
|
inline |
|
inline |
constructor
n | maximal number of elements |
arr_ | array with elements which are to compare. note that non of these are in the queue in the beginning |
References ug::BoxPriorityQueue2< T >::create().
|
inline |
References ug::BoxPriorityQueue2< T >::create().
|
inline |
deconstructor
|
inline |
returns size of external array
References ug::BoxPriorityQueue2< T >::m_size.
Referenced by ug::BoxPriorityQueue2< T >::size_check().
|
inline |
References ug::BoxPriorityQueue2< T >::create().
|
inline |
creates the queue on a external array arr_[0]..arr_[n-1]
create
References ug::BoxPriorityQueue2< T >::arr, ug::BoxPriorityQueue2< T >::m_next, ug::BoxPriorityQueue2< T >::m_prev, ug::BoxPriorityQueue2< T >::m_size, ug::BoxPriorityQueue2< T >::m_values, and ug::BoxPriorityQueue2< T >::reset().
Referenced by ug::BoxPriorityQueue2< T >::BoxPriorityQueue2(), and ug::BoxPriorityQueue2< T >::create().
|
inline |
returns the index in m_arr of maximal element of the heap
References ug::BoxPriorityQueue2< T >::m_box, ug::BoxPriorityQueue2< T >::m_boxBegin, ug::BoxPriorityQueue2< T >::m_height, and UG_ASSERT.
|
inline |
returns nr of elements in the heap.
References ug::BoxPriorityQueue2< T >::m_height.
|
inline |
insertItem inserts Item arr[i] (see constructor) into heap
i | index of item in arr |
References ug::BoxPriorityQueue2< T >::arr, ug::BOXPRIORITYQUEUE2_MAXIMAL_VALUE, ug::BOXPRIORITYQUEUE_MAXIMAL_VALUE, ug::get_val(), ug::BoxPriorityQueue2< T >::is_in(), ug::BoxPriorityQueue2< T >::m_box, ug::BoxPriorityQueue2< T >::m_boxBegin, ug::BoxPriorityQueue2< T >::m_boxEnd, ug::BoxPriorityQueue2< T >::m_height, ug::BoxPriorityQueue2< T >::m_next, ug::BoxPriorityQueue2< T >::m_prev, ug::BoxPriorityQueue2< T >::m_values, ug::BoxPriorityQueue2< T >::size_check(), and UG_ASSERT.
Referenced by ug::BoxPriorityQueue2< T >::update().
|
inline |
|
inline |
removes index i in arr
References ug::BoxPriorityQueue2< T >::is_in(), ug::BoxPriorityQueue2< T >::m_boxBegin, ug::BoxPriorityQueue2< T >::m_boxEnd, ug::BoxPriorityQueue2< T >::m_height, ug::BoxPriorityQueue2< T >::m_next, ug::BoxPriorityQueue2< T >::m_prev, ug::BoxPriorityQueue2< T >::m_values, ug::BoxPriorityQueue2< T >::size_check(), and UG_ASSERT.
Referenced by ug::BoxPriorityQueue2< T >::remove_max(), and ug::BoxPriorityQueue2< T >::update().
|
inline |
returns the index in arr of maximal element of the heap
References ug::BoxPriorityQueue2< T >::m_box, ug::BoxPriorityQueue2< T >::m_boxBegin, ug::BoxPriorityQueue2< T >::m_height, ug::BoxPriorityQueue2< T >::remove(), and UG_ASSERT.
|
inline |
References ug::BoxPriorityQueue2< T >::m_box, ug::BoxPriorityQueue2< T >::m_height, and ug::BoxPriorityQueue2< T >::m_prev.
Referenced by ug::BoxPriorityQueue2< T >::create().
|
inlineprivate |
debug print output
References ug::BoxPriorityQueue2< T >::arr_size(), and UG_ASSERT.
Referenced by ug::BoxPriorityQueue2< T >::insert_item(), and ug::BoxPriorityQueue2< T >::remove().
|
inline |
i | index in arr for which to update |
References ug::BoxPriorityQueue2< T >::arr, ug::get_val(), ug::BoxPriorityQueue2< T >::insert_item(), ug::BoxPriorityQueue2< T >::is_in(), ug::BoxPriorityQueue2< T >::m_values, and ug::BoxPriorityQueue2< T >::remove().
|
private |
|
private |
|
private |
|
private |
Referenced by ug::BoxPriorityQueue2< T >::insert_item(), and ug::BoxPriorityQueue2< T >::remove().
|
private |
|
private |
|
private |
|
private |
Referenced by ug::BoxPriorityQueue2< T >::arr_size(), and ug::BoxPriorityQueue2< T >::create().
|
private |