12 #ifndef __KOME_CORE_HEAP_H__
13 #define __KOME_CORE_HEAP_H__
17 #include <boost/function.hpp>
27 template <
typename T >
class Heap {
45 Heap( boost::function<
bool( T&, T& ) > lessFun ) {
71 boost::function< bool( T&, T& ) >
m_less;
106 T
at(
const unsigned int index ) {
107 return m_arr[ index ];
142 int hlfIdx = ( idx - 1 ) / 2;
144 T tmp =
m_arr[ idx ];
146 m_arr[ hlfIdx ] = tmp;
160 void remove(
const unsigned int index ) {
174 int hlfIdx = ( idx - 1 ) / 2;
176 T tmp =
m_arr[ idx ];
178 m_arr[ hlfIdx ] = tmp;
187 while( idx < (
int)
m_size ) {
189 int lIdx = idx * 2 + 1;
190 int rIdx = idx * 2 + 2;
194 if( lIdx < (
int)
m_size ) {
202 if( rIdx < (
int)
m_size ) {
209 if( lswap && rswap ) {
219 int swapIdx = (int)
m_size;
227 if( swapIdx < (
int)
m_size ) {
228 T tmp =
m_arr[ idx ];
230 m_arr[ swapIdx ] = tmp;
240 #endif // __KOME_CORE_HEAP_H__
T at(const unsigned int index)
gets heap element
virtual ~Heap()
destructor
void add(T elm)
adds element
Heap(boost::function< bool(T &, T &) > lessFun)
constructor
boost::function< bool(T &, T &) > m_less
heap data management class
unsigned size()
gets heap size