59 template <
typename Val,
typename Cmp >
63 GUM_CONSTRUCTOR(
Heap);
67 template <
typename Val,
typename Cmp >
69 _heap_.reserve(list.size());
70 for (
const auto& elt: list) {
74 GUM_CONSTRUCTOR(
Heap);
78 template <
typename Val,
typename Cmp >
86 template <
typename Val,
typename Cmp >
89 _cmp_(std::move(from._cmp_)) {
95 template <
typename Val,
typename Cmp >
102 template <
typename Val,
typename Cmp >
127 template <
typename Val,
typename Cmp >
131 _heap_ = std::move(from._heap_);
133 _cmp_ = std::move(from._cmp_);
140 template <
typename Val,
typename Cmp >
148 template <
typename Val,
typename Cmp >
154 template <
typename Val,
typename Cmp >
160 template <
typename Val,
typename Cmp >
166 template <
typename Val,
typename Cmp >
190 _heap_[i] = std::move(last);
194 template <
typename Val,
typename Cmp >
205 template <
typename Val,
typename Cmp >
213 template <
typename Val,
typename Cmp >
223 template <
typename Val,
typename Cmp >
227 Val v = std::move(
_heap_[i]);
230 for (
Size j = (i - 1) >> 1; i &&
_cmp_(v,
_heap_[j]); i = j, j = (j - 1) >> 1)
239 template <
typename Val,
typename Cmp >
248 template <
typename Val,
typename Cmp >
251 _heap_.push_back(std::move(val));
257 template <
typename Val,
typename Cmp >
258 template <
typename... Args >
261 _heap_.emplace_back(std::forward< Args >(args)...);
267 template <
typename Val,
typename Cmp >
273 template <
typename Val,
typename Cmp >
276 if (
_heap_[i] == val)
return true;
282 template <
typename Val,
typename Cmp >
291 template <
typename Val,
typename Cmp >
294 std::stringstream stream;
298 if (deja) stream <<
" , ";
309 template <
typename Val,
typename Cmp >
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 empty() const noexcept
Indicates whether the heap is empty.
void resize(Size new_size)
Changes the size of the internal structure storing the heap.
Size _nb_elements_
The number of elements in the heap.
bool contains(const Val &) const
Indicates whether the heap contains a given value.
Size size() const noexcept
Returns the number of elements in the heap.
Size emplace(Args &&... args)
Emplace a new element in the heap and returns its index.
Heap< Val, Cmp > & operator=(const Heap< Val, Cmp > &from)
Copy operator.
Heap(Cmp compare=Cmp(), Size capacity=GUM_HEAP_DEFAULT_CAPACITY)
Basic constructor: creates an empty heap.
Size capacity() const noexcept
Returns the size of the internal structure storing the heap.
std::string toString() const
void eraseByPos(Size index)
Removes the element positioned at "index" from the heap.
const Val & top() const
Returns the element at the top of the heap.
Cmp _cmp_
Comparison function.
void erase(const Val &val)
Removes a given element from the heap (but does not return it).
const Val & operator[](Size index_elt) const
Returns the element at index index_elt from the heap.
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.
Size insert(const Val &val)
inserts a new element (actually a copy) in the heap and returns its index
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