23#ifndef FROZEN_LETITGO_UNORDERED_MAP_H
24#define FROZEN_LETITGO_UNORDERED_MAP_H
42 template <
class KV>
constexpr auto const &
operator()(KV
const &kv)
const {
49template <
class Key,
class Value, std::
size_t N,
typename Hash = anna<Key>,
50 class KeyEqual = std::equal_to<Key>>
52 static constexpr std::size_t storage_size =
57 container_type items_;
81 Hash
const &hash, KeyEqual
const &equal)
85 bits::make_pmh_tables<storage_size>(
92 Hash
const & hash, KeyEqual
const & equal)
108 constexpr bool empty()
const {
return !N; }
113 template <
class KeyType>
114 constexpr std::size_t
count(KeyType
const &key)
const {
118 template <
class KeyType>
119 constexpr Value
const &
at(KeyType
const &key)
const {
120 return at_impl(*
this, key);
122 template <
class KeyType>
123 constexpr Value &
at(KeyType
const &key) {
124 return at_impl(*
this, key);
127 template <
class KeyType>
131 template <
class KeyType>
136 template <
class KeyType>
137 constexpr bool contains(KeyType
const &key)
const {
138 return this->
find(key) != this->
end();
141 template <
class KeyType>
142 constexpr std::pair<const_iterator, const_iterator>
equal_range(KeyType
const &key)
const {
143 return equal_range_impl(*
this, key);
145 template <
class KeyType>
146 constexpr std::pair<iterator, iterator>
equal_range(KeyType
const &key) {
147 return equal_range_impl(*
this, key);
156 constexpr const key_equal&
key_eq()
const {
return static_cast<KeyEqual const&
>(*this); }
159 template <
class This,
class KeyType>
160 static inline constexpr auto& at_impl(This&& self, KeyType
const &key) {
161 auto it = self.find(key);
162 if (it != self.end())
168 template <
class This,
class KeyType,
class Hasher,
class Equal>
169 static inline constexpr auto find_impl(This&& self, KeyType
const &key, Hasher
const &hash, Equal
const &equal) {
170 auto const pos = self.tables_.lookup(key, hash);
171 auto it = self.items_.begin() + pos;
172 if (it != self.items_.end() && equal(it->first, key))
175 return self.items_.end();
178 template <
class This,
class KeyType>
179 static inline constexpr auto equal_range_impl(This&& self, KeyType
const &key) {
180 auto const it = self.find(key);
181 if (it != self.end())
182 return std::make_pair(it, it + 1);
184 return std::make_pair(self.end(), self.end());
188template <
typename T,
typename U, std::
size_t N>
193template <
typename T,
typename U, std::
size_t N,
typename Hasher,
typename Equal>
195 std::pair<T, U>
const (&items)[N],
196 Hasher
const &hash =
elsa<T>{},
197 Equal
const &equal = std::equal_to<T>{}) {
201template <
typename T,
typename U, std::
size_t N>
206template <
typename T,
typename U, std::
size_t N,
typename Hasher,
typename Equal>
208 std::array<std::pair<T, U>, N>
const &items,
209 Hasher
const &hash =
elsa<T>{},
210 Equal
const &equal = std::equal_to<T>{}) {
Definition basic_types.h:90
const value_type & const_reference
Definition basic_types.h:109
value_type * pointer
Definition basic_types.h:110
std::ptrdiff_t difference_type
Definition basic_types.h:115
const_pointer const_iterator
Definition basic_types.h:113
pointer iterator
Definition basic_types.h:112
const value_type * const_pointer
Definition basic_types.h:111
std::size_t size_type
Definition basic_types.h:114
std::pair< const Key, Value > value_type
Definition basic_types.h:107
value_type & reference
Definition basic_types.h:108
Definition unordered_map.h:51
constexpr const_iterator find(KeyType const &key) const
Definition unordered_map.h:128
constexpr bool contains(KeyType const &key) const
Definition unordered_map.h:137
constexpr iterator begin()
Definition unordered_map.h:100
constexpr const_iterator cbegin() const
Definition unordered_map.h:104
constexpr bool empty() const
Definition unordered_map.h:108
typename container_type::size_type size_type
Definition unordered_map.h:66
typename container_type::const_iterator const_iterator
Definition unordered_map.h:75
typename container_type::pointer pointer
Definition unordered_map.h:72
constexpr const_iterator begin() const
Definition unordered_map.h:102
Hash hasher
Definition unordered_map.h:68
typename container_type::difference_type difference_type
Definition unordered_map.h:67
Value mapped_type
Definition unordered_map.h:64
KeyEqual key_equal
Definition unordered_map.h:69
constexpr iterator find(KeyType const &key)
Definition unordered_map.h:132
typename container_type::const_reference const_reference
Definition unordered_map.h:71
constexpr Value & at(KeyType const &key)
Definition unordered_map.h:123
constexpr size_type max_size() const
Definition unordered_map.h:110
constexpr const key_equal & key_eq() const
Definition unordered_map.h:156
constexpr const_iterator cend() const
Definition unordered_map.h:105
constexpr size_type size() const
Definition unordered_map.h:109
unordered_map(unordered_map const &)=default
constexpr std::pair< iterator, iterator > equal_range(KeyType const &key)
Definition unordered_map.h:146
typename container_type::const_pointer const_pointer
Definition unordered_map.h:73
constexpr const hasher & hash_function() const
Definition unordered_map.h:155
constexpr std::size_t count(KeyType const &key) const
Definition unordered_map.h:114
constexpr std::pair< const_iterator, const_iterator > equal_range(KeyType const &key) const
Definition unordered_map.h:142
Key key_type
Definition unordered_map.h:63
constexpr std::size_t bucket_count() const
Definition unordered_map.h:151
typename container_type::iterator iterator
Definition unordered_map.h:74
constexpr iterator end()
Definition unordered_map.h:101
constexpr Value const & at(KeyType const &key) const
Definition unordered_map.h:119
constexpr unordered_map(container_type items)
Definition unordered_map.h:87
constexpr unordered_map(std::initializer_list< value_type > items, Hash const &hash, KeyEqual const &equal)
Definition unordered_map.h:91
typename container_type::reference reference
Definition unordered_map.h:70
constexpr const_iterator end() const
Definition unordered_map.h:103
unordered_map< Key, Value, N, Hash, KeyEqual > Self
Definition unordered_map.h:62
constexpr unordered_map(std::initializer_list< value_type > items)
Definition unordered_map.h:96
constexpr std::size_t max_bucket_count() const
Definition unordered_map.h:152
constexpr unordered_map(container_type items, Hash const &hash, KeyEqual const &equal)
Definition unordered_map.h:80
typename container_type::value_type value_type
Definition unordered_map.h:65
#define FROZEN_THROW_OR_ABORT(_)
Definition exceptions.h:29
Hash::value_type hash(const Object &v)
Definition algorithms.h:33
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
Definition algorithms.h:210
auto constexpr next_highest_power_of_two(std::size_t v)
Definition algorithms.h:35
Definition algorithm.h:30
minstd_rand default_prg_t
Definition random.h:93
constexpr auto make_unordered_map(std::pair< T, U > const (&items)[N])
Definition unordered_map.h:189
Definition unordered_map.h:41
constexpr auto const & operator()(KV const &kv) const
Definition unordered_map.h:42