mirror of
https://github.com/boostorg/unordered.git
synced 2025-06-25 11:51:33 +02:00
Compare commits
10 Commits
svn-trunk
...
boost-1.36
Author | SHA1 | Date | |
---|---|---|---|
81d2bd284c | |||
93141c26b9 | |||
dd2a994874 | |||
6571648bac | |||
f20f72bade | |||
4e4f99d51f | |||
56b9e0da1a | |||
4f27a146ef | |||
c8d0cb88ad | |||
5a898f2419 |
@ -1,3 +1,8 @@
|
||||
<!--
|
||||
Copyright Daniel James 2008
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
-->
|
||||
<section id="unordered.bibliography">
|
||||
<title>Bibliography</title>
|
||||
<bibliography>
|
||||
|
@ -10,7 +10,7 @@
|
||||
Initial review version, for the review conducted from 7th December 2007 to
|
||||
16th December 2007.
|
||||
|
||||
[h2 1.35.0 Add-on - 31st Match 2008]
|
||||
[h2 1.35.0 Add-on - 31st March 2008]
|
||||
|
||||
Unofficial release uploaded to vault, to be used with Boost 1.35.0. Incorporated
|
||||
many of the suggestions from the review.
|
||||
@ -31,7 +31,6 @@ First official release.
|
||||
* Emplace support when rvalue references and variadic template are available.
|
||||
* More efficient node allocation when rvalue references and variadic template
|
||||
are available.
|
||||
* Added equality operators and hash functions
|
||||
([@http://svn.boost.org/trac/boost/ticket/1557 Ticket 1557]).
|
||||
* Added equality operators.
|
||||
|
||||
[endsect]
|
||||
|
@ -72,7 +72,7 @@
|
||||
[
|
||||
[Can be compared using the `==`, `!=`, `<`, `<=`, `>`, `>=` operators.]
|
||||
[No comparison operators are defined in the standard, although
|
||||
[link unordered.rationale.equality_operator
|
||||
[link unordered.rationale.equality_operators
|
||||
implementations might extend the containers to support `==` and
|
||||
`!=`].]
|
||||
]
|
||||
|
@ -23,8 +23,8 @@ but not the equality predicate. For example, if you wanted to use the
|
||||
[import src_code/dictionary.cpp]
|
||||
[case_sensitive_dictionary_fnv]
|
||||
|
||||
An example implementation of FNV-1, and some other hash functions are supplied
|
||||
in the examples directory.
|
||||
There is an [@../../libs/unordered/examples/fnv1.hpp implementation
|
||||
of FNV-1] in the examples directory.
|
||||
|
||||
If you wish to use a different equality function,
|
||||
you will also need to use a matching hash function. For
|
||||
|
@ -36,9 +36,7 @@ which are implemented using hash tables, and they have now been added to the
|
||||
__draft__.
|
||||
|
||||
This library supplies an almost complete implementation of the specification in
|
||||
the __draft__, (it doesn't support `emplace` yet, see the [link
|
||||
unordered.rationale.future_developments Implementation Rationale] section for more
|
||||
details). If accepted the containers should also be added to __boost-tr1__.
|
||||
the __draft__.
|
||||
|
||||
`unordered_set` and `unordered_multiset` are defined in the header
|
||||
<[headerref boost/unordered_set.hpp]>
|
||||
|
@ -96,6 +96,15 @@ efficiency advantage of power of 2 hash tables.
|
||||
|
||||
So, this implementation uses a prime number for the hash table size.
|
||||
|
||||
[h2 Equality operators]
|
||||
|
||||
`operator==` and `operator!=` are not included in the standard, but I've
|
||||
added them as I think they could be useful and can be efficiently
|
||||
implemented. They are specified
|
||||
differently to the standard associative containers, comparing keys
|
||||
using the equality predicate rather than `operator==`. This is inconsistent
|
||||
with the other containers but it is probably closer to user's expectations.
|
||||
|
||||
[h2 Active Issues and Proposals]
|
||||
|
||||
[h3 Removing unused allocator functions]
|
||||
@ -181,32 +190,14 @@ It is not specified if `unordered_multiset` and `unordered_multimap` preserve th
|
||||
of elements with equivalent keys (i.e. if they're stable under `insert` and `erase`).
|
||||
This is [@http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#518 issue 581].
|
||||
The current proposal is that insert, erase and rehash are stable - so they are here.
|
||||
(Update: during the release of this version, this requirement was added to
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2691.pdf
|
||||
the lastest working draft]).
|
||||
|
||||
[h3 const_local_iterator cbegin, cend missing from TR1]
|
||||
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2482.html#691
|
||||
[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2684.html#691
|
||||
Issue 691] is that `cbegin` and `cend` are missing for local iterators.
|
||||
The current resolution is that they'll be added, so I've added them.
|
||||
|
||||
[h2 Future Developments]
|
||||
|
||||
[h3 Support for `emplace`]
|
||||
|
||||
In __n2369__ a new member function, `emplace` was added to the containers to
|
||||
allow placement insert, as described in __n2345__. To fully implement this
|
||||
`std::forward` is required, along with new functions in `std::allocator` and
|
||||
new constructors in `std::pair`. But partial support is possible - especially
|
||||
if I don't use the `construct` member of allocators.
|
||||
|
||||
[h3 Equality operator]
|
||||
|
||||
While `operator==` and `operator!=` are not included in the standard, it's
|
||||
possible to implement them for all the containers - this is helped by having
|
||||
stable order of elements with equivalent keys. They will need to be specified
|
||||
differently to the standard associative containers, probably comparing keys
|
||||
using the equality predicate rather than `operator==`. This is inconsistent
|
||||
with the other containers but it is probably closer to user's expectations.
|
||||
|
||||
If these are added then a `hash_value` free function should also be added.
|
||||
|
||||
[endsect]
|
||||
|
122
doc/ref.xml
122
doc/ref.xml
@ -181,7 +181,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
||||
</description>
|
||||
</constructor>
|
||||
<constructor>
|
||||
<constructor specifiers="explicit">
|
||||
<parameter name="a">
|
||||
<paramtype>Allocator const&</paramtype>
|
||||
</parameter>
|
||||
@ -284,6 +284,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<notes>
|
||||
<para>Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.</para>
|
||||
<para>Pointers and references to elements are never invalidated.</para>
|
||||
<para>Only available on compilers with support for variadic template arguments and rvalue references.</para>
|
||||
</notes>
|
||||
</method>
|
||||
<method name="emplace">
|
||||
@ -312,6 +313,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>The standard is fairly vague on the meaning of the hint. But the only practical way to use it, and the only way that Boost.Unordered supports is to point to an existing element with the same value. </para>
|
||||
<para>Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.</para>
|
||||
<para>Pointers and references to elements are never invalidated.</para>
|
||||
<para>Only available on compilers with support for variadic template arguments and rvalue references.</para>
|
||||
</notes>
|
||||
</method>
|
||||
<method name="insert">
|
||||
@ -636,10 +638,10 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<parameter name="z">
|
||||
<paramtype>float</paramtype>
|
||||
</parameter>
|
||||
<type>float</type>
|
||||
<returns>
|
||||
<type>void</type>
|
||||
<effects>
|
||||
<para>Changes the container's maximum load factor, using <code>z</code> as a hint.</para>
|
||||
</returns>
|
||||
</effects>
|
||||
</method>
|
||||
<method name="rehash">
|
||||
<parameter name="n">
|
||||
@ -700,25 +702,6 @@ 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">
|
||||
@ -928,7 +911,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
||||
</description>
|
||||
</constructor>
|
||||
<constructor>
|
||||
<constructor specifiers="explicit">
|
||||
<parameter name="a">
|
||||
<paramtype>Allocator const&</paramtype>
|
||||
</parameter>
|
||||
@ -1030,6 +1013,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<notes>
|
||||
<para>Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.</para>
|
||||
<para>Pointers and references to elements are never invalidated.</para>
|
||||
<para>Only available on compilers with support for variadic template arguments and rvalue references.</para>
|
||||
</notes>
|
||||
</method>
|
||||
<method name="emplace">
|
||||
@ -1058,6 +1042,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>The standard is fairly vague on the meaning of the hint. But the only practical way to use it, and the only way that Boost.Unordered supports is to point to an existing element with the same value. </para>
|
||||
<para>Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.</para>
|
||||
<para>Pointers and references to elements are never invalidated.</para>
|
||||
<para>Only available on compilers with support for variadic template arguments and rvalue references.</para>
|
||||
</notes>
|
||||
</method>
|
||||
<method name="insert">
|
||||
@ -1381,10 +1366,10 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<parameter name="z">
|
||||
<paramtype>float</paramtype>
|
||||
</parameter>
|
||||
<type>float</type>
|
||||
<returns>
|
||||
<type>void</type>
|
||||
<effects>
|
||||
<para>Changes the container's maximum load factor, using <code>z</code> as a hint.</para>
|
||||
</returns>
|
||||
</effects>
|
||||
</method>
|
||||
<method name="rehash">
|
||||
<parameter name="n">
|
||||
@ -1445,25 +1430,6 @@ 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">
|
||||
@ -1685,7 +1651,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
||||
</description>
|
||||
</constructor>
|
||||
<constructor>
|
||||
<constructor specifiers="explicit">
|
||||
<parameter name="a">
|
||||
<paramtype>Allocator const&</paramtype>
|
||||
</parameter>
|
||||
@ -1788,6 +1754,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<notes>
|
||||
<para>Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.</para>
|
||||
<para>Pointers and references to elements are never invalidated.</para>
|
||||
<para>Only available on compilers with support for variadic template arguments and rvalue references.</para>
|
||||
</notes>
|
||||
</method>
|
||||
<method name="emplace">
|
||||
@ -1816,6 +1783,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>The standard is fairly vague on the meaning of the hint. But the only practical way to use it, and the only way that Boost.Unordered supports is to point to an existing element with the same key. </para>
|
||||
<para>Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.</para>
|
||||
<para>Pointers and references to elements are never invalidated.</para>
|
||||
<para>Only available on compilers with support for variadic template arguments and rvalue references.</para>
|
||||
</notes>
|
||||
</method>
|
||||
<method name="insert">
|
||||
@ -2175,10 +2143,10 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<parameter name="z">
|
||||
<paramtype>float</paramtype>
|
||||
</parameter>
|
||||
<type>float</type>
|
||||
<returns>
|
||||
<type>void</type>
|
||||
<effects>
|
||||
<para>Changes the container's maximum load factor, using <code>z</code> as a hint.</para>
|
||||
</returns>
|
||||
</effects>
|
||||
</method>
|
||||
<method name="rehash">
|
||||
<parameter name="n">
|
||||
@ -2243,27 +2211,6 @@ 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">
|
||||
@ -2483,7 +2430,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>The copy constructor. Copies the contained elements, hash function, predicate, maximum load factor and allocator.</para>
|
||||
</description>
|
||||
</constructor>
|
||||
<constructor>
|
||||
<constructor specifiers="explicit">
|
||||
<parameter name="a">
|
||||
<paramtype>Allocator const&</paramtype>
|
||||
</parameter>
|
||||
@ -2585,6 +2532,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<notes>
|
||||
<para>Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.</para>
|
||||
<para>Pointers and references to elements are never invalidated.</para>
|
||||
<para>Only available on compilers with support for variadic template arguments and rvalue references.</para>
|
||||
</notes>
|
||||
</method>
|
||||
<method name="emplace">
|
||||
@ -2613,6 +2561,7 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<para>The standard is fairly vague on the meaning of the hint. But the only practical way to use it, and the only way that Boost.Unordered supports is to point to an existing element with the same key. </para>
|
||||
<para>Can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.</para>
|
||||
<para>Pointers and references to elements are never invalidated.</para>
|
||||
<para>Only available on compilers with support for variadic template arguments and rvalue references.</para>
|
||||
</notes>
|
||||
</method>
|
||||
<method name="insert">
|
||||
@ -2936,10 +2885,10 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
<parameter name="z">
|
||||
<paramtype>float</paramtype>
|
||||
</parameter>
|
||||
<type>float</type>
|
||||
<returns>
|
||||
<type>void</type>
|
||||
<effects>
|
||||
<para>Changes the container's maximum load factor, using <code>z</code> as a hint.</para>
|
||||
</returns>
|
||||
</effects>
|
||||
</method>
|
||||
<method name="rehash">
|
||||
<parameter name="n">
|
||||
@ -3004,27 +2953,6 @@ 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">
|
||||
@ -3062,4 +2990,4 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
</class>
|
||||
</namespace>
|
||||
</header>
|
||||
</library-reference>
|
||||
</library-reference>
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include "../../examples/hash_functions/fnv-1.hpp"
|
||||
#include "../../examples/fnv1.hpp"
|
||||
|
||||
//[case_insensitive_functions
|
||||
struct iequal_to
|
||||
|
66
examples/fnv1.hpp
Normal file
66
examples/fnv1.hpp
Normal file
@ -0,0 +1,66 @@
|
||||
|
||||
// Copyright 2008 Daniel James.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// This code is also released into the public domain.
|
||||
|
||||
// Algorithm from: http://www.isthe.com/chongo/tech/comp/fnv/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace hash
|
||||
{
|
||||
template <std::size_t FnvPrime, std::size_t OffsetBasis>
|
||||
struct basic_fnv_1
|
||||
{
|
||||
std::size_t operator()(std::string const& text) const
|
||||
{
|
||||
std::size_t hash = OffsetBasis;
|
||||
for(std::string::const_iterator it = text.begin(), end = text.end();
|
||||
it != end; ++it)
|
||||
{
|
||||
hash *= FnvPrime;
|
||||
hash ^= *it;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t FnvPrime, std::size_t OffsetBasis>
|
||||
struct basic_fnv_1a
|
||||
{
|
||||
std::size_t operator()(std::string const& text) const
|
||||
{
|
||||
std::size_t hash = OffsetBasis;
|
||||
for(std::string::const_iterator it = text.begin(), end = text.end();
|
||||
it != end; ++it)
|
||||
{
|
||||
hash ^= *it;
|
||||
hash *= FnvPrime;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
// For 32 bit machines:
|
||||
const std::size_t fnv_prime = 16777619u;
|
||||
const std::size_t fnv_offset_basis = 2166136261u;
|
||||
|
||||
// For 64 bit machines:
|
||||
// const std::size_t fnv_prime = 1099511628211u;
|
||||
// const std::size_t fnv_offset_basis = 14695981039346656037u;
|
||||
|
||||
// For 128 bit machines:
|
||||
// const std::size_t fnv_prime = 309485009821345068724781401u;
|
||||
// const std::size_t fnv_offset_basis = 275519064689413815358837431229664493455u;
|
||||
|
||||
// For 256 bit machines:
|
||||
// const std::size_t fnv_prime = 374144419156711147060143317175368453031918731002211u;
|
||||
// const std::size_t fnv_offset_basis = 100029257958052580907070968620625704837092796014241193945225284501741471925557u;
|
||||
|
||||
typedef basic_fnv_1<fnv_prime, fnv_offset_basis> fnv_1;
|
||||
typedef basic_fnv_1a<fnv_prime, fnv_offset_basis> fnv_1a;
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
// See: http://www.isthe.com/chongo/tech/comp/fnv/
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace hash
|
||||
{
|
||||
template <std::size_t FnvPrime, std::size_t OffsetBias>
|
||||
struct basic_fnv_1
|
||||
{
|
||||
std::size_t operator()(std::string const& text) const
|
||||
{
|
||||
std::size_t hash = OffsetBias;
|
||||
for(std::string::const_iterator it = text.begin(), end = text.end();
|
||||
it != end; ++it)
|
||||
{
|
||||
hash *= FnvPrime;
|
||||
hash ^= *it;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t FnvPrime, std::size_t OffsetBias>
|
||||
struct basic_fnv_1a
|
||||
{
|
||||
std::size_t operator()(std::string const& text) const
|
||||
{
|
||||
std::size_t hash = OffsetBias;
|
||||
for(std::string::const_iterator it = text.begin(), end = text.end();
|
||||
it != end; ++it)
|
||||
{
|
||||
hash ^= *it;
|
||||
hash *= FnvPrime;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: Select Bias & Prime base on the size of std::size_t.
|
||||
//
|
||||
// 32 bit FNV_prime = 16777619
|
||||
// 64 bit FNV_prime = 1099511628211
|
||||
// 128 bit FNV_prime = 309485009821345068724781401
|
||||
// 256 bit FNV_prime = 374144419156711147060143317175368453031918731002211
|
||||
//
|
||||
// 32 bit offset_basis = 2166136261
|
||||
// 64 bit offset_basis = 14695981039346656037
|
||||
// 128 bit offset_basis = 275519064689413815358837431229664493455
|
||||
// 256 bit offset_basis = 100029257958052580907070968620625704837092796014241193945225284501741471925557
|
||||
|
||||
const std::size_t fnv_prime = 16777619;
|
||||
// 64 bit FNV_prime = 1099511628211
|
||||
// 128 bit FNV_prime = 309485009821345068724781401
|
||||
// 256 bit FNV_prime = 374144419156711147060143317175368453031918731002211
|
||||
|
||||
const std::size_t fnv_offset_bias = 2166136261u;
|
||||
// 64 bit offset_basis = 14695981039346656037
|
||||
// 128 bit offset_basis = 275519064689413815358837431229664493455
|
||||
// 256 bit offset_basis = 100029257958052580907070968620625704837092796014241193945225284501741471925557
|
||||
|
||||
typedef basic_fnv_1<fnv_prime, fnv_offset_bias> fnv_1;
|
||||
typedef basic_fnv_1a<fnv_prime, fnv_offset_bias> fnv_1a;
|
||||
|
||||
}
|
@ -1493,8 +1493,6 @@ namespace boost {
|
||||
/ static_cast<float>(data_.bucket_manager_.bucket_count());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// key extractors
|
||||
|
||||
// no throw
|
||||
@ -2127,100 +2125,6 @@ namespace boost {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// equals
|
||||
//
|
||||
|
||||
private:
|
||||
#if BOOST_UNORDERED_EQUIVALENT_KEYS
|
||||
static inline bool group_equals(link_ptr it1, link_ptr it2,
|
||||
type_wrapper<key_type>*)
|
||||
{
|
||||
return data::group_count(it1) == data::group_count(it2);
|
||||
}
|
||||
|
||||
static inline bool group_equals(link_ptr it1, link_ptr it2, void*)
|
||||
{
|
||||
link_ptr end1 = data::next_group(it1);
|
||||
link_ptr end2 = data::next_group(it2);
|
||||
do {
|
||||
if(data::get_value(it1).second != data::get_value(it2).second) return false;
|
||||
it1 = it1->next_;
|
||||
it2 = it2->next_;
|
||||
} while(it1 != end1 && it2 != end2);
|
||||
return it1 == end1 && it2 == end2;
|
||||
}
|
||||
#else
|
||||
static inline bool group_equals(link_ptr, link_ptr,
|
||||
type_wrapper<key_type>*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool group_equals(link_ptr it1, link_ptr it2, void*)
|
||||
{
|
||||
return data::get_value(it1).second == data::get_value(it2).second;
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
bool equals(BOOST_UNORDERED_TABLE const& other) const
|
||||
{
|
||||
if(size() != other.size()) return false;
|
||||
|
||||
for(bucket_ptr i = data_.cached_begin_bucket_,
|
||||
j = data_.buckets_end(); i != j; ++i)
|
||||
{
|
||||
for(link_ptr it(i->next_); BOOST_UNORDERED_BORLAND_BOOL(it); it = data::next_group(it))
|
||||
{
|
||||
link_ptr other_pos = other.find_iterator(other.extract_key(data::get_value(it)));
|
||||
if(!BOOST_UNORDERED_BORLAND_BOOL(other_pos) ||
|
||||
!group_equals(it, other_pos, (type_wrapper<value_type>*)0))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline std::size_t group_hash(link_ptr it, type_wrapper<key_type>*) const
|
||||
{
|
||||
std::size_t seed = data::group_count(it);
|
||||
std::size_t hashed_key = hash_function()(data::get_value(it));
|
||||
boost::hash_combine(seed, hashed_key);
|
||||
return seed;
|
||||
}
|
||||
|
||||
inline std::size_t group_hash(link_ptr it, void*) const
|
||||
{
|
||||
std::size_t seed = hash_function()(data::get_value(it).first);
|
||||
|
||||
link_ptr end = data::next_group(it);
|
||||
|
||||
do {
|
||||
boost::hash_combine(seed, data::get_value(it).second);
|
||||
it = it->next_;
|
||||
} while(it != end);
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
std::size_t hash_value() const
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
|
||||
for(bucket_ptr i = data_.cached_begin_bucket_,
|
||||
j = data_.buckets_end(); i != j; ++i)
|
||||
{
|
||||
for(link_ptr it(i->next_); BOOST_UNORDERED_BORLAND_BOOL(it); it = data::next_group(it))
|
||||
seed ^= group_hash(it, (type_wrapper<value_type>*)0);
|
||||
}
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// strong exception safety, no side effects
|
||||
bool equal(key_type const& k, value_type const& v) const
|
||||
{
|
||||
@ -2255,6 +2159,92 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Equals - unordered container equality comparison.
|
||||
//
|
||||
|
||||
#if BOOST_UNORDERED_EQUIVALENT_KEYS
|
||||
template <typename A, typename KeyType>
|
||||
inline bool group_equals(
|
||||
BOOST_UNORDERED_TABLE_DATA<A>*,
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr it1,
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr it2,
|
||||
KeyType*,
|
||||
type_wrapper<KeyType>*)
|
||||
{
|
||||
typedef BOOST_UNORDERED_TABLE_DATA<A> data;
|
||||
return data::group_count(it1) == data::group_count(it2);
|
||||
}
|
||||
|
||||
template <typename A, typename KeyType>
|
||||
inline bool group_equals(
|
||||
BOOST_UNORDERED_TABLE_DATA<A>*,
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr it1,
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr it2,
|
||||
KeyType*,
|
||||
void*)
|
||||
{
|
||||
typedef BOOST_UNORDERED_TABLE_DATA<A> data;
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr end1 = data::next_group(it1);
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr end2 = data::next_group(it2);
|
||||
|
||||
do {
|
||||
if(data::get_value(it1).second != data::get_value(it2).second) return false;
|
||||
it1 = it1->next_;
|
||||
it2 = it2->next_;
|
||||
} while(it1 != end1 && it2 != end2);
|
||||
return it1 == end1 && it2 == end2;
|
||||
}
|
||||
#else
|
||||
template <typename A, typename KeyType>
|
||||
inline bool group_equals(
|
||||
BOOST_UNORDERED_TABLE_DATA<A>*,
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr,
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr,
|
||||
KeyType*,
|
||||
type_wrapper<KeyType>*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename A, typename KeyType>
|
||||
inline bool group_equals(
|
||||
BOOST_UNORDERED_TABLE_DATA<A>*,
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr it1,
|
||||
typename BOOST_UNORDERED_TABLE_DATA<A>::link_ptr it2,
|
||||
KeyType*,
|
||||
void*)
|
||||
{
|
||||
typedef BOOST_UNORDERED_TABLE_DATA<A> data;
|
||||
return data::get_value(it1).second == data::get_value(it2).second;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename V, typename K, typename H, typename P, typename A>
|
||||
bool equals(BOOST_UNORDERED_TABLE<V, K, H, P, A> const& t1,
|
||||
BOOST_UNORDERED_TABLE<V, K, H, P, A> const& t2)
|
||||
{
|
||||
typedef BOOST_UNORDERED_TABLE_DATA<A> data;
|
||||
typedef typename data::bucket_ptr bucket_ptr;
|
||||
typedef typename data::link_ptr link_ptr;
|
||||
|
||||
if(t1.size() != t2.size()) return false;
|
||||
|
||||
for(bucket_ptr i = t1.data_.cached_begin_bucket_,
|
||||
j = t1.data_.buckets_end(); i != j; ++i)
|
||||
{
|
||||
for(link_ptr it(i->next_); BOOST_UNORDERED_BORLAND_BOOL(it); it = data::next_group(it))
|
||||
{
|
||||
link_ptr other_pos = t2.find_iterator(t2.extract_key(data::get_value(it)));
|
||||
if(!BOOST_UNORDERED_BORLAND_BOOL(other_pos) ||
|
||||
!group_equals((data*)0, it, other_pos, (K*)0, (type_wrapper<V>*)0))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Iterators
|
||||
|
||||
template <typename Alloc> class BOOST_UNORDERED_ITERATOR;
|
||||
|
@ -32,6 +32,34 @@ namespace boost
|
||||
class Hash = hash<Key>,
|
||||
class Pred = std::equal_to<Key>,
|
||||
class Alloc = std::allocator<std::pair<const Key, T> > >
|
||||
class unordered_map;
|
||||
template <class K, class T, class H, class P, class A>
|
||||
bool operator==(unordered_map<K, T, H, P, A> const&,
|
||||
unordered_map<K, T, H, P, A> const&);
|
||||
template <class K, class T, class H, class P, class A>
|
||||
bool operator!=(unordered_map<K, T, H, P, A> const&,
|
||||
unordered_map<K, T, H, P, A> const&);
|
||||
template <class K, class T, class H, class P, class A>
|
||||
void swap(unordered_map<K, T, H, P, A>&,
|
||||
unordered_map<K, T, H, P, A>&);
|
||||
|
||||
template <class Key,
|
||||
class T,
|
||||
class Hash = hash<Key>,
|
||||
class Pred = std::equal_to<Key>,
|
||||
class Alloc = std::allocator<std::pair<const Key, T> > >
|
||||
class unordered_multimap;
|
||||
template <class K, class T, class H, class P, class A>
|
||||
bool operator==(unordered_multimap<K, T, H, P, A> const&,
|
||||
unordered_multimap<K, T, H, P, A> const&);
|
||||
template <class K, class T, class H, class P, class A>
|
||||
bool operator!=(unordered_multimap<K, T, H, P, A> const&,
|
||||
unordered_multimap<K, T, H, P, A> const&);
|
||||
template <class K, class T, class H, class P, class A>
|
||||
void swap(unordered_multimap<K, T, H, P, A>&,
|
||||
unordered_multimap<K, T, H, P, A>&);
|
||||
|
||||
template <class Key, class T, class Hash, class Pred, class Alloc>
|
||||
class unordered_map
|
||||
{
|
||||
typedef boost::unordered_detail::hash_types_unique_keys<
|
||||
@ -75,8 +103,7 @@ namespace boost
|
||||
{
|
||||
}
|
||||
|
||||
// TODO: Should this be explicit?
|
||||
unordered_map(allocator_type const& a)
|
||||
explicit unordered_map(allocator_type const& a)
|
||||
: base(boost::unordered_detail::default_initial_bucket_count,
|
||||
hasher(), key_equal(), a)
|
||||
{
|
||||
@ -122,7 +149,7 @@ namespace boost
|
||||
}
|
||||
#else
|
||||
unordered_map(boost::unordered_detail::move_from<unordered_map<Key, T, Hash, Pred, Alloc> > other)
|
||||
: base(other.base, boost::unordered_detail::move_tag())
|
||||
: base(other.source.base, boost::unordered_detail::move_tag())
|
||||
{
|
||||
}
|
||||
|
||||
@ -390,34 +417,37 @@ namespace boost
|
||||
base.rehash(n);
|
||||
}
|
||||
|
||||
friend bool operator==(unordered_map const& m1, unordered_map const& m2)
|
||||
{
|
||||
return m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend bool operator!=(unordered_map const& m1, unordered_map const& m2)
|
||||
{
|
||||
return !m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend std::size_t hash_value(unordered_map const& m)
|
||||
{
|
||||
return m.base.hash_value();
|
||||
}
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
friend bool operator==(unordered_map const&, unordered_map const&);
|
||||
friend bool operator!=(unordered_map const&, unordered_map const&);
|
||||
#else
|
||||
friend bool operator==<>(unordered_map const&, unordered_map const&);
|
||||
friend bool operator!=<>(unordered_map const&, unordered_map const&);
|
||||
#endif
|
||||
}; // class template unordered_map
|
||||
|
||||
template <class K, class T, class H, class P, class A>
|
||||
void swap(unordered_map<K, T, H, P, A> &m1,
|
||||
inline bool operator==(unordered_map<K, T, H, P, A> const& m1,
|
||||
unordered_map<K, T, H, P, A> const& m2)
|
||||
{
|
||||
return boost::unordered_detail::equals(m1.base, m2.base);
|
||||
}
|
||||
|
||||
template <class K, class T, class H, class P, class A>
|
||||
inline bool operator!=(unordered_map<K, T, H, P, A> const& m1,
|
||||
unordered_map<K, T, H, P, A> const& m2)
|
||||
{
|
||||
return !boost::unordered_detail::equals(m1.base, m2.base);
|
||||
}
|
||||
|
||||
template <class K, class T, class H, class P, class A>
|
||||
inline void swap(unordered_map<K, T, H, P, A> &m1,
|
||||
unordered_map<K, T, H, P, A> &m2)
|
||||
{
|
||||
m1.swap(m2);
|
||||
}
|
||||
|
||||
template <class Key,
|
||||
class T,
|
||||
class Hash = hash<Key>,
|
||||
class Pred = std::equal_to<Key>,
|
||||
class Alloc = std::allocator<std::pair<const Key, T> > >
|
||||
template <class Key, class T, class Hash, class Pred, class Alloc>
|
||||
class unordered_multimap
|
||||
{
|
||||
typedef boost::unordered_detail::hash_types_equivalent_keys<
|
||||
@ -461,7 +491,7 @@ namespace boost
|
||||
{
|
||||
}
|
||||
|
||||
unordered_multimap(allocator_type const& a)
|
||||
explicit unordered_multimap(allocator_type const& a)
|
||||
: base(boost::unordered_detail::default_initial_bucket_count,
|
||||
hasher(), key_equal(), a)
|
||||
{
|
||||
@ -507,7 +537,7 @@ namespace boost
|
||||
}
|
||||
#else
|
||||
unordered_multimap(boost::unordered_detail::move_from<unordered_multimap<Key, T, Hash, Pred, Alloc> > other)
|
||||
: base(other.base, boost::unordered_detail::move_tag())
|
||||
: base(other.source.base, boost::unordered_detail::move_tag())
|
||||
{
|
||||
}
|
||||
|
||||
@ -759,24 +789,31 @@ namespace boost
|
||||
base.rehash(n);
|
||||
}
|
||||
|
||||
friend bool operator==(unordered_multimap const& m1, unordered_multimap const& m2)
|
||||
{
|
||||
return m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend bool operator!=(unordered_multimap const& m1, unordered_multimap const& m2)
|
||||
{
|
||||
return !m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend std::size_t hash_value(unordered_multimap const& m)
|
||||
{
|
||||
return m.base.hash_value();
|
||||
}
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
friend bool operator==(unordered_multimap const&, unordered_multimap const&);
|
||||
friend bool operator!=(unordered_multimap const&, unordered_multimap const&);
|
||||
#else
|
||||
friend bool operator==<>(unordered_multimap const&, unordered_multimap const&);
|
||||
friend bool operator!=<>(unordered_multimap const&, unordered_multimap const&);
|
||||
#endif
|
||||
}; // class template unordered_multimap
|
||||
|
||||
template <class K, class T, class H, class P, class A>
|
||||
void swap(unordered_multimap<K, T, H, P, A> &m1,
|
||||
inline bool operator==(unordered_multimap<K, T, H, P, A> const& m1,
|
||||
unordered_multimap<K, T, H, P, A> const& m2)
|
||||
{
|
||||
return boost::unordered_detail::equals(m1.base, m2.base);
|
||||
}
|
||||
|
||||
template <class K, class T, class H, class P, class A>
|
||||
inline bool operator!=(unordered_multimap<K, T, H, P, A> const& m1,
|
||||
unordered_multimap<K, T, H, P, A> const& m2)
|
||||
{
|
||||
return !boost::unordered_detail::equals(m1.base, m2.base);
|
||||
}
|
||||
|
||||
template <class K, class T, class H, class P, class A>
|
||||
inline void swap(unordered_multimap<K, T, H, P, A> &m1,
|
||||
unordered_multimap<K, T, H, P, A> &m2)
|
||||
{
|
||||
m1.swap(m2);
|
||||
|
@ -31,6 +31,33 @@ namespace boost
|
||||
class Hash = hash<Value>,
|
||||
class Pred = std::equal_to<Value>,
|
||||
class Alloc = std::allocator<Value> >
|
||||
class unordered_set;
|
||||
template <class T, class H, class P, class A>
|
||||
bool operator==(unordered_set<T, H, P, A> const&,
|
||||
unordered_set<T, H, P, A> const&);
|
||||
template <class T, class H, class P, class A>
|
||||
bool operator!=(unordered_set<T, H, P, A> const&,
|
||||
unordered_set<T, H, P, A> const&);
|
||||
template <class T, class H, class P, class A>
|
||||
void swap(unordered_set<T, H, P, A> &m1,
|
||||
unordered_set<T, H, P, A> &m2);
|
||||
|
||||
template <class Value,
|
||||
class Hash = hash<Value>,
|
||||
class Pred = std::equal_to<Value>,
|
||||
class Alloc = std::allocator<Value> >
|
||||
class unordered_multiset;
|
||||
template <class T, class H, class P, class A>
|
||||
bool operator==(unordered_multiset<T, H, P, A> const&,
|
||||
unordered_multiset<T, H, P, A> const&);
|
||||
template <class T, class H, class P, class A>
|
||||
bool operator!=(unordered_multiset<T, H, P, A> const&,
|
||||
unordered_multiset<T, H, P, A> const&);
|
||||
template <class T, class H, class P, class A>
|
||||
void swap(unordered_multiset<T, H, P, A> &m1,
|
||||
unordered_multiset<T, H, P, A> &m2);
|
||||
|
||||
template <class Value, class Hash, class Pred, class Alloc>
|
||||
class unordered_set
|
||||
{
|
||||
typedef boost::unordered_detail::hash_types_unique_keys<
|
||||
@ -73,8 +100,7 @@ namespace boost
|
||||
{
|
||||
}
|
||||
|
||||
// TODO: Should this be explicit?
|
||||
unordered_set(allocator_type const& a)
|
||||
explicit unordered_set(allocator_type const& a)
|
||||
: base(boost::unordered_detail::default_initial_bucket_count,
|
||||
hasher(), key_equal(), a)
|
||||
{
|
||||
@ -119,7 +145,7 @@ namespace boost
|
||||
}
|
||||
#else
|
||||
unordered_set(boost::unordered_detail::move_from<unordered_set<Value, Hash, Pred, Alloc> > other)
|
||||
: base(other.base, boost::unordered_detail::move_tag())
|
||||
: base(other.source.base, boost::unordered_detail::move_tag())
|
||||
{
|
||||
}
|
||||
|
||||
@ -361,33 +387,37 @@ namespace boost
|
||||
base.rehash(n);
|
||||
}
|
||||
|
||||
friend bool operator==(unordered_set const& m1, unordered_set const& m2)
|
||||
{
|
||||
return m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend bool operator!=(unordered_set const& m1, unordered_set const& m2)
|
||||
{
|
||||
return !m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend std::size_t hash_value(unordered_set const& m)
|
||||
{
|
||||
return m.base.hash_value();
|
||||
}
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
friend bool operator==(unordered_set const&, unordered_set const&);
|
||||
friend bool operator!=(unordered_set const&, unordered_set const&);
|
||||
#else
|
||||
friend bool operator==<>(unordered_set const&, unordered_set const&);
|
||||
friend bool operator!=<>(unordered_set const&, unordered_set const&);
|
||||
#endif
|
||||
}; // class template unordered_set
|
||||
|
||||
template <class T, class H, class P, class A>
|
||||
void swap(unordered_set<T, H, P, A> &m1,
|
||||
inline bool operator==(unordered_set<T, H, P, A> const& m1,
|
||||
unordered_set<T, H, P, A> const& m2)
|
||||
{
|
||||
return boost::unordered_detail::equals(m1.base, m2.base);
|
||||
}
|
||||
|
||||
template <class T, class H, class P, class A>
|
||||
inline bool operator!=(unordered_set<T, H, P, A> const& m1,
|
||||
unordered_set<T, H, P, A> const& m2)
|
||||
{
|
||||
return !boost::unordered_detail::equals(m1.base, m2.base);
|
||||
}
|
||||
|
||||
template <class T, class H, class P, class A>
|
||||
inline void swap(unordered_set<T, H, P, A> &m1,
|
||||
unordered_set<T, H, P, A> &m2)
|
||||
{
|
||||
m1.swap(m2);
|
||||
}
|
||||
|
||||
template <class Value,
|
||||
class Hash = hash<Value>,
|
||||
class Pred = std::equal_to<Value>,
|
||||
class Alloc = std::allocator<Value> >
|
||||
template <class Value, class Hash, class Pred, class Alloc>
|
||||
class unordered_multiset
|
||||
{
|
||||
typedef boost::unordered_detail::hash_types_equivalent_keys<
|
||||
@ -430,8 +460,7 @@ namespace boost
|
||||
{
|
||||
}
|
||||
|
||||
// TODO: Should this be explicit?
|
||||
unordered_multiset(allocator_type const& a)
|
||||
explicit unordered_multiset(allocator_type const& a)
|
||||
: base(boost::unordered_detail::default_initial_bucket_count,
|
||||
hasher(), key_equal(), a)
|
||||
{
|
||||
@ -476,7 +505,7 @@ namespace boost
|
||||
}
|
||||
#else
|
||||
unordered_multiset(boost::unordered_detail::move_from<unordered_multiset<Value, Hash, Pred, Alloc> > other)
|
||||
: base(other.base, boost::unordered_detail::move_tag())
|
||||
: base(other.source.base, boost::unordered_detail::move_tag())
|
||||
{
|
||||
}
|
||||
|
||||
@ -715,24 +744,31 @@ namespace boost
|
||||
base.rehash(n);
|
||||
}
|
||||
|
||||
friend bool operator==(unordered_multiset const& m1, unordered_multiset const& m2)
|
||||
{
|
||||
return m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend bool operator!=(unordered_multiset const& m1, unordered_multiset const& m2)
|
||||
{
|
||||
return !m1.base.equals(m2.base);
|
||||
}
|
||||
|
||||
friend std::size_t hash_value(unordered_multiset const& m)
|
||||
{
|
||||
return m.base.hash_value();
|
||||
}
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
||||
friend bool operator==(unordered_multiset const&, unordered_multiset const&);
|
||||
friend bool operator!=(unordered_multiset const&, unordered_multiset const&);
|
||||
#else
|
||||
friend bool operator==<>(unordered_multiset const&, unordered_multiset const&);
|
||||
friend bool operator!=<>(unordered_multiset const&, unordered_multiset const&);
|
||||
#endif
|
||||
}; // class template unordered_multiset
|
||||
|
||||
template <class T, class H, class P, class A>
|
||||
void swap(unordered_multiset<T, H, P, A> &m1,
|
||||
inline bool operator==(unordered_multiset<T, H, P, A> const& m1,
|
||||
unordered_multiset<T, H, P, A> const& m2)
|
||||
{
|
||||
return boost::unordered_detail::equals(m1.base, m2.base);
|
||||
}
|
||||
|
||||
template <class T, class H, class P, class A>
|
||||
inline bool operator!=(unordered_multiset<T, H, P, A> const& m1,
|
||||
unordered_multiset<T, H, P, A> const& m2)
|
||||
{
|
||||
return !boost::unordered_detail::equals(m1.base, m2.base);
|
||||
}
|
||||
|
||||
template <class T, class H, class P, class A>
|
||||
inline void swap(unordered_multiset<T, H, P, A> &m1,
|
||||
unordered_multiset<T, H, P, A> &m2)
|
||||
{
|
||||
m1.swap(m2);
|
||||
|
@ -53,6 +53,11 @@ namespace test {
|
||||
struct globally_counted_object
|
||||
: counted_object<globally_counted_object> {};
|
||||
|
||||
// This won't be a problem as I'm only using a single compile unit
|
||||
// in each test (this is actually require by the minimal test
|
||||
// framework).
|
||||
//
|
||||
// boostinspect:nounnamed
|
||||
namespace {
|
||||
object_count& global_object_count = globally_counted_object::count_;
|
||||
}
|
||||
|
@ -44,6 +44,11 @@ namespace test
|
||||
}
|
||||
};
|
||||
|
||||
// This won't be a problem as I'm only using a single compile unit
|
||||
// in each test (this is actually require by the minimal test
|
||||
// framework).
|
||||
//
|
||||
// boostinspect:nounnamed
|
||||
namespace {
|
||||
equivalent_type equivalent;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <new>
|
||||
#include "../helpers/fwd.hpp"
|
||||
#include "../helpers/allocator.hpp"
|
||||
#include "./memory.hpp"
|
||||
#include "../helpers/memory.hpp"
|
||||
|
||||
namespace test
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include <iostream>
|
||||
#include "../helpers/fwd.hpp"
|
||||
#include "../helpers/count.hpp"
|
||||
#include "./memory.hpp"
|
||||
#include "../helpers/memory.hpp"
|
||||
#include <map>
|
||||
|
||||
namespace test
|
||||
@ -156,6 +156,11 @@ namespace test
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// This won't be a problem as I'm only using a single compile unit
|
||||
// in each test (this is actually require by the minimal test
|
||||
// framework).
|
||||
//
|
||||
// boostinspect:nounnamed
|
||||
namespace {
|
||||
test::detail::memory_tracker<std::allocator<int> > tracker;
|
||||
}
|
||||
|
@ -13,6 +13,21 @@
|
||||
#include "../objects/minimal.hpp"
|
||||
#include "./compile_tests.hpp"
|
||||
|
||||
// Explicit instantiation to catch compile-time errors
|
||||
|
||||
template class boost::unordered_map<
|
||||
test::minimal::assignable,
|
||||
test::minimal::default_copy_constructible,
|
||||
test::minimal::hash<test::minimal::assignable>,
|
||||
test::minimal::equal_to<test::minimal::assignable>,
|
||||
test::minimal::allocator<test::minimal::assignable> >;
|
||||
template class boost::unordered_multimap<
|
||||
test::minimal::assignable,
|
||||
test::minimal::copy_constructible,
|
||||
test::minimal::hash<test::minimal::assignable>,
|
||||
test::minimal::equal_to<test::minimal::assignable>,
|
||||
test::minimal::allocator<test::minimal::assignable> >;
|
||||
|
||||
UNORDERED_AUTO_TEST(test0)
|
||||
{
|
||||
typedef std::pair<test::minimal::assignable const,
|
||||
|
@ -13,6 +13,19 @@
|
||||
#include "../objects/minimal.hpp"
|
||||
#include "./compile_tests.hpp"
|
||||
|
||||
// Explicit instantiation to catch compile-time errors
|
||||
|
||||
template class boost::unordered_set<
|
||||
test::minimal::assignable,
|
||||
test::minimal::hash<test::minimal::assignable>,
|
||||
test::minimal::equal_to<test::minimal::assignable>,
|
||||
test::minimal::allocator<test::minimal::assignable> >;
|
||||
template class boost::unordered_multiset<
|
||||
test::minimal::assignable,
|
||||
test::minimal::hash<test::minimal::assignable>,
|
||||
test::minimal::equal_to<test::minimal::assignable>,
|
||||
test::minimal::allocator<test::minimal::assignable> >;
|
||||
|
||||
UNORDERED_AUTO_TEST(test0)
|
||||
{
|
||||
test::minimal::assignable assignable = test::minimal::assignable::create();
|
||||
|
@ -168,11 +168,6 @@ void equality_test(X& r)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
template <class X, class T>
|
||||
|
@ -25,118 +25,118 @@ namespace equality_tests
|
||||
};
|
||||
|
||||
#define UNORDERED_EQUALITY_SET_TEST(seq1, op, seq2) \
|
||||
do { \
|
||||
boost::unordered_set<int, mod_compare, mod_compare> set1, set2; \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set1, seq1) \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set2, seq2) \
|
||||
BOOST_CHECK(set1 op set2); \
|
||||
} while(false)
|
||||
do { \
|
||||
boost::unordered_set<int, mod_compare, mod_compare> set1, set2; \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set1, seq1) \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set2, seq2) \
|
||||
BOOST_CHECK(set1 op set2); \
|
||||
} while(false)
|
||||
|
||||
#define UNORDERED_EQUALITY_MULTISET_TEST(seq1, op, seq2) \
|
||||
do { \
|
||||
boost::unordered_multiset<int, mod_compare, mod_compare> set1, set2; \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set1, seq1) \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set2, seq2) \
|
||||
BOOST_CHECK(set1 op set2); \
|
||||
} while(false)
|
||||
do { \
|
||||
boost::unordered_multiset<int, mod_compare, mod_compare> set1, set2; \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set1, seq1) \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_SET_INSERT, set2, seq2) \
|
||||
BOOST_CHECK(set1 op set2); \
|
||||
} while(false)
|
||||
|
||||
#define UNORDERED_EQUALITY_MAP_TEST(seq1, op, seq2) \
|
||||
do { \
|
||||
boost::unordered_map<int, int, mod_compare, mod_compare> map1, map2; \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map1, seq1) \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map2, seq2) \
|
||||
BOOST_CHECK(map1 op map2); \
|
||||
} while(false)
|
||||
do { \
|
||||
boost::unordered_map<int, int, mod_compare, mod_compare> map1, map2; \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map1, seq1) \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map2, seq2) \
|
||||
BOOST_CHECK(map1 op map2); \
|
||||
} while(false)
|
||||
|
||||
#define UNORDERED_EQUALITY_MULTIMAP_TEST(seq1, op, seq2) \
|
||||
do { \
|
||||
boost::unordered_multimap<int, int, mod_compare, mod_compare> map1, map2; \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map1, seq1) \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map2, seq2) \
|
||||
BOOST_CHECK(map1 op map2); \
|
||||
} while(false)
|
||||
do { \
|
||||
boost::unordered_multimap<int, int, mod_compare, mod_compare> map1, map2; \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map1, seq1) \
|
||||
BOOST_PP_SEQ_FOR_EACH(UNORDERED_MAP_INSERT, map2, seq2) \
|
||||
BOOST_CHECK(map1 op map2); \
|
||||
} while(false)
|
||||
|
||||
#define UNORDERED_SET_INSERT(r, set, item) set.insert(item);
|
||||
#define UNORDERED_MAP_INSERT(r, map, item) \
|
||||
map.insert(std::pair<int const, int> BOOST_PP_SEQ_TO_TUPLE(item));
|
||||
map.insert(std::pair<int const, int> BOOST_PP_SEQ_TO_TUPLE(item));
|
||||
|
||||
UNORDERED_AUTO_TEST(equality_size_tests)
|
||||
{
|
||||
boost::unordered_set<int> x1, x2;
|
||||
BOOST_CHECK(x1 == x2);
|
||||
BOOST_CHECK(!(x1 != x2));
|
||||
UNORDERED_AUTO_TEST(equality_size_tests)
|
||||
{
|
||||
boost::unordered_set<int> x1, x2;
|
||||
BOOST_CHECK(x1 == x2);
|
||||
BOOST_CHECK(!(x1 != x2));
|
||||
|
||||
x1.insert(1);
|
||||
BOOST_CHECK(x1 != x2);
|
||||
BOOST_CHECK(!(x1 == x2));
|
||||
BOOST_CHECK(x2 != x1);
|
||||
BOOST_CHECK(!(x2 == x1));
|
||||
|
||||
x2.insert(1);
|
||||
BOOST_CHECK(x1 == x2);
|
||||
BOOST_CHECK(!(x1 != x2));
|
||||
|
||||
x2.insert(2);
|
||||
BOOST_CHECK(x1 != x2);
|
||||
BOOST_CHECK(!(x1 == x2));
|
||||
BOOST_CHECK(x2 != x1);
|
||||
BOOST_CHECK(!(x2 == x1));
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST(equality_key_value_tests)
|
||||
{
|
||||
UNORDERED_EQUALITY_MULTISET_TEST((1), !=, (2));
|
||||
UNORDERED_EQUALITY_SET_TEST((2), ==, (2));
|
||||
UNORDERED_EQUALITY_MAP_TEST(((1)(1))((2)(1)), !=, ((1)(1))((3)(1)));
|
||||
}
|
||||
|
||||
x1.insert(1);
|
||||
BOOST_CHECK(x1 != x2);
|
||||
BOOST_CHECK(!(x1 == x2));
|
||||
BOOST_CHECK(x2 != x1);
|
||||
BOOST_CHECK(!(x2 == x1));
|
||||
|
||||
x2.insert(1);
|
||||
BOOST_CHECK(x1 == x2);
|
||||
BOOST_CHECK(!(x1 != x2));
|
||||
|
||||
x2.insert(2);
|
||||
BOOST_CHECK(x1 != x2);
|
||||
BOOST_CHECK(!(x1 == x2));
|
||||
BOOST_CHECK(x2 != x1);
|
||||
BOOST_CHECK(!(x2 == x1));
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST(equality_key_value_tests)
|
||||
{
|
||||
UNORDERED_EQUALITY_MULTISET_TEST((1), !=, (2));
|
||||
UNORDERED_EQUALITY_SET_TEST((2), ==, (2));
|
||||
UNORDERED_EQUALITY_MAP_TEST(((1)(1))((2)(1)), !=, ((1)(1))((3)(1)));
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST(equality_collision_test)
|
||||
{
|
||||
UNORDERED_EQUALITY_MULTISET_TEST(
|
||||
(1), !=, (501));
|
||||
UNORDERED_EQUALITY_MULTISET_TEST(
|
||||
(1)(251), !=, (1)(501));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((251)(1))((1)(1)), !=, ((501)(1))((1)(1)));
|
||||
UNORDERED_EQUALITY_MULTISET_TEST(
|
||||
(1)(501), ==, (1)(501));
|
||||
UNORDERED_EQUALITY_SET_TEST(
|
||||
(1)(501), ==, (501)(1));
|
||||
UNORDERED_EQUALITY_MULTISET_TEST(
|
||||
(1), !=, (501));
|
||||
UNORDERED_EQUALITY_MULTISET_TEST(
|
||||
(1)(251), !=, (1)(501));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((251)(1))((1)(1)), !=, ((501)(1))((1)(1)));
|
||||
UNORDERED_EQUALITY_MULTISET_TEST(
|
||||
(1)(501), ==, (1)(501));
|
||||
UNORDERED_EQUALITY_SET_TEST(
|
||||
(1)(501), ==, (501)(1));
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST(equality_group_size_test)
|
||||
{
|
||||
UNORDERED_EQUALITY_MULTISET_TEST(
|
||||
(10)(20)(20), !=, (10)(10)(20));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((10)(1))((20)(1))((20)(1)), !=,
|
||||
((10)(1))((20)(1))((10)(1)));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((20)(1))((10)(1))((10)(1)), ==,
|
||||
((10)(1))((20)(1))((10)(1)));
|
||||
UNORDERED_AUTO_TEST(equality_group_size_test)
|
||||
{
|
||||
UNORDERED_EQUALITY_MULTISET_TEST(
|
||||
(10)(20)(20), !=, (10)(10)(20));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((10)(1))((20)(1))((20)(1)), !=,
|
||||
((10)(1))((20)(1))((10)(1)));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((20)(1))((10)(1))((10)(1)), ==,
|
||||
((10)(1))((20)(1))((10)(1)));
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST(equality_map_value_test)
|
||||
{
|
||||
UNORDERED_EQUALITY_MAP_TEST(
|
||||
((1)(1)), !=, ((1)(2)));
|
||||
UNORDERED_EQUALITY_MAP_TEST(
|
||||
((1)(1)), ==, ((1)(1)));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((1)(1)), !=, ((1)(2)));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((1)(1))((1)(1)), !=, ((1)(1))((1)(2)));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((1)(2))((1)(1)), !=, ((1)(1))((1)(2)));
|
||||
}
|
||||
UNORDERED_EQUALITY_MAP_TEST(
|
||||
((1)(1)), !=, ((1)(2)));
|
||||
UNORDERED_EQUALITY_MAP_TEST(
|
||||
((1)(1)), ==, ((1)(1)));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((1)(1)), !=, ((1)(2)));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((1)(1))((1)(1)), !=, ((1)(1))((1)(2)));
|
||||
UNORDERED_EQUALITY_MULTIMAP_TEST(
|
||||
((1)(2))((1)(1)), !=, ((1)(1))((1)(2)));
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST(equality_predicate_test)
|
||||
{
|
||||
UNORDERED_EQUALITY_SET_TEST(
|
||||
(1), ==, (1001));
|
||||
UNORDERED_EQUALITY_MAP_TEST(
|
||||
((1)(2))((1001)(1)), ==, ((1001)(2))((1)(1)));
|
||||
}
|
||||
UNORDERED_EQUALITY_SET_TEST(
|
||||
(1), ==, (1001));
|
||||
UNORDERED_EQUALITY_MAP_TEST(
|
||||
((1)(2))((1001)(1)), ==, ((1001)(2))((1)(1)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -84,12 +84,11 @@ namespace unnecessary_copy_tests
|
||||
template <class T>
|
||||
void unnecessary_copy_insert_test(T*)
|
||||
{
|
||||
reset();
|
||||
T x;
|
||||
BOOST_DEDUCED_TYPENAME T::value_type a;
|
||||
COPY_COUNT(1);
|
||||
reset();
|
||||
x.insert(a);
|
||||
COPY_COUNT(2);
|
||||
COPY_COUNT(1);
|
||||
}
|
||||
|
||||
boost::unordered_set<count_copies>* set;
|
||||
|
Reference in New Issue
Block a user