MySQL 8.0.39
Source Code Documentation
dd::cache::Element_map< K, E > Class Template Reference

Implementation of a map between a key type and an element type. More...

#include <element_map.h>

Public Types

typedef std::map< K, E *, std::less< K >, Malloc_allocator< std::pair< const K, E * > > > Element_map_type
 
typedef Element_map_type::const_iterator Const_iterator
 
typedef Element_map_type::iterator Iterator
 

Public Member Functions

 Element_map ()
 
Const_iterator begin () const
 Get an iterator to the beginning of the map. More...
 
Iterator begin ()
 
Const_iterator end () const
 Get an iterator to one past the end of the map. More...
 
Iterator end ()
 
size_t size () const
 Return the number of elements in the map. More...
 
bool is_present (const K &key) const
 Check if the given key is present in the map. More...
 
void get (const K &key, E **element) const
 Get the element associated with the given key. More...
 
void put (const K &key, E *element)
 Put the element into the map and associate it with the given key. More...
 
void remove (const K &key)
 Remove an element from the map. More...
 
bool is_missed (const K &key) const
 Check if the given key has been missed in the cache. More...
 
void set_missed (const K &key)
 Register the given key as being missed in the cache. More...
 
void set_miss_handled (const K &key)
 Register that the miss of a key has been handled. More...
 
void dump () const
 Debug dump of the element map to stderr. More...
 

Private Attributes

Element_map_type m_map
 
std::set< K, std::less< K >, Malloc_allocator< K > > m_missed
 

Detailed Description

template<typename K, typename E>
class dd::cache::Element_map< K, E >

Implementation of a map between a key type and an element type.

The map supports storing associations between instances of the key type K and pointers to the element type E. Additionally, the map provides support for registering keys that have been searched for in the map without being present. This allows registering a cache miss to avoid situations where several similar cache misses are handled simultaneously. Instead, only the first cache miss needs to be processed, while the subsequent ones can just wait for the first one to complete.

There are no expectations as far as the element type E is concerned. Tracking object usage, memory management, loading and evicting elements, locking and synchronization, as well as registering cache misses are all issues that are handled by users of this interface.

Basic assumptions regarding correct usage is implemented in terms of asserts to verify that, e.g., a key does not already exist in the map when it is added. There is, however, no assumptions regarding the relationship between the set of missed keys and the state of the map.

There is support for representing missed keys, but the usage of this feature is left to the outer layer; e.g., this class does not assert that an element has been registered as missing before it is added to the map.

Note
The element pointer in a key/value pair may not be NULL.
Template Parameters
KKey type.
EElement type (a Cache_element wrapping some dictionary object type).

Member Typedef Documentation

◆ Const_iterator

template<typename K , typename E >
typedef Element_map_type::const_iterator dd::cache::Element_map< K, E >::Const_iterator

◆ Element_map_type

template<typename K , typename E >
typedef std::map<K, E *, std::less<K>, Malloc_allocator<std::pair<const K, E *> > > dd::cache::Element_map< K, E >::Element_map_type

◆ Iterator

template<typename K , typename E >
typedef Element_map_type::iterator dd::cache::Element_map< K, E >::Iterator

Constructor & Destructor Documentation

◆ Element_map()

template<typename K , typename E >
dd::cache::Element_map< K, E >::Element_map ( )
inline

Member Function Documentation

◆ begin() [1/2]

template<typename K , typename E >
Iterator dd::cache::Element_map< K, E >::begin ( void  )
inline

◆ begin() [2/2]

template<typename K , typename E >
Const_iterator dd::cache::Element_map< K, E >::begin ( void  ) const
inline

Get an iterator to the beginning of the map.

Const and non-const variants.

Returns
Iterator to the beginning of the map.

◆ dump()

template<typename K , typename E >
void dd::cache::Element_map< K, E >::dump ( ) const
inline

Debug dump of the element map to stderr.

Iterates over all elements and dumps debug information for each of them.

◆ end() [1/2]

template<typename K , typename E >
Iterator dd::cache::Element_map< K, E >::end ( void  )
inline

◆ end() [2/2]

template<typename K , typename E >
Const_iterator dd::cache::Element_map< K, E >::end ( void  ) const
inline

Get an iterator to one past the end of the map.

Const and non-const variants.

Returns
Iterator to one past the end of the map.

◆ get()

template<typename K , typename E >
void dd::cache::Element_map< K, E >::get ( const K &  key,
E **  element 
) const
inline

Get the element associated with the given key.

If the element is present in the map, return a pointer to it. If the element is not present, return NULL as the element pointer.

Parameters
keyThe key to use for looking up the element.
[out]elementThe element associated with the key (if present), or NULL (if not present).

◆ is_missed()

template<typename K , typename E >
bool dd::cache::Element_map< K, E >::is_missed ( const K &  key) const
inline

Check if the given key has been missed in the cache.

Parameters
keyKey representing element to check for recent cache miss.
Returns
true if the element has been missed, otherwise false.

◆ is_present()

template<typename K , typename E >
bool dd::cache::Element_map< K, E >::is_present ( const K &  key) const
inline

Check if the given key is present in the map.

If the key is present in the map, return true, otherwise false.

Parameters
keyThe key to look for.
Returns
true if present, otherwise false.

◆ put()

template<typename K , typename E >
void dd::cache::Element_map< K, E >::put ( const K &  key,
E *  element 
)
inline

Put the element into the map and associate it with the given key.

The element may not be NULL, and the key may not be already present.

Parameters
keyThe key to be associated with the element.
elementThe element to be associated with the key.

◆ remove()

template<typename K , typename E >
void dd::cache::Element_map< K, E >::remove ( const K &  key)
inline

Remove an element from the map.

The key/value pair, as indicated by the key, is removed from the map. The element being pointed to is not deleted. The key must be present in the map.

Parameters
keyThe key to be removed.

◆ set_miss_handled()

template<typename K , typename E >
void dd::cache::Element_map< K, E >::set_miss_handled ( const K &  key)
inline

Register that the miss of a key has been handled.

The key must have been reported as missing.

Parameters
keyKey representing element previously missed in the cache.

◆ set_missed()

template<typename K , typename E >
void dd::cache::Element_map< K, E >::set_missed ( const K &  key)
inline

Register the given key as being missed in the cache.

The key cannot already be reported as missing.

Parameters
keyKey representing element missed in the cache.

◆ size()

template<typename K , typename E >
size_t dd::cache::Element_map< K, E >::size ( ) const
inline

Return the number of elements in the map.

Returns
Number of elements in the map.

Member Data Documentation

◆ m_map

template<typename K , typename E >
Element_map_type dd::cache::Element_map< K, E >::m_map
private

◆ m_missed

template<typename K , typename E >
std::set<K, std::less<K>, Malloc_allocator<K> > dd::cache::Element_map< K, E >::m_missed
private

The documentation for this class was generated from the following file: