24#ifndef MAP_HELPERS_INCLUDED
25#define MAP_HELPERS_INCLUDED
31#include <unordered_map>
32#include <unordered_set>
53template <
class Container,
class Key>
56 if constexpr (std::is_pointer_v<typename Container::mapped_type>) {
67template <
class Container,
class Value>
72 for (
auto it = it_range.first; it != it_range.second; ++it) {
73 if constexpr (std::is_pointer_v<typename Container::mapped_type>) {
74 if (it->second == value)
return container->erase(it);
77 if (it->second.get() == value)
return container->erase(it);
115 hash_sort(
cs, pointer_cast<const uchar *>(s.data()), s.size(), &nr1, &nr2);
130 size_t operator()(
const std::string &a,
const std::string &b)
const {
131 return strnncollsp(
cs, pointer_cast<const uchar *>(a.data()), a.size(),
132 pointer_cast<const uchar *>(b.data()), b.size()) == 0;
144template <
class Key,
class Value,
class Hash = std::hash<Key>,
145 class KeyEqual = std::equal_to<Key>>
148 Malloc_allocator<std::pair<const Key, Value>>> {
157 10, Hash(), KeyEqual(),
165template <
class Key,
class Hash = std::hash<Key>,
166 class KeyEqual = std::equal_to<Key>>
176 10, Hash(), KeyEqual(),
184template <
class Key,
class Value,
class Hash = std::hash<Key>,
185 class KeyEqual = std::equal_to<Key>>
187 :
public std::unordered_multimap<
188 Key, Value, Hash, KeyEqual,
189 Malloc_allocator<std::pair<const Key, Value>>> {
197 :
std::unordered_multimap<
Key,
Value, Hash, KeyEqual,
199 10, Hash(), KeyEqual(),
206template <
class Key,
class Value>
210 Malloc_allocator<std::pair<const Key, Value>>> {
222template <
class Key,
class Value>
224 :
public std::unordered_multimap<
225 Key, Value, Collation_hasher, Collation_key_equal,
226 Malloc_allocator<std::pair<const Key, Value>>> {
242 Malloc_allocator<Key>> {
258template <
class Key,
class Hash = std::hash<Key>,
259 class KeyEqual = std::equal_to<Key>>
268 KeyEqual key_equal_arg = KeyEqual())
270 10, hash, key_equal_arg,
277template <
class Key,
class Value,
class Hash = std::hash<Key>,
278 class KeyEqual = std::equal_to<Key>>
281 Key, Value, Hash, KeyEqual,
282 Mem_root_allocator<std::pair<const Key, Value>>> {
287 10, hash, KeyEqual(),
294template <
class Key,
class Value,
class Hash = std::hash<Key>,
295 class KeyEqual = std::equal_to<Key>>
297 :
public std::unordered_multimap<
298 Key, Value, Hash, KeyEqual,
299 Mem_root_allocator<std::pair<const Key, Value>>> {
302 :
std::unordered_multimap<
305 10, hash, KeyEqual(),
312template <
class Key,
class Value>
315 Key, Value, Collation_hasher, Collation_key_equal,
316 Mem_root_allocator<std::pair<const Key, Value>>> {
A Hasher that hashes std::strings according to a MySQL collation.
Definition: map_helpers.h:108
decltype(cs->coll->hash_sort) hash_sort
Definition: map_helpers.h:121
Collation_hasher(const CHARSET_INFO *cs_arg)
Definition: map_helpers.h:110
const CHARSET_INFO * cs
Definition: map_helpers.h:120
size_t operator()(const std::string &s) const
Definition: map_helpers.h:113
A KeyEqual that compares std::strings according to a MySQL collation.
Definition: map_helpers.h:125
decltype(cs->coll->strnncollsp) strnncollsp
Definition: map_helpers.h:137
Collation_key_equal(const CHARSET_INFO *cs_arg)
Definition: map_helpers.h:127
size_t operator()(const std::string &a, const std::string &b) const
Definition: map_helpers.h:130
const CHARSET_INFO * cs
Definition: map_helpers.h:136
Malloc_allocator is a C++ STL memory allocator based on my_malloc/my_free.
Definition: malloc_allocator.h:63
Mem_root_allocator is a C++ STL memory allocator based on MEM_ROOT.
Definition: mem_root_allocator.h:68
a nullable SQL value.
Definition: sql_value.h:40
std::unordered_map, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:210
collation_unordered_map(const CHARSET_INFO *cs, PSI_memory_key psi_key)
Definition: map_helpers.h:212
std::unordered_multimap, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:226
collation_unordered_multimap(CHARSET_INFO *cs, PSI_memory_key psi_key)
Definition: map_helpers.h:228
std::unordered_set, but with my_malloc and collation-aware comparison.
Definition: map_helpers.h:242
collation_unordered_set(std::initializer_list< Key > il, CHARSET_INFO *cs, PSI_memory_key psi_key)
Definition: map_helpers.h:249
collation_unordered_set(CHARSET_INFO *cs, PSI_memory_key psi_key)
Definition: map_helpers.h:244
std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys.
Definition: map_helpers.h:148
malloc_unordered_map(PSI_memory_key psi_key)
Definition: map_helpers.h:154
std::unordered_multimap, but with my_malloc, so that you can track the memory used using PSI memory k...
Definition: map_helpers.h:189
malloc_unordered_multimap(PSI_memory_key psi_key)
Definition: map_helpers.h:196
std::unordered_set, but with my_malloc, so that you can track the memory used using PSI memory keys.
Definition: map_helpers.h:168
malloc_unordered_set(PSI_memory_key psi_key)
Definition: map_helpers.h:174
std::unordered_map, but collation aware and allocated on a MEM_ROOT.
Definition: map_helpers.h:316
mem_root_collation_unordered_map(const CHARSET_INFO *cs, MEM_ROOT *mem_root)
Definition: map_helpers.h:318
std::unordered_map, but allocated on a MEM_ROOT.
Definition: map_helpers.h:282
mem_root_unordered_map(MEM_ROOT *mem_root, Hash hash=Hash())
Definition: map_helpers.h:284
std::unordered_multimap, but allocated on a MEM_ROOT.
Definition: map_helpers.h:299
mem_root_unordered_multimap(MEM_ROOT *mem_root, Hash hash=Hash())
Definition: map_helpers.h:301
std::unordered_set, but allocated on a MEM_ROOT.
Definition: map_helpers.h:261
mem_root_unordered_set(MEM_ROOT *mem_root, Hash hash=Hash(), KeyEqual key_equal_arg=KeyEqual())
Definition: map_helpers.h:267
static MEM_ROOT mem_root
Definition: client_plugin.cc:110
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
#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:68
std::unique_ptr< T, Free_deleter > unique_ptr_free
std::unique_ptr, but with free as deleter.
Definition: map_helpers.h:105
std::unique_ptr< T, My_free_deleter > unique_ptr_my_free
std::unique_ptr, but with my_free as deleter.
Definition: map_helpers.h:97
std::unique_ptr< T, void(*)(T *)> unique_ptr_with_deleter
std::unique_ptr, but with a custom delete function.
Definition: map_helpers.h:89
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:54
Some integer typedefs for easier portability.
uint64_t uint64
Definition: my_inttypes.h:69
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
int key_type
Definition: http_request.h:50
Definition: atomics_array.h:39
Definition: commit_order_queue.h:34
std::string_view Key
The key type for the hash structure in HashJoinRowBuffer.
Definition: hash_join_buffer.h:102
Definition: gcs_xcom_synode.h:64
std::unordered_map< Key, Value, Hash, Key_equal, ut::allocator< std::pair< const Key, Value > > > unordered_map
Definition: ut0new.h:2899
std::unordered_set< Key, std::hash< Key >, std::equal_to< Key >, ut::allocator< Key > > unordered_set
Definition: ut0new.h:2888
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:2439
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Definition: m_ctype.h:385
Definition: map_helpers.h:99
void operator()(void *ptr) const
Definition: map_helpers.h:100
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: map_helpers.h:91
void operator()(void *ptr) const
Definition: map_helpers.h:92