59#include <initializer_list>
63#define GUM_HEAP_DEFAULT_CAPACITY 10
67 template <
typename Val,
typename Cmp >
69 template <
typename Val,
typename Cmp >
70 std::ostream&
operator<<(std::ostream&,
const Heap< Val, Cmp >&);
140 template <
typename Val,
typename Cmp = std::less< Val > >
173 explicit Heap(std::initializer_list< Val > list);
243 const Val&
top()
const;
288 void erase(
const Val& val);
315 template <
typename... Args >
328 bool empty() const noexcept;
383#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
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).
std::size_t size_type
Types for STL compliance.
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.
Val * pointer
Types for STL compliance.
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
Val value_type
Types for STL compliance.
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.
Val & reference
Types for STL compliance.
const Val & top() const
Returns the element at the top of the heap.
std::ptrdiff_t difference_type
Types for STL compliance.
bool empty() const noexcept
Indicates whether the heap is empty.
const Val & const_reference
Types for STL compliance.
const Val * const_pointer
Types for STL compliance.
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.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
#define GUM_HEAP_DEFAULT_CAPACITY
template implementations of heaps
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