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