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,
typename Cmp = std::less< Val >,
typename Alloc = std::allocator< Val > >
125 using value_type = Val;
126 using reference = Val&;
127 using const_reference =
const Val&;
128 using pointer = Val*;
129 using const_pointer =
const Val*;
130 using size_type = std::size_t;
131 using difference_type = std::ptrdiff_t;
132 using allocator_type = Alloc;
154 explicit Heap(std::initializer_list< Val > list);
160 Heap(
const Heap< Val, Cmp, Alloc >& from);
167 template <
typename OtherAlloc >
168 Heap(
const Heap< Val, Cmp, OtherAlloc >& from);
174 Heap(Heap< Val, Cmp, Alloc >&& from)
noexcept;
197 Heap< Val, Cmp, Alloc >&
operator=(
const Heap< Val, Cmp, Alloc >& from);
210 template <
typename OtherAlloc >
211 Heap< Val, Cmp, Alloc >&
operator=(
const Heap< Val, Cmp, OtherAlloc >& from);
223 Heap< Val, Cmp, Alloc >&
operator=(Heap< Val, Cmp, Alloc >&& from)
noexcept;
233 const Val&
operator[](Size index_elt)
const;
246 const Val&
top()
const;
291 void erase(
const Val& val);
318 template <
typename... Args >
331 bool empty()
const noexcept;
365 void resize(Size new_size);
386 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 387 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 388 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 389 extern template class gum::Heap<
int >;
393 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 394 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 395 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 396 extern template class gum::Heap<
long >;
401 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 402 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 403 # ifndef GUM_NO_EXTERN_TEMPLATE_CLASS 404 extern template class gum::Heap<
double >;
411 #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.
std::vector< Val, Alloc > _heap_
An array storing all the elements of the 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.
Size _nb_elements_
The number of elements in the heap.
Size emplace(Args &&... args)
Emplace a new element in the heap and returns its index.
Size _restoreHeap_()
After inserting an element at the end of the heap, restore heap property.
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.
Cmp _cmp_
Comparison function.
const Val & top() const
Returns the element at the top of the heap.