diff options
Diffstat (limited to 'src/lib/netlist/plib/ptimed_queue.h')
-rw-r--r-- | src/lib/netlist/plib/ptimed_queue.h | 73 |
1 files changed, 17 insertions, 56 deletions
diff --git a/src/lib/netlist/plib/ptimed_queue.h b/src/lib/netlist/plib/ptimed_queue.h index 6d8858a86ba..33c14f3bdb9 100644 --- a/src/lib/netlist/plib/ptimed_queue.h +++ b/src/lib/netlist/plib/ptimed_queue.h @@ -150,6 +150,7 @@ namespace plib { } void pop() noexcept { --m_end; } + const T &top() const noexcept { return *(m_end-1); } template <bool KEEPSTAT, class R> @@ -171,34 +172,6 @@ namespace plib { //printf("Element not found in delete %s\n", elem->name().c_str()); } - template <bool KEEPSTAT, class R> - void retime(R && elem) noexcept - { - // Lock - lock_guard_type lck(m_lock); - if (KEEPSTAT) - m_prof_retime.inc(); - - for (R * i = m_end - 1; i > &m_list[0]; --i) - { - if (*i == elem) // partial equal! - { - *i = std::forward<R>(elem); - while (*(i-1) < *i) - { - std::swap(*(i-1), *i); - --i; - } - while (i < m_end && *i < *(i+1)) - { - std::swap(*(i+1), *i); - ++i; - } - return; - } - } - } - void clear() noexcept { lock_guard_type lck(m_lock); @@ -230,7 +203,6 @@ namespace plib { pperfcount_t<true> m_prof_sortmove; // NOLINT pperfcount_t<true> m_prof_call; // NOLINT pperfcount_t<true> m_prof_remove; // NOLINT - pperfcount_t<true> m_prof_retime; // NOLINT }; template <class T, bool TS> @@ -240,7 +212,7 @@ namespace plib { struct compare { - constexpr bool operator()(const T &a, const T &b) const { return b <= a; } + constexpr bool operator()(const T &a, const T &b) const noexcept { return b <= a; } }; explicit timed_queue_heap(const std::size_t list_size) @@ -255,6 +227,17 @@ namespace plib { std::size_t capacity() const noexcept { return m_list.capacity(); } bool empty() const noexcept { return &m_list[0] == m_end; } + template<bool KEEPSTAT, typename... Args> + void emplace(Args&&... args) noexcept + { + // Lock + lock_guard_type lck(m_lock); + *m_end++ = T(std::forward<Args>(args)...); + std::push_heap(&m_list[0], m_end, compare()); + if (KEEPSTAT) + m_prof_call.inc(); + } + template <bool KEEPSTAT> void push(T &&e) noexcept { @@ -266,12 +249,10 @@ namespace plib { m_prof_call.inc(); } - T pop() noexcept + void pop() noexcept { - T ret(m_list[0]); std::pop_heap(&m_list[0], m_end, compare()); m_end--; - return ret; } const T &top() const noexcept { return m_list[0]; } @@ -295,24 +276,6 @@ namespace plib { } } - template <bool KEEPSTAT> - void retime(const T &elem) noexcept - { - // Lock - lock_guard_type lck(m_lock); - if (KEEPSTAT) - m_prof_retime.inc(); - for (T * i = m_end - 1; i >= &m_list[0]; i--) - { - if (*i == elem) // partial equal! - { - *i = elem; - std::make_heap(&m_list[0], m_end, compare()); - return; - } - } - } - void clear() { lock_guard_type lck(m_lock); @@ -329,19 +292,17 @@ namespace plib { using mutex_type = pspin_mutex<TS>; using lock_guard_type = std::lock_guard<mutex_type>; - mutex_type m_lock; - std::vector<T> m_list; - T *m_end; + mutex_type m_lock; + T * m_end; + aligned_vector<T> m_list; public: // profiling pperfcount_t<true> m_prof_sortmove; // NOLINT pperfcount_t<true> m_prof_call; // NOLINT pperfcount_t<true> m_prof_remove; // NOLINT - pperfcount_t<true> m_prof_retime; // NOLINT }; } // namespace plib #endif // PTIMED_QUEUE_H_ -#include <cstdlib> |