Slightly more consistent variable names. In detail 'n' is now always a node pointer.

[SVN r56346]
This commit is contained in:
Daniel James
2009-09-21 21:17:19 +00:00
parent 78b078f41d
commit 965c2ae89c
7 changed files with 165 additions and 160 deletions

View File

@ -19,9 +19,9 @@ namespace boost { namespace unordered_detail {
template <class A, class G> template <class A, class G>
inline BOOST_DEDUCED_TYPENAME hash_buckets<A, G>::bucket_ptr inline BOOST_DEDUCED_TYPENAME hash_buckets<A, G>::bucket_ptr
hash_buckets<A, G>::get_bucket(std::size_t n) const hash_buckets<A, G>::get_bucket(std::size_t num) const
{ {
return buckets_ + static_cast<std::ptrdiff_t>(n); return buckets_ + static_cast<std::ptrdiff_t>(num);
} }
template <class A, class G> template <class A, class G>
@ -46,9 +46,9 @@ namespace boost { namespace unordered_detail {
template <class A, class G> template <class A, class G>
inline BOOST_DEDUCED_TYPENAME hash_buckets<A, G>::node_ptr inline BOOST_DEDUCED_TYPENAME hash_buckets<A, G>::node_ptr
hash_buckets<A, G>::bucket_begin(std::size_t n) const hash_buckets<A, G>::bucket_begin(std::size_t num) const
{ {
return buckets_ ? get_bucket(n)->next_ : node_ptr(); return buckets_ ? get_bucket(num)->next_ : node_ptr();
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -103,9 +103,9 @@ namespace boost { namespace unordered_detail {
{ {
std::size_t count = 0; std::size_t count = 0;
while(begin != end) { while(begin != end) {
node_ptr node = begin; node_ptr n = begin;
begin = begin->next_; begin = begin->next_;
delete_node(node); delete_node(n);
++count; ++count;
} }
return count; return count;

View File

@ -177,27 +177,27 @@ namespace boost { namespace unordered_detail {
#else #else
#define BOOST_UNORDERED_INSERT_IMPL(z, n, _) \ #define BOOST_UNORDERED_INSERT_IMPL(z, num_params, _) \
template <class H, class P, class A, class K> \ template <class H, class P, class A, class K> \
template <BOOST_UNORDERED_TEMPLATE_ARGS(z, n)> \ template <BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params)> \
BOOST_DEDUCED_TYPENAME hash_equivalent_table<H, P, A, K>::iterator_base \ BOOST_DEDUCED_TYPENAME hash_equivalent_table<H, P, A, K>::iterator_base \
hash_equivalent_table<H, P, A, K> \ hash_equivalent_table<H, P, A, K> \
::emplace(BOOST_UNORDERED_FUNCTION_PARAMS(z, n)) \ ::emplace(BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params)) \
{ \ { \
node_constructor a(*this); \ node_constructor a(*this); \
a.construct(BOOST_UNORDERED_CALL_PARAMS(z, n)); \ a.construct(BOOST_UNORDERED_CALL_PARAMS(z, num_params)); \
return emplace_impl(a); \ return emplace_impl(a); \
} \ } \
\ \
template <class H, class P, class A, class K> \ template <class H, class P, class A, class K> \
template <BOOST_UNORDERED_TEMPLATE_ARGS(z, n)> \ template <BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params)> \
BOOST_DEDUCED_TYPENAME hash_equivalent_table<H, P, A, K>::iterator_base \ BOOST_DEDUCED_TYPENAME hash_equivalent_table<H, P, A, K>::iterator_base \
hash_equivalent_table<H, P, A, K> \ hash_equivalent_table<H, P, A, K> \
::emplace_hint(iterator_base const& it, \ ::emplace_hint(iterator_base const& it, \
BOOST_UNORDERED_FUNCTION_PARAMS(z, n)) \ BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params)) \
{ \ { \
node_constructor a(*this); \ node_constructor a(*this); \
a.construct(BOOST_UNORDERED_CALL_PARAMS(z, n)); \ a.construct(BOOST_UNORDERED_CALL_PARAMS(z, num_params)); \
return emplace_hint_impl(it, a); \ return emplace_hint_impl(it, a); \
} }

View File

@ -50,12 +50,12 @@
#include <boost/preprocessor/repetition/enum_binary_params.hpp> #include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp> #include <boost/preprocessor/repetition/repeat_from_to.hpp>
#define BOOST_UNORDERED_TEMPLATE_ARGS(z, n) \ #define BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params) \
BOOST_PP_ENUM_PARAMS_Z(z, n, class Arg) BOOST_PP_ENUM_PARAMS_Z(z, num_params, class Arg)
#define BOOST_UNORDERED_FUNCTION_PARAMS(z, n) \ #define BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params) \
BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, Arg, const& arg) BOOST_PP_ENUM_BINARY_PARAMS_Z(z, num_params, Arg, const& arg)
#define BOOST_UNORDERED_CALL_PARAMS(z, n) \ #define BOOST_UNORDERED_CALL_PARAMS(z, num_params) \
BOOST_PP_ENUM_PARAMS_Z(z, n, arg) BOOST_PP_ENUM_PARAMS_Z(z, num_params, arg)
#endif #endif
@ -126,7 +126,7 @@ namespace boost { namespace unordered_detail {
static inline std::size_t group_count(node_ptr ptr); static inline std::size_t group_count(node_ptr ptr);
static inline void add_to_bucket(node_ptr n, bucket& b); static inline void add_to_bucket(node_ptr n, bucket& b);
static inline void add_after_node(node_ptr n, node_ptr position); static inline void add_after_node(node_ptr n, node_ptr position);
static void unlink_node(bucket& b, node_ptr node); static void unlink_node(bucket& b, node_ptr n);
static void unlink_nodes(bucket& b, node_ptr begin, node_ptr end); static void unlink_nodes(bucket& b, node_ptr begin, node_ptr end);
static void unlink_nodes(bucket& b, node_ptr end); static void unlink_nodes(bucket& b, node_ptr end);
}; };
@ -146,7 +146,7 @@ namespace boost { namespace unordered_detail {
static inline std::size_t group_count(node_ptr ptr); static inline std::size_t group_count(node_ptr ptr);
static inline void add_to_bucket(node_ptr n, bucket& b); static inline void add_to_bucket(node_ptr n, bucket& b);
static inline void add_after_node(node_ptr n, node_ptr position); static inline void add_after_node(node_ptr n, node_ptr position);
static void unlink_node(bucket& b, node_ptr node); static void unlink_node(bucket& b, node_ptr n);
static void unlink_nodes(bucket& b, node_ptr begin, node_ptr end); static void unlink_nodes(bucket& b, node_ptr begin, node_ptr end);
static void unlink_nodes(bucket& b, node_ptr end); static void unlink_nodes(bucket& b, node_ptr end);
@ -237,12 +237,12 @@ namespace boost { namespace unordered_detail {
return node::get_value(node_); return node::get_value(node_);
} }
void increment_bucket(node_ptr node) { void increment_bucket(node_ptr n) {
while(!node) { while(!n) {
++bucket_; ++bucket_;
node = bucket_->next_; n = bucket_->next_;
} }
node_ = bucket_ == node ? node_ptr() : node; node_ = bucket_ == n ? node_ptr() : n;
} }
void increment() { void increment() {

View File

@ -71,9 +71,9 @@ namespace boost { namespace unordered_detail {
} }
template <class A> template <class A>
inline void ungrouped_node_base<A>::unlink_node(bucket& b, node_ptr node) inline void ungrouped_node_base<A>::unlink_node(bucket& b, node_ptr n)
{ {
unlink_nodes(b, node, node->next_); unlink_nodes(b, n, n->next_);
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -144,41 +144,41 @@ namespace boost { namespace unordered_detail {
} }
template <class A> template <class A>
void grouped_node_base<A>::unlink_node(bucket& b, node_ptr node) void grouped_node_base<A>::unlink_node(bucket& b, node_ptr n)
{ {
node_ptr next = node->next_; node_ptr next = n->next_;
node_ptr* pos = &next_group(node); node_ptr* pos = &next_group(n);
if(*pos != node) { if(*pos != n) {
// The node is at the beginning of a group. // The node is at the beginning of a group.
// Find the previous node pointer: // Find the previous node pointer:
pos = &b.next_; pos = &b.next_;
while(*pos != node) pos = &next_group(*pos); while(*pos != n) pos = &next_group(*pos);
// Remove from group // Remove from group
if(BOOST_UNORDERED_BORLAND_BOOL(next) && if(BOOST_UNORDERED_BORLAND_BOOL(next) &&
get(next).group_prev_ == node) get(next).group_prev_ == n)
{ {
get(next).group_prev_ = get(node).group_prev_; get(next).group_prev_ = get(n).group_prev_;
} }
} }
else if(BOOST_UNORDERED_BORLAND_BOOL(next) && else if(BOOST_UNORDERED_BORLAND_BOOL(next) &&
get(next).group_prev_ == node) get(next).group_prev_ == n)
{ {
// The deleted node is not at the end of the group, so // The deleted node is not at the end of the group, so
// change the link from the next node. // change the link from the next node.
get(next).group_prev_ = get(node).group_prev_; get(next).group_prev_ = get(n).group_prev_;
} }
else { else {
// The deleted node is at the end of the group, so the // The deleted node is at the end of the group, so the
// first node in the group is pointing to it. // first node in the group is pointing to it.
// Find that to change its pointer. // Find that to change its pointer.
node_ptr x = get(node).group_prev_; node_ptr x = get(n).group_prev_;
while(get(x).group_prev_ != node) { while(get(x).group_prev_ != n) {
x = get(x).group_prev_; x = get(x).group_prev_;
} }
get(x).group_prev_ = get(node).group_prev_; get(x).group_prev_ = get(n).group_prev_;
} }
*pos = next; *pos = next;
} }

View File

@ -116,7 +116,7 @@ namespace boost { namespace unordered_detail {
// no throw // no throw
template <class H, class P, class A, class G, class K> template <class H, class P, class A, class G, class K>
inline std::size_t hash_table<H, P, A, G, K>::min_buckets_for_size( inline std::size_t hash_table<H, P, A, G, K>::min_buckets_for_size(
std::size_t n) const std::size_t size) const
{ {
BOOST_ASSERT(this->mlf_ != 0); BOOST_ASSERT(this->mlf_ != 0);
@ -128,7 +128,7 @@ namespace boost { namespace unordered_detail {
// //
// Or from rehash post-condition: // Or from rehash post-condition:
// count > size / mlf_ // count > size / mlf_
return next_prime(double_to_size_t(floor(n / (double) mlf_)) + 1); return next_prime(double_to_size_t(floor(size / (double) mlf_)) + 1);
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -199,9 +199,9 @@ namespace boost { namespace unordered_detail {
// Constructors // Constructors
template <class H, class P, class A, class G, class K> template <class H, class P, class A, class G, class K>
hash_table<H, P, A, G, K>::hash_table(std::size_t n, hash_table<H, P, A, G, K>::hash_table(std::size_t num_buckets,
hasher const& hf, key_equal const& eq, node_allocator const& a) hasher const& hf, key_equal const& eq, node_allocator const& a)
: buckets(a, next_prime(n)), : buckets(a, next_prime(num_buckets)),
base(hf, eq), base(hf, eq),
size_(), size_(),
mlf_(1.0f), mlf_(1.0f),
@ -404,24 +404,26 @@ namespace boost { namespace unordered_detail {
// basic exception safety // basic exception safety
template <class H, class P, class A, class G, class K> template <class H, class P, class A, class G, class K>
inline void hash_table<H, P, A, G, K>::create_for_insert(std::size_t n) inline void hash_table<H, P, A, G, K>::create_for_insert(std::size_t size)
{ {
if(n > this->bucket_count_) // TODO: Write a test to detect this bug:
this->bucket_count_ = this->min_buckets_for_size(n); if(size > this->bucket_count_)
this->bucket_count_ = this->min_buckets_for_size(size);
this->create_buckets(); this->create_buckets();
this->init_buckets(); this->init_buckets();
} }
// basic exception safety // basic exception safety
template <class H, class P, class A, class G, class K> template <class H, class P, class A, class G, class K>
inline bool hash_table<H, P, A, G, K>::reserve_for_insert(std::size_t n) inline bool hash_table<H, P, A, G, K>::reserve_for_insert(std::size_t size)
{ {
if(n >= max_load_) { if(size >= max_load_) {
std::size_t s = this->size_; std::size_t s = this->size_;
s = s + (s >> 1); s = s + (s >> 1);
n = this->min_buckets_for_size(s > n ? s : n); std::size_t num_buckets
if(n != this->bucket_count_) { = this->min_buckets_for_size(s > size ? s : size);
rehash_impl(n); if(num_buckets != this->bucket_count_) {
rehash_impl(num_buckets);
return true; return true;
} }
} }
@ -433,24 +435,24 @@ namespace boost { namespace unordered_detail {
// strong otherwise. // strong otherwise.
// TODO: Should this always create buckets? // TODO: Should this always create buckets?
template <class H, class P, class A, class G, class K> template <class H, class P, class A, class G, class K>
inline void hash_table<H, P, A, G, K> inline void hash_table<H, P, A, G, K>::rehash(std::size_t min_buckets)
::rehash(std::size_t n)
{ {
using namespace std; using namespace std;
if(!this->buckets_) { if(!this->buckets_) {
this->bucket_count_ = next_prime(n); this->bucket_count_ = next_prime(min_buckets);
this->create_buckets(); this->create_buckets();
this->init_buckets(); this->init_buckets();
} }
else if(n != this->bucket_count_) { // TODO: Another bug:
else if(min_buckets != this->bucket_count_) {
// no throw: // no throw:
// TODO: Needlessly calling next_prime twice. // TODO: Needlessly calling next_prime twice.
std::size_t min_size = this->min_buckets_for_size(this->size_); std::size_t min_size = this->min_buckets_for_size(this->size_);
n = next_prime(n); min_buckets = next_prime(min_buckets);
n = min_size > n ? min_size : n; min_buckets = min_size > min_buckets ? min_size : min_buckets;
rehash_impl(n); rehash_impl(min_buckets);
} }
} }
@ -461,13 +463,13 @@ namespace boost { namespace unordered_detail {
template <class H, class P, class A, class G, class K> template <class H, class P, class A, class G, class K>
void hash_table<H, P, A, G, K> void hash_table<H, P, A, G, K>
::rehash_impl(std::size_t n) ::rehash_impl(std::size_t num_buckets)
{ {
hasher const& hf = this->hash_function(); hasher const& hf = this->hash_function();
std::size_t size = this->size_; std::size_t size = this->size_;
bucket_ptr end = this->get_bucket(this->bucket_count_); bucket_ptr end = this->get_bucket(this->bucket_count_);
buckets dst(this->node_alloc(), n); buckets dst(this->node_alloc(), num_buckets);
dst.create_buckets(); dst.create_buckets();
buckets src(this->node_alloc(), this->bucket_count_); buckets src(this->node_alloc(), this->bucket_count_);
@ -726,18 +728,18 @@ namespace boost { namespace unordered_detail {
template <class H, class P, class A, class G, class K> template <class H, class P, class A, class G, class K>
BOOST_DEDUCED_TYPENAME hash_table<H, P, A, G, K>::iterator_base BOOST_DEDUCED_TYPENAME hash_table<H, P, A, G, K>::iterator_base
hash_table<H, P, A, G, K>::emplace_empty_impl_with_node( hash_table<H, P, A, G, K>::emplace_empty_impl_with_node(
node_constructor& a, std::size_t n) node_constructor& a, std::size_t size)
{ {
key_type const& k = get_key(a.value()); key_type const& k = get_key(a.value());
std::size_t hash_value = this->hash_function()(k); std::size_t hash_value = this->hash_function()(k);
if(this->buckets_) this->reserve_for_insert(n); if(this->buckets_) this->reserve_for_insert(size);
else this->create_for_insert(n); else this->create_for_insert(size);
bucket_ptr bucket = this->bucket_ptr_from_hash(hash_value); bucket_ptr bucket = this->bucket_ptr_from_hash(hash_value);
node_ptr node = a.release(); node_ptr n = a.release();
node::add_to_bucket(node, *bucket); node::add_to_bucket(n, *bucket);
++this->size_; ++this->size_;
this->cached_begin_bucket_ = bucket; this->cached_begin_bucket_ = bucket;
return iterator_base(bucket, node); return iterator_base(bucket, n);
} }
}} }}

View File

@ -191,56 +191,58 @@ namespace boost { namespace unordered_detail {
#else #else
#define BOOST_UNORDERED_INSERT_IMPL(z, n, _) \ #define BOOST_UNORDERED_INSERT_IMPL(z, num_params, _) \
template <class H, class P, class A, class K> \ template <class H, class P, class A, class K> \
template <BOOST_UNORDERED_TEMPLATE_ARGS(z, n)> \ template <BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params)> \
inline BOOST_DEDUCED_TYPENAME \ inline BOOST_DEDUCED_TYPENAME \
hash_unique_table<H, P, A, K>::emplace_return \ hash_unique_table<H, P, A, K>::emplace_return \
hash_unique_table<H, P, A, K>::emplace_impl( \ hash_unique_table<H, P, A, K>::emplace_impl( \
key_type const& k, \ key_type const& k, \
BOOST_UNORDERED_FUNCTION_PARAMS(z, n)) \ BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params)) \
{ \ { \
std::size_t hash_value = this->hash_function()(k); \ std::size_t hash_value = this->hash_function()(k); \
bucket_ptr bucket \ bucket_ptr bucket \
= this->bucket_ptr_from_hash(hash_value); \ = this->bucket_ptr_from_hash(hash_value); \
node_ptr pos = find_iterator(bucket, k); \ node_ptr pos = find_iterator(bucket, k); \
\ \
if (BOOST_UNORDERED_BORLAND_BOOL(pos)) { \ if (BOOST_UNORDERED_BORLAND_BOOL(pos)) { \
return emplace_return(iterator_base(bucket, pos), false); \ return emplace_return(iterator_base(bucket, pos), false); \
} else { \ } else { \
node_constructor a(*this); \ node_constructor a(*this); \
a.construct(BOOST_UNORDERED_CALL_PARAMS(z, n)); \ a.construct(BOOST_UNORDERED_CALL_PARAMS(z, num_params)); \
\ \
if(this->reserve_for_insert(this->size_ + 1)) \ if(this->reserve_for_insert(this->size_ + 1)) \
bucket = this->bucket_ptr_from_hash(hash_value); \ bucket = this->bucket_ptr_from_hash(hash_value); \
\ \
return emplace_return(iterator_base(bucket, \ return emplace_return(iterator_base(bucket, \
add_node(a, bucket)), true); \ add_node(a, bucket)), true); \
} \ } \
} \ } \
\ \
template <class H, class P, class A, class K> \ template <class H, class P, class A, class K> \
template <BOOST_UNORDERED_TEMPLATE_ARGS(z, n)> \ template <BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params)> \
inline BOOST_DEDUCED_TYPENAME \ inline BOOST_DEDUCED_TYPENAME \
hash_unique_table<H, P, A, K>::emplace_return \ hash_unique_table<H, P, A, K>::emplace_return \
hash_unique_table<H, P, A, K>:: \ hash_unique_table<H, P, A, K>:: \
emplace_impl(no_key, BOOST_UNORDERED_FUNCTION_PARAMS(z, n)) \ emplace_impl(no_key, \
{ \ BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params)) \
node_constructor a(*this); \ { \
a.construct(BOOST_UNORDERED_CALL_PARAMS(z, n)); \ node_constructor a(*this); \
return emplace_impl_with_node(a); \ a.construct(BOOST_UNORDERED_CALL_PARAMS(z, num_params)); \
} \ return emplace_impl_with_node(a); \
\ } \
template <class H, class P, class A, class K> \ \
template <BOOST_UNORDERED_TEMPLATE_ARGS(z, n)> \ template <class H, class P, class A, class K> \
inline BOOST_DEDUCED_TYPENAME \ template <BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params)> \
hash_unique_table<H, P, A, K>::emplace_return \ inline BOOST_DEDUCED_TYPENAME \
hash_unique_table<H, P, A, K>:: \ hash_unique_table<H, P, A, K>::emplace_return \
emplace_empty_impl(BOOST_UNORDERED_FUNCTION_PARAMS(z, n)) \ hash_unique_table<H, P, A, K>:: \
{ \ emplace_empty_impl( \
node_constructor a(*this); \ BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params)) \
a.construct(BOOST_UNORDERED_CALL_PARAMS(z, n)); \ { \
return emplace_return(this->emplace_empty_impl_with_node(a, 1), true); \ node_constructor a(*this); \
a.construct(BOOST_UNORDERED_CALL_PARAMS(z, num_params)); \
return emplace_return(this->emplace_empty_impl_with_node(a, 1), true); \
} }
BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT,
@ -312,33 +314,33 @@ namespace boost { namespace unordered_detail {
emplace_empty_impl(arg0).first; emplace_empty_impl(arg0).first;
} }
#define BOOST_UNORDERED_INSERT_IMPL(z, n, _) \ #define BOOST_UNORDERED_INSERT_IMPL(z, num_params, _) \
template <class H, class P, class A, class K> \ template <class H, class P, class A, class K> \
template <BOOST_UNORDERED_TEMPLATE_ARGS(z, n)> \ template <BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params)> \
BOOST_DEDUCED_TYPENAME hash_unique_table<H, P, A, K>::emplace_return \ BOOST_DEDUCED_TYPENAME hash_unique_table<H, P, A, K>::emplace_return \
hash_unique_table<H, P, A, K>::emplace( \ hash_unique_table<H, P, A, K>::emplace( \
BOOST_UNORDERED_FUNCTION_PARAMS(z, n)) \ BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params)) \
{ \ { \
return this->size_ ? \ return this->size_ ? \
emplace_impl(extractor::extract(arg0, arg1), \ emplace_impl(extractor::extract(arg0, arg1), \
BOOST_UNORDERED_CALL_PARAMS(z, n)) : \ BOOST_UNORDERED_CALL_PARAMS(z, num_params)) : \
emplace_empty_impl( \ emplace_empty_impl( \
BOOST_UNORDERED_CALL_PARAMS(z, n)); \ BOOST_UNORDERED_CALL_PARAMS(z, num_params)); \
} \ } \
\ \
template <class H, class P, class A, class K> \ template <class H, class P, class A, class K> \
template <BOOST_UNORDERED_TEMPLATE_ARGS(z, n)> \ template <BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params)> \
BOOST_DEDUCED_TYPENAME hash_unique_table<H, P, A, K>::iterator_base \ BOOST_DEDUCED_TYPENAME hash_unique_table<H, P, A, K>::iterator_base \
hash_unique_table<H, P, A, K>:: \ hash_unique_table<H, P, A, K>:: \
emplace_hint(iterator_base const& it, \ emplace_hint(iterator_base const& it, \
BOOST_UNORDERED_FUNCTION_PARAMS(z, n)) \ BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params)) \
{ \ { \
return this->size_ ? \ return this->size_ ? \
emplace_impl(extractor::extract(arg0, arg1), \ emplace_impl(extractor::extract(arg0, arg1), \
BOOST_UNORDERED_CALL_PARAMS(z, n)) : \ BOOST_UNORDERED_CALL_PARAMS(z, num_params)) : \
emplace_empty_impl( \ emplace_empty_impl( \
BOOST_UNORDERED_CALL_PARAMS(z, n)); \ BOOST_UNORDERED_CALL_PARAMS(z, num_params)); \
} \ } \
BOOST_PP_REPEAT_FROM_TO(2, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_PP_REPEAT_FROM_TO(2, BOOST_UNORDERED_EMPLACE_LIMIT,
BOOST_UNORDERED_INSERT_IMPL, _) BOOST_UNORDERED_INSERT_IMPL, _)

View File

@ -61,24 +61,24 @@ namespace boost { namespace unordered_detail {
typedef prime_list_template<std::size_t> prime_list; typedef prime_list_template<std::size_t> prime_list;
// no throw // no throw
inline std::size_t next_prime(std::size_t n) { inline std::size_t next_prime(std::size_t num) {
std::size_t const* const prime_list_begin = prime_list::value; std::size_t const* const prime_list_begin = prime_list::value;
std::size_t const* const prime_list_end = prime_list_begin + std::size_t const* const prime_list_end = prime_list_begin +
prime_list::length; prime_list::length;
std::size_t const* bound = std::size_t const* bound =
std::lower_bound(prime_list_begin, prime_list_end, n); std::lower_bound(prime_list_begin, prime_list_end, num);
if(bound == prime_list_end) if(bound == prime_list_end)
bound--; bound--;
return *bound; return *bound;
} }
// no throw // no throw
inline std::size_t prev_prime(std::size_t n) { inline std::size_t prev_prime(std::size_t num) {
std::size_t const* const prime_list_begin = prime_list::value; std::size_t const* const prime_list_begin = prime_list::value;
std::size_t const* const prime_list_end = prime_list_begin + std::size_t const* const prime_list_end = prime_list_begin +
prime_list::length; prime_list::length;
std::size_t const* bound = std::size_t const* bound =
std::upper_bound(prime_list_begin,prime_list_end, n); std::upper_bound(prime_list_begin,prime_list_end, num);
if(bound != prime_list_begin) if(bound != prime_list_begin)
bound--; bound--;
return *bound; return *bound;
@ -129,9 +129,10 @@ namespace boost { namespace unordered_detail {
template <class I> template <class I>
inline std::size_t initial_size(I i, I j, inline std::size_t initial_size(I i, I j,
std::size_t n = boost::unordered_detail::default_bucket_count) std::size_t num_buckets = boost::unordered_detail::default_bucket_count)
{ {
return (std::max)(static_cast<std::size_t>(insert_size(i, j)) + 1, n); return (std::max)(static_cast<std::size_t>(insert_size(i, j)) + 1,
num_buckets);
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -158,29 +159,29 @@ namespace boost { namespace unordered_detail {
#else #else
#define BOOST_UNORDERED_CONSTRUCT_IMPL(z, n, _) \ #define BOOST_UNORDERED_CONSTRUCT_IMPL(z, num_params, _) \
template < \ template < \
class T, \ class T, \
BOOST_UNORDERED_TEMPLATE_ARGS(z, n) \ BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params) \
> \ > \
inline void construct_impl( \ inline void construct_impl( \
T*, void* address, \ T*, void* address, \
BOOST_UNORDERED_FUNCTION_PARAMS(z, n) \ BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params) \
) \ ) \
{ \ { \
new(address) T( \ new(address) T( \
BOOST_UNORDERED_CALL_PARAMS(z, n)); \ BOOST_UNORDERED_CALL_PARAMS(z, num_params)); \
} \ } \
\ \
template <class First, class Second, class Key, \ template <class First, class Second, class Key, \
BOOST_UNORDERED_TEMPLATE_ARGS(z, n) \ BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params) \
> \ > \
inline void construct_impl( \ inline void construct_impl( \
std::pair<First, Second>*, void* address, \ std::pair<First, Second>*, void* address, \
Key const& k, BOOST_UNORDERED_FUNCTION_PARAMS(z, n)) \ Key const& k, BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params)) \
{ \ { \
new(address) std::pair<First, Second>(k, \ new(address) std::pair<First, Second>(k, \
Second(BOOST_UNORDERED_CALL_PARAMS(z, n))); \ Second(BOOST_UNORDERED_CALL_PARAMS(z, num_params))); \
} }
BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT, BOOST_PP_REPEAT_FROM_TO(1, BOOST_UNORDERED_EMPLACE_LIMIT,
@ -230,18 +231,18 @@ namespace boost { namespace unordered_detail {
} }
#else #else
#define BOOST_UNORDERED_CONSTRUCT(z, n, _) \ #define BOOST_UNORDERED_CONSTRUCT(z, num_params, _) \
template < \ template < \
BOOST_UNORDERED_TEMPLATE_ARGS(z, n) \ BOOST_UNORDERED_TEMPLATE_ARGS(z, num_params) \
> \ > \
void construct( \ void construct( \
BOOST_UNORDERED_FUNCTION_PARAMS(z, n) \ BOOST_UNORDERED_FUNCTION_PARAMS(z, num_params) \
) \ ) \
{ \ { \
construct_preamble(); \ construct_preamble(); \
construct_impl( \ construct_impl( \
(value_type*) 0, node_->address(), \ (value_type*) 0, node_->address(), \
BOOST_UNORDERED_CALL_PARAMS(z, n) \ BOOST_UNORDERED_CALL_PARAMS(z, num_params) \
); \ ); \
value_constructed_ = true; \ value_constructed_ = true; \
} }