From ba5cbd5ca60c30a8185f849e58ae38e40ee07d03 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Mon, 26 Sep 2022 15:18:13 -0700 Subject: [PATCH] Add simple initial draft of unordered_flat_map --- .../boost/unordered/unordered_flat_map.hpp | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 include/boost/unordered/unordered_flat_map.hpp diff --git a/include/boost/unordered/unordered_flat_map.hpp b/include/boost/unordered/unordered_flat_map.hpp new file mode 100644 index 00000000..fddadd4a --- /dev/null +++ b/include/boost/unordered/unordered_flat_map.hpp @@ -0,0 +1,90 @@ +#ifndef BOOST_UNORDERED_UNORDERED_FLAT_MAP_HPP_INCLUDED +#define BOOST_UNORDERED_UNORDERED_FLAT_MAP_HPP_INCLUDED + +#include +#if defined(BOOST_HAS_PRAGMA_ONCE) +#pragma once +#endif + +#include + +#include + +#include + +namespace boost { + namespace unordered { + template + class unordered_flat_map + { + struct map_types + { + using key_type = Key; + using value_type = std::pair; + static Key const& extract(value_type const& kv) { return kv.first; } + }; + + using table_type = detail::foa::table::type>; + + table_type table_; + + public: + using key_type = Key; + using mapped_type = T; + using value_type = typename map_types::value_type; + using size_type = std::size_t; + using key_equal = KeyEqual; + using iterator = typename table_type::iterator; + using const_iterator = typename table_type::const_iterator; + + iterator begin() noexcept { return table_.begin(); } + const_iterator begin() const noexcept { return table_.begin(); } + const_iterator cbegin() const noexcept { return table_.cbegin(); } + + iterator end() noexcept { return table_.end(); } + const_iterator end() const noexcept { return table_.end(); } + const_iterator cend() const noexcept { return table_.cend(); } + + size_type size() const noexcept { return table_.size(); } + + std::pair insert(value_type const& value) + { + return table_.insert(value); + } + + size_type count(key_type const& key) const + { + auto pos = table_.find(key); + return pos != table_.end() ? 1 : 0; + } + + std::pair equal_range(key_type const& key) + { + auto pos = table_.find(key); + return {pos, pos == table_.end() ? pos : ++pos}; + } + + std::pair equal_range( + key_type const& key) const + { + auto pos = table_.find(key); + return {pos, pos == table_.end() ? pos : ++pos}; + } + + size_type bucket_count() const noexcept { return table_.capacity(); } + + float load_factor() const noexcept { return table_.load_factor(); } + + float max_load_factor() const noexcept + { + return table_.max_load_factor(); + } + + key_equal key_eq() const { return table_.key_eq(); } + }; + } // namespace unordered +} // namespace boost + +#endif