-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganize hash header (again) and add hash_range (#26)
* reorganize hash header (again) and add hash_range * resolve circular dependency * use hash_combine instead of hash_range * remove no longer neccesary forward declaration * move forward declaration header, enable hashing empty range * make hash_value_for depends on Boost * fix hash_combine related operations * IWYU * add test * Revert "fix hash_combine related operations" This reverts commit 1ae9e25. * yet another fix
- Loading branch information
Showing
9 changed files
with
94 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef YK_HASH_HASH_VALUE_FOR_HPP | ||
#define YK_HASH_HASH_VALUE_FOR_HPP | ||
|
||
#include "yk/hash/range.hpp" | ||
|
||
#include <boost/container_hash/hash_fwd.hpp> | ||
|
||
#include <functional> | ||
|
||
namespace yk { | ||
|
||
template <class T> | ||
[[nodiscard]] constexpr std::size_t std_hash_value_for(const T& x) noexcept { | ||
return std::hash<T>{}(x); | ||
} | ||
|
||
template <class T> | ||
[[nodiscard]] constexpr std::size_t boost_hash_value_for(const T& x) noexcept { | ||
return boost::hash<T>{}(x); | ||
} | ||
|
||
template <class T> | ||
[[nodiscard]] constexpr std::size_t hash_value_for(const T& x) noexcept { | ||
if constexpr (requires(std::hash<T> hasher) { hasher(x); }) { | ||
return std::hash<T>{}(x); | ||
} else if constexpr (requires { hash_value(x); }) { | ||
return hash_value(x); | ||
} else if constexpr (requires { ::yk::hash_range(x); }) { | ||
return ::yk::hash_range(x); | ||
} else { | ||
static_assert(false, "no hasher found"); | ||
} | ||
} | ||
|
||
} // namespace yk | ||
|
||
#endif // YK_HASH_HASH_VALUE_FOR_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef YK_HASH_HASH_VALUE_FOR_FWD_HPP | ||
#define YK_HASH_HASH_VALUE_FOR_FWD_HPP | ||
|
||
#include <cstddef> | ||
|
||
namespace yk { | ||
|
||
template <class T> | ||
[[nodiscard]] constexpr std::size_t hash_value_for(const T& x) noexcept; | ||
|
||
} | ||
|
||
#endif // YK_HASH_HASH_VALUE_FOR_FWD_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef YK_HASH_RANGE_HPP | ||
#define YK_HASH_RANGE_HPP | ||
|
||
#include "yk/hash/hash_value_for/fwd.hpp" | ||
|
||
#include <boost/container_hash/hash_fwd.hpp> | ||
|
||
#include <ranges> | ||
#include <utility> | ||
|
||
#include <cassert> | ||
#include <cstddef> | ||
|
||
namespace yk { | ||
|
||
template <std::ranges::range R> | ||
[[nodiscard]] constexpr std::size_t hash_range(R&& r) noexcept { | ||
std::size_t seed = 0; | ||
for (auto&& elem : r) boost::hash_combine(seed, ::yk::hash_value_for(elem)); | ||
return seed; | ||
} | ||
|
||
} // namespace yk | ||
|
||
#endif // YK_HASH_RANGE_HPP |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters