Ocean
Loading...
Searching...
No Matches
RingMap.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_BASE_RING_MAP_H
9#define META_OCEAN_BASE_RING_MAP_H
10
11#include "ocean/base/Base.h"
12#include "ocean/base/DataType.h"
13#include "ocean/base/Lock.h"
14
15#include <optional>
16#include <list>
17
18namespace Ocean
19{
20
21/**
22 * This class implements a data storage map that stores the data elements in a ring manner.
23 * The map can hold a maximal number of elements and exchanges the oldest object by a new object if this map is full.<br>
24 * Each stored object is connected with a key so that the object can be addressed.<br>
25 * @tparam TKey Data type of the map keys
26 * @tparam T Data type of the map elements
27 * @tparam tThreadsafe True, to create a thread-safe object
28 * @tparam tOrderedKeys True, to allow accessing the keys in order; False, if the order of the keys is not of interest
29 * @ingroup base
30 */
31template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys = false>
33{
34 template <typename TKey2, typename T2, bool tThreadsafe2, bool tOrderedKeys2> friend class RingMapT;
35
36 public:
37
38 /**
39 * The data type of the objects that are stored in this container.
40 */
41 using Type = T;
42
43 /**
44 * The data type of the keys that are used to address the data objects.
45 */
46 using TypeKey = TKey;
47
48 /**
49 * Definition of a pair combining a key with an element.
50 */
51 using KeyElementPair = std::pair<TKey, T>;
52
53 /**
54 * Definition of individual element access modes.
55 */
56 enum AccessMode : uint32_t
57 {
58 /// The element's key must be a perfect match.
60 /// The element with highest key is returned if no perfect match can be found, only if 'tOrderedKeys == true'.
62 /// The element with lowest key is returned if no perfect match can be found, only if 'tOrderedKeys == true'.
64 };
65
66 protected:
67
68 /**
69 * Definition of a double-linked list holding the keys in order how they have been inserted.
70 */
71 using KeyList = std::list<TKey>;
72
73 /**
74 * Definition of a pair combining a value with a list iterator.
75 */
76 using ValuePair = std::pair<T, typename KeyList::iterator>;
77
78 /**
79 * Definition of a map that maps keys to value pairs.
80 */
81 using KeyMap = typename MapTyper<tOrderedKeys>::template TMap<TKey, ValuePair>;
82
83 public:
84
85 /**
86 * Creates a new ring storage object with no capacity.
87 */
88 RingMapT() = default;
89
90 /**
91 * Move constructor.
92 * @param ringMap Object to be moved
93 */
95
96 /**
97 * Copy constructor.
98 * @param ringMap Object to be copied
99 */
101
102 /**
103 * Creates a new ring storage object with a specified capacity.
104 * @param capacity The capacity of the storage container, with range [0, infinity)
105 */
106 explicit inline RingMapT(const size_t capacity);
107
108 /**
109 * Returns the capacity of this storage container.
110 * @return Capacity of this storage container
111 */
112 inline size_t capacity() const;
113
114 /**
115 * Returns the number of elements that are currently stored in this container.
116 * @return Number of elements, with range [0, capacity()]
117 */
118 inline size_t size() const;
119
120 /**
121 * Sets or changes the capacity of this storage container.
122 * @param capacity The capacity to be set, with range [0, infinity)
123 */
124 void setCapacity(const size_t capacity);
125
126 /**
127 * Inserts a new element into this storage container.
128 * @param key The key of the new element
129 * @param element The element that will be inserted
130 * @param forceOverwrite True, to overwrite an existing element with some key, False to avoid that an element is inserted if an element with same key exists already
131 * @return True, if the element has been inserted
132 */
133 bool insertElement(const TKey& key, const T& element, const bool forceOverwrite = false);
134
135 /**
136 * Inserts a new element into this storage container.
137 * This function moves the new element.
138 * @param key The key of the new element
139 * @param element The element that will be inserted
140 * @param forceOverwrite True, to overwrite an existing element with some key, False to avoid that an element is inserted if an element with same key exists already
141 * @return True, if the element has been inserted
142 */
143 bool insertElement(const TKey& key, T&& element, const bool forceOverwrite = false);
144
145 /**
146 * Returns an element of this storage container.
147 * @param key The key of the element to be returned
148 * @param element Resulting element
149 * @return True, if the requested element exists
150 * @tparam tAccessMode The access mode to be used
151 * @see checkoutElement().
152 */
153 template <AccessMode tAccessMode = AM_MATCH>
154 bool element(const TKey& key, T& element) const;
155
156 /**
157 * Returns either the specified element if it exists or the two elements neighboring to the specified element.
158 * @param key The key of the element to be returned
159 * @param lowerElement Resulting neighboring element with key lower than the specified key, std::nullopt if no such element exists or the exact element is returned
160 * @param higherElement Resulting neighboring element with key higher than the specified key, std::nullopt if no such element exists or the exact element is returned
161 * @return The resulting element with exact key, if it exists
162 */
163 std::optional<T> elements(const TKey& key, std::optional<KeyElementPair>& lowerElement, std::optional<KeyElementPair>& higherElement) const;
164
165 /**
166 * Returns the element with highest key.
167 * The map must be created with 'tOrderedKeys == true'.
168 * @param element Resulting element
169 * @return True, if the requested element exists
170 * @see element().
171 */
172 bool highestElement(T& element) const;
173
174 /**
175 * Returns the element with lowest key.
176 * The map must be created with 'tOrderedKeys == true'.
177 * @param element Resulting element
178 * @return True, if the requested element exists
179 * @see element().
180 */
181 bool lowestElement(T& element) const;
182
183 /**
184 * Returns an element of this storage container and removes the element from the container.
185 * @param key The key of the element to be returned
186 * @param element Resulting element
187 * @return True, if the requested element exists
188 * @tparam tAccessMode The access mode to be used
189 * @see element().
190 */
191 template <AccessMode tAccessMode = AM_MATCH>
192 bool checkoutElement(const TKey& key, T& element);
193
194 /**
195 * Returns whether this storage container holds a specific element.
196 * @param key The key of the element that is checked
197 * @return True, if so
198 */
199 bool hasElement(const TKey& key) const;
200
201 /**
202 * Checks whether a specified element exists and changes the age of this element.
203 * If the specified element exists, the age of the element will be changed so that the element is the newest element in the database.<br>
204 * @param key The key of the element that will be refreshed
205 * @return True, if the element exists
206 */
207 bool refreshElement(const TKey& key);
208
209 /**
210 * Returns all elements of this map as a vector.
211 * In case 'tOrderedKeys == true', the resulting elements will be in order based on their corresponding keys.
212 * @return The map's element
213 */
214 std::vector<T> elements() const;
215
216 /**
217 * Clears all elements of this storage container.
218 */
219 void clear();
220
221 /**
222 * Returns whether this ring map holds at least one element.
223 * @return True, if so
224 */
225 inline bool isEmpty() const;
226
227 /**
228 * Move operator.
229 * @param ringMap The ring map to be moved
230 * @return Reference to this object
231 */
233
234 /**
235 * Move operator.
236 * @param ringMap The ring map to be moved
237 * @return Reference to this object
238 * @tparam tThreadSafeSecond True, if the map to be moved is thread-safe
239 */
240 template <bool tThreadSafeSecond>
242
243 /**
244 * Copy operator.
245 * @param ringMap The ring map to be moved
246 * @return Reference to this object
247 */
249
250 /**
251 * Copy operator.
252 * @param ringMap The ring map to be moved
253 * @return Reference to this object
254 * @tparam tThreadSafeSecond True, if the map to be moved is thread-safe
255 */
256 template <bool tThreadSafeSecond>
258
259 protected:
260
261 /**
262 * Returns whether the internal states of this storage container is valid.
263 * @return True, if so
264 */
265 inline bool isValid() const;
266
267 protected:
268
269 /// The map mapping keys to value pairs.
271
272 /// The list holding the keys in order how they have been added, oldest keys first.
274
275 /// The capacity of this storage container.
277
278 /// The container lock.
280};
281
282template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
284{
285 *this = std::move(ringMap);
286}
287
288template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
293
294template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
296 storageCapacity_(capacity)
297{
298 // nothing to do here
299}
300
301template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
303{
304 return storageCapacity_;
305}
306
307template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
309{
310 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
311 ocean_assert(isValid());
312
313 return keyMap_.size();
314}
315
316template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
318{
319 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
320 ocean_assert(isValid());
321
322 if (capacity == storageCapacity_)
323 {
324 return;
325 }
326
327 if (capacity == 0)
328 {
329 keyMap_.clear();
330 keyList_.clear();
331
332 }
333 else if (capacity < storageCapacity_)
334 {
335 while (keyMap_.size() > capacity)
336 {
337 ocean_assert(keyMap_.find(keyList_.front()) != keyMap_.cend());
338 keyMap_.erase(keyList_.front());
339
340 keyList_.pop_front();
341 }
342 }
343
344 storageCapacity_ = capacity;
345
346 ocean_assert(isValid());
347}
348
349template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
350bool RingMapT<TKey, T, tThreadsafe, tOrderedKeys>::insertElement(const TKey& key, const T& element, const bool forceOverwrite)
351{
352 T copyElement(element);
353
354 return insertElement(key, std::move(copyElement), forceOverwrite);
355}
356
357template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
358bool RingMapT<TKey, T, tThreadsafe, tOrderedKeys>::insertElement(const TKey& key, T&& element, const bool forceOverwrite)
359{
360 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
361 ocean_assert(isValid());
362
363 if (storageCapacity_ == 0)
364 {
365 return false;
366 }
367
368 // check whether the key exist already
369 const typename KeyMap::iterator iMap = keyMap_.find(key);
370 if (iMap != keyMap_.cend())
371 {
372 if (!forceOverwrite)
373 {
374 return false;
375 }
376
377 iMap->second.first = std::move(element);
378
379 // moving the list entry to the end (making it the youngest entry), note: a list's iterator is still valid after moving an element
380 keyList_.splice(keyList_.cend(), keyList_, iMap->second.second);
381
382 return true;
383 }
384
385 // the key does not exist
386
387 ocean_assert(keyMap_.size() <= storageCapacity_);
388
389 if (keyMap_.size() >= storageCapacity_)
390 {
391 // the map is too big, we remove the oldest entry
392 const TKey oldKey(keyList_.front());
393 keyList_.pop_front();
394
395 ocean_assert(keyMap_.find(oldKey) != keyMap_.end());
396 keyMap_.erase(oldKey);
397 }
398
399 ocean_assert(keyMap_.size() < storageCapacity_);
400
401 keyList_.emplace_back(key);
402
403 keyMap_[key] = std::make_pair(std::move(element), --keyList_.end());
404
405 ocean_assert(isValid());
406 return true;
407}
408
409template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
410template <typename RingMapT<TKey, T, tThreadsafe, tOrderedKeys>::AccessMode tAccessMode>
411bool RingMapT<TKey, T, tThreadsafe, tOrderedKeys>::element(const TKey& key, T& element) const
412{
413 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
414 ocean_assert(isValid());
415
416 if (storageCapacity_ == 0 || keyMap_.empty())
417 {
418 return false;
419 }
420
421 typename KeyMap::const_iterator iMap = keyMap_.find(key);
422 if (iMap == keyMap_.end())
423 {
424 if constexpr (tOrderedKeys)
425 {
426 if constexpr (tAccessMode == AM_MATCH_OR_HIGHEST)
427 {
428 iMap = keyMap_.rbegin().base();
429 --iMap;
430 }
431 else if constexpr (tAccessMode == AM_MATCH_OR_LOWEST)
432 {
433 iMap = keyMap_.begin();
434 }
435 else
436 {
437 ocean_assert(tAccessMode == AM_MATCH);
438 return false;
439 }
440 }
441 else
442 {
443 ocean_assert(tAccessMode == AM_MATCH);
444 return false;
445 }
446 }
447
448 element = iMap->second.first;
449
450 ocean_assert(isValid());
451 return true;
452}
453
454template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
455std::optional<T> RingMapT<TKey, T, tThreadsafe, tOrderedKeys>::elements(const TKey& key, std::optional<KeyElementPair>& lowerElement, std::optional<KeyElementPair>& higherElement) const
456{
457 if constexpr (!tOrderedKeys)
458 {
459 return std::nullopt;
460 }
461
462 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
463 ocean_assert(isValid());
464
465 if (storageCapacity_ == 0 || keyMap_.empty())
466 {
467 return std::nullopt;
468 }
469
470 lowerElement = std::nullopt;
471 higherElement = std::nullopt;
472
473 typename KeyMap::const_iterator iMap = keyMap_.find(key);
474
475 if (iMap != keyMap_.end())
476 {
477 // we found an exact match
478
479 return iMap->second.first;
480 }
481
482 // no exact match found, let's find the next higher element
483
484 iMap = keyMap_.lower_bound(key);
485
486 if (iMap != keyMap_.end())
487 {
488 higherElement = KeyElementPair(iMap->first, iMap->second.first);
489 }
490
491 if (iMap != keyMap_.begin())
492 {
493 typename KeyMap::const_iterator iLower = iMap;
494
495 --iLower;
496 lowerElement = KeyElementPair(iLower->first, iLower->second.first);
497 }
498
499 ocean_assert(lowerElement.has_value() || higherElement.has_value());
500
501 return std::nullopt;
502}
503
504template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
506{
507 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
508 ocean_assert(isValid());
509
510 if (keyMap_.empty())
511 {
512 return false;
513 }
514
515 if constexpr (tOrderedKeys)
516 {
517 element = keyMap_.rbegin()->second.first;
518
519 return true;
520 }
521
522 return false;
523}
524
525template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
527{
528 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
529 ocean_assert(isValid());
530
531 if (keyMap_.empty())
532 {
533 return false;
534 }
535
536 if constexpr (tOrderedKeys)
537 {
538 element = keyMap_.begin()->second;
539
540 return true;
541 }
542
543 return false;
544}
545
546template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
547template <typename RingMapT<TKey, T, tThreadsafe, tOrderedKeys>::AccessMode tAccessMode>
549{
550 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
551 ocean_assert(isValid());
552
553 if (storageCapacity_ == 0 || keyMap_.empty())
554 {
555 return false;
556 }
557
558 typename KeyMap::iterator iMap = keyMap_.find(key);
559 if (iMap == keyMap_.end())
560 {
561 if constexpr (tOrderedKeys)
562 {
563 if constexpr (tAccessMode == AM_MATCH_OR_HIGHEST)
564 {
565 iMap = keyMap_.rbegin().base();
566 --iMap;
567 }
568 else if constexpr (tAccessMode == AM_MATCH_OR_LOWEST)
569 {
570 iMap = keyMap_.begin();
571 }
572 else
573 {
574 ocean_assert(tAccessMode == AM_MATCH);
575 return false;
576 }
577 }
578 else
579 {
580 ocean_assert(tAccessMode == AM_MATCH);
581 return false;
582 }
583 }
584
585 keyList_.erase(iMap->second.second);
586
587 element = std::move(iMap->second.first);
588
589 keyMap_.erase(iMap);
590
591 ocean_assert(isValid());
592 return true;
593}
594
595template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
597{
598 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
599 ocean_assert(isValid());
600
601 return keyMap_.find(key) != keyMap_.end();
602}
603
604template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
606{
607 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
608 ocean_assert(isValid());
609
610 std::vector<T> result;
611 result.reserve(keyMap_.size());
612
613 for (typename KeyMap::const_iterator iMap = keyMap_.cbegin(); iMap != keyMap_.cend(); ++iMap)
614 {
615 result.emplace_back(iMap->second.first);
616 }
617
618 return result;
619}
620
621template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
623{
624 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
625 ocean_assert(isValid());
626
627 const typename KeyMap::const_iterator iMap = keyMap_.find(key);
628
629 if (iMap == keyMap_.cend())
630 {
631 return false;
632 }
633
634 // moving the list entry to the end (making it the youngest entry), note: a list's iterator is still valid after moving an element
635 keyList_.splice(keyList_.cend(), keyList_, iMap->second.second);
636
637 ocean_assert(isValid());
638 return true;
639}
640
641template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
643{
644 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
645 ocean_assert(isValid());
646
647 keyMap_.clear();
648 keyList_.clear();
649
650 ocean_assert(isValid());
651}
652
653template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
655{
656 ocean_assert(keyMap_.size() == keyList_.size());
657
658 return keyMap_.size() <= storageCapacity_ && keyMap_.size() == keyList_.size();
659}
660
661template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
663{
664 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
665 ocean_assert(isValid());
666
667 return keyMap_.empty();
668}
669
670template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
672{
673 if (this != &ringMap)
674 {
675 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
676 const TemplatedScopedLock<tThreadsafe> scopedLockSecond(ringMap.lock_); // will not create a dead-lock unless both maps depend on each other
677
678 keyMap_ = std::move(ringMap.keyMap_);
679 keyList_ = std::move(ringMap.keyList_);
680 storageCapacity_ = ringMap.storageCapacity_;
681 ringMap.storageCapacity_ = 0;
682 }
683
684 return *this;
685}
686
687template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
688template <bool tThreadSafeSecond>
690{
691 if ((void*)(this) != (void*)(&ringMap))
692 {
693 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
694 const TemplatedScopedLock<tThreadSafeSecond> scopedLockSecond(ringMap.lock_); // will not create a dead-lock unless both maps depend on each other
695
696 keyMap_ = std::move(ringMap.keyMap_);
697 keyList_ = std::move(ringMap.keyList_);
698 storageCapacity_ = ringMap.storageCapacity_;
699 ringMap.storageCapacity_ = 0;
700 }
701
702 return *this;
703}
704
705template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
707{
708 if (this != &ringMap)
709 {
710 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
711 const TemplatedScopedLock<tThreadsafe> scopedLockSecond(ringMap.lock_); // will not create a dead-lock unless both maps depend on each other
712
713 keyMap_ = ringMap.keyMap_;
714 keyList_ = ringMap.keyList_;
715 storageCapacity_ = ringMap.storageCapacity_;
716 }
717
718 return *this;
719}
720
721template <typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys>
722template <bool tThreadSafeSecond>
724{
725 if ((void*)(this) != (void*)(&ringMap))
726 {
727 const TemplatedScopedLock<tThreadsafe> scopedLock(lock_);
728 const TemplatedScopedLock<tThreadSafeSecond> scopedLockSecond(ringMap.lock_); // will not create a dead-lock unless both maps depend on each other
729
730 keyMap_ = ringMap.keyMap_;
731 keyList_ = ringMap.keyList_;
732 storageCapacity_ = ringMap.storageCapacity_;
733 }
734
735 return *this;
736}
737
738}
739
740#endif // META_OCEAN_BASE_RING_MAP_H
Helper class allowing to define an ordered or unordered map based on the template parameter 'tOrdered...
Definition DataType.h:518
This class implements a data storage map that stores the data elements in a ring manner.
Definition RingMap.h:33
std::pair< T, typename KeyList::iterator > ValuePair
Definition of a pair combining a value with a list iterator.
Definition RingMap.h:76
KeyMap keyMap_
The map mapping keys to value pairs.
Definition RingMap.h:270
bool hasElement(const TKey &key) const
Returns whether this storage container holds a specific element.
Definition RingMap.h:596
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & operator=(RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &&ringMap) noexcept
Move operator.
Definition RingMap.h:671
std::list< TKey > KeyList
Definition of a double-linked list holding the keys in order how they have been inserted.
Definition RingMap.h:71
bool lowestElement(T &element) const
Returns the element with lowest key.
Definition RingMap.h:526
std::pair< TKey, T > KeyElementPair
Definition of a pair combining a key with an element.
Definition RingMap.h:51
T Type
The data type of the objects that are stored in this container.
Definition RingMap.h:41
TemplatedLock< tThreadsafe > lock_
The container lock.
Definition RingMap.h:279
bool isValid() const
Returns whether the internal states of this storage container is valid.
Definition RingMap.h:654
TKey TypeKey
The data type of the keys that are used to address the data objects.
Definition RingMap.h:46
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & operator=(RingMapT< TKey, T, tThreadSafeSecond, tOrderedKeys > &&ringMap) noexcept
Move operator.
Definition RingMap.h:689
bool refreshElement(const TKey &key)
Checks whether a specified element exists and changes the age of this element.
Definition RingMap.h:622
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & operator=(const RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &ringMap)
Copy operator.
Definition RingMap.h:706
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & operator=(const RingMapT< TKey, T, tThreadSafeSecond, tOrderedKeys > &ringMap)
Copy operator.
Definition RingMap.h:723
void clear()
Clears all elements of this storage container.
Definition RingMap.h:642
RingMapT(const RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &ringMap)
Copy constructor.
Definition RingMap.h:289
size_t size() const
Returns the number of elements that are currently stored in this container.
Definition RingMap.h:308
size_t capacity() const
Returns the capacity of this storage container.
Definition RingMap.h:302
bool highestElement(T &element) const
Returns the element with highest key.
Definition RingMap.h:505
std::optional< T > elements(const TKey &key, std::optional< KeyElementPair > &lowerElement, std::optional< KeyElementPair > &higherElement) const
Returns either the specified element if it exists or the two elements neighboring to the specified el...
Definition RingMap.h:455
KeyList keyList_
The list holding the keys in order how they have been added, oldest keys first.
Definition RingMap.h:273
std::vector< T > elements() const
Returns all elements of this map as a vector.
Definition RingMap.h:605
bool element(const TKey &key, T &element) const
Returns an element of this storage container.
Definition RingMap.h:411
bool insertElement(const TKey &key, T &&element, const bool forceOverwrite=false)
Inserts a new element into this storage container.
Definition RingMap.h:358
bool insertElement(const TKey &key, const T &element, const bool forceOverwrite=false)
Inserts a new element into this storage container.
Definition RingMap.h:350
bool isEmpty() const
Returns whether this ring map holds at least one element.
Definition RingMap.h:662
RingMapT()=default
Creates a new ring storage object with no capacity.
size_t storageCapacity_
The capacity of this storage container.
Definition RingMap.h:276
AccessMode
Definition of individual element access modes.
Definition RingMap.h:57
@ AM_MATCH_OR_LOWEST
The element with lowest key is returned if no perfect match can be found, only if 'tOrderedKeys == tr...
Definition RingMap.h:63
@ AM_MATCH_OR_HIGHEST
The element with highest key is returned if no perfect match can be found, only if 'tOrderedKeys == t...
Definition RingMap.h:61
@ AM_MATCH
The element's key must be a perfect match.
Definition RingMap.h:59
bool checkoutElement(const TKey &key, T &element)
Returns an element of this storage container and removes the element from the container.
Definition RingMap.h:548
RingMapT(const size_t capacity)
Creates a new ring storage object with a specified capacity.
Definition RingMap.h:295
friend class RingMapT
Definition RingMap.h:34
void setCapacity(const size_t capacity)
Sets or changes the capacity of this storage container.
Definition RingMap.h:317
RingMapT(RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &&ringMap) noexcept
Move constructor.
Definition RingMap.h:283
typename MapTyper< tOrderedKeys >::template TMap< TKey, ValuePair > KeyMap
Definition of a map that maps keys to value pairs.
Definition RingMap.h:81
This class implements a template-based recursive lock object.
Definition Lock.h:99
This class implements a recursive scoped lock object that is activated by a boolean template paramete...
Definition Lock.h:190
The namespace covering the entire Ocean framework.
Definition Accessor.h:15