MySQL 8.3.0
Source Code Documentation
map_helpers.h File Reference
#include <map>
#include <memory>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include "my_inttypes.h"
#include "mysql/strings/m_ctype.h"
#include "sql/malloc_allocator.h"
#include "sql/mem_root_allocator.h"
#include "template_utils.h"

Go to the source code of this file.

Classes

struct  My_free_deleter
 
struct  Free_deleter
 
class  Collation_hasher
 A Hasher that hashes std::strings according to a MySQL collation. More...
 
class  Collation_key_equal
 A KeyEqual that compares std::strings according to a MySQL collation. More...
 
class  malloc_unordered_map< Key, Value, Hash, KeyEqual >
 std::unordered_map, but with my_malloc, so that you can track the memory used using PSI memory keys. More...
 
class  malloc_unordered_set< Key, Hash, KeyEqual >
 std::unordered_set, but with my_malloc, so that you can track the memory used using PSI memory keys. More...
 
class  malloc_unordered_multimap< Key, Value, Hash, KeyEqual >
 std::unordered_multimap, but with my_malloc, so that you can track the memory used using PSI memory keys. More...
 
class  collation_unordered_map< Key, Value >
 std::unordered_map, but with my_malloc and collation-aware comparison. More...
 
class  collation_unordered_multimap< Key, Value >
 std::unordered_multimap, but with my_malloc and collation-aware comparison. More...
 
class  collation_unordered_set< Key >
 std::unordered_set, but with my_malloc and collation-aware comparison. More...
 
class  mem_root_unordered_set< Key, Hash, KeyEqual >
 std::unordered_set, but allocated on a MEM_ROOT. More...
 
class  mem_root_unordered_map< Key, Value, Hash, KeyEqual >
 std::unordered_map, but allocated on a MEM_ROOT. More...
 
class  mem_root_unordered_multimap< Key, Value, Hash, KeyEqual >
 std::unordered_multimap, but allocated on a MEM_ROOT. More...
 
class  mem_root_collation_unordered_map< Key, Value >
 std::unordered_map, but collation aware and allocated on a MEM_ROOT. More...
 

Typedefs

template<class T >
using unique_ptr_with_deleter = std::unique_ptr< T, void(*)(T *)>
 std::unique_ptr, but with a custom delete function. More...
 
template<class T >
using unique_ptr_my_free = std::unique_ptr< T, My_free_deleter >
 std::unique_ptr, but with my_free as deleter. More...
 
template<class T >
using unique_ptr_free = std::unique_ptr< T, Free_deleter >
 std::unique_ptr, but with free as deleter. More...
 
template<class Key , class Value >
using Map_allocator_type = Malloc_allocator< std::pair< const Key, Value > >
 Allocator type used in Map_myalloc. More...
 
template<class Key , class Value , class Compare = std::less<Key>>
using Map_myalloc = std::map< Key, Value, Compare, Map_allocator_type< Key, Value > >
 Map using custom Malloc_allocator allocator. More...
 

Functions

template<class Container , class Key >
static auto find_or_nullptr (const Container &container, const Key &key)
 Some useful helpers for associative arrays with MySQL-specific semantics. More...
 
template<class Container , class Value >
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 and value. More...
 

Typedef Documentation

◆ Map_allocator_type

template<class Key , class Value >
using Map_allocator_type = Malloc_allocator<std::pair<const Key, Value> >

Allocator type used in Map_myalloc.

◆ Map_myalloc

template<class Key , class Value , class Compare = std::less<Key>>
using Map_myalloc = std::map<Key, Value, Compare, Map_allocator_type<Key, Value> >

Map using custom Malloc_allocator allocator.

◆ unique_ptr_free

template<class T >
using unique_ptr_free = std::unique_ptr<T, Free_deleter>

std::unique_ptr, but with free as deleter.

◆ unique_ptr_my_free

template<class T >
using unique_ptr_my_free = std::unique_ptr<T, My_free_deleter>

std::unique_ptr, but with my_free as deleter.

◆ unique_ptr_with_deleter

template<class T >
using unique_ptr_with_deleter = std::unique_ptr<T, void (*)(T *)>

std::unique_ptr, but with a custom delete function.

Normally, it is more efficient to have a deleter class instead, but this allows you to have a unique_ptr to a forward-declared class, so it keeps include dependencies down somewhat.

Function Documentation

◆ erase_specific_element()

template<class Container , class Value >
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 and value.

◆ find_or_nullptr()

template<class Container , class Key >
static auto find_or_nullptr ( const Container &  container,
const Key &  key 
)
inlinestatic

Some useful helpers for associative arrays with MySQL-specific semantics.

For unordered_map<Key, T*> or unordered_map<Key, unique_ptr<T>>, does find() and returns nullptr if the element was not found.

It is not possible to distinguish between "not found" and "found, but contained nullptr" in this case. Thus, you should normally prefer checking against container.end() yourself.