Ponca  6d7f3619cbd70eb6ac131a3267ba1a351b1c9d07
Point Cloud Analysis library
Loading...
Searching...
No Matches
limitedPriorityQueue.h
1
8#pragma once
9
10#include <cstddef>
11#include <array>
12#include <algorithm>
13#include <functional>
14
15#include "../defines.h"
16#include "./iteratorUtils.h"
17#include "../Assert.h"
18
19namespace Ponca
20{
21
83 template <class T, int N, class CompareT = std::less<T>>
85 {
86 static_assert(N > 0, "The capacity must be strictly positive");
87
88 public:
89 using value_type = T;
90 using container_type = std::array<T, N>;
91 using compare = CompareT;
92 using iterator = typename container_type::iterator;
93 using const_iterator = typename container_type::const_iterator;
95
96 // LimitedPriorityQueue --------------------------------------------------
97 public:
98 PONCA_MULTIARCH inline LimitedPriorityQueue();
99 PONCA_MULTIARCH inline LimitedPriorityQueue(const Self& other);
100 PONCA_MULTIARCH inline explicit LimitedPriorityQueue(int capacity);
101 template <class InputIt>
102 PONCA_MULTIARCH LimitedPriorityQueue(int capacity, InputIt first, InputIt last);
103
104 PONCA_MULTIARCH inline ~LimitedPriorityQueue() = default;
105
106 PONCA_MULTIARCH inline LimitedPriorityQueue& operator=(const Self& other) = default;
107
108 // Iterator ----------------------------------------------------------------
109 public:
110 PONCA_MULTIARCH [[nodiscard]] inline iterator begin();
111 PONCA_MULTIARCH [[nodiscard]] inline const_iterator begin() const;
112 PONCA_MULTIARCH [[nodiscard]] inline const_iterator cbegin() const;
113
114 PONCA_MULTIARCH [[nodiscard]] inline iterator end();
115 PONCA_MULTIARCH [[nodiscard]] inline const_iterator end() const;
116 PONCA_MULTIARCH [[nodiscard]] inline const_iterator cend() const;
117
118 // Element access ----------------------------------------------------------
119 public:
120 PONCA_MULTIARCH [[nodiscard]] inline const T& top() const;
121 PONCA_MULTIARCH [[nodiscard]] inline const T& bottom() const;
122
123 PONCA_MULTIARCH [[nodiscard]] inline T& top();
124 PONCA_MULTIARCH [[nodiscard]] inline T& bottom();
125
126 // Capacity ----------------------------------------------------------------
127 public:
128 PONCA_MULTIARCH [[nodiscard]] inline bool empty() const;
129 PONCA_MULTIARCH [[nodiscard]] inline bool full() const;
130 PONCA_MULTIARCH [[nodiscard]] inline size_t size() const;
131 PONCA_MULTIARCH [[nodiscard]] inline size_t capacity() const;
132
133 // Modifiers ---------------------------------------------------------------
134 protected:
135 PONCA_MULTIARCH inline bool pushImpl(const T& _value, T** _addr);
136
137 public:
138 PONCA_MULTIARCH bool push(T&& _value);
139 PONCA_MULTIARCH bool push(const T& _value);
140 PONCA_MULTIARCH void pop();
141 PONCA_MULTIARCH void reserve(int _capacity);
142 PONCA_MULTIARCH void clear();
143
144 // Data --------------------------------------------------------------------
145 public:
146 PONCA_MULTIARCH const container_type& container() const;
147
148 protected:
149 container_type m_data{};
150 compare m_comp;
151 size_t m_size{0};
152 size_t m_capacity{0};
153 };
154
159
160 // LimitedPriorityQueue ------------------------------------------------------
161
162 template <class T, int N, class Cmp>
163 PONCA_MULTIARCH LimitedPriorityQueue<T, N, Cmp>::LimitedPriorityQueue() : m_comp()
164 {
165 PONCA_ASSERT((m_capacity <= N));
166 }
167
168 template <class T, int N, class Cmp>
169 PONCA_MULTIARCH LimitedPriorityQueue<T, N, Cmp>::LimitedPriorityQueue(const Self& other)
170 : m_data(other.m_data), m_comp(other.m_comp), m_size(other.m_size), m_capacity(other.m_capacity)
171 {
172 PONCA_ASSERT((m_capacity <= N));
173 }
174
175 template <class T, int N, class Cmp>
176 PONCA_MULTIARCH LimitedPriorityQueue<T, N, Cmp>::LimitedPriorityQueue(const int capacity)
177 : m_comp(), m_capacity(capacity)
178 {
179 PONCA_ASSERT((capacity >= 0));
180 PONCA_ASSERT((capacity <= N));
181 }
182
183 template <class T, int N, class Cmp>
184 template <class InputIt>
185 PONCA_MULTIARCH LimitedPriorityQueue<T, N, Cmp>::LimitedPriorityQueue(const int capacity, InputIt first,
186 InputIt last)
187 : m_comp(), m_capacity(capacity)
188 {
189 for (InputIt it = first; it < last; ++it)
190 {
191 push(*it);
192 }
193 PONCA_ASSERT((capacity >= 0));
194 PONCA_ASSERT((capacity <= N));
195 }
196} // namespace Ponca
197
198#include "limitedPriorityQueue.hpp"
Aggregator class used to declare specialized structures using CRTP.
Definition basket.h:257
The LimitedPriorityQueue class is similar to std::priority_queue but has a limited capacity and handl...
size_t m_capacity
The capacity of the limited queue.
size_t m_size
The current size of the Queue.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
Definition bitset.h:16