34 #include <initializer_list> 38 #include <agrum/agrum.h> 42 #define GUM_HEAP_DEFAULT_CAPACITY 10
46 template <
typename Val,
typename Cmp,
typename Alloc >
48 template <
typename Val,
typename Cmp,
typename Alloc >
49 std::ostream& operator<<(std::ostream&,
const Heap< Val, Cmp, Alloc >&);
120 template <
typename Val,
121 typename Cmp = std::less< Val >,
122 typename Alloc = std::allocator< Val > >
127 using value_type = Val;
128 using reference = Val&;
129 using const_reference =
const Val&;
130 using pointer = Val*;
131 using const_pointer =
const Val*;
132 using size_type = std::size_t;
133 using difference_type = std::ptrdiff_t;
134 using allocator_type = Alloc;
156 explicit Heap(std::initializer_list< Val > list);
162 Heap(
const Heap< Val, Cmp, Alloc >& from);
169 template <
typename OtherAlloc >
170 Heap(
const Heap< Val, Cmp, OtherAlloc >& from);
176 Heap(Heap< Val, Cmp, Alloc >&& from)
noexcept;
199 Heap< Val, Cmp, Alloc >&
operator=(
const Heap< Val, Cmp, Alloc >& from);
212 template <
typename OtherAlloc >
213 Heap< Val, Cmp, Alloc >&
operator=(
const Heap< Val, Cmp, OtherAlloc >& from);
225 Heap< Val, Cmp, Alloc >&
operator=(Heap< Val, Cmp, Alloc >&& from)
noexcept;
235 const Val&
operator[](Size index_elt)
const;
248 const Val&
top()
const;
293 void erase(
const Val& val);
320 template <
typename... Args >
333 bool empty()
const noexcept;
367 void resize(Size new_size);
388 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 389 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 390 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 391 extern template class gum::Heap<
int >;
395 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 396 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 397 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 398 extern template class gum::Heap<
long >;
403 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 404 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 405 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 406 extern template class gum::Heap<
double >;
413 #include <agrum/tools/core/heap_tpl.h> bool contains(const Val &) const
Indicates whether the heap contains a given value.
Heap(Heap< Val, Cmp, Alloc > &&from) noexcept
Move constructor.
Heap(std::initializer_list< Val > list)
Initializer list constructor.
bool empty() const noexcept
Indicates whether the heap is empty.
Heap(Cmp compare=Cmp(), Size capacity=GUM_HEAP_DEFAULT_CAPACITY)
Basic constructor: creates an empty heap.
#define GUM_HEAP_DEFAULT_CAPACITY
INLINE void emplace(Args &&... args)
const Val & operator[](Size index_elt) const
Returns the element at index index_elt from the heap.
Val pop()
Removes the top element from the heap and return it.
Cmp cmp__
Comparison function.
Size restoreHeap__()
After inserting an element at the end of the heap, restore heap property.
std::vector< Val, Alloc > heap__
An array storing all the elements of the heap.
Size emplace(Args &&... args)
Emplace a new element in the heap and returns its index.
Size nb_elements__
The number of elements in the heap.
void erase(const Val &val)
Removes a given element from the heap (but does not return it).
std::string toString() const
Size size() const noexcept
Returns the number of elements in the heap.
Heap< Val, Cmp, Alloc > & operator=(Heap< Val, Cmp, Alloc > &&from) noexcept
Move operator.
Heap< Val, Cmp, Alloc > & operator=(const Heap< Val, Cmp, OtherAlloc > &from)
Generalized copy operator.
Size insert(const Val &val)
inserts a new element (actually a copy) in the heap and returns its index
Size insert(Val &&val)
Inserts a new element (by moving it) in the heap and returns its index.
void eraseTop()
Removes the top of the heap (but does not return it).
Heap(const Heap< Val, Cmp, Alloc > &from)
Copy constructor.
Heap< Val, Cmp, Alloc > & operator=(const Heap< Val, Cmp, Alloc > &from)
Copy operator.
Size capacity() const noexcept
Returns the size of the internal structure storing the heap.
void resize(Size new_size)
Changes the size of the the internal structure storing the heap.
void eraseByPos(Size index)
Removes the element positioned at "index" from the heap.
Heap(const Heap< Val, Cmp, OtherAlloc > &from)
Generalized copy constructor.
const Val & top() const
Returns the element at the top of the heap.