StableVector.hpp
Go to the documentation of this file.
1 
28 /*
29  * StableVector.hpp
30  *
31  * @date 08.06.2017
32  * @author Johan M. von Behren <johan@vonbehren.eu>
33  */
34 
35 #ifndef LVR2_ATTRMAPS_STABLEVECTOR_H_
36 #define LVR2_ATTRMAPS_STABLEVECTOR_H_
37 
38 #include <vector>
39 #include <utility>
40 #include <boost/optional.hpp>
41 #include <boost/shared_array.hpp>
42 
43 using std::move;
44 using std::vector;
45 
46 
47 #include "lvr2/util/BaseHandle.hpp"
49 
50 
51 namespace lvr2
52 {
53 
60 template<typename HandleT, typename ElemT>
62 {
63 private:
65  const vector<boost::optional<ElemT>>* m_elements;
66 
68  size_t m_pos;
69 public:
70  StableVectorIterator(const vector<boost::optional<ElemT>>* deleted, bool startAtEnd = false);
71 
73  bool operator==(const StableVectorIterator& other) const;
74  bool operator!=(const StableVectorIterator& other) const;
75 
77 
78  bool isAtEnd() const;
79 
80  HandleT operator*() const;
81 };
82 
103 template<typename HandleT, typename ElemT>
105 {
106  static_assert(
107  std::is_base_of<BaseHandle<Index>, HandleT>::value,
108  "HandleT must inherit from BaseHandle!"
109  );
110 
111 public:
112 
113  using ElementType = ElemT;
114  using HandleType = HandleT;
115 
119  StableVector() : m_usedCount(0) {};
120 
128  StableVector(size_t countElements, const ElementType& defaultValue);
129 
130  StableVector(size_t countElements, const boost::shared_array<ElementType>& sharedArray);
131 
137  HandleType push(const ElementType& elem);
138 
144  HandleType push(ElementType&& elem);
145 
156  void increaseSize(HandleType upTo);
157 
167  void increaseSize(HandleType upTo, const ElementType& elem);
168 
172  HandleType nextHandle() const;
173 
182  void erase(HandleType handle);
183 
187  void clear();
188 
195  boost::optional<ElementType&> get(HandleType handle);
196 
203  boost::optional<const ElementType&> get(HandleType handle) const;
204 
212  void set(HandleType handle, const ElementType& elem);
213 
221  void set(HandleType handle, ElementType&& elem);
222 
230  ElementType& operator[](HandleType handle);
231 
239  const ElementType& operator[](HandleType handle) const;
240 
244  size_t size() const;
245 
249  size_t numUsed() const;
250 
258 
264 
274  void reserve(size_t newCap);
275 
276 private:
278  size_t m_usedCount;
279 
281  vector<boost::optional<ElementType>> m_elements;
282 
287  void checkAccess(HandleType handle) const;
288 };
289 
290 } // namespace lvr2
291 
292 #include "lvr2/attrmaps/StableVector.tcc"
293 
294 #endif /* LVR2_ATTRMAPS_STABLEVECTOR_H_ */
StableVectorIterator & operator++()
HandleT operator*() const
A vector which guarantees stable indices and features O(1) deletion.
size_t m_pos
Current position in the vector.
bool operator==(const StableVectorIterator &other) const
size_t m_usedCount
Count of used elements in elements vector.
vector< boost::optional< ElementType > > m_elements
Vector for stored elements.
StableVector()
Creates an empty StableVector.
Iterator over handles in this vector, which skips deleted elements.
StableVectorIterator & operator=(const StableVectorIterator &other)
StableVectorIterator(const vector< boost::optional< ElemT >> *deleted, bool startAtEnd=false)
Handle to access Cluster of the ClusterBiMap.
Definition: Handles.hpp:152
bool operator!=(const StableVectorIterator &other) const
Represents a group of handles, which are somehow connected.
Definition: Cluster.hpp:50
const vector< boost::optional< ElemT > > * m_elements
Reference to the deleted marker array this iterator belongs to.


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:09