24#ifndef FROZEN_LETITGO_PMH_H
25#define FROZEN_LETITGO_PMH_H
44 return b0.size() > b1.size();
53template <std::
size_t M>
73 constexpr auto size()
const {
return ptr->size(); }
74 constexpr const auto &
operator[](std::size_t idx)
const {
return (*
ptr)[idx]; }
75 constexpr auto begin()
const {
return ptr->begin(); }
76 constexpr auto end()
const {
return ptr->end(); }
80 template <std::size_t... Is>
93template <std::
size_t M,
class Item, std::
size_t N,
class Hash,
class Key,
class PRG>
103 bool rejected =
false;
104 for (std::size_t i = 0; i < items.
size(); ++i) {
105 auto & bucket = result.buckets[hash(key(items[i]),
static_cast<std::size_t
>(result.seed)) % M];
106 if (bucket.size() >= result_t::bucket_max) {
112 if (!rejected) {
return result; }
117template<
class T, std::
size_t N>
119 for (std::size_t i = 0; i < data.
size(); ++i)
132 static constexpr value_type MINUS_ONE = std::numeric_limits<value_type>::max();
133 static constexpr value_type HIGH_BIT = ~(MINUS_ONE >> 1);
139 constexpr bool is_seed()
const {
return value_ & HIGH_BIT; }
150template <std::
size_t M,
class Hasher>
157 std::uint64_t first_seed,
160 Hasher hash) noexcept
168 return static_cast<Hasher const&
>(*this);
171 template <
typename KeyType>
172 constexpr std::size_t
lookup(
const KeyType & key)
const {
178 template <
typename KeyType,
typename HasherType>
179 constexpr std::size_t
lookup(
const KeyType & key,
const HasherType& hasher)
const {
181 if (!d.is_seed()) {
return static_cast<std::size_t
>(d.value()); }
182 else {
return second_table_[hasher(key,
static_cast<std::size_t
>(d.value())) % M]; }
187template <std::
size_t M,
class Item, std::
size_t N,
class Hash,
class Key,
class KeyEqual,
class PRG>
191 KeyEqual
const &
equal,
198 for(
auto const& bucket : step_one.buckets)
199 for(std::size_t i = 1; i < bucket.size(); ++i)
203 auto buckets = step_one.get_sorted_buckets();
210 const auto UNUSED = items.
size();
219 for (
const auto & bucket : buckets) {
220 auto const bsize = bucket.size();
225 G[bucket.hash] = {
false,
static_cast<std::uint64_t
>(bucket[0])};
226 }
else if (bsize > 1) {
231 cvector<std::size_t,
decltype(step_one)::bucket_max> bucket_slots;
233 while (bucket_slots.size() < bsize) {
234 auto slot = hash(key(items[bucket[bucket_slots.size()]]),
static_cast<std::size_t
>(d.
value())) % M;
237 bucket_slots.clear();
242 bucket_slots.push_back(slot);
248 for (std::size_t i = 0; i < bsize; ++i)
249 H[bucket_slots[i]] = bucket[i];
253 return {step_one.seed, G, H, hash};
Definition basic_types.h:90
constexpr iterator end() noexcept
Definition basic_types.h:147
constexpr size_type size() const
Definition basic_types.h:151
constexpr iterator begin() noexcept
Definition basic_types.h:145
Definition basic_types.h:42
constexpr size_type size() const
Definition basic_types.h:72
const_pointer const_iterator
Definition basic_types.h:54
std::size_t value_type
Definition basic_types.h:48
#define constexpr_assert(cond, msg)
Definition constexpr_assert.h:31
Definition algorithms.h:33
constexpr bool all_different_from(cvector< T, N > &data, T &a)
Definition pmh.h:118
constexpr bool equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
Definition algorithms.h:210
auto constexpr log(T v)
Definition algorithms.h:46
constexpr void quicksort(Iterator left, Iterator right, Compare const &compare)
Definition algorithms.h:134
pmh_buckets< M > constexpr make_pmh_buckets(const carray< Item, N > &items, Hash const &hash, Key const &key, PRG &prg)
Definition pmh.h:94
pmh_tables< M, Hash > constexpr make_pmh_tables(const carray< Item, N > &items, Hash const &hash, KeyEqual const &equal, Key const &key, PRG prg)
Definition pmh.h:188
Definition algorithm.h:30
bool constexpr operator()(B const &b0, B const &b1) const
Definition pmh.h:42
constexpr const auto & operator[](std::size_t idx) const
Definition pmh.h:74
constexpr auto begin() const
Definition pmh.h:75
const bucket_t * ptr
Definition pmh.h:67
typename bucket_t::value_type value_type
Definition pmh.h:70
constexpr auto size() const
Definition pmh.h:73
constexpr auto end() const
Definition pmh.h:76
typename bucket_t::const_iterator const_iterator
Definition pmh.h:71
unsigned hash
Definition pmh.h:66
carray< bucket_ref, M > constexpr get_sorted_buckets() const
Definition pmh.h:86
carray< bucket_ref, M > constexpr make_bucket_refs(std::index_sequence< Is... >) const
Definition pmh.h:81
carray< bucket_t, M > buckets
Definition pmh.h:60
std::uint64_t seed
Definition pmh.h:61
cvector< std::size_t, bucket_max > bucket_t
Definition pmh.h:59
static constexpr auto bucket_max
Definition pmh.h:57
constexpr Hasher const & hash_function() const noexcept
Definition pmh.h:167
constexpr std::size_t lookup(const KeyType &key, const HasherType &hasher) const
Definition pmh.h:179
constexpr std::size_t lookup(const KeyType &key) const
Definition pmh.h:172
constexpr pmh_tables(std::uint64_t first_seed, carray< seed_or_index, M > first_table, carray< std::size_t, M > second_table, Hasher hash) noexcept
Definition pmh.h:156
std::uint64_t first_seed_
Definition pmh.h:152
carray< std::size_t, M > second_table_
Definition pmh.h:154
carray< seed_or_index, M > first_table_
Definition pmh.h:153
constexpr seed_or_index(bool is_seed, value_type value)
Definition pmh.h:141
constexpr seed_or_index(const seed_or_index &)=default
constexpr bool is_seed() const
Definition pmh.h:139
std::uint64_t value_type
Definition pmh.h:129
constexpr value_type value() const
Definition pmh.h:138
constexpr seed_or_index & operator=(const seed_or_index &)=default
constexpr seed_or_index()=default