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