MySQL 8.0.39
Source Code Documentation
|
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 |
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.
K | Key type. |
E | Element type (a Cache_element wrapping some dictionary object type). |
typedef Element_map_type::const_iterator dd::cache::Element_map< K, E >::Const_iterator |
typedef std::map<K, E *, std::less<K>, Malloc_allocator<std::pair<const K, E *> > > dd::cache::Element_map< K, E >::Element_map_type |
typedef Element_map_type::iterator dd::cache::Element_map< K, E >::Iterator |
|
inline |
|
inline |
|
inline |
Get an iterator to the beginning of the map.
Const and non-const variants.
|
inline |
Debug dump of the element map to stderr.
Iterates over all elements and dumps debug information for each of them.
|
inline |
|
inline |
Get an iterator to one past the end of the map.
Const and non-const variants.
|
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.
key | The key to use for looking up the element. | |
[out] | element | The element associated with the key (if present), or NULL (if not present). |
|
inline |
Check if the given key has been missed in the cache.
key | Key representing element to check for recent cache miss. |
|
inline |
Check if the given key is present in the map.
If the key is present in the map, return true, otherwise false.
key | The key to look for. |
|
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.
key | The key to be associated with the element. |
element | The element to be associated with the 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.
key | The key to be removed. |
|
inline |
Register that the miss of a key has been handled.
The key must have been reported as missing.
key | Key representing element previously missed in the cache. |
|
inline |
Register the given key as being missed in the cache.
The key cannot already be reported as missing.
key | Key representing element missed in the cache. |
|
inline |
Return the number of elements in the map.
|
private |
|
private |