mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-30 03:17:15 +02:00
If the containers have equality comparisons, they'll also need 'hash_value'. Untested and undocumented, as before.
[SVN r42108]
This commit is contained in:
80
doc/ref.xml
80
doc/ref.xml
@ -636,6 +636,25 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>This is a boost extension.</para>
|
||||
</notes>
|
||||
</function>
|
||||
<function name="hash_value">
|
||||
<template>
|
||||
<template-type-parameter name="Value">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Hash">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Pred">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Alloc">
|
||||
</template-type-parameter>
|
||||
</template>
|
||||
<parameter name="x">
|
||||
<paramtype>unordered_set<Value, Hash, Pred, Alloc> const&</paramtype>
|
||||
</parameter>
|
||||
<type>std::size_t</type>
|
||||
<notes>
|
||||
<para>This is a boost extension.</para>
|
||||
</notes>
|
||||
</function>
|
||||
</free-function-group>
|
||||
<free-function-group name="swap">
|
||||
<function name="swap">
|
||||
@ -1293,6 +1312,25 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>This is a boost extension.</para>
|
||||
</notes>
|
||||
</function>
|
||||
<function name="hash_value">
|
||||
<template>
|
||||
<template-type-parameter name="Value">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Hash">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Pred">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Alloc">
|
||||
</template-type-parameter>
|
||||
</template>
|
||||
<parameter name="x">
|
||||
<paramtype>unordered_multiset<Value, Hash, Pred, Alloc> const&</paramtype>
|
||||
</parameter>
|
||||
<type>std::size_t</type>
|
||||
<notes>
|
||||
<para>This is a boost extension.</para>
|
||||
</notes>
|
||||
</function>
|
||||
</free-function-group>
|
||||
<free-function-group name="swap">
|
||||
<function name="swap">
|
||||
@ -2005,6 +2043,27 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>This is a boost extension.</para>
|
||||
</notes>
|
||||
</function>
|
||||
<function name="hash_value">
|
||||
<template>
|
||||
<template-type-parameter name="Key">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Mapped">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Hash">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Pred">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Alloc">
|
||||
</template-type-parameter>
|
||||
</template>
|
||||
<parameter name="x">
|
||||
<paramtype>unordered_map<Key, Mapped, Hash, Pred, Alloc> const&</paramtype>
|
||||
</parameter>
|
||||
<type>std::size_t</type>
|
||||
<notes>
|
||||
<para>This is a boost extension.</para>
|
||||
</notes>
|
||||
</function>
|
||||
</free-function-group>
|
||||
<free-function-group name="swap">
|
||||
<function name="swap">
|
||||
@ -2676,6 +2735,27 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>This is a boost extension.</para>
|
||||
</notes>
|
||||
</function>
|
||||
<function name="hash_value">
|
||||
<template>
|
||||
<template-type-parameter name="Key">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Mapped">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Hash">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Pred">
|
||||
</template-type-parameter>
|
||||
<template-type-parameter name="Alloc">
|
||||
</template-type-parameter>
|
||||
</template>
|
||||
<parameter name="x">
|
||||
<paramtype>unordered_multimap<Key, Mapped, Hash, Pred, Alloc> const&</paramtype>
|
||||
</parameter>
|
||||
<type>std::size_t</type>
|
||||
<notes>
|
||||
<para>This is a boost extension.</para>
|
||||
</notes>
|
||||
</function>
|
||||
</free-function-group>
|
||||
<free-function-group name="swap">
|
||||
<function name="swap">
|
||||
|
@ -1926,6 +1926,41 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool group_hash(local_iterator_base it, type_wrapper<key_type>*) const
|
||||
{
|
||||
std::size_t seed = group_count(it);
|
||||
boost::hash_combine(seed, hash_function()(*it));
|
||||
return seed;
|
||||
}
|
||||
|
||||
inline bool group_hash(local_iterator_base it, void*) const
|
||||
{
|
||||
std::size_t seed = hash_function()(it->first);
|
||||
|
||||
local_iterator_base end = it;
|
||||
end.next_group();
|
||||
|
||||
do {
|
||||
boost::hash_combine(seed, it->second);
|
||||
} while(it != end);
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
std::size_t hash_value() const
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
|
||||
for(bucket_ptr i = this->cached_begin_bucket_,
|
||||
j = this->buckets_ + this->bucket_count_; i != j; ++i)
|
||||
{
|
||||
for(local_iterator_base it(i->next_); it.not_finished(); it.next_group())
|
||||
seed ^= group_hash(it, (type_wrapper<value_type>*)0);
|
||||
}
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// strong exception safety, no side effects
|
||||
|
@ -16,8 +16,8 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include <boost/unordered/detail/hash_table.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/unordered/detail/hash_table.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -335,6 +335,11 @@ namespace boost
|
||||
{
|
||||
return !m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend std::size_t hash_value(unordered_map const& m)
|
||||
{
|
||||
return m.base.hash_value();
|
||||
}
|
||||
}; // class template unordered_map
|
||||
|
||||
template <class K, class T, class H, class P, class A>
|
||||
@ -642,6 +647,11 @@ namespace boost
|
||||
{
|
||||
return !m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend std::size_t hash_value(unordered_multimap const& m)
|
||||
{
|
||||
return m.base.hash_value();
|
||||
}
|
||||
}; // class template unordered_multimap
|
||||
|
||||
template <class K, class T, class H, class P, class A>
|
||||
|
@ -16,8 +16,8 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include <boost/unordered/detail/hash_table.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/unordered/detail/hash_table.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -305,6 +305,11 @@ namespace boost
|
||||
{
|
||||
return !m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend std::size_t hash_value(unordered_set const& m)
|
||||
{
|
||||
return m.base.hash_value();
|
||||
}
|
||||
}; // class template unordered_set
|
||||
|
||||
template <class T, class H, class P, class A>
|
||||
@ -597,6 +602,11 @@ namespace boost
|
||||
{
|
||||
return !m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend std::size_t hash_value(unordered_multiset const& m)
|
||||
{
|
||||
return m.base.hash_value();
|
||||
}
|
||||
}; // class template unordered_multiset
|
||||
|
||||
template <class T, class H, class P, class A>
|
||||
|
@ -129,4 +129,9 @@ void equality_test(X& r, T&)
|
||||
|
||||
test::check_return_type<bool>::equals(a == b);
|
||||
test::check_return_type<bool>::equals(a != b);
|
||||
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
||||
test::check_return_type<std::size_t>::equals(boost::hash_value(a));
|
||||
#else
|
||||
test::check_return_type<std::size_t>::equals(hash_value(a));
|
||||
#endif
|
||||
}
|
||||
|
@ -57,6 +57,10 @@ namespace minimal
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t hash_value(copy_constructible_equality_comparable) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
class default_copy_constructible
|
||||
{
|
||||
public:
|
||||
|
Reference in New Issue
Block a user