mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-12 14:54:10 +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
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue