Unordered: Implement reserve. Refs #6857.

[SVN r78365]
This commit is contained in:
Daniel James
2012-05-07 10:58:32 +00:00
parent 275b03e76b
commit 32dc45b7bd
7 changed files with 133 additions and 2 deletions
+12 -2
View File
@@ -387,6 +387,7 @@ namespace boost { namespace unordered { namespace detail {
void reserve_for_insert(std::size_t);
void rehash(std::size_t);
void reserve(std::size_t);
};
////////////////////////////////////////////////////////////////////////////
@@ -402,7 +403,9 @@ namespace boost { namespace unordered { namespace detail {
this->create_buckets();
this->max_load_ = this->calculate_max_load();
}
else if(size >= max_load_) {
// According to the standard this should be 'size >= max_load_',
// but I think this is better, defect report filed.
else if(size > max_load_) {
std::size_t num_buckets
= this->min_buckets_for_size((std::max)(size,
this->size_ + (this->size_ >> 1)));
@@ -417,7 +420,7 @@ namespace boost { namespace unordered { namespace detail {
// strong otherwise.
template <typename Types>
void table<Types>::rehash(std::size_t min_buckets)
inline void table<Types>::rehash(std::size_t min_buckets)
{
using namespace std;
@@ -437,6 +440,13 @@ namespace boost { namespace unordered { namespace detail {
}
}
}
template <typename Types>
inline void table<Types>::reserve(std::size_t num_elements)
{
rehash(static_cast<std::size_t>(
std::ceil(static_cast<double>(num_elements) / this->mlf_)));
}
}}}
#endif