fix bitset hash support

This commit is contained in:
bolero-MURAKAMI 2012-06-19 13:18:49 +09:00
parent f00b15b8bf
commit c2a401326c
2 changed files with 28 additions and 8 deletions

View file

@ -192,6 +192,11 @@ namespace testspr {
is >> bits; is >> bits;
TESTSPR_ASSERT(bits == bitset_t(0xDEADBEEF)); TESTSPR_ASSERT(bits == bitset_t(0xDEADBEEF));
} }
// 20.5.3 hash support
// sprout::to_hash, sprout::hash
TESTSPR_BOTH_ASSERT(sprout::to_hash(bits1) == sprout::hash<bitset_t>()(bits1));
} }
} }
} // namespace testspr } // namespace testspr

View file

@ -61,8 +61,8 @@ namespace sprout {
public: public:
typedef unsigned long word_type; typedef unsigned long word_type;
typedef word_type value_type; typedef word_type value_type;
typedef sprout::index_iterator<base_bitset<N>&> iterator; typedef sprout::index_iterator<base_bitset&> iterator;
typedef sprout::index_iterator<base_bitset<N> const&> const_iterator; typedef sprout::index_iterator<base_bitset const&> const_iterator;
typedef value_type& reference; typedef value_type& reference;
typedef value_type const& const_reference; typedef value_type const& const_reference;
typedef std::size_t size_type; typedef std::size_t size_type;
@ -464,6 +464,10 @@ namespace sprout {
; ;
} }
SPROUT_CONSTEXPR std::size_t do_to_hash() const {
return sprout::hash_range(begin(), end());
}
word_type& operator[](std::size_t i) { word_type& operator[](std::size_t i) {
return w_[i]; return w_[i];
} }
@ -663,6 +667,10 @@ namespace sprout {
: find_next_impl(prev + 1, not_found, w_ >> (prev + 1)) : find_next_impl(prev + 1, not_found, w_ >> (prev + 1))
; ;
} }
SPROUT_CONSTEXPR std::size_t do_to_hash() const {
return sprout::hash_value(w_);
}
}; };
template<> template<>
@ -802,6 +810,10 @@ namespace sprout {
find_next(std::size_t, std::size_t) const SPROUT_NOEXCEPT { find_next(std::size_t, std::size_t) const SPROUT_NOEXCEPT {
return 0; return 0;
} }
SPROUT_CONSTEXPR std::size_t do_to_hash() const {
return 0;
}
}; };
template<std::size_t Extrabits> template<std::size_t Extrabits>
@ -1069,6 +1081,10 @@ namespace sprout {
copy_to_string(std::basic_string<Char, Traits,Alloc>& s) const { copy_to_string(std::basic_string<Char, Traits,Alloc>& s) const {
copy_to_string(s, Char('0'), Char('1')); copy_to_string(s, Char('0'), Char('1'));
} }
SPROUT_CONSTEXPR std::size_t to_hash() const {
return this->do_to_hash();
}
public: public:
// 20.5.1 constructors: // 20.5.1 constructors:
SPROUT_CONSTEXPR bitset() SPROUT_NOEXCEPT {} SPROUT_CONSTEXPR bitset() SPROUT_NOEXCEPT {}
@ -1365,8 +1381,9 @@ namespace sprout {
friend std::basic_ostream<Char, Traits>& friend std::basic_ostream<Char, Traits>&
sprout::operator<<(std::basic_ostream<Char, Traits>& lhs, sprout::bitset<M> const& rhs); sprout::operator<<(std::basic_ostream<Char, Traits>& lhs, sprout::bitset<M> const& rhs);
friend std::size_t template<std::size_t M>
hash_value<N>(sprout::bitset<N> const& v); friend SPROUT_CONSTEXPR std::size_t
hash_value(sprout::bitset<M> const& v);
}; };
// 20.5.4 bitset operators: // 20.5.4 bitset operators:
@ -1445,10 +1462,8 @@ namespace sprout {
// 20.5.3 hash support // 20.5.3 hash support
template<std::size_t N> template<std::size_t N>
inline SPROUT_CONSTEXPR std::size_t inline SPROUT_CONSTEXPR std::size_t
hash_value(sprout::bitset<N> const& v); // !!! hash_value(sprout::bitset<N> const& v) {
inline SPROUT_CONSTEXPR std::size_t return v.to_hash();
hash_value(sprout::bitset<0> const& v) {
return 0;
} }
} // namespace sprout } // namespace sprout