Ponca  82fc77e8c6294111c6f00670e92ec58a24e2ecf2
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#include "concepts.h"
19
20namespace Ponca
21{
22
84 template <class T, int N, class CompareT = std::less<T>>
85 requires ValidCapacity<N>
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 requires ValidCapacity<N>
164 PONCA_MULTIARCH LimitedPriorityQueue<T, N, Cmp>::LimitedPriorityQueue() : m_comp()
165 {
166 PONCA_ASSERT((m_capacity <= N));
167 }
168
169 template <class T, int N, class Cmp>
170 requires ValidCapacity<N>
171 PONCA_MULTIARCH LimitedPriorityQueue<T, N, Cmp>::LimitedPriorityQueue(const Self& other)
172 : m_data(other.m_data), m_comp(other.m_comp), m_size(other.m_size), m_capacity(other.m_capacity)
173 {
174 PONCA_ASSERT((m_capacity <= N));
175 }
176
177 template <class T, int N, class Cmp>
178 requires ValidCapacity<N>
179 PONCA_MULTIARCH LimitedPriorityQueue<T, N, Cmp>::LimitedPriorityQueue(const int capacity)
180 : m_comp(), m_capacity(capacity)
181 {
182 PONCA_ASSERT((capacity >= 0));
183 PONCA_ASSERT((capacity <= N));
184 }
185
186 template <class T, int N, class Cmp>
187 requires ValidCapacity<N>
188 template <class InputIt>
189 PONCA_MULTIARCH LimitedPriorityQueue<T, N, Cmp>::LimitedPriorityQueue(const int capacity, InputIt first,
190 InputIt last)
191 : m_comp(), m_capacity(capacity)
192 {
193 for (InputIt it = first; it < last; ++it)
194 {
195 push(*it);
196 }
197 PONCA_ASSERT((capacity >= 0));
198 PONCA_ASSERT((capacity <= N));
199 }
200} // namespace Ponca
201
202#include "limitedPriorityQueue.hpp"
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 concepts.h:11