23#ifndef MAP_HELPERS_INCLUDED
24#define MAP_HELPERS_INCLUDED
30#include <unordered_map>
31#include <unordered_set>
52template <
class Container,
class Key>
55 if constexpr (std::is_pointer_v<typename Container::mapped_type>) {
66template <
class Container,
class Value>
71 for (
auto it = it_range.first; it != it_range.second; ++it) {
72 if constexpr (std::is_pointer_v<typename Container::mapped_type>) {
73 if (it->second == value)
return container->erase(it);
76 if (it->second.get() == value)
return container->erase(it);
114 hash_sort(
cs, pointer_cast<const uchar *>(s.data()), s.size(), &nr1, &nr2);
129 size_t operator()(
const std::string &a,
const std::string &b)
const {
130 return strnncollsp(
cs, pointer_cast<const uchar *>(a.data()), a.size(),
131 pointer_cast<const uchar *>(b.data()), b.size()) == 0;
143template <
class Key,
class Value,
class Hash = std::hash<Key>,
144 class KeyEqual = std::equal_to<Key>>
147 Malloc_allocator<std::pair<const Key, Value>>> {
156 10,
Hash(), KeyEqual(),
164template <
class Key,
class Hash = std::hash<Key>,
165 class KeyEqual = std::equal_to<Key>>
175 10,
Hash(), KeyEqual(),
183template <
class Key,
class Value,
class Hash = std::hash<Key>,
184 class KeyEqual = std::equal_to<Key>>
186 :
public std::unordered_multimap<
187 Key, Value, Hash, KeyEqual,
188 Malloc_allocator<std::pair<const Key, Value>>> {
198 10,
Hash(), KeyEqual(),
205template <
class Key,
class Value>
209 Malloc_allocator<std::pair<const Key, Value>>> {
221template <
class Key,
class Value>
223 :
public std::unordered_multimap<
224 Key, Value, Collation_hasher, Collation_key_equal,
225 Malloc_allocator<std::pair<const Key, Value>>> {
241 Malloc_allocator<Key>> {
257template <
class Key,
class Hash = std::hash<Key>,
258 class KeyEqual = std::equal_to<Key>>
267 KeyEqual key_equal_arg = KeyEqual())
269 10, hash, key_equal_arg,
276template <
class Key,
class Value,
class Hash = std::hash<Key>,
277 class KeyEqual = std::equal_to<Key>>
280 Key, Value, Hash, KeyEqual,
281 Mem_root_allocator<std::pair<const Key, Value>>> {
286 10, hash, KeyEqual(),
293template <
class Key,
class Value,
class Hash = std::hash<Key>,
294 class KeyEqual = std::equal_to<Key>>
296 :
public std::unordered_multimap<
297 Key, Value, Hash, KeyEqual,
298 Mem_root_allocator<std::pair<const Key, Value>>> {
301 :
std::unordered_multimap<
304 10, hash, KeyEqual(),
311template <
class Key,
class Value>
314 Key, Value, Collation_hasher, Collation_key_equal,
315 Mem_root_allocator<std::pair<const Key, Value>>> {
A Hasher that hashes std::strings according to a MySQL collation.
Definition: map_helpers.h:107
decltype(cs->coll->hash_sort) hash_sort
Definition: map_helpers.h:120
Collation_hasher(const CHARSET_INFO *cs_arg)
Definition: map_helpers.h:109
const CHARSET_INFO * cs
Definition: map_helpers.h:119
size_t operator()(const std::string &s) const
Definition: map_helpers.h:112
A KeyEqual that compares std::strings according to a MySQL collation.
Definition: map_helpers.h:124
decltype(cs->coll->strnncollsp) strnncollsp
Definition: map_helpers.h:136
Collation_key_equal(const CHARSET_INFO *cs_arg)
Definition: map_helpers.h:126
size_t operator()(const std::string &a, const std::string &b) const
Definition: map_helpers.h:129
const CHARSET_INFO * cs
Definition: map_helpers.h:135
Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
Definition: malloc_allocator.h:62
Mem_root_allocator is a C++ STL memory allocator based on MEM_ROOT.
Definition: mem_root_allocator.h:67
a nullable SQL value.
Definition: sql_value.h:39
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:209
collation_unordered_map(const CHARSET_INFO *cs, PSI_memory_key psi_key)
Definition: map_helpers.h:211
std::unordered_multimap, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:225
collation_unordered_multimap(CHARSET_INFO *cs, PSI_memory_key psi_key)
Definition: map_helpers.h:227
std::unordered_set, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:241
collation_unordered_set(std::initializer_list< Key > il, CHARSET_INFO *cs, PSI_memory_key psi_key)
Definition: map_helpers.h:248
collation_unordered_set(CHARSET_INFO *cs, PSI_memory_key psi_key)
Definition: map_helpers.h:243
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys.
Definition: map_helpers.h:147
malloc_unordered_map(PSI_memory_key psi_key)
Definition: map_helpers.h:153
std::unordered_multimap, but with my_malloc, so that you can track the memory used using PSI memory k...
Definition: map_helpers.h:188
malloc_unordered_multimap(PSI_memory_key psi_key)
Definition: map_helpers.h:195
std::unordered_set, but with my_malloc, so that you can track the memory used using PSI memory keys.
Definition: map_helpers.h:167
malloc_unordered_set(PSI_memory_key psi_key)
Definition: map_helpers.h:173
std::unordered_map, but collation aware and allocated on a MEM_ROOT.
Definition: map_helpers.h:315
mem_root_collation_unordered_map(const CHARSET_INFO *cs, MEM_ROOT *mem_root)
Definition: map_helpers.h:317
std::unordered_map, but allocated on a MEM_ROOT.
Definition: map_helpers.h:281
mem_root_unordered_map(MEM_ROOT *mem_root, Hash hash=Hash())
Definition: map_helpers.h:283
std::unordered_multimap, but allocated on a MEM_ROOT.
Definition: map_helpers.h:298
mem_root_unordered_multimap(MEM_ROOT *mem_root, Hash hash=Hash())
Definition: map_helpers.h:300
std::unordered_set, but allocated on a MEM_ROOT.
Definition: map_helpers.h:260
mem_root_unordered_set(MEM_ROOT *mem_root, Hash hash=Hash(), KeyEqual key_equal_arg=KeyEqual())
Definition: map_helpers.h:266
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:48
#define free(A)
Definition: lexyy.cc:915
A better implementation of the UNIX ctype(3) library.
Container::iterator erase_specific_element(Container *container, const typename Container::key_type &key, const Value &value)
For unordered_multimap<Key, Value>, erase the first specific element that matches both the given key ...
Definition: map_helpers.h:67
std::unique_ptr< T, Free_deleter > unique_ptr_free
std::unique_ptr, but with free as deleter.
Definition: map_helpers.h:104
std::unique_ptr< T, My_free_deleter > unique_ptr_my_free
std::unique_ptr, but with my_free as deleter.
Definition: map_helpers.h:96
std::unique_ptr< T, void(*)(T *)> unique_ptr_with_deleter
std::unique_ptr, but with a custom delete function.
Definition: map_helpers.h:88
static auto find_or_nullptr(const Container &container, const Key &key)
Some useful helpers for associative arrays with MySQL-specific semantics.
Definition: map_helpers.h:53
Some integer typedefs for easier portability.
uint64_t uint64
Definition: my_inttypes.h:68
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:80
int key_type
Definition: http_request.h:49
std::unordered_map< Key, CHARSET_INFO * > Hash
Definition: collations_internal.cc:547
Definition: atomics_array.h:38
Definition: commit_order_queue.h:33
std::string_view Key
The key type for the hash structure in HashJoinRowBuffer.
Definition: hash_join_buffer.h:107
Definition: varlen_sort.h:183
std::unordered_map< Key, Value, Hash, Key_equal, ut::allocator< std::pair< const Key, Value > > > unordered_map
Definition: ut0new.h:2897
std::unordered_set< Key, std::hash< Key >, std::equal_to< Key >, ut::allocator< Key > > unordered_set
Definition: ut0new.h:2886
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2437
required string key
Definition: replication_asynchronous_connection_failover.proto:59
Definition: m_ctype.h:422
Definition: map_helpers.h:98
void operator()(void *ptr) const
Definition: map_helpers.h:99
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: map_helpers.h:90
void operator()(void *ptr) const
Definition: map_helpers.h:91