Template Class CExpirationMap
Defined in File ecal_expmap.h
Nested Relationships
Nested Types
Class Documentation
-
template<class Key, class T, class ClockType = std::chrono::steady_clock, class Compare = std::less<Key>, class Alloc = std::allocator<std::pair<const Key, T>>>
class CExpirationMap A map that stores key-value pairs and the time at which they have last been updated.
This class is not threadsafe and needs to be protected by locks / mutexes in multithreaded environments.
From the outside / for the user, this class acts as a regular std::map. However, it provides one additional function (erase_expired) that removes expired elements from this map. Elements are considered to be expired, if they have not been accessed (via
operator[]
) within a given timeout period.Internally, this is realized by storing both a map and a list. The map stores the regular key, and then the actual value and additional an iterator into the timestamp list. The timestamp list stores together a timestamp and the key which was inserted into the list at that given timestamp. It is always kept in a sorted order.
Whenever a map element is accessed, the responding timestamp is updated and moved to the end of the list. This happens in constant time.
- Template Parameters:
Key – The type of the keys.
T – The type of the values.
ClockType – The type of the clock based on which the Map expires its elements
Public Types
Public Functions
-
inline CExpirationMap()
-
inline const_iterator begin() const noexcept
-
inline const_iterator end() const noexcept
-
inline const_iterator cbegin() const noexcept
-
inline const_iterator cend() const noexcept
-
inline bool empty() const noexcept
-
inline T &operator[](const Key &k)
Accesses the value associated with the given key, resetting its expiration time.
- Parameters:
key – The key to access the value for.
- Returns:
The value associated with the key.
-
inline mapped_type &at(const key_type &k)
-
inline const mapped_type &at(const key_type &k) const
-
inline std::pair<iterator, bool> insert(const value_type &val)
-
inline const_iterator find(const Key &k) const
-
inline std::map<Key, T> erase_expired()
Erase all expired key-value pairs from the map.
This function erases all expired key-value pairs from the internal map / timestamp list. The CExpirationMap class does not call this function internally, it has to be called explicitly by the user.
-
inline void clear()
-
class const_iterator
Public Types
-
using iterator_category = std::bidirectional_iterator_tag
-
using difference_type = std::ptrdiff_t
Public Functions
-
inline explicit const_iterator(const typename InternalMapType::const_iterator _it)
-
inline const_iterator &operator++()
-
inline const_iterator &operator--()
-
inline bool operator==(const const_iterator &rhs) const
-
inline bool operator!=(const const_iterator &rhs) const
-
using iterator_category = std::bidirectional_iterator_tag