OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved > Class Template Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/MutablePriorityQueue.hpp>

Public Types

using iterator = typename std::vector<T>::iterator
using const_iterator = typename std::vector<T>::const_iterator

Public Member Functions

 MutablePriorityQueue (IndexSetter &&index_setter, LessPredicate &&less_predicate)
 ~MutablePriorityQueue ()
void clear ()
void reserve (size_t cnt)
void push (const T &item)
void push (T &&item)
void pop ()
T & top ()
void remove (size_t idx)
void update (size_t idx)
size_t size () const
bool empty () const
T & operator[] (std::size_t idx) noexcept
const T & operator[] (std::size_t idx) const noexcept
iterator begin ()
iterator end ()
const_iterator cbegin () const
const_iterator cend () const

Protected Member Functions

void update_heap_up (size_t top, size_t bottom)
void update_heap_down (size_t top, size_t bottom)

Private Attributes

std::vector< T > m_heap
IndexSetter m_index_setter
LessPredicate m_less_predicate

Detailed Description

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
class MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >

Member Typedef Documentation

◆ const_iterator

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
using MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::const_iterator = typename std::vector<T>::const_iterator

◆ iterator

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
using MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::iterator = typename std::vector<T>::iterator

Constructor & Destructor Documentation

◆ MutablePriorityQueue()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::MutablePriorityQueue ( IndexSetter && index_setter,
LessPredicate && less_predicate )
inline
18 :
21 {}
Definition MutablePriorityQueue.hpp:13
IndexSetter m_index_setter
Definition MutablePriorityQueue.hpp:51
LessPredicate m_less_predicate
Definition MutablePriorityQueue.hpp:52

References m_index_setter, and m_less_predicate.

◆ ~MutablePriorityQueue()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::~MutablePriorityQueue ( )
inline
22{ clear(); }
void clear()
Definition MutablePriorityQueue.hpp:63

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ begin()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
iterator MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::begin ( )
inline
40{ return m_heap.begin(); }
std::vector< T > m_heap
Definition MutablePriorityQueue.hpp:50

References m_heap.

◆ cbegin()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
const_iterator MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::cbegin ( ) const
inline
42{ return m_heap.cbegin(); }

References m_heap.

◆ cend()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
const_iterator MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::cend ( ) const
inline
43{ return m_heap.cend(); }

References m_heap.

◆ clear()

template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
void MutablePriorityQueue< T, LessPredicate, IndexSetter, ResetIndexWhenRemoved >::clear ( )
inline
64{
65#ifdef NDEBUG
66 // Only mark as removed from the queue in release mode, if configured so.
68#endif /* NDEBUG */
69 {
70 for (size_t idx = 0; idx < m_heap.size(); ++ idx)
71 // Mark as removed from the queue.
73 }
74 m_heap.clear();
75}

References m_heap, and m_index_setter.

Referenced by ~MutablePriorityQueue().

Here is the caller graph for this function:

◆ empty()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
bool MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::empty ( ) const
inline
34{ return m_heap.empty(); }

References m_heap.

◆ end()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
iterator MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::end ( )
inline
41{ return m_heap.end(); }

References m_heap.

◆ operator[]() [1/2]

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
const T & MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::operator[] ( std::size_t idx) const
inlinenoexcept
36{ return m_heap[idx]; }

References m_heap.

◆ operator[]() [2/2]

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
T & MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::operator[] ( std::size_t idx)
inlinenoexcept
35{ return m_heap[idx]; }

References m_heap.

◆ pop()

template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
void MutablePriorityQueue< T, LessPredicate, IndexSetter, ResetIndexWhenRemoved >::pop ( )
inline
97{
98 assert(! m_heap.empty());
99#ifdef NDEBUG
100 // Only mark as removed from the queue in release mode, if configured so.
102#endif /* NDEBUG */
103 {
104 // Mark as removed from the queue.
106 }
107 if (m_heap.size() > 1) {
108 m_heap.front() = m_heap.back();
109 m_heap.pop_back();
110 m_index_setter(m_heap.front(), 0);
111 update_heap_down(0, m_heap.size() - 1);
112 } else
113 m_heap.clear();
114}
void update_heap_down(size_t top, size_t bottom)
Definition MutablePriorityQueue.hpp:164

References m_heap, m_index_setter, and update_heap_down().

Here is the call graph for this function:

◆ push() [1/2]

template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
void MutablePriorityQueue< T, LessPredicate, IndexSetter, ResetIndexWhenRemoved >::push ( const T & item)
inline
79{
80 size_t idx = m_heap.size();
81 m_heap.emplace_back(item);
82 m_index_setter(m_heap.back(), idx);
84}
void update_heap_up(size_t top, size_t bottom)
Definition MutablePriorityQueue.hpp:140

References m_heap, m_index_setter, and update_heap_up().

Referenced by update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ push() [2/2]

template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
void MutablePriorityQueue< T, LessPredicate, IndexSetter, ResetIndexWhenRemoved >::push ( T && item)
inline
88{
89 size_t idx = m_heap.size();
90 m_heap.emplace_back(std::move(item));
91 m_index_setter(m_heap.back(), idx);
93}

References m_heap, m_index_setter, and update_heap_up().

Here is the call graph for this function:

◆ remove()

template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
void MutablePriorityQueue< T, LessPredicate, IndexSetter, ResetIndexWhenRemoved >::remove ( size_t idx)
inline
118{
119 assert(idx < m_heap.size());
120#ifdef NDEBUG
121 // Only mark as removed from the queue in release mode, if configured so.
123#endif /* NDEBUG */
124 {
125 // Mark as removed from the queue.
127 }
128 if (idx + 1 == m_heap.size()) {
129 m_heap.pop_back();
130 return;
131 }
132 m_heap[idx] = m_heap.back();
134 m_heap.pop_back();
135 update_heap_down(idx, m_heap.size() - 1);
137}

References m_heap, m_index_setter, update_heap_down(), and update_heap_up().

Referenced by update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reserve()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
void MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::reserve ( size_t cnt)
inline
25{ m_heap.reserve(cnt); }

References m_heap.

◆ size()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
size_t MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::size ( ) const
inline
33{ return m_heap.size(); }

References m_heap.

◆ top()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
T & MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::top ( )
inline
29{ return m_heap.front(); }

References m_heap.

Referenced by update_heap_down(), and update_heap_up().

Here is the caller graph for this function:

◆ update()

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
void MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::update ( size_t idx)
inline
31{ T item = m_heap[idx]; remove(idx); push(item); }
void remove(size_t idx)
Definition MutablePriorityQueue.hpp:117
void push(const T &item)
Definition MutablePriorityQueue.hpp:78

References m_heap, push(), and remove().

Here is the call graph for this function:

◆ update_heap_down()

template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
void MutablePriorityQueue< T, LessPredicate, IndexSetter, ResetIndexWhenRemoved >::update_heap_down ( size_t top,
size_t bottom )
inlineprotected
165{
166 size_t parentIdx = top;
168 for (;;) {
169 size_t childIdx = (parentIdx << 1) + 1;
170 if (childIdx > bottom)
171 break;
172 T *child = &m_heap[childIdx];
173 size_t child2Idx = childIdx + 1;
174 if (child2Idx <= bottom) {
176 if (! m_less_predicate(*child, *child2)) {
177 child = child2;
179 }
180 }
182 return;
183 // switch nodes
184 T tmp = *parent;
189 // shift down
191 parent = child;
192 }
193}
T & top()
Definition MutablePriorityQueue.hpp:29

References m_heap, m_index_setter, m_less_predicate, and top().

Referenced by pop(), and remove().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_heap_up()

template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
void MutablePriorityQueue< T, LessPredicate, IndexSetter, ResetIndexWhenRemoved >::update_heap_up ( size_t top,
size_t bottom )
inlineprotected
141{
142 size_t childIdx = bottom;
143 T *child = &m_heap[childIdx];
144 for (;;) {
145 size_t parentIdx = (childIdx - 1) >> 1;
146 if (childIdx == 0 || parentIdx < top)
147 break;
149 // switch nodes
150 if (! m_less_predicate(*parent, *child)) {
151 T tmp = *parent;
156 }
157 // shift up
159 child = parent;
160 }
161}

References m_heap, m_index_setter, m_less_predicate, and top().

Referenced by push(), push(), and remove().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_heap

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
std::vector<T> MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::m_heap
private

◆ m_index_setter

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
IndexSetter MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::m_index_setter
private

◆ m_less_predicate

template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
LessPredicate MutablePriorityQueue< T, IndexSetter, LessPredicate, ResetIndexWhenRemoved >::m_less_predicate
private

The documentation for this class was generated from the following file: