sfl::smallunorderedmultimap

March 1, 2026 ยท View on GitHub

Table of Contents

Summary

Defined in header sfl/small_unordered_multimap.hpp:

namespace sfl
{
    template < typename Key,
               typename T,
               std::size_t StaticCapacity,
               std::size_t StaticBucketCount = /* see description below */,
               typename Hash = sfl::hash<Key>,
               typename KeyEqual = std::equal_to<Key>,
               typename Allocator = std::allocator<std::pair<const Key, T>> >
    class small_unordered_multimap;
}

sfl::small_unordered_multimap is an associative container similar to std::unordered_multimap, but it internally holds a small amount of statically allocated memory to avoid dynamic memory management when the number of stored elements is small. Dynamic memory management is used when the number of elements exceeds StaticCapacity, or when the number of buckets exceeds StaticBucketCount. This design provides a compact and cache-friendly representation optimized for small sizes.

The underlying storage is implemented as a hash table with separate chaining.

The complexity of search, insert, and erase operations is O(1) on average.

References and pointers to elements are stable: insert and erase operations do not invalidate them unless the referenced element is erased.

Iterators to elements are forward iterators, and they meet the requirements of LegacyForwardIterator.

sfl::small_unordered_multimap meets the requirements of Container, AllocatorAwareContainer, and UnorderedAssociativeContainer.



Template Parameters

  1. typename Key
    

    Key type.

  2. typename T
    

    Value type.

  3. std::size_t StaticCapacity
    

    Size of the internal statically allocated array used for elements.

    This parameters can be zero.

  4. std::size_t StaticBucketCount
    

    Size of the internal statically allocated array used for buckets.

    Default value of this parameter is StaticCapacity rounded up to the nearest power of two.

    This parameters can be zero.

  5. typename Hash
    

    Hash function for keys.

  6. typename KeyEqual
    

    Comparison function for keys.

  7. typename Allocator
    

    Allocator used for memory allocation/deallocation and construction/destruction of elements.

    This type must meet the requirements of Allocator.

    The program is ill-formed if Allocator::value_type is not the same as std::pair<const Key, T>.



Public Member Types

Member TypeDefinition
allocator_typeAllocator
key_typeKey
mapped_typeT
value_typestd::pair<const Key, T>
size_typeUnsigned integer type
difference_typeSigned integer type
hasherHash
key_equalKeyEqual
referencevalue_type&
const_referenceconst value_type&
pointerPointer to value_type
const_pointerPointer to const value_type
iteratorLegacyForwardIterator to value_type
const_iteratorLegacyForwardIterator to const value_type
local_iteratorLegacyForwardIterator to value_type. This iterator can be used to iterate through a single bucket but not across buckets.
const_local_iteratorLegacyForwardIterator to const value_type. This iterator can be used to iterate through a single bucket but not across buckets



Public Data Members

static_capacity

  1. static constexpr size_type static_capacity = StaticCapacity;
    



static_bucket_count

  1. static constexpr size_type static_bucket_count = StaticBucketCount;
    



Public Member Functions

(constructor)

  1. small_unordered_multimap();
    
  2. explicit
    small_unordered_multimap(const Allocator& alloc);
    
  3. explicit
    small_unordered_multimap(size_type bucket_count);
    
  4. small_unordered_multimap(size_type bucket_count, const Allocator& alloc);
    
  5. small_unordered_multimap(size_type bucket_count, const Hash& hash);
    
  6. small_unordered_multimap(size_type bucket_count, const Hash& hash, const Allocator& alloc);
    
  7. small_unordered_multimap(size_type bucket_count, const Hash& hash, const KeyEqual& equal);
    
  8. small_unordered_multimap(size_type bucket_count, const Hash& hash, const KeyEqual& equal, const Allocator& alloc);
    

    Effects: Constructs an empty container.

    Parameter bucket_count specifies minimal number of buckets to use on initialization. If it is not specified, an unspecified default value is used.

    Complexity: Constant.



  9. template <typename InputIt>
    small_unordered_multimap(InputIt first, InputIt last);
    
  10. template <typename InputIt>
    small_unordered_multimap(InputIt first, InputIt last, size_type bucket_count);
    
  11. template <typename InputIt>
    small_unordered_multimap(InputIt first, InputIt last, size_type bucket_count, const Allocator& alloc);
    
  12. template <typename InputIt>
    small_unordered_multimap(InputIt first, InputIt last, size_type bucket_count, const Hash& hash);
    
  13. template <typename InputIt>
    small_unordered_multimap(InputIt first, InputIt last, size_type bucket_count, const Hash& hash, const Allocator& alloc);
    
  14. template <typename InputIt>
    small_unordered_multimap(InputIt first, InputIt last, size_type bucket_count, const Hash& hash, const KeyEqual& equal);
    
  15. template <typename InputIt>
    small_unordered_multimap(InputIt first, InputIt last, size_type bucket_count, const Hash& hash, const KeyEqual& equal, const Allocator& alloc);
    

    Effects: Constructs the container with the contents of the range [first, last).

    Parameter bucket_count specifies minimal number of buckets to use on initialization. If it is not specified, an unspecified default value is used.

    Note: These overloads participate in overload resolution only if InputIt satisfies requirements of LegacyInputIterator.



  16. small_unordered_multimap(std::initializer_list<value_type> ilist);
    
  17. small_unordered_multimap(std::initializer_list<value_type> ilist, size_type bucket_count);
    
  18. small_unordered_multimap(std::initializer_list<value_type> ilist, size_type bucket_count, const Allocator& alloc);
    
  19. small_unordered_multimap(std::initializer_list<value_type> ilist, size_type bucket_count, const Hash& hash);
    
  20. small_unordered_multimap(std::initializer_list<value_type> ilist, size_type bucket_count, const Hash& hash, const Allocator& alloc);
    
  21. small_unordered_multimap(std::initializer_list<value_type> ilist, size_type bucket_count, const Hash& hash, const KeyEqual& equal);
    
  22. small_unordered_multimap(std::initializer_list<value_type> ilist, size_type bucket_count, const Hash& hash, const KeyEqual& equal, const Allocator& alloc);
    

    Effects: Constructs the container with the contents of the initializer list ilist.

    Parameter bucket_count specifies minimal number of buckets to use on initialization. If it is not specified, an unspecified default value is used.



  23. small_unordered_multimap(const small_unordered_multimap& other);
    
  24. small_unordered_multimap(const small_unordered_multimap& other, const Allocator& alloc);
    

    Effects: Copy constructor. Constructs the container with the copy of the contents of other.



  25. small_unordered_multimap(small_unordered_multimap&& other);
    
  26. small_unordered_multimap(small_unordered_multimap&& other, const Allocator& alloc);
    

    Effects: Move constructor. Constructs the container with the contents of other using move semantics.

    other is not guaranteed to be empty after the move.

    other is in a valid but unspecified state after the move.



  27. template <typename Range>
    small_unordered_multimap(sfl::from_range_t, Range&& range);
    
  28. template <typename Range>
    small_unordered_multimap(sfl::from_range_t, Range&& range, size_type bucket_count);
    
  29. template <typename Range>
    small_unordered_multimap(sfl::from_range_t, Range&& range, size_type bucket_count, const Allocator& alloc);
    
  30. template <typename Range>
    small_unordered_multimap(sfl::from_range_t, Range&& range, size_type bucket_count, const Hash& hash);
    
  31. template <typename Range>
    small_unordered_multimap(sfl::from_range_t, Range&& range, size_type bucket_count, const Hash& hash, const Allocator& alloc);
    
  32. template <typename Range>
    small_unordered_multimap(sfl::from_range_t, Range&& range, size_type bucket_count, const Hash& hash, const KeyEqual& equal);
    
  33. template <typename Range>
    small_unordered_multimap(sfl::from_range_t, Range&& range, size_type bucket_count, const Hash& hash, const KeyEqual& equal, const Allocator& alloc);
    

    Effects: Constructs the container with the contents of range.

    Parameter bucket_count specifies minimal number of buckets to use on initialization. If it is not specified, an unspecified default value is used.

    Note: These overloads are available in C++11. If compiled with C++20 or later, proper C++20 range concepts are used.



(destructor)

  1. ~small_unordered_multimap();
    

    Effects: Destructs the container. The destructors of the elements are called and the used storage is deallocated.

    Complexity: Linear in size().



operator=

  1. small_unordered_multimap& operator=(const small_unordered_multimap& other);
    

    Effects: Copy assignment operator. Replaces the contents with a copy of the contents of other.

    Returns: *this().



  2. small_unordered_multimap& operator=(small_unordered_multimap&& other);
    

    Effects: Move assignment operator. Replaces the contents with those of other using move semantics.

    other is not guaranteed to be empty after the move.

    other is in a valid but unspecified state after the move.

    Returns: *this().



  3. small_unordered_multimap& operator=(std::initializer_list<value_type> ilist);
    

    Effects: Replaces the contents with those identified by initializer list ilist.

    Returns: *this().



get_allocator

  1. allocator_type get_allocator() const noexcept;
    

    Effects: Returns the allocator associated with the container.

    Complexity: Constant.



hash_function

  1. hasher hash_function() const;
    

    Effects: Returns the function object that hashes the keys.

    Complexity: Constant.



key_eq

  1. key_equal key_eq() const;
    

    Effects: Returns a function object that compares keys for equality.

    Complexity: Constant.



begin, cbegin

  1. iterator begin() noexcept;
    
  2. const_iterator begin() const noexcept;
    
  3. const_iterator cbegin() const noexcept;
    

    Effects: Returns an iterator to the first element of the container. If the container is empty, the returned iterator will be equal to end().

    Complexity: Constant.



end, cend

  1. iterator end() noexcept;
    
  2. const_iterator end() const noexcept;
    
  3. const_iterator cend() const noexcept;
    

    Effects: Returns an iterator to the element following the last element of the container. This element acts as a placeholder; attempting to access it results in undefined behavior.

    Complexity: Constant.



empty

  1. bool empty() const noexcept;
    

    Effects: Returns true if the container has no elements, i.e. whether begin() == end().

    Complexity: Constant.



size

  1. size_type size() const noexcept;
    

    Effects: Returns the number of elements in the container, i.e. std::distance(begin(), end()).

    Complexity: Constant.



max_size

  1. size_type max_size() const noexcept;
    

    Effects: Returns the maximum number of elements the container is able to hold, i.e. std::distance(begin(), end()) for the largest container.

    Complexity: Constant.



clear

  1. void clear() noexcept;
    

    Effects: Erases all elements from the container. After this call, size() returns zero.

    Complexity: Linear in size().



emplace

  1. template <typename... Args>
    iterator emplace(Args&&... args);
    

    Effects: Inserts new element into the container.

    New element is constructed as value_type(std::forward<Args>(args)...).

    Returns: Iterator to the inserted element.



emplace_hint

  1. template <typename... Args>
    iterator emplace_hint(const_iterator hint, Args&&... args);
    

    Effects: Inserts new element into the container.

    New element is constructed as value_type(std::forward<Args>(args)...).

    Iterator hint is used as a suggestion where to start to search insert position.

    Returns: Iterator to the inserted element.



insert

  1. iterator insert(const value_type& value);
    

    Effects: Inserts copy of value.

    Returns: Iterator to the inserted element.



  2. iterator insert(value_type&& value);
    

    Effects: Inserts value using move semantics.

    Returns: Iterator to the inserted element.



  3. template <typename P>
    iterator insert(P&& value);
    

    Effects: Inserts new element into the container.

    New element is constructed as value_type(std::forward<P>(value)).

    Note: This overload participates in overload resolution only if std::is_constructible<value_type, P&&>::value is true.

    Returns: Iterator to the inserted element.



  4. iterator insert(const_iterator hint, const value_type& value);
    

    Effects: Inserts copy of value.

    Iterator hint is used as a suggestion where to start to search insert position.

    Returns: Iterator to the inserted element.



  5. iterator insert(const_iterator hint, value_type&& value);
    

    Effects: Inserts value using move semantics.

    Iterator hint is used as a suggestion where to start to search insert position.

    Returns: Iterator to the inserted element.



  6. template <typename P>
    iterator insert(const_iterator hint, P&& value);
    

    Effects: Inserts new element into the container.

    New element is constructed as value_type(std::forward<P>(value)).

    Iterator hint is used as a suggestion where to start to search insert position.

    Note: This overload participates in overload resolution only if std::is_constructible<value_type, P&&>::value is true.

    Returns: Iterator to the inserted element.



  7. template <typename InputIt>
    void insert(InputIt first, InputIt last);
    

    Effects: Inserts elements from range [first, last).

    The call to this function is equivalent to:

    while (first != last)
    {
        insert(*first);
        ++first;
    }
    

    Note: This overload participates in overload resolution only if InputIt satisfies requirements of LegacyInputIterator.



  8. void insert(std::initializer_list<value_type> ilist);
    

    Effects: Inserts elements from initializer list ilist.

    The call to this function is equivalent to insert(ilist.begin(), ilist.end()).



insert_range

  1. template <typename Range>
    void insert_range(Range&& range);
    

    Effects: Inserts elements from range.

    Note: This function is available in C++11. If compiled with C++20 or later, proper C++20 range concepts are used.



erase

  1. iterator erase(iterator pos);
    
  2. iterator erase(const_iterator pos);
    

    Effects: Removes the element at pos.

    Returns: Iterator following the last removed element.



  3. iterator erase(const_iterator first, const_iterator last);
    

    Effects: Removes the elements in the range [first, last).

    Returns: Iterator following the last removed element.



  4. size_type erase(const Key& key);
    
  5. template <typename K>
    size_type erase(K&& x);
    

    Effects: Removes all elements with the key equivalent to key or x.

    Note: Overload (5) participates in overload resolution only if both Hash::is_transparent and KeyEqual::is_transparent exist and are valid types. This allows the function to be called without constructing an instance of Key.

    Returns: Number of elements removed.



swap

  1. void swap(small_unordered_multimap& other);
    

    Effects: Exchanges the contents of the container with those of other.



equal_range

  1. std::pair<iterator, iterator> equal_range(const Key& key);
    
  2. std::pair<const_iterator, const_iterator> equal_range(const Key& key) const;
    
  3. template <typename K>
    std::pair<iterator, iterator> equal_range(const K& x);
    
  4. template <typename K>
    std::pair<const_iterator, const_iterator> equal_range(const K& x) const;
    

    Effects: Returns a range containing all elements with key that compares equivalent to key or x.

    • The first iterator in pair points to the first element of range. It is equal to end() if no such element is found.
    • The second iterator in pair points to the one-past-last element of range. It is equal to end() is no such element is found.

    Note: Overloads (3) and (4) participate in overload resolution only if both Hash::is_transparent and KeyEqual::is_transparent exist and are valid types. This allows these functions to be called without constructing an instance of Key.

    Complexity: Average case linear in number of elements with key that compares equivalent to key or x. Worst case linear in size().



find

  1. iterator find(const Key& key);
    
  2. const_iterator find(const Key& key) const;
    
  3. template <typename K>
    iterator find(const K& x);
    
  4. template <typename K>
    const_iterator find(const K& x) const;
    

    Effects: Returns an iterator pointing to the element with key equivalent to key or x. Returns end() if no such element is found. If there are several elements with key in the container, any of them may be returned.

    Note: Overloads (3) and (4) participate in overload resolution only if both Hash::is_transparent and KeyEqual::is_transparent exist and are valid types. This allows these functions to be called without constructing an instance of Key.

    Complexity: Constant on average. Worst case linear in size().



count

  1. size_type count(const Key& key) const;
    
  2. template <typename K>
    size_type count(const K& x) const;
    

    Effects: Returns the number of elements with key equivalent to key or x.

    Note: Overload (2) participates in overload resolution only if both Hash::is_transparent and KeyEqual::is_transparent exist and are valid types. This allows the function to be called without constructing an instance of Key.

    Complexity: Constant on average. Worst case linear in size().



contains

  1. bool contains(const Key& key) const;
    
  2. template <typename K>
    bool contains(const K& x) const;
    

    Effects: Returns true if the container contains an element with key equivalent to key or x, otherwise returns false.

    Note: Overload (2) participates in overload resolution only if both Hash::is_transparent and KeyEqual::is_transparent exist and are valid types. This allows the function to be called without constructing an instance of Key.

    Complexity: Constant on average. Worst case linear in size().



begin, cbegin (bucket interface)

  1. local_iterator begin(size_type n) noexcept;
    
  2. const_local_iterator begin(size_type n) const noexcept;
    
  3. const_local_iterator cbegin(size_type n) const noexcept;
    

    Effects: Returns an iterator to the first element of the bucket with index n.

    Complexity: Constant.



end, cend (bucket interface)

  1. local_iterator end(size_type n) noexcept;
    
  2. const_local_iterator end(size_type n) const noexcept;
    
  3. const_local_iterator cend(size_type n) const noexcept;
    

    Effects: Returns an iterator to the element following the last element of the bucket with index n. This element acts as a placeholder; attempting to access it results in undefined behavior.

    Complexity: Constant.



bucket_count

  1. size_type bucket_count() const;
    

    Effects: Returns the number of buckets in the container.

    Complexity: Constant.



max_bucket_count

  1. size_type max_bucket_count() const;
    

    Effects: Returns the maximum number of buckets the container is able to hold due to system or library implementation limitations.

    Complexity: Constant.



bucket_size

  1. size_type bucket_size(size_type n) const;
    

    Effects: Returns the number of elements in the bucket with index n.

    Complexity: Linear in the size of the bucket n.



bucket

  1. size_type bucket(const Key& key) const;
    
  2. template <typename K>
    size_type bucket(const K& x) const;
    

    Effects: Returns the index of the bucket for key equivalent to key or x.

    Note: Overload (2) participates in overload resolution only if both Hash::is_transparent and KeyEqual::is_transparent exist and are valid types. This allows the function to be called without constructing an instance of Key.

    Complexity: Constant.



load_factor

  1. float load_factor() const;
    

    Effects: Returns the average number of elements per bucket, that is, size() divided by bucket_count().

    Complexity: Constant.



max_load_factor

  1. float max_load_factor() const;
    

    Effects: Returns current maximum load factor.

    Complexity: Constant.



  2. void max_load_factor(float mlf);
    

    Effects: Sets the maximum load factor to mlf.

    Complexity: Constant.



rehash

  1. void rehash(size_type count);
    

    Effects: Changes the number of buckets to a value n that is not less than count and satisfies n >= size() / max_load_factor(), then rehashes the container, i.e. puts the elements into appropriate buckets considering that total number of buckets has changed.



reserve

  1. void reserve(size_type count);
    

    Effects: Sets the number of buckets to the number needed to accommodate at least count elements without exceeding maximum load factor and rehashes the container, i.e. puts the elements into appropriate buckets considering that total number of buckets has changed. Effectively calls rehash(std::ceil(count / max_load_factor())).



Non-member Functions

operator==

  1. template <typename K, typename T, std::size_t N, std::size_t M, typename H, typename E, typename A>
    bool operator==
    (
        const small_unordered_multimap<K, T, N, M, H, E, A>& x,
        const small_unordered_multimap<K, T, N, M, H, E, A>& y
    );
    

    Effects: Compares the contents of two containers.

    Returns: Returns true if the contents of the x and y are equal, false otherwise.



operator!=

  1. template <typename K, typename T, std::size_t N, std::size_t M, typename H, typename E, typename A>
    bool operator!=
    (
        const small_unordered_multimap<K, T, N, M, H, E, A>& x,
        const small_unordered_multimap<K, T, N, M, H, E, A>& y
    );
    

    Effects: Compares the contents of two containers.

    Returns: Returns true if the contents of the x and y are not equal, false otherwise.



swap

  1. template <typename K, typename T, std::size_t N, std::size_t M, typename H, typename E, typename A>
    void swap
    (
        small_unordered_multimap<K, T, N, M, H, E, A>& x,
        small_unordered_multimap<K, T, N, M, H, E, A>& y
    );
    

    Effects: Swaps the contents of x and y. Calls x.swap(y).



erase_if

  1. template <typename K, typename T, std::size_t N, std::size_t M, typename H, typename E, typename A, typename Predicate>
    typename small_unordered_multimap<K, T, N, M, H, E, A>::size_type
        erase_if(small_unordered_multimap<K, T, N, M, H, E, A>& c, Predicate pred);
    

    Effects: Erases all elements that satisfy the predicate pred from the container.

    pred is unary predicate which returns true if the element should be removed.

    Returns: The number of erased elements.



End of document.