15template <
typename T,
typename Comparator = std::less < T > >
22 void insert (
const T & value );
45template <
typename T,
typename Comparator >
47 m_data.push_back ( value );
48 std::push_heap ( m_data.begin ( ), m_data.end ( ), m_comparator );
51template <
typename T,
typename Comparator >
53 if ( m_data.size ( ) == 0 )
54 throw std::out_of_range (
"Heap is empty." );
56 std::pop_heap ( m_data.begin ( ), m_data.end ( ), m_comparator );
57 T
res = std::move ( m_data.back ( ) );
62template <
typename T,
typename Comparator >
64 m_data.
insert ( m_data.end ( ), that.m_data.begin ( ), that.m_data.end ( ) );
65 std::make_heap ( m_data.begin ( ), m_data.end ( ), m_comparator );
heap build using C++ algorithm features
Definition: CppHeap.h:16
Comparator m_comparator
Definition: CppHeap.h:40
void mergeWith(CppHeap< T, Comparator > &&that)
merges this heap with another heap (!! this is a DESTRUCTIVE merge, heap in argument will be cleared ...
Definition: CppHeap.h:63
const T & getMax() const
finds the maximum value in the heap
Definition: CppHeap.h:25
CppHeap(Comparator comparator=Comparator())
Definition: CppHeap.h:18
void insert(const T &value)
Definition: CppHeap.h:46
size_t size() const
Definition: CppHeap.h:35
T extractMax()
finds and removes the maximum value from the heap
Definition: CppHeap.h:52
std::vector< T > m_data
Definition: CppHeap.h:41
Definition: ExceptionHandler.cpp:13
return res
Definition: MinimizeByPartitioning.h:145