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

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

Public Types

using address = SkipHeapAddressing<blocking>

Public Member Functions

 MutableSkipHeapPriorityQueue (IndexSetter &&index_setter, LessPredicate &&less_predicate)
 ~MutableSkipHeapPriorityQueue ()
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 noexcept
bool empty () const
T & operator[] (std::size_t idx) noexcept
const T & operator[] (std::size_t idx) const noexcept

Protected Member Functions

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

Private Attributes

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

Detailed Description

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
class MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >

Member Typedef Documentation

◆ address

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
using MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::address = SkipHeapAddressing<blocking>

Constructor & Destructor Documentation

◆ MutableSkipHeapPriorityQueue()

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::MutableSkipHeapPriorityQueue ( IndexSetter && index_setter,
LessPredicate && less_predicate )
inline
267 :
270 {}
Definition MutablePriorityQueue.hpp:261
LessPredicate m_less_predicate
Definition MutablePriorityQueue.hpp:302
IndexSetter m_index_setter
Definition MutablePriorityQueue.hpp:301

References m_index_setter, and m_less_predicate.

◆ ~MutableSkipHeapPriorityQueue()

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::~MutableSkipHeapPriorityQueue ( )
inline
271{ clear(); }
void clear()
Definition MutablePriorityQueue.hpp:314

References clear().

Here is the call graph for this function:

Member Function Documentation

◆ clear()

template<class T, class LessPredicate, class IndexSetter, std::size_t blocking, const bool ResetIndexWhenRemoved>
void MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::clear ( )
inline
315{
316#ifdef NDEBUG
317 // Only mark as removed from the queue in release mode, if configured so.
319#endif /* NDEBUG */
320 {
321 for (size_t idx = 0; idx < m_heap.size(); ++ idx)
322 // Mark as removed from the queue.
325 }
326 m_heap.clear();
327}
std::vector< T > m_heap
Definition MutablePriorityQueue.hpp:300
static bool is_padding(std::size_t node_no) noexcept
Definition MutablePriorityQueue.hpp:244

References SkipHeapAddressing< blocking >::is_padding(), m_heap, and m_index_setter.

Referenced by ~MutableSkipHeapPriorityQueue().

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

◆ empty()

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
bool MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::empty ( ) const
inline
284{ return m_heap.empty(); }

References m_heap.

◆ operator[]() [1/2]

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
const T & MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::operator[] ( std::size_t idx) const
inlinenoexcept
286{ assert(! address::is_padding(idx)); return m_heap[idx]; }

References SkipHeapAddressing< blocking >::is_padding(), and m_heap.

Here is the call graph for this function:

◆ operator[]() [2/2]

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
T & MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::operator[] ( std::size_t idx)
inlinenoexcept
285{ assert(! address::is_padding(idx)); return m_heap[idx]; }

References SkipHeapAddressing< blocking >::is_padding(), and m_heap.

Here is the call graph for this function:

◆ pop()

template<class T, class LessPredicate, class IndexSetter, std::size_t blocking, const bool ResetIndexWhenRemoved>
void MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::pop ( )
inline
353{
354 assert(! m_heap.empty());
355#ifdef NDEBUG
356 // Only mark as removed from the queue in release mode, if configured so.
358#endif /* NDEBUG */
359 {
360 // Mark as removed from the queue.
362 }
363 // Zero'th element is padding, thus non-empty queue must have at least two elements.
364 if (m_heap.size() > 2) {
365 m_heap[1] = m_heap.back();
366 this->pop_back();
367 m_index_setter(m_heap[1], 1);
368 update_heap_down(1, m_heap.size() - 1);
369 } else
370 m_heap.clear();
371}
void update_heap_down(size_t top, size_t bottom)
Definition MutablePriorityQueue.hpp:424
void pop_back() noexcept
Definition MutablePriorityQueue.hpp:291

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

Here is the call graph for this function:

◆ pop_back()

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
void MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::pop_back ( )
inlineprotectednoexcept
291 {
292 assert(m_heap.size() > 1);
293 assert(! address::is_padding(m_heap.size() - 1));
294 m_heap.pop_back();
295 if (address::is_padding(m_heap.size() - 1))
296 m_heap.pop_back();
297 }

References SkipHeapAddressing< blocking >::is_padding(), and m_heap.

Referenced by pop(), and remove().

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

◆ push() [1/2]

template<class T, class LessPredicate, class IndexSetter, std::size_t blocking, const bool ResetIndexWhenRemoved>
void MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::push ( const T & item)
inline
331{
332 if (address::is_padding(m_heap.size()))
333 m_heap.emplace_back(T());
334 size_t idx = m_heap.size();
335 m_heap.emplace_back(item);
336 m_index_setter(m_heap.back(), idx);
338}
void update_heap_up(size_t top, size_t bottom)
Definition MutablePriorityQueue.hpp:398

References SkipHeapAddressing< blocking >::is_padding(), 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, std::size_t blocking, const bool ResetIndexWhenRemoved>
void MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::push ( T && item)
inline
342{
343 if (address::is_padding(m_heap.size()))
344 m_heap.emplace_back(T());
345 size_t idx = m_heap.size();
346 m_heap.emplace_back(std::move(item));
347 m_index_setter(m_heap.back(), idx);
349}

References SkipHeapAddressing< blocking >::is_padding(), 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, std::size_t blocking, const bool ResetIndexWhenRemoved>
void MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::remove ( size_t idx)
inline
375{
376 assert(idx < m_heap.size());
378#ifdef NDEBUG
379 // Only mark as removed from the queue in release mode, if configured so.
381#endif /* NDEBUG */
382 {
383 // Mark as removed from the queue.
385 }
386 if (idx + 1 == m_heap.size()) {
387 this->pop_back();
388 return;
389 }
390 m_heap[idx] = m_heap.back();
392 this->pop_back();
393 update_heap_down(idx, m_heap.size() - 1);
395}

References SkipHeapAddressing< blocking >::is_padding(), m_heap, m_index_setter, pop_back(), 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, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
void MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::reserve ( size_t cnt)
inline
275{ m_heap.reserve(cnt + ((cnt + (address::block_size - 1)) / (address::block_size - 1))); }
static const constexpr std::size_t block_size
Definition MutablePriorityQueue.hpp:210

References SkipHeapAddressing< blocking >::block_size, and m_heap.

◆ size()

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
size_t MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::size ( ) const
inlinenoexcept

◆ top()

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
T & MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::top ( )
inline
279{ return m_heap[1]; }

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, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
void MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::update ( size_t idx)
inline
void remove(size_t idx)
Definition MutablePriorityQueue.hpp:374
void push(const T &item)
Definition MutablePriorityQueue.hpp:330

References SkipHeapAddressing< blocking >::is_padding(), m_heap, push(), and remove().

Here is the call graph for this function:

◆ update_heap_down()

template<class T, class LessPredicate, class IndexSetter, std::size_t blocking, const bool ResetIndexWhenRemoved>
void MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::update_heap_down ( size_t top,
size_t bottom )
inlineprotected
425{
428 size_t parentIdx = top;
430 for (;;) {
432 if (childIdx > bottom)
433 break;
434 T *child = &m_heap[childIdx];
436 if (child2Idx <= bottom) {
438 if (! m_less_predicate(*child, *child2)) {
439 child = child2;
441 }
442 }
444 return;
445 // switch nodes
446 T tmp = *parent;
451 // shift down
453 parent = child;
454 }
455}
T & top()
Definition MutablePriorityQueue.hpp:279
static std::size_t child_of(std::size_t node_no) noexcept
Definition MutablePriorityQueue.hpp:214
static bool is_block_leaf(std::size_t node_no) noexcept
Definition MutablePriorityQueue.hpp:242

References SkipHeapAddressing< blocking >::block_size, SkipHeapAddressing< blocking >::child_of(), SkipHeapAddressing< blocking >::is_block_leaf(), SkipHeapAddressing< blocking >::is_padding(), 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, std::size_t blocking, const bool ResetIndexWhenRemoved>
void MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::update_heap_up ( size_t top,
size_t bottom )
inlineprotected
399{
402 size_t childIdx = bottom;
403 T *child = &m_heap[childIdx];
404 for (;;) {
406 if (childIdx == 1 || parentIdx < top)
407 break;
409 // switch nodes
410 if (! m_less_predicate(*parent, *child)) {
411 T tmp = *parent;
416 }
417 // shift up
419 child = parent;
420 }
421}
static std::size_t parent_of(std::size_t node_no) noexcept
Definition MutablePriorityQueue.hpp:224

References SkipHeapAddressing< blocking >::is_padding(), m_heap, m_index_setter, m_less_predicate, SkipHeapAddressing< blocking >::parent_of(), 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, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
std::vector<T> MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::m_heap
private

◆ m_index_setter

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
IndexSetter MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::m_index_setter
private

◆ m_less_predicate

template<typename T, typename IndexSetter, typename LessPredicate, std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
LessPredicate MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::m_less_predicate
private

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