Factor out the code for choosing the bucket count, and which bucket that hash values map to make it easier to experiment with alternative policies.

[SVN r44697]
This commit is contained in:
Daniel James committed 2008-04-21 15:55:40 +00:00
1 parent ed97a43f40
commit c56213442d
2 files changed
+69 -33

No files matched your search

+26 -1
View File
@@ -50,7 +50,6 @@ namespace boost {
static const std::size_t default_initial_bucket_count = 50;
static const float minimum_max_load_factor = 1e-3f;
inline std::size_t next_prime(std::size_t n);
template <class T>
inline void hash_swap(T& x, T& y)
@@ -101,6 +100,32 @@ namespace boost {
bound--;
return *bound;
}
// Controls how many buckets are allocated and which buckets hash
// values map to. Does not contain the buckets themselves, or ever
// deal with them directly.
struct bucket_manager {
std::size_t bucket_count_;
bucket_manager()
: bucket_count_(0) {}
explicit bucket_manager(std::size_t n)
: bucket_count_(next_prime(n)) {}
std::size_t bucket_count() const {
return bucket_count_;
}
std::size_t bucket_from_hash(std::size_t hashed) const {
return hashed % bucket_count_;
}
std::size_t max_bucket_count(std::size_t max_size) const {
return prev_prime(max_size);
}
};
// pair_cast - used to convert between pair types.