Template Class SmallMap#

Class Documentation#

template<typename Key, typename Value, typename Compare = std::less<Key>>
class SmallMap#

Sorted associative container backed by a contiguous std::vector. Cheaper than std::map for small sizes and cache-friendly to iterate. Insertion and erasure are O(n), lookup is O(log n).

Public Types

using key_type = Key#
using mapped_type = Value#
using value_type = std::pair<Key, Value>#
using key_compare = Compare#
using container_type = std::vector<value_type>#
using iterator = typename container_type::iterator#
using const_iterator = typename container_type::const_iterator#
using size_type = typename container_type::size_type#

Public Functions

SmallMap() = default#
inline explicit SmallMap(Compare comp)#
inline SmallMap(std::initializer_list<value_type> init, Compare comp = Compare())#
inline iterator begin() noexcept#
inline iterator end() noexcept#
inline const_iterator begin() const noexcept#
inline const_iterator end() const noexcept#
inline const_iterator cbegin() const noexcept#
inline const_iterator cend() const noexcept#
inline bool empty() const noexcept#
inline size_type size() const noexcept#
inline void reserve(size_type n)#
inline size_type capacity() const noexcept#
inline void clear() noexcept#
inline iterator find(const Key &key)#
inline const_iterator find(const Key &key) const#
inline bool contains(const Key &key) const#
inline size_type count(const Key &key) const#
inline Value &at(const Key &key)#
inline const Value &at(const Key &key) const#
inline Value &operator[](const Key &key)#
inline Value &operator[](Key &&key)#
inline std::pair<iterator, bool> insert(const value_type &kv)#
inline std::pair<iterator, bool> insert(value_type &&kv)#
template<typename ...Args>
inline std::pair<iterator, bool> emplace(Args&&... args)#
template<typename V>
inline std::pair<iterator, bool> insert_or_assign(const Key &key, V &&value)#
inline iterator erase(iterator pos)#
inline iterator erase(const_iterator pos)#
inline size_type erase(const Key &key)#
inline container_type &data() noexcept#
inline const container_type &data() const noexcept#
inline key_compare key_comp() const#