Unordered: Hashing policy for 64 bit computers.

[SVN r77066]
This commit is contained in:
Daniel James committed 2012-02-18 15:47:59 +00:00
1 parent 29d63e378b
commit 2fed2fbd9e
6 files changed
+179 -66

No files matched your search

+22 -17
View File
@@ -136,6 +136,8 @@ namespace boost { namespace unordered { namespace detail {
typedef boost::unordered::detail::grouped_table_impl<types> table;
typedef boost::unordered::detail::set_extractor<value_type> extractor;
typedef boost::unordered::detail::pick_policy::type policy;
};
template <typename A, typename K, typename M, typename H, typename P>
@@ -160,6 +162,8 @@ namespace boost { namespace unordered { namespace detail {
typedef boost::unordered::detail::grouped_table_impl<types> table;
typedef boost::unordered::detail::map_extractor<key_type, value_type>
extractor;
typedef boost::unordered::detail::pick_policy::type policy;
};
template <typename Types>
@@ -219,7 +223,7 @@ namespace boost { namespace unordered { namespace detail {
Key const& k,
Pred const& eq) const
{
std::size_t bucket_index = hash % this->bucket_count_;
std::size_t bucket_index = this->to_bucket(this->bucket_count_, hash);
node_pointer n = this->get_start(bucket_index);
for (;;)
@@ -234,7 +238,7 @@ namespace boost { namespace unordered { namespace detail {
}
else
{
if (node_hash % this->bucket_count_ != bucket_index)
if (this->to_bucket(this->bucket_count_, node_hash) != bucket_index)
return node_pointer();
}
@@ -397,25 +401,25 @@ namespace boost { namespace unordered { namespace detail {
if(pos) {
this->add_after_node(n, pos);
if (n->next_) {
std::size_t next_bucket =
static_cast<node_pointer>(n->next_)->hash_ %
this->bucket_count_;
if (next_bucket != hash % this->bucket_count_) {
std::size_t next_bucket = this->to_bucket(
this->bucket_count_,
static_cast<node_pointer>(n->next_)->hash_);
if (next_bucket != this->to_bucket(this->bucket_count_, hash)) {
this->get_bucket(next_bucket)->next_ = n;
}
}
}
else {
bucket_pointer b = this->get_bucket(hash % this->bucket_count_);
bucket_pointer b = this->get_bucket(this->to_bucket(this->bucket_count_, hash));
if (!b->next_)
{
previous_pointer start_node = this->get_previous_start();
if (start_node->next_) {
this->get_bucket(
this->get_bucket(this->to_bucket(this->bucket_count_,
static_cast<node_pointer>(start_node->next_)->hash_
% this->bucket_count_)->next_ = n;
))->next_ = n;
}
b->next_ = start_node;
@@ -435,7 +439,7 @@ namespace boost { namespace unordered { namespace detail {
node_pointer emplace_impl(node_constructor& a)
{
key_type const& k = this->get_key(a.value());
std::size_t hash = this->hash_function()(k);
std::size_t hash = this->hash(k);
node_pointer position = this->find_node(hash, k);
// reserve has basic exception safety if the hash function
@@ -447,7 +451,7 @@ namespace boost { namespace unordered { namespace detail {
void emplace_impl_no_rehash(node_constructor& a)
{
key_type const& k = this->get_key(a.value());
std::size_t hash = this->hash_function()(k);
std::size_t hash = this->hash(k);
this->add_node(a, hash,
this->find_node(hash, k));
}
@@ -523,8 +527,8 @@ namespace boost { namespace unordered { namespace detail {
{
if(!this->size_) return 0;
std::size_t hash = this->hash_function()(k);
std::size_t bucket_index = hash % this->bucket_count_;
std::size_t hash = this->hash(k);
std::size_t bucket_index = this->to_bucket(this->bucket_count_, hash);
bucket_pointer bucket = this->get_bucket(bucket_index);
previous_pointer prev = bucket->next_;
@@ -535,7 +539,7 @@ namespace boost { namespace unordered { namespace detail {
if (!prev->next_) return 0;
std::size_t node_hash =
static_cast<node_pointer>(prev->next_)->hash_;
if (node_hash % this->bucket_count_ != bucket_index)
if (this->to_bucket(this->bucket_count_, node_hash) != bucket_index)
return 0;
if (node_hash == hash &&
this->key_eq()(k, this->get_key(
@@ -560,7 +564,7 @@ namespace boost { namespace unordered { namespace detail {
node_pointer next = static_cast<node_pointer>(r->next_);
bucket_pointer bucket = this->get_bucket(
r->hash_ % this->bucket_count_);
this->to_bucket(this->bucket_count_, r->hash_));
previous_pointer prev = unlink_node(*bucket, r);
this->fix_buckets(bucket, prev, next);
@@ -574,7 +578,7 @@ namespace boost { namespace unordered { namespace detail {
{
if (r1 == r2) return r2;
std::size_t bucket_index = r1->hash_ % this->bucket_count_;
std::size_t bucket_index = this->to_bucket(this->bucket_count_, r1->hash_);
previous_pointer prev = unlink_nodes(
*this->get_bucket(bucket_index), r1, r2);
this->fix_buckets_range(bucket_index, prev, r1, r2);
@@ -809,7 +813,8 @@ namespace boost { namespace unordered { namespace detail {
static previous_pointer place_in_bucket(buckets& dst,
previous_pointer prev, node_pointer end)
{
bucket_pointer b = dst.get_bucket(end->hash_ % dst.bucket_count_);
bucket_pointer b = dst.get_bucket(dst.to_bucket(
dst.bucket_count_, end->hash_));
if (!b->next_) {
b->next_ = static_cast<node_pointer>(prev);