mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
rename hash_values_combine -> hash_combine
fix hash_range
This commit is contained in:
parent
4332b26a0e
commit
6e5f4c5606
6 changed files with 65 additions and 60 deletions
|
@ -7,8 +7,7 @@
|
|||
#include <sprout/functional/hash/to_hash.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/functional/hash/hash_combine.hpp>
|
||||
#include <sprout/functional/hash/hash_range.hpp>
|
||||
#include <sprout/functional/hash/hash_values_combine.hpp>
|
||||
#include <sprout/functional/hash/hash_values.hpp>
|
||||
#include <sprout/functional/hash/hash_range.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HPP
|
||||
|
|
|
@ -7,13 +7,30 @@
|
|||
#include <sprout/functional/hash/to_hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_combine_impl(std::size_t seed) {
|
||||
return seed;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_combine_impl(std::size_t seed, T const& v) {
|
||||
return seed ^ (sprout::to_hash(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
|
||||
}
|
||||
template<typename Head, typename... Tail>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_combine_impl(std::size_t seed, Head const& head, Tail const&... tail) {
|
||||
return sprout::detail::hash_combine_impl(sprout::detail::hash_combine_impl(seed, head), tail...);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// hash_combine
|
||||
//
|
||||
template<typename T>
|
||||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_combine(std::size_t seed, T const& v) {
|
||||
return seed ^ (sprout::to_hash(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
|
||||
hash_combine(std::size_t seed, Args const&... args) {
|
||||
return sprout::detail::hash_combine_impl(seed, args...);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -20,23 +20,9 @@ namespace sprout {
|
|||
//
|
||||
// hash_combine
|
||||
//
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR std::size_t hash_combine(std::size_t seed, T const& v);
|
||||
|
||||
//
|
||||
// hash_range
|
||||
//
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR std::size_t hash_range(Iterator first, Iterator last);
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, Iterator first, Iterator last);
|
||||
|
||||
//
|
||||
// hash_values_combine
|
||||
//
|
||||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine(std::size_t seed, Args const&... args);
|
||||
hash_combine(std::size_t seed, Args const&... args);
|
||||
|
||||
//
|
||||
// hash_values
|
||||
|
@ -44,6 +30,18 @@ namespace sprout {
|
|||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values(Args const&... args);
|
||||
|
||||
//
|
||||
// hash_range
|
||||
//
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, Iterator first, Iterator last);
|
||||
template<typename Iterator>
|
||||
SPROUT_CONSTEXPR std::size_t hash_range(Iterator first, Iterator last);
|
||||
template<typename InputRange>
|
||||
SPROUT_CONSTEXPR std::size_t hash_range(std::size_t seed, InputRange const& rng);
|
||||
template<typename InputRange>
|
||||
SPROUT_CONSTEXPR std::size_t hash_range(InputRange const& rng);
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_FWD_HPP
|
||||
|
|
|
@ -5,25 +5,49 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/functional/hash/hash_combine.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/numeric/accumulate.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_combine_accumulator
|
||||
//
|
||||
template<typename T = std::size_t>
|
||||
struct hash_combine_accumulator {
|
||||
public:
|
||||
typedef T first_argument_type;
|
||||
typedef T result_type;
|
||||
public:
|
||||
template<typename U>
|
||||
SPROUT_CONSTEXPR T operator()(T const& seed, U const& v) const {
|
||||
return sprout::hash_combine(seed, v);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// hash_range
|
||||
//
|
||||
template<typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_range(std::size_t seed, InputIterator first, InputIterator last) {
|
||||
return first != last
|
||||
? sprout::hash_range(sprout::hash_combine(seed, *first), sprout::next(first), last)
|
||||
: seed
|
||||
;
|
||||
return sprout::accumulate(first, last, seed, sprout::hash_combine_accumulator<>());
|
||||
}
|
||||
template<typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_range(InputIterator first, InputIterator last) {
|
||||
return sprout::hash_range(0, first, last);
|
||||
}
|
||||
|
||||
template<typename InputRange>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_range(std::size_t seed, InputRange const& rng) {
|
||||
return sprout::hash_range(seed, sprout::begin(rng), sprout::end(rng));
|
||||
}
|
||||
template<typename InputRange>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_range(InputRange const& rng) {
|
||||
return sprout::hash_range(0, rng);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_RANGE_HPP
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/functional/hash/hash_values_combine.hpp>
|
||||
#include <sprout/functional/hash/hash_combine.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -13,7 +13,7 @@ namespace sprout {
|
|||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values(Args const&... args) {
|
||||
return sprout::hash_values_combine(0, args...);
|
||||
return sprout::hash_combine(0, args...);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUES_COMBINE_HPP
|
||||
#define SPROUT_FUNCTIONAL_HASH_HASH_VALUES_COMBINE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/functional/hash/hash_combine.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine_impl(std::size_t seed, T const& v) {
|
||||
return sprout::hash_combine(seed, v);
|
||||
}
|
||||
template<typename Head, typename... Tail>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine_impl(std::size_t seed, Head const& head, Tail const&... tail) {
|
||||
return sprout::detail::hash_values_combine_impl(sprout::hash_combine(seed, head), tail...);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// hash_values_combine
|
||||
//
|
||||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine(std::size_t seed, Args const&... args) {
|
||||
return sprout::detail::hash_values_combine_impl(seed, args...);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUES_COMBINE_HPP
|
Loading…
Reference in a new issue