2013-02-04 09:42:39 +00:00
|
|
|
#ifndef SPROUT_FUNCTIONAL_HASH_HASH_RANGE_HPP
|
|
|
|
#define SPROUT_FUNCTIONAL_HASH_HASH_RANGE_HPP
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/functional/hash/hash_fwd.hpp>
|
|
|
|
#include <sprout/functional/hash/hash_combine.hpp>
|
2013-02-04 14:10:24 +00:00
|
|
|
#include <sprout/container/begin.hpp>
|
|
|
|
#include <sprout/container/end.hpp>
|
2013-02-04 13:13:27 +00:00
|
|
|
#include <sprout/numeric/accumulate.hpp>
|
2013-02-04 09:42:39 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
2013-02-04 13:13:27 +00:00
|
|
|
//
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-02-04 09:42:39 +00:00
|
|
|
//
|
|
|
|
// hash_range
|
|
|
|
//
|
|
|
|
template<typename InputIterator>
|
|
|
|
inline SPROUT_CONSTEXPR std::size_t
|
|
|
|
hash_range(std::size_t seed, InputIterator first, InputIterator last) {
|
2013-02-04 13:13:27 +00:00
|
|
|
return sprout::accumulate(first, last, seed, sprout::hash_combine_accumulator<>());
|
2013-02-04 09:42:39 +00:00
|
|
|
}
|
|
|
|
template<typename InputIterator>
|
|
|
|
inline SPROUT_CONSTEXPR std::size_t
|
|
|
|
hash_range(InputIterator first, InputIterator last) {
|
|
|
|
return sprout::hash_range(0, first, last);
|
|
|
|
}
|
2013-02-04 13:13:27 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2013-02-04 09:42:39 +00:00
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_RANGE_HPP
|