2006-05-17 17:19:16 +00:00
|
|
|
|
Merge hash and unordered changes.
Remove deprecated headers, move hash_fwd.hpp into hash subdirectory. And
several minor internal changes.
Mostly minor internal details.
Merged revisions 51262-51263,51407-51409,51504-51505,51644-51646,51667 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r51262 | danieljames | 2009-02-15 19:32:04 +0000 (Sun, 15 Feb 2009) | 1 line
Use the new 'boost:' links for the hash, unordered and quickbook documentation.
........
r51263 | danieljames | 2009-02-15 19:32:19 +0000 (Sun, 15 Feb 2009) | 2 lines
Don't copy images for the standalone hash and unordered documentation, was only
really required before the libraries were integrated into boost.
........
r51407 | danieljames | 2009-02-22 23:49:51 +0000 (Sun, 22 Feb 2009) | 1 line
Fix the hash dirname.
........
r51408 | danieljames | 2009-02-22 23:50:04 +0000 (Sun, 22 Feb 2009) | 1 line
Make copy_buckets and move_buckets member functions - so that calling them is a bit simpler.
........
r51409 | danieljames | 2009-02-22 23:50:20 +0000 (Sun, 22 Feb 2009) | 1 line
Move some of the data structure classes out of hash table data.
........
r51504 | danieljames | 2009-03-01 14:15:09 +0000 (Sun, 01 Mar 2009) | 1 line
Add missing return for operator=.
........
r51505 | danieljames | 2009-03-01 14:15:39 +0000 (Sun, 01 Mar 2009) | 3 lines
Make the sort stable.
Doesn't really matter, but it might as well be.
........
r51644 | danieljames | 2009-03-08 09:44:51 +0000 (Sun, 08 Mar 2009) | 1 line
Detab.
........
r51645 | danieljames | 2009-03-08 09:45:11 +0000 (Sun, 08 Mar 2009) | 4 lines
Move hash_fwd into the hash subdirectory.
I should have done this in the last release. But now all of the hash
implementation is in the hash subdirectory.
........
r51646 | danieljames | 2009-03-08 09:45:30 +0000 (Sun, 08 Mar 2009) | 3 lines
Remove deprecated headers.
Fixes #2412.
........
r51667 | danieljames | 2009-03-09 20:56:23 +0000 (Mon, 09 Mar 2009) | 1 line
Update copyright dates in hash and unordered.
........
[SVN r51729]
2009-03-11 22:51:09 +00:00
|
|
|
// Copyright 2006-2009 Daniel James.
|
2006-07-01 22:31:26 +00:00
|
|
|
// 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)
|
2006-05-17 17:19:16 +00:00
|
|
|
|
|
|
|
|
// This header contains metafunctions/functions to get the equivalent
|
|
|
|
|
// associative container for an unordered container, and compare the contents.
|
|
|
|
|
|
|
|
|
|
#if !defined(BOOST_UNORDERED_TEST_HELPERS_INVARIANT_HEADER)
|
|
|
|
|
#define BOOST_UNORDERED_TEST_HELPERS_INVARIANT_HEADER
|
|
|
|
|
|
|
|
|
|
#include <set>
|
2006-06-12 23:30:46 +00:00
|
|
|
#include <cmath>
|
2006-05-17 17:19:16 +00:00
|
|
|
#include "./metafunctions.hpp"
|
|
|
|
|
#include "./helpers.hpp"
|
2007-07-01 11:54:22 +00:00
|
|
|
#include "./allocator.hpp"
|
2006-05-17 17:19:16 +00:00
|
|
|
|
2007-08-14 09:55:30 +00:00
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
|
#pragma warning(push)
|
2010-01-08 05:39:54 +00:00
|
|
|
#pragma warning(disable:4127) // conditional expression is constant
|
|
|
|
|
#pragma warning(disable:4267) // conversion from 'size_t' to 'unsigned int',
|
|
|
|
|
// possible loss of data
|
2007-08-14 09:55:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
2006-05-17 17:19:16 +00:00
|
|
|
namespace test
|
|
|
|
|
{
|
|
|
|
|
template <class X>
|
|
|
|
|
void check_equivalent_keys(X const& x1)
|
|
|
|
|
{
|
2008-01-10 22:30:46 +00:00
|
|
|
BOOST_DEDUCED_TYPENAME X::key_equal eq = x1.key_eq();
|
|
|
|
|
typedef BOOST_DEDUCED_TYPENAME X::key_type key_type;
|
2007-07-01 11:16:57 +00:00
|
|
|
// Boost.Test was reporting memory leaks for std::set on g++-3.3.
|
|
|
|
|
// So I work around it by using malloc.
|
2010-01-08 05:39:54 +00:00
|
|
|
std::set<key_type, std::less<key_type>,
|
|
|
|
|
test::malloc_allocator<key_type> > found_;
|
2006-05-17 17:19:16 +00:00
|
|
|
|
2010-01-08 05:39:54 +00:00
|
|
|
BOOST_DEDUCED_TYPENAME X::const_iterator
|
|
|
|
|
it = x1.begin(), end = x1.end();
|
2008-01-10 22:30:46 +00:00
|
|
|
BOOST_DEDUCED_TYPENAME X::size_type size = 0;
|
2006-05-17 17:19:16 +00:00
|
|
|
while(it != end) {
|
|
|
|
|
// First test that the current key has not occured before, required
|
|
|
|
|
// to test either that keys are unique or that equivalent keys are
|
|
|
|
|
// adjacent. (6.3.1/6)
|
|
|
|
|
key_type key = get_key<X>(*it);
|
2007-07-01 11:54:22 +00:00
|
|
|
if(!found_.insert(key).second)
|
2006-05-17 17:19:16 +00:00
|
|
|
BOOST_ERROR("Elements with equivalent keys aren't adjacent.");
|
|
|
|
|
|
|
|
|
|
// Iterate over equivalent keys, counting them.
|
|
|
|
|
unsigned int count = 0;
|
|
|
|
|
do {
|
|
|
|
|
++it;
|
|
|
|
|
++count;
|
|
|
|
|
++size;
|
|
|
|
|
} while(it != end && eq(get_key<X>(*it), key));
|
|
|
|
|
|
|
|
|
|
// If the container has unique keys, test that there's only one.
|
|
|
|
|
// Since the previous test makes sure that all equivalent keys are
|
|
|
|
|
// adjacent, this is all the equivalent keys - so the test is
|
|
|
|
|
// sufficient. (6.3.1/6 again).
|
|
|
|
|
if(test::has_unique_keys<X>::value && count != 1)
|
|
|
|
|
BOOST_ERROR("Non-unique key.");
|
|
|
|
|
|
2006-10-31 22:19:26 +00:00
|
|
|
if(x1.count(key) != count) {
|
2006-05-17 17:19:16 +00:00
|
|
|
BOOST_ERROR("Incorrect output of count.");
|
2006-10-31 22:19:26 +00:00
|
|
|
std::cerr<<x1.count(key)<<","<<count<<"\n";
|
|
|
|
|
}
|
2006-05-17 17:19:16 +00:00
|
|
|
|
2006-05-21 17:14:11 +00:00
|
|
|
// I'm not bothering with the following test for now, as the
|
|
|
|
|
// previous test is probably more enough to catch the kind of
|
|
|
|
|
// errors that this would catch (if an element was in the wrong
|
|
|
|
|
// bucket it not be found by the call to count, if elements are not
|
|
|
|
|
// adjacent then they would be caught when checking against
|
|
|
|
|
// found_.
|
|
|
|
|
|
|
|
|
|
// // Check that the keys are in the correct bucket and are
|
|
|
|
|
// // adjacent in the bucket.
|
2008-01-10 22:30:46 +00:00
|
|
|
// BOOST_DEDUCED_TYPENAME X::size_type bucket = x1.bucket(key);
|
2010-01-08 05:39:54 +00:00
|
|
|
// BOOST_DEDUCED_TYPENAME X::const_local_iterator
|
|
|
|
|
// lit = x1.begin(bucket), lend = x1.end(bucket);
|
2006-05-21 17:14:11 +00:00
|
|
|
// for(; lit != lend && !eq(get_key<X>(*lit), key); ++lit) continue;
|
|
|
|
|
// if(lit == lend)
|
|
|
|
|
// BOOST_ERROR("Unable to find element with a local_iterator");
|
|
|
|
|
// unsigned int count2 = 0;
|
|
|
|
|
// for(; lit != lend && eq(get_key<X>(*lit), key); ++lit) ++count2;
|
|
|
|
|
// if(count != count2)
|
|
|
|
|
// BOOST_ERROR("Element count doesn't match local_iterator.");
|
|
|
|
|
// for(; lit != lend; ++lit) {
|
|
|
|
|
// if(eq(get_key<X>(*lit), key)) {
|
2010-01-08 05:39:54 +00:00
|
|
|
// BOOST_ERROR("Non-adjacent element with equivalent key "
|
|
|
|
|
// "in bucket.");
|
2006-05-21 17:14:11 +00:00
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2006-05-17 17:19:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Finally, check that size matches up.
|
|
|
|
|
if(x1.size() != size)
|
|
|
|
|
BOOST_ERROR("x1.size() doesn't match actual size.");
|
2010-01-08 05:39:54 +00:00
|
|
|
float load_factor =
|
|
|
|
|
static_cast<float>(size) / static_cast<float>(x1.bucket_count());
|
2006-06-12 23:30:46 +00:00
|
|
|
using namespace std;
|
|
|
|
|
if(fabs(x1.load_factor() - load_factor) > x1.load_factor() / 64)
|
2006-05-17 17:19:16 +00:00
|
|
|
BOOST_ERROR("x1.load_factor() doesn't match actual load_factor.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-14 09:55:30 +00:00
|
|
|
#if defined(BOOST_MSVC)
|
|
|
|
|
#pragma warning(pop)
|
|
|
|
|
#endif
|
|
|
|
|
|
2006-05-17 17:19:16 +00:00
|
|
|
#endif
|
|
|
|
|
|