Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved > Class Template Reference

#include <src/libslic3r/MutablePriorityQueue.hpp>

Public Types

using address = SkipHeapAddressing< blocking >
 

Public Member Functions

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

Static Public Member Functions

static constexpr size_t invalid_id ()
 

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 Slic3r::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 Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::address = SkipHeapAddressing<blocking>

Constructor & Destructor Documentation

◆ MutableSkipHeapPriorityQueue() [1/3]

template<typename T , typename IndexSetter , typename LessPredicate , std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::MutableSkipHeapPriorityQueue ( IndexSetter &&  index_setter,
LessPredicate &&  less_predicate 
)
inline
268 :
269 m_index_setter(std::forward<IndexSetter>(index_setter)),
270 m_less_predicate(std::forward<LessPredicate>(less_predicate))
271 {}
IndexSetter m_index_setter
Definition MutablePriorityQueue.hpp:313
LessPredicate m_less_predicate
Definition MutablePriorityQueue.hpp:314

◆ ~MutableSkipHeapPriorityQueue()

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

References Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::clear().

+ Here is the call graph for this function:

◆ MutableSkipHeapPriorityQueue() [2/3]

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

◆ MutableSkipHeapPriorityQueue() [3/3]

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

Member Function Documentation

◆ clear()

template<class T , class LessPredicate , class IndexSetter , std::size_t blocking, const bool ResetIndexWhenRemoved>
void Slic3r::MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::clear
inline
327{
328 if constexpr (ResetIndexWhenRemoved) {
329 for (size_t idx = 0; idx < m_heap.size(); ++ idx)
330 // Mark as removed from the queue.
331 if (! address::is_padding(idx))
332 m_index_setter(m_heap[idx], this->invalid_id());
333 }
334 m_heap.clear();
335}
static constexpr size_t invalid_id()
Definition MutablePriorityQueue.hpp:298
std::vector< T > m_heap
Definition MutablePriorityQueue.hpp:312
static bool is_padding(std::size_t node_no) noexcept
Definition MutablePriorityQueue.hpp:245

Referenced by Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::~MutableSkipHeapPriorityQueue().

+ 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 Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::empty ( ) const
inline

◆ heap_size()

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

◆ invalid_id()

template<typename T , typename IndexSetter , typename LessPredicate , std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
static constexpr size_t Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::invalid_id ( )
inlinestaticconstexpr
298{ return InvalidQueueID; }
constexpr auto InvalidQueueID
Definition MutablePriorityQueue.hpp:12

References Slic3r::InvalidQueueID.

◆ operator=() [1/2]

template<typename T , typename IndexSetter , typename LessPredicate , std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
MutableSkipHeapPriorityQueue & Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::operator= ( const MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved > &  )
delete

◆ operator=() [2/2]

template<typename T , typename IndexSetter , typename LessPredicate , std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
MutableSkipHeapPriorityQueue & Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::operator= ( MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved > &&  )
default

◆ operator[]() [1/2]

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

References Slic3r::SkipHeapAddressing< blocking >::is_padding(), and Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::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 & Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::operator[] ( std::size_t  idx)
inlinenoexcept
296{ assert(! address::is_padding(idx)); return m_heap[idx]; }

References Slic3r::SkipHeapAddressing< blocking >::is_padding(), and Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::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 Slic3r::MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::pop
inline
361{
362 assert(! m_heap.empty());
363 if constexpr (ResetIndexWhenRemoved) {
364 // Mark as removed from the queue.
365 m_index_setter(m_heap[1], this->invalid_id());
366 }
367 // Zero'th element is padding, thus non-empty queue must have at least two elements.
368 if (m_heap.size() > 2) {
369 m_heap[1] = m_heap.back();
370 this->pop_back();
371 m_index_setter(m_heap[1], 1);
372 update_heap_down(1, m_heap.size() - 1);
373 } else
374 m_heap.clear();
375}
void pop_back() noexcept
Definition MutablePriorityQueue.hpp:303
void update_heap_down(size_t top, size_t bottom)
Definition MutablePriorityQueue.hpp:424

◆ pop_back()

template<typename T , typename IndexSetter , typename LessPredicate , std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
void Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::pop_back ( )
inlineprotectednoexcept
303 {
304 assert(m_heap.size() > 1);
305 assert(! address::is_padding(m_heap.size() - 1));
306 m_heap.pop_back();
307 if (address::is_padding(m_heap.size() - 1))
308 m_heap.pop_back();
309 }

References Slic3r::SkipHeapAddressing< blocking >::is_padding(), and Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::m_heap.

+ Here is the call graph for this function:

◆ push() [1/2]

template<class T , class LessPredicate , class IndexSetter , std::size_t blocking, const bool ResetIndexWhenRemoved>
void Slic3r::MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::push ( const T &  item)
inline
339{
340 if (address::is_padding(m_heap.size()))
341 m_heap.emplace_back(T());
342 size_t idx = m_heap.size();
343 m_heap.emplace_back(item);
344 m_index_setter(m_heap.back(), idx);
345 update_heap_up(1, idx);
346}
void update_heap_up(size_t top, size_t bottom)
Definition MutablePriorityQueue.hpp:398

Referenced by Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::update().

+ 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 Slic3r::MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::push ( T &&  item)
inline
350{
351 if (address::is_padding(m_heap.size()))
352 m_heap.emplace_back(T());
353 size_t idx = m_heap.size();
354 m_heap.emplace_back(std::move(item));
355 m_index_setter(m_heap.back(), idx);
356 update_heap_up(1, idx);
357}

◆ remove()

template<class T , class LessPredicate , class IndexSetter , std::size_t blocking, const bool ResetIndexWhenRemoved>
void Slic3r::MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::remove ( size_t  idx)
inline
379{
380 assert(idx < m_heap.size());
381 assert(! address::is_padding(idx));
382 if constexpr (ResetIndexWhenRemoved) {
383 // Mark as removed from the queue.
384 m_index_setter(m_heap[idx], this->invalid_id());
385 }
386 if (idx + 1 == m_heap.size()) {
387 this->pop_back();
388 return;
389 }
390 m_heap[idx] = m_heap.back();
391 m_index_setter(m_heap[idx], idx);
392 this->pop_back();
393 update_heap_down(idx, m_heap.size() - 1);
394 update_heap_up(1, idx);
395}

Referenced by Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::update().

+ 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 Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::reserve ( size_t  cnt)
inline

◆ size()

template<typename T , typename IndexSetter , typename LessPredicate , std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
size_t Slic3r::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 & Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::top ( )
inline

◆ update()

template<typename T , typename IndexSetter , typename LessPredicate , std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
void Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::update ( size_t  idx)
inline
290{ assert(! address::is_padding(idx)); T item = m_heap[idx]; remove(idx); push(item); }
void remove(size_t idx)
Definition MutablePriorityQueue.hpp:378
void push(const T &item)
Definition MutablePriorityQueue.hpp:338

References Slic3r::SkipHeapAddressing< blocking >::is_padding(), Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::m_heap, Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::push(), and Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::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 Slic3r::MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::update_heap_down ( size_t  top,
size_t  bottom 
)
inlineprotected
425{
426 assert(! address::is_padding(top));
427 assert(! address::is_padding(bottom));
428 size_t parentIdx = top;
429 T *parent = &m_heap[parentIdx];
430 for (;;) {
431 size_t childIdx = address::child_of(parentIdx);
432 if (childIdx > bottom)
433 break;
434 T *child = &m_heap[childIdx];
435 size_t child2Idx = childIdx + (address::is_block_leaf(parentIdx) ? address::block_size : 1);
436 if (child2Idx <= bottom) {
437 T *child2 = &m_heap[child2Idx];
438 if (! m_less_predicate(*child, *child2)) {
439 child = child2;
440 childIdx = child2Idx;
441 }
442 }
443 if (m_less_predicate(*parent, *child))
444 return;
445 // switch nodes
446 T tmp = *parent;
447 m_index_setter(tmp, childIdx);
448 m_index_setter(*child, parentIdx);
449 m_heap[parentIdx] = *child;
450 m_heap[childIdx] = tmp;
451 // shift down
452 parentIdx = childIdx;
453 parent = child;
454 }
455}
T & top()
Definition MutablePriorityQueue.hpp:288
static std::size_t child_of(std::size_t node_no) noexcept
Definition MutablePriorityQueue.hpp:215
static bool is_block_leaf(std::size_t node_no) noexcept
Definition MutablePriorityQueue.hpp:243

◆ update_heap_up()

template<class T , class LessPredicate , class IndexSetter , std::size_t blocking, const bool ResetIndexWhenRemoved>
void Slic3r::MutableSkipHeapPriorityQueue< T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved >::update_heap_up ( size_t  top,
size_t  bottom 
)
inlineprotected
399{
400 assert(! address::is_padding(top));
401 assert(! address::is_padding(bottom));
402 size_t childIdx = bottom;
403 T *child = &m_heap[childIdx];
404 for (;;) {
405 size_t parentIdx = address::parent_of(childIdx);
406 if (childIdx == 1 || parentIdx < top)
407 break;
408 T *parent = &m_heap[parentIdx];
409 // switch nodes
410 if (! m_less_predicate(*parent, *child)) {
411 T tmp = *parent;
412 m_index_setter(tmp, childIdx);
413 m_index_setter(*child, parentIdx);
414 m_heap[parentIdx] = *child;
415 m_heap[childIdx] = tmp;
416 }
417 // shift up
418 childIdx = parentIdx;
419 child = parent;
420 }
421}
static std::size_t parent_of(std::size_t node_no) noexcept
Definition MutablePriorityQueue.hpp:225

Member Data Documentation

◆ m_heap

◆ m_index_setter

template<typename T , typename IndexSetter , typename LessPredicate , std::size_t blocking = 32, const bool ResetIndexWhenRemoved = false>
IndexSetter Slic3r::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 Slic3r::MutableSkipHeapPriorityQueue< T, IndexSetter, LessPredicate, blocking, ResetIndexWhenRemoved >::m_less_predicate
private

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