Skip to content

Commit

Permalink
🐛 [clang] fixup for config
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-jusiak committed Apr 25, 2024
1 parent 386e0a7 commit a3945fb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion example/policies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// clang-format off
constexpr auto policies = []<const auto... ts>(auto &&...args) {
if constexpr (constexpr auto pext = mph::pext<{.max_bits_size=7u}>{}; requires { pext.template operator()<ts...>( std::forward<decltype(args)>(args)...); }) {
if constexpr (constexpr auto pext = mph::pext<mph::config<>{.max_bits_size=7u}>{}; requires { pext.template operator()<ts...>( std::forward<decltype(args)>(args)...); }) {
return pext.template operator()<ts...>(std::forward<decltype(args)>(args)...);
} else {
static_assert([](auto &&...) { return false; }(ts...), "hash can't be created with given policies!");
Expand Down
21 changes: 6 additions & 15 deletions mph
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ template<const auto Fn = conditional>
struct config {
static constexpr auto apply = Fn;
std::size_t max_bits_size{};
std::size_t split_index{}; // only used by split
std::size_t alignment{};
bool single_table{true};
bool minimize_storage{false};
Expand All @@ -587,7 +588,7 @@ struct config {
* Minimal perfect hash based on intel's pext with support up to 2^max_bits_size elements and with max 8 characters
* requires platform with bmi2 support (https://en.wikipedia.org/wiki/X86_Bit_manipulation_instruction_set)
*/
template <const config config = {}>
template <const config config = config{}>
class pext {
template <class T, const auto keys, const auto mask, const std::size_t size>
[[nodiscard]] static consteval auto make_lookup() {
Expand Down Expand Up @@ -670,21 +671,11 @@ class pext {
}
};

template<const auto Fn = conditional>
struct config_split {
static constexpr auto apply = Fn;
std::size_t max_bits_size{7u};
std::size_t split_index{};
std::size_t alignment{};
bool single_table{true};
bool minimize_storage{false};
};

/**
* Minimal perfect hash based on intel's pext with support up to 2^max_bits_size per split on N'th character and with max 8 characters
* requires platform with bmi2 support (https://en.wikipedia.org/wiki/X86_Bit_manipulation_instruction_set)
*/
template <const config_split config = {}>
template <const config config = config{}>
class pext_split {
template<class T, const auto keys>
[[nodiscard]] static consteval auto make_masks() {
Expand Down Expand Up @@ -841,9 +832,9 @@ constexpr auto policies = []<const auto unknown, const auto keys>(auto&& data, a
return mph::swar<std::uint32_t>{}.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...);
} else if constexpr (min_max.first == min_max.second and min_max.first == sizeof(std::uint64_t) and std::size(keys) < 4u) {
return mph::swar<std::uint64_t>{}.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...);
} else if constexpr (constexpr auto pext = mph::pext<config{.max_bits_size=7u}>{}; requires { pext.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...); }) {
} else if constexpr (constexpr auto pext = mph::pext<config<>{.max_bits_size=7u}>{}; requires { pext.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...); }) {
return pext.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...);
} else if constexpr (constexpr auto pext_split = mph::pext_split<config_split{.max_bits_size=7u, .split_index=utility::find_unique_char_max_dist<keys>}>{}; requires { pext_split.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...); }) {
} else if constexpr (constexpr auto pext_split = mph::pext_split<config<>{.max_bits_size=7u, .split_index=utility::find_unique_char_max_dist<keys>}>{}; requires { pext_split.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...); }) {
return pext_split.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...);
} else {
static_assert(hash_cant_be_created, "string hash can't be created with given policies!");
Expand All @@ -853,7 +844,7 @@ constexpr auto policies = []<const auto unknown, const auto keys>(auto&& data, a
return mph::swar<std::uint32_t>{}.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...);
} else if constexpr (sizeof(type) <= sizeof(std::uint64_t) and std::size(keys) < 4u) {
return mph::swar<std::uint64_t>{}.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...);
} else if constexpr (constexpr auto pext = mph::pext<config{.max_bits_size=7u}>{}; requires { pext.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...); }) {
} else if constexpr (constexpr auto pext = mph::pext<config<>{.max_bits_size=7u}>{}; requires { pext.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...); }) {
return pext.template operator()<unknown, keys>(std::forward<decltype(data)>(data), std::forward<decltype(args)>(args)...);
} else {
static_assert(hash_cant_be_created, "integral hash can't be created with given policies!");
Expand Down
10 changes: 5 additions & 5 deletions test/mph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ int main() {

constexpr auto hash = mph::hash < keys,
[]<const auto... ts>(auto &&...args) {
return mph::pext<{.max_bits_size=5}>{}.template operator()<ts...>(
return mph::pext<mph::config<>{.max_bits_size=5}>{}.template operator()<ts...>(
std::forward<decltype(args)>(args)...);
}
> ;
Expand Down Expand Up @@ -183,7 +183,7 @@ int main() {

constexpr auto hash = mph::hash < keys,
[]<const auto... ts>(auto &&...args) {
return mph::pext<{.max_bits_size=5}>{}.template operator()<ts...>(
return mph::pext<mph::config<>{.max_bits_size=5}>{}.template operator()<ts...>(
std::forward<decltype(args)>(args)...);
}
> ;
Expand All @@ -210,7 +210,7 @@ int main() {

constexpr auto hash = mph::hash < keys,
[]<const auto... ts>(auto &&...args) {
return mph::pext_split<{.max_bits_size=5u, .split_index=0u}>{}.template operator()<ts...>(
return mph::pext_split<mph::config<>{.max_bits_size=5u, .split_index=0u}>{}.template operator()<ts...>(
std::forward<decltype(args)>(args)...);
}
> ;
Expand All @@ -233,7 +233,7 @@ int main() {

constexpr auto hash = mph::hash < keys,
[]<const auto... ts>(auto &&...args) {
return mph::pext_split<{.max_bits_size=7u, .split_index=0u}>{}.template operator()<ts...>(
return mph::pext_split<mph::config<>{.max_bits_size=7u, .split_index=0u}>{}.template operator()<ts...>(
std::forward<decltype(args)>(args)...);
}
> ;
Expand All @@ -252,7 +252,7 @@ int main() {

constexpr auto hash = mph::hash < keys,
[]<const auto... ts>(auto &&...args) {
return mph::pext_split<{.max_bits_size=7, .split_index=7u}>{}.template operator()<ts...>(
return mph::pext_split<mph::config<>{.max_bits_size=7, .split_index=7u}>{}.template operator()<ts...>(
std::forward<decltype(args)>(args)...);
}
> ;
Expand Down

0 comments on commit a3945fb

Please sign in to comment.