RHUnorderedMultimap#
Fully qualified name: carb::container::RHUnorderedMultimap
Defined in carb/container/RHUnorderedMultimap.h
-
template<typename Key, typename Value, typename Hasher = std::hash<Key>, typename Equals = std::equal_to<Key>, size_t LoadFactorMax100 = kDefaultLoadFactor, typename Allocator = std::allocator<std::pair<const Key, Value>>>
class RHUnorderedMultimap : public detail::RobinHood<detail::RobinHoodMapTraits<Key, Value, std::hash<Key>, std::equal_to<Key>, std::allocator<std::pair<const Key, Value>>, kDefaultLoadFactor>># Implements an Unordered Multimap, that is: a container that contains a mapping of keys to values where keys may be inserted multiple times, each creating a new element.
There is no defined order to the set of keys.
Iterator/reference/pointer invalidation (note differences from
std::unordered_multimap):Operation
Invalidates
All read operations
Never
clear,rehash,reserve,operator=,insert,emplaceAlways
eraseOnly the element removed
swapAll iterators, no pointers/references
Warning
This container is similar to, but not a drop-in replacement for
std::unordered_multimapdue to differences in iterator invalidation and memory layout.- Template Parameters:
Key – The key type
Value – The mapped type to be associated with
KeyHasher – A functor to use as a hashing function for
KeyEquals – A functor to use to compare two
Keyvalues for equalityLoadFactorMax100 – The load factor to use for the table. This value must be in the range
[10, 100]and represents the percentage of entries in the hash table that will be filled before resizing. Open-addressing hash maps with 100% usage have better memory usage but worse performance since they need “gaps” in the hash table to terminate runs. The default value is kDefaultLoadFactor.Allocator – The Allocator to use. Must support rebind.
Public Types
-
using key_type = typename Base::key_type#
The key type.
-
using value_type = typename Base::value_type#
The value type (effectively
std::pair<const key_type, mapped_type>)
-
using size_type = typename Base::size_type#
Unsigned integer type (typically
size_t)
-
using difference_type = typename Base::difference_type#
Signed integer type (typically
ptrdiff_t)
-
using hasher = typename Base::hasher#
The hash function.
-
using key_equal = typename Base::key_equal#
The key-equals function.
-
using reference = typename Base::reference#
value_type&
-
using const_reference = typename Base::const_reference#
const value_type&
-
using pointer = typename Base::pointer#
value_type*
-
using const_pointer = typename Base::const_pointer#
const value_type*
-
using iterator = typename Base::iterator#
A LegacyForwardIterator to
value_type.
-
using const_iterator = typename Base::const_iterator#
A LegacyForwardIterator to
const value_type
-
using find_iterator = typename Base::find_iterator#
A LegacyForwardIterator to
value_typethat proceeds to the next matching key when incremented.
-
using const_find_iterator = typename Base::const_find_iterator#
A LegacyForwardIterator to
const value_typethat proceeds to the next matching key when incremented.
Public Functions
-
constexpr RHUnorderedMultimap() noexcept = default#
Constructs empty container.
- inline explicit RHUnorderedMultimap(
- size_type reserved,
- const hasher &h = hasher(),
- const key_equal &ke = key_equal(),
- const allocator_type &al = allocator_type(),
Constructor with reservation hint.
- Parameters:
reserved – Minimal number of slots to reserve on initialization.
h – Hash function to use.
ke – Comparison function to use for all key comparisons of this container.
al – Allocator to use for all memory allocations of this container.
- inline RHUnorderedMultimap(
- size_type reserved,
- const allocator_type &al,
Constructor with reservation hint and allocator.
- Parameters:
reserved – Minimal number of slots to reserve on initialization.
al – Allocator to use for all memory allocations of this container.
- inline RHUnorderedMultimap(
- size_type reserved,
- const hasher &h,
- const allocator_type &al,
Constructor with reservation hint, hash function and allocator.
- Parameters:
reserved – Minimal number of slots to reserve on initialization.
h – Hash function to use.
al – Allocator to use for all memory allocations of this container.
-
inline explicit RHUnorderedMultimap(const allocator_type &al)#
Constructor with allocator.
- Parameters:
al – Allocator to use for all memory allocations of this container.
-
template<class InputIt>
inline RHUnorderedMultimap( - InputIt first,
- InputIt last,
- size_type reserved = 0,
- const hasher &h = hasher(),
- const key_equal &ke = key_equal(),
- const allocator_type &al = allocator_type(),
Constructs the container with the contents of range [first, last).
- Parameters:
first – The first iterator defining the source range of elements to copy.
last – The last iterator defining the source range of elements to copy.
reserved – A hint to the minimal number of slots to reserve.
h – Hash function to use.
ke – Comparison function to use for all key comparisons of this container.
al – Allocator to use for all memory allocations of this container.
-
template<class InputIt>
inline RHUnorderedMultimap( - InputIt first,
- InputIt last,
- size_type reserved,
- const allocator_type &al,
Constructs the container with the contents of range [first, last).
- Parameters:
first – The first iterator defining the source range of elements to copy.
last – The last iterator defining the source range of elements to copy.
reserved – A hint to the minimal number of slots to reserve.
al – Allocator to use for all memory allocations of this container.
-
template<class InputIt>
inline RHUnorderedMultimap( - InputIt first,
- InputIt last,
- size_type reserved,
- const hasher &h,
- const allocator_type &al,
Constructs the container with the contents of range [first, last).
- Parameters:
first – The first iterator defining the source range of elements to copy.
last – The last iterator defining the source range of elements to copy.
reserved – A hint to the minimal number of slots to reserve.
h – Hash function to use.
al – Allocator to use for all memory allocations of this container.
- inline RHUnorderedMultimap(
- std::initializer_list<value_type> init,
- size_type reserved = 0,
- const hasher &h = hasher(),
- const key_equal &ke = key_equal(),
- const allocator_type &al = allocator_type(),
Constructs the container with the contents of items from an initializer_list.
- Parameters:
init – initializer list to initialize the elements of the container with.
reserved – A hint to the minimal number of slots to reserve. If not specified,
init.size()is used.h – Hash function to use.
ke – Comparison function to use for all key comparisons of this container.
al – Allocator to use for all memory allocations of this container.
- inline RHUnorderedMultimap(
- std::initializer_list<value_type> init,
- size_type reserved,
- const allocator_type &al,
Constructs the container with the contents of items from an initializer_list.
- Parameters:
init – initializer list to initialize the elements of the container with.
reserved – A hint to the minimal number of slots to reserve.
al – Allocator to use for all memory allocations of this container.
- inline RHUnorderedMultimap(
- std::initializer_list<value_type> init,
- size_type reserved,
- const hasher &h,
- const allocator_type &al,
Constructs the container with the contents of items from an initializer_list.
- Parameters:
init – initializer list to initialize the elements of the container with.
reserved – A hint to the minimal number of slots to reserve.
h – Hash function to use.
al – Allocator to use for all memory allocations of this container.
-
inline RHUnorderedMultimap(const RHUnorderedMultimap &other)#
Copy constructor.
Copies elements from another container.
- Complexity
Linear in size of
other.
Note
*thismay have a differentcapacity()thanother.- Parameters:
other – The other container to copy entries from.
- inline RHUnorderedMultimap(
- const RHUnorderedMultimap &other,
- const Allocator &alloc,
Copy constructor.
Copies elements from another container.
- Complexity
Linear in size of
other.
Note
*thismay have a differentcapacity()thanother.- Parameters:
other – The other container to copy entries from.
alloc – The allocator to use for all memory allocations of this container.
-
inline RHUnorderedMultimap(RHUnorderedMultimap &&other)#
Move constructor.
Moves elements from another container.
- Complexity
Constant.
Note
No move constructors on contained elements are invoked.
otherwill beempty()after this operation.- Parameters:
other – The other container to move entries from.
- inline RHUnorderedMultimap(
- RHUnorderedMultimap &&other,
- const Allocator &alloc,
Move constructor.
Moves elements from another container.
- Complexity
Constant. If
allocis not equal toother.get_allocator(), then linear.
Note
No move constructors on contained elements are invoked.
otherwill beempty()after this operation.- Parameters:
other – The other container to move entries from.
alloc – The Allocator to use for all memory allocations of this container.
-
~RHUnorderedMultimap() = default#
Destructor.
Destroys all contained elements and frees memory.
- inline RHUnorderedMultimap &operator=(
- const RHUnorderedMultimap &other,
Copy-assign operator.
Destroys all currently stored elements and copies elements from another container.
- Parameters:
other – The other container to copy entries from.
- Returns:
*this
-
inline RHUnorderedMultimap &operator=(RHUnorderedMultimap &&other)#
Move-assign operator.
Effectively swaps with another container.
- Parameters:
other – The other container to copy entries from.
- Returns:
*this
-
inline iterator insert(const value_type &value)#
Inserts an element into the container.
All iterators, references and pointers are invalidated.
- Parameters:
value – The value to insert by copying.
- Returns:
an
iteratorto the inserted element.
-
inline iterator insert(value_type &&value)#
Inserts an element into the container.
All iterators, references and pointers are invalidated.
- Parameters:
value – The value to insert by moving.
- Returns:
an
iteratorto the inserted element.
-
template<typename P>
inline iterator insert( - std::enable_if_t<std::is_constructible<value_type, P&&>::value, P&&> value,
Inserts an element into the container.
Only participates in overload resolution if
std::is_constructible_v<value_type, P&&>is true.All iterators, references and pointers are invalidated.
- Parameters:
value – The value to insert by constructing via
std::forward<P>(value).- Returns:
an
iteratorto the inserted element.
-
template<typename ...Args>
inline iterator emplace(Args&&... args)# Constructs an element in-place.
All iterators, references and pointers are invalidated.
- Parameters:
args – The arguments to pass to the
value_typeconstructor.- Returns:
an
iteratorto the inserted element.
-
inline size_type erase(const key_type &key)#
Removes elements with the given key.
References, pointers and iterators to the erased elements are invalidated. All other iterators, pointers and references remain valid.
- Parameters:
key – the key value of elements to remove
- Returns:
the number of elements removed.
-
template<typename K, typename = std::enable_if_t<IsTransparent_v<K> && !std::is_convertible_v<K, const_iterator> && !std::is_convertible_v<K, const_find_iterator>>>
inline size_type erase( - K &&key,
Removes all elements with key that compares equivalent to the given key.
References, pointers and iterators to the erased elements are invalidated. All other iterators, pointers and references remain valid.
Note
This overload participates in overload resolution only if Hash and KeyEqual are both transparent. This assumes that such Hash is callable with both
KandKeytype and that KeyEqual is transparent, which, together, allows calling this function without constructing an instance of Key.- Parameters:
key – A value of any type that can be transparently compared with a key denoting the elements to remove.
- Returns:
the number of elements removed.
-
inline size_type count(const key_type &key) const#
Returns the number of elements matching the specified key.
- Parameters:
key – The key to check for.
- Returns:
The number of elements with the given key.
-
template<typename K, typename = std::enable_if_t<IsTransparent_v<K>>>
inline size_type count( - const K &key,
Returns the number of elements matching the specified key.
Note
This overload participates in overload resolution only if Hash and KeyEqual are both transparent. This assumes that such Hash is callable with both
KandKeytype and that KeyEqual is transparent, which, together, allows calling this function without constructing an instance of Key.- Parameters:
key – A value of any type that can be transparently compared with a key
- Returns:
The number of elements with key that compares equivalent to
key
Public Static Attributes
-
static constexpr size_t LoadFactor = Base::LoadFactor#
The container’s LoadFactor.