mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-31 11:57:15 +02:00
Remove use of compressed_pair for unordered containers.
Put a lower bound on the maximum load factor. [SVN r2958]
This commit is contained in:
@@ -35,10 +35,6 @@
|
|||||||
|
|
||||||
#include <boost/mpl/aux_/config/eti.hpp>
|
#include <boost/mpl/aux_/config/eti.hpp>
|
||||||
|
|
||||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
|
||||||
#include <boost/compressed_pair.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// See hash_table::swap() for details about this.
|
// See hash_table::swap() for details about this.
|
||||||
#if !defined(BOOST_UNORDERED_SWAP_METHOD)
|
#if !defined(BOOST_UNORDERED_SWAP_METHOD)
|
||||||
#define BOOST_UNORDERED_SWAP_METHOD 3
|
#define BOOST_UNORDERED_SWAP_METHOD 3
|
||||||
@@ -65,6 +61,7 @@ namespace boost {
|
|||||||
template <class T> struct type_wrapper {};
|
template <class T> struct type_wrapper {};
|
||||||
|
|
||||||
const static std::size_t default_initial_bucket_count = 50;
|
const static std::size_t default_initial_bucket_count = 50;
|
||||||
|
const static float minimum_max_load_factor = 1e-3;
|
||||||
inline std::size_t next_prime(std::size_t n);
|
inline std::size_t next_prime(std::size_t n);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
@@ -73,7 +70,7 @@ namespace boost {
|
|||||||
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
||||||
std::swap(x,y);
|
std::swap(x,y);
|
||||||
#else
|
#else
|
||||||
using namespace std;
|
using std::swap;
|
||||||
swap(x, y);
|
swap(x, y);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@@ -1056,25 +1056,9 @@ namespace boost {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// From the compressed functions docs:
|
|
||||||
//
|
|
||||||
// "Finally, a word of caution for Visual C++ 6 users: if either
|
|
||||||
// argument is an empty type, then assigning to that member will
|
|
||||||
// produce memory corruption, unless the empty type has a "do
|
|
||||||
// nothing" assignment operator defined. This is due to a bug in
|
|
||||||
// the way VC6 generates implicit assignment operators."
|
|
||||||
//
|
|
||||||
// Nice.
|
|
||||||
//
|
|
||||||
// So use std::pair for Visual C++.
|
|
||||||
|
|
||||||
class functions
|
class functions
|
||||||
{
|
{
|
||||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
|
||||||
boost::compressed_pair<hasher, key_equal> functions_;
|
|
||||||
#else
|
|
||||||
std::pair<hasher, key_equal> functions_;
|
std::pair<hasher, key_equal> functions_;
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@@ -1083,20 +1067,12 @@ namespace boost {
|
|||||||
|
|
||||||
hasher const& hash_function() const
|
hasher const& hash_function() const
|
||||||
{
|
{
|
||||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
|
||||||
return functions_.first();
|
|
||||||
#else
|
|
||||||
return functions_.first;
|
return functions_.first;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
key_equal const& key_eq() const
|
key_equal const& key_eq() const
|
||||||
{
|
{
|
||||||
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
|
|
||||||
return functions_.second();
|
|
||||||
#else
|
|
||||||
return functions_.second;
|
return functions_.second;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1429,8 +1405,9 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
bool need_to_reserve = n >= max_load_;
|
bool need_to_reserve = n >= max_load_;
|
||||||
// throws - basic:
|
// throws - basic:
|
||||||
if (need_to_reserve) rehash_impl(min_buckets_for_size(n));
|
if (need_to_reserve) rehash_impl(min_buckets_for_size(n));
|
||||||
BOOST_ASSERT(n < max_load_);
|
// TODO: Deal with this special case better:
|
||||||
|
BOOST_ASSERT(n < max_load_ || this->bucket_count_ == max_bucket_count());
|
||||||
return need_to_reserve;
|
return need_to_reserve;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1443,13 +1420,10 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no throw
|
// no throw
|
||||||
//
|
|
||||||
// TODO: the argument is a hint. So don't use it if it's
|
|
||||||
// unreasonably small.
|
|
||||||
void max_load_factor(float z)
|
void max_load_factor(float z)
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(z > 0);
|
BOOST_ASSERT(z > 0);
|
||||||
mlf_ = z;
|
mlf_ = (std::max)(z, minimum_max_load_factor);
|
||||||
calculate_max_load();
|
calculate_max_load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user