MySQL 8.1.0
Source Code Documentation
local_multi_map.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2023, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef DD_CACHE__LOCAL_MULTI_MAP_INCLUDED
24#define DD_CACHE__LOCAL_MULTI_MAP_INCLUDED
25
26#include <stdio.h>
27
28#include "multi_map_base.h" // Multi_map_base
29#include "my_dbug.h"
30#include "sql/dd/types/entity_object_table.h" // dd::Entity_object_table
31
32namespace dd {
33namespace cache {
34
35template <typename K, typename E>
36class Element_map;
37template <typename T>
38class Cache_element;
39
40/**
41 Implementation of a local set of maps for a given object type.
42
43 The implementation is an extension of the multi map base, adding support
44 for iteration. It is intended to be used in a single threaded context, and
45 there is no support for tracking object usage, free list management,
46 thread synchronization, etc.
47
48 @tparam T Dictionary object type.
49*/
50
51template <typename T>
53 private:
54 /**
55 Template helper function getting the element map.
56
57 Const and non-const variants.
58
59 @note Slightly weird syntax is needed to help the parser
60 to resolve this correctly.
61
62 @tparam K Key type.
63
64 @return The element map handling keys of type K.
65 */
66
67 template <typename K>
69 return Multi_map_base<T>::template m_map<K>();
70 }
71
72 template <typename K>
74 return Multi_map_base<T>::template m_map<K>();
75 }
76
77 public:
78 /**
79 Get an iterator to the beginning of the map.
80
81 Const and non-const variants.
82
83 @return Iterator to the beginning of the map.
84 */
85
86 /* purecov: begin inspected */
88 return m_map<const T *>()->begin();
89 }
90 /* purecov: end */
91
93 return m_map<const T *>()->begin();
94 }
95
96 /**
97 Get an iterator to one past the end of the map.
98
99 Const and non-const variants.
100
101 @return Iterator to one past the end of the map.
102 */
103
104 /* purecov: begin inspected */
106 return m_map<const T *>()->end();
107 }
108 /* purecov: end */
109
111 return m_map<const T *>()->end();
112 }
113
114 /**
115 Get an element from the map handling the given key type.
116
117 If the element is present, return a pointer to it. Otherwise,
118 return NULL.
119
120 @tparam K Key type.
121 @param key Key to use for looking up the element.
122 @param [out] element Element pointer, if present, otherwise NULL.
123 */
124
125 template <typename K>
126 void get(const K &key, Cache_element<T> **element) const {
127 m_map<K>()->get(key, element);
128 }
129
130 /**
131 Put a new element into the map.
132
133 None of the keys may exist in advance, and the wrapped object may not
134 be present in this map already.
135
136 @param element New element to be added.
137 */
138
139 void put(Cache_element<T> *element);
140
141 /**
142 Remove an element from the map.
143
144 This function will remove the element from the multi map. This means that
145 all keys associated with the element will be removed from the maps, and
146 the cache element wrapper will be removed, but not deleted. The object
147 itself is not deleted. It is up to the outer layer to decide what to do
148 with the element and object.
149
150 @param element Element to be removed.
151 */
152
153 void remove(Cache_element<T> *element);
154
155 /**
156 Remove and delete all objects from the map. This includes
157 Cache_elements and the Dictionary objects themselves.
158 */
159
160 void erase();
161
162 /**
163 Get the number of elements in the map.
164
165 @return Number of elements.
166 */
167
168 size_t size() const { return m_map<const T *>()->size(); }
169
170 /**
171 Debug dump of the local multi map to stderr.
172 */
173
174 void dump() const;
175};
176
177} // namespace cache
178} // namespace dd
179
180#endif // DD_CACHE__LOCAL_MULTI_MAP_INCLUDED
Implementation of a dictionary client.
Definition: cache_element.h:68
Implementation of a map between a key type and an element type.
Definition: element_map.h:71
Implementation of a local set of maps for a given object type.
Definition: local_multi_map.h:52
void dump() const
Debug dump of the local multi map to stderr.
Definition: local_multi_map.cc:129
Multi_map_base< T >::Iterator begin()
Definition: local_multi_map.h:92
void erase()
Remove and delete all objects from the map.
Definition: local_multi_map.cc:109
size_t size() const
Get the number of elements in the map.
Definition: local_multi_map.h:168
Multi_map_base< T >::Const_iterator begin() const
Get an iterator to the beginning of the map.
Definition: local_multi_map.h:87
const Element_map< K, Cache_element< T > > * m_map() const
Definition: local_multi_map.h:73
Multi_map_base< T >::Const_iterator end() const
Get an iterator to one past the end of the map.
Definition: local_multi_map.h:105
void get(const K &key, Cache_element< T > **element) const
Get an element from the map handling the given key type.
Definition: local_multi_map.h:126
Element_map< K, Cache_element< T > > * m_map()
Template helper function getting the element map.
Definition: local_multi_map.h:68
void remove(Cache_element< T > *element)
Remove an element from the map.
Definition: local_multi_map.cc:85
Multi_map_base< T >::Iterator end()
Definition: local_multi_map.h:110
void put(Cache_element< T > *element)
Put a new element into the map.
Definition: local_multi_map.cc:58
Implementation of a set of maps for a given object type.
Definition: multi_map_base.h:63
Element_map< constT *, Cache_element< T > >::Iterator Iterator
Definition: multi_map_base.h:127
Element_map< constT *, Cache_element< T > >::Const_iterator Const_iterator
Definition: multi_map_base.h:125
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
required string key
Definition: replication_asynchronous_connection_failover.proto:59