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