mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-22 14:13:57 -06:00
MutablePriorityQueue: Added is_trivially_copyable test for queue value
types, added [] accessors.
This commit is contained in:
parent
e4fd6a828f
commit
5bbe76003e
1 changed files with 8 additions and 0 deletions
|
@ -2,11 +2,14 @@
|
||||||
#define slic3r_MutablePriorityQueue_hpp_
|
#define slic3r_MutablePriorityQueue_hpp_
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
|
template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
|
||||||
class MutablePriorityQueue
|
class MutablePriorityQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static_assert(std::is_trivially_copyable<T>::value, "Template argument T must be a trivially copiable type in class template MutablePriorityQueue");
|
||||||
|
|
||||||
// It is recommended to use make_mutable_priority_queue() for construction.
|
// It is recommended to use make_mutable_priority_queue() for construction.
|
||||||
MutablePriorityQueue(IndexSetter &&index_setter, LessPredicate &&less_predicate) :
|
MutablePriorityQueue(IndexSetter &&index_setter, LessPredicate &&less_predicate) :
|
||||||
m_index_setter(std::forward<IndexSetter>(index_setter)),
|
m_index_setter(std::forward<IndexSetter>(index_setter)),
|
||||||
|
@ -25,6 +28,8 @@ public:
|
||||||
|
|
||||||
size_t size() const { return m_heap.size(); }
|
size_t size() const { return m_heap.size(); }
|
||||||
bool empty() const { return m_heap.empty(); }
|
bool empty() const { return m_heap.empty(); }
|
||||||
|
T& operator[](std::size_t idx) noexcept { return m_heap[idx]; }
|
||||||
|
const T& operator[](std::size_t idx) const noexcept { return m_heap[idx]; }
|
||||||
|
|
||||||
using iterator = typename std::vector<T>::iterator;
|
using iterator = typename std::vector<T>::iterator;
|
||||||
using const_iterator = typename std::vector<T>::const_iterator;
|
using const_iterator = typename std::vector<T>::const_iterator;
|
||||||
|
@ -251,6 +256,7 @@ template<typename T, typename IndexSetter, typename LessPredicate, std::size_t b
|
||||||
class MutableSkipHeapPriorityQueue
|
class MutableSkipHeapPriorityQueue
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static_assert(std::is_trivially_copyable<T>::value, "Template argument T must be a trivially copiable type in class template MutableSkipHeapPriorityQueue");
|
||||||
using address = SkipHeapAddressing<blocking>;
|
using address = SkipHeapAddressing<blocking>;
|
||||||
|
|
||||||
// It is recommended to use make_miniheap_mutable_priority_queue() for construction.
|
// It is recommended to use make_miniheap_mutable_priority_queue() for construction.
|
||||||
|
@ -272,6 +278,8 @@ public:
|
||||||
// There is one padding element storead at each miniheap, thus lower the number of elements by the number of miniheaps.
|
// There is one padding element storead at each miniheap, thus lower the number of elements by the number of miniheaps.
|
||||||
size_t size() const noexcept { return m_heap.size() - (m_heap.size() + address::block_size - 1) / address::block_size; }
|
size_t size() const noexcept { return m_heap.size() - (m_heap.size() + address::block_size - 1) / address::block_size; }
|
||||||
bool empty() const { return m_heap.empty(); }
|
bool empty() const { return m_heap.empty(); }
|
||||||
|
T& operator[](std::size_t idx) noexcept { assert(! address::is_padding(idx)); return m_heap[idx]; }
|
||||||
|
const T& operator[](std::size_t idx) const noexcept { assert(! address::is_padding(idx)); return m_heap[idx]; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void update_heap_up(size_t top, size_t bottom);
|
void update_heap_up(size_t top, size_t bottom);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue