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, emplace

Always

erase

Only the element removed

swap

All iterators, no pointers/references

Warning

This container is similar to, but not a drop-in replacement for std::unordered_multimap due to differences in iterator invalidation and memory layout.

Template Parameters:
  • Key – The key type

  • Value – The mapped type to be associated with Key

  • Hasher – A functor to use as a hashing function for Key

  • Equals – A functor to use to compare two Key values for equality

  • LoadFactorMax100 – 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 mapped_type = Value#

The mapped value 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_type that proceeds to the next matching key when incremented.

using const_find_iterator = typename Base::const_find_iterator#

A LegacyForwardIterator to const value_type that proceeds to the next matching key when incremented.

using allocator_type = typename Base::allocator_type#

The Allocator.

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.

  • alAllocator 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.

  • alAllocator 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.

  • alAllocator to use for all memory allocations of this container.

inline explicit RHUnorderedMultimap(const allocator_type &al)#

Constructor with allocator.

Parameters:

alAllocator 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.

  • alAllocator 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.

  • alAllocator 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.

  • alAllocator 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.

  • alAllocator 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.

  • alAllocator 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.

  • alAllocator 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

*this may have a different capacity() than other.

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

*this may have a different capacity() than other.

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. other will be empty() 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 alloc is not equal to other.get_allocator(), then linear.

Note

No move constructors on contained elements are invoked. other will be empty() 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 iterator to 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 iterator to 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 iterator to 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_type constructor.

Returns:

an iterator to 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 K and Key type 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,
) const#

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 K and Key type 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.