58 template <
typename Val,
typename Cmp >
62 GUM_CONSTRUCTOR(
Heap);
66 template <
typename Val,
typename Cmp >
68 _heap_.reserve(list.size());
69 for (
const auto& elt: list) {
73 GUM_CONSTRUCTOR(
Heap);
77 template <
typename Val,
typename Cmp >
85 template <
typename Val,
typename Cmp >
88 _cmp_(std::move(from._cmp_)) {
94 template <
typename Val,
typename Cmp >
101 template <
typename Val,
typename Cmp >
126 template <
typename Val,
typename Cmp >
130 _heap_ = std::move(from._heap_);
132 _cmp_ = std::move(from._cmp_);
139 template <
typename Val,
typename Cmp >
147 template <
typename Val,
typename Cmp >
153 template <
typename Val,
typename Cmp >
159 template <
typename Val,
typename Cmp >
165 template <
typename Val,
typename Cmp >
189 _heap_[i] = std::move(last);
193 template <
typename Val,
typename Cmp >
204 template <
typename Val,
typename Cmp >
212 template <
typename Val,
typename Cmp >
222 template <
typename Val,
typename Cmp >
226 Val v = std::move(
_heap_[i]);
229 for (
Size j = (i - 1) >> 1; i &&
_cmp_(v,
_heap_[j]); i = j, j = (j - 1) >> 1)
238 template <
typename Val,
typename Cmp >
247 template <
typename Val,
typename Cmp >
250 _heap_.push_back(std::move(val));
256 template <
typename Val,
typename Cmp >
257 template <
typename... Args >
260 _heap_.emplace_back(std::forward< Args >(args)...);
266 template <
typename Val,
typename Cmp >
272 template <
typename Val,
typename Cmp >
275 if (
_heap_[i] == val)
return true;
281 template <
typename Val,
typename Cmp >
290 template <
typename Val,
typename Cmp >
293 std::stringstream stream;
297 if (deja) stream <<
" , ";
308 template <
typename Val,
typename Cmp >
Size size() const noexcept
Returns the number of elements in the heap.
void eraseTop()
Removes the top of the heap (but does not return it).
Val pop()
Removes the top element from the heap and return it.
bool contains(const Val &) const
Indicates whether the heap contains a given value.
Size _nb_elements_
The number of elements in the heap.
const Val & operator[](Size index_elt) const
Returns the element at index index_elt from the heap.
void resize(Size new_size)
Changes the size of the the internal structure storing the heap.
Size emplace(Args &&... args)
Emplace a new element in the heap and returns its index.
Size insert(const Val &val)
inserts a new element (actually a copy) in the heap and returns its index
Heap< Val, Cmp > & operator=(const Heap< Val, Cmp > &from)
Copy operator.
Size capacity() const noexcept
Returns the size of the internal structure storing the heap.
Heap(Cmp compare=Cmp(), Size capacity=GUM_HEAP_DEFAULT_CAPACITY)
Basic constructor: creates an empty heap.
const Val & top() const
Returns the element at the top of the heap.
bool empty() const noexcept
Indicates whether the heap is empty.
std::string toString() const
void eraseByPos(Size index)
Removes the element positioned at "index" from the heap.
Cmp _cmp_
Comparison function.
void erase(const Val &val)
Removes a given element from the heap (but does not return it).
Size _restoreHeap_()
After inserting an element at the end of the heap, restore heap property.
std::vector< Val > _heap_
An array storing all the elements of the heap.
Exception : the element we looked for cannot be found.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree