38 template <
typename Val,
typename Cmp,
typename Alloc >
43 GUM_CONSTRUCTOR(
Heap);
47 template <
typename Val,
typename Cmp,
typename Alloc >
49 __heap.reserve(list.size());
50 for (
const auto& elt : list) {
55 GUM_CONSTRUCTOR(
Heap);
59 template <
typename Val,
typename Cmp,
typename Alloc >
67 template <
typename Val,
typename Cmp,
typename Alloc >
68 template <
typename OtherAlloc >
82 template <
typename Val,
typename Cmp,
typename Alloc >
85 __cmp(std::move(from.__cmp)) {
91 template <
typename Val,
typename Cmp,
typename Alloc >
98 template <
typename Val,
typename Cmp,
typename Alloc >
124 template <
typename Val,
typename Cmp,
typename Alloc >
125 template <
typename OtherAlloc >
156 template <
typename Val,
typename Cmp,
typename Alloc >
161 __heap = std::move(from.__heap);
163 __cmp = std::move(from.__cmp);
170 template <
typename Val,
typename Cmp,
typename Alloc >
178 template <
typename Val,
typename Cmp,
typename Alloc >
184 template <
typename Val,
typename Cmp,
typename Alloc >
190 template <
typename Val,
typename Cmp,
typename Alloc >
196 template <
typename Val,
typename Cmp,
typename Alloc >
220 __heap[i] = std::move(last);
224 template <
typename Val,
typename Cmp,
typename Alloc >
235 template <
typename Val,
typename Cmp,
typename Alloc >
243 template <
typename Val,
typename Cmp,
typename Alloc >
253 template <
typename Val,
typename Cmp,
typename Alloc >
257 Val v = std::move(
__heap[i]);
260 for (
Size j = (i - 1) >> 1; i &&
__cmp(v,
__heap[j]); i = j, j = (j - 1) >> 1)
269 template <
typename Val,
typename Cmp,
typename Alloc >
278 template <
typename Val,
typename Cmp,
typename Alloc >
281 __heap.push_back(std::move(val));
287 template <
typename Val,
typename Cmp,
typename Alloc >
288 template <
typename... Args >
291 __heap.emplace_back(std::forward< Args >(args)...);
297 template <
typename Val,
typename Cmp,
typename Alloc >
303 template <
typename Val,
typename Cmp,
typename Alloc >
306 if (
__heap[i] == val)
return true;
312 template <
typename Val,
typename Cmp,
typename Alloc >
323 template <
typename Val,
typename Cmp,
typename Alloc >
326 std::stringstream stream;
330 if (deja) stream <<
" , ";
341 template <
typename Val,
typename Cmp,
typename Alloc >
bool contains(const Val &) const
Indicates whether the heap contains a given value.
Size __nb_elements
The number of elements in the heap.
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.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size emplace(Args &&... args)
Emplace a new element in the heap and returns its index.
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map's DAG in output using the Graphviz-dot format.
Cmp __cmp
Comparison function.
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.
std::vector< Val, Alloc > __heap
An array storing all the elements of the heap.
Size __restoreHeap()
After inserting an element at the end of the heap, restore heap property.
Size insert(const Val &val)
inserts a new element (actually a copy) in the heap and returns its index
void eraseTop()
Removes the top of the heap (but does not return it).
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.
Heap data structureThis structure is a basic heap data structure, i.e., it is a container in which el...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
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.
#define GUM_ERROR(type, msg)
const Val & top() const
Returns the element at the top of the heap.