Unorderd: Stop deriving from hash policy.

[SVN r81209]
This commit is contained in:
Daniel James
2012-11-05 18:33:29 +00:00
parent d495cbd7e6
commit 73c0d85ae6
6 changed files with 29 additions and 47 deletions

View File

@ -578,8 +578,6 @@ namespace boost { namespace unordered { namespace detail {
///////////////////////////////////////////////////////////////////
//
// Hash Policy
//
// Don't really want table to derive from this, but will for now.
template <typename SizeT>
struct prime_policy

View File

@ -237,8 +237,7 @@ namespace boost { namespace unordered { namespace detail {
Key const& k,
Pred const& eq) const
{
std::size_t bucket_index =
policy::to_bucket(this->bucket_count_, key_hash);
std::size_t bucket_index = this->hash_to_bucket(key_hash);
iterator n = this->begin(bucket_index);
for (;;)
@ -253,8 +252,7 @@ namespace boost { namespace unordered { namespace detail {
}
else
{
if (policy::to_bucket(this->bucket_count_, node_hash)
!= bucket_index)
if (this->hash_to_bucket(node_hash) != bucket_index)
return iterator();
}
@ -408,25 +406,23 @@ namespace boost { namespace unordered { namespace detail {
if (pos.node_) {
this->add_after_node(n, pos.node_);
if (n->next_) {
std::size_t next_bucket = policy::to_bucket(
this->bucket_count_,
std::size_t next_bucket = this->hash_to_bucket(
static_cast<node_pointer>(n->next_)->hash_);
if (next_bucket !=
policy::to_bucket(this->bucket_count_, key_hash)) {
if (next_bucket != this->hash_to_bucket(key_hash)) {
this->get_bucket(next_bucket)->next_ = n;
}
}
}
else {
bucket_pointer b = this->get_bucket(
policy::to_bucket(this->bucket_count_, key_hash));
this->hash_to_bucket(key_hash));
if (!b->next_)
{
link_pointer start_node = this->get_previous_start();
if (start_node->next_) {
this->get_bucket(policy::to_bucket(this->bucket_count_,
this->get_bucket(this->hash_to_bucket(
static_cast<node_pointer>(start_node->next_)->hash_
))->next_ = n;
}
@ -541,8 +537,7 @@ namespace boost { namespace unordered { namespace detail {
if(!this->size_) return 0;
std::size_t key_hash = this->hash(k);
std::size_t bucket_index =
policy::to_bucket(this->bucket_count_, key_hash);
std::size_t bucket_index = this->hash_to_bucket(key_hash);
link_pointer prev = this->get_previous_start(bucket_index);
if (!prev) return 0;
@ -551,8 +546,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 (policy::to_bucket(this->bucket_count_, node_hash)
!= bucket_index)
if (this->hash_to_bucket(node_hash) != bucket_index)
return 0;
if (node_hash == key_hash &&
this->key_eq()(k, this->get_key(
@ -587,8 +581,7 @@ namespace boost { namespace unordered { namespace detail {
link_pointer erase_nodes(node_pointer begin, node_pointer end)
{
std::size_t bucket_index =
policy::to_bucket(this->bucket_count_, begin->hash_);
std::size_t bucket_index = this->hash_to_bucket(begin->hash_);
// Split the groups containing 'begin' and 'end'.
// And get the pointer to the node before begin while
@ -689,8 +682,7 @@ namespace boost { namespace unordered { namespace detail {
static link_pointer place_in_bucket(table& dst,
link_pointer prev, node_pointer end)
{
bucket_pointer b = dst.get_bucket(policy::to_bucket(
dst.bucket_count_, end->hash_));
bucket_pointer b = dst.get_bucket(dst.hash_to_bucket(end->hash_));
if (!b->next_) {
b->next_ = prev;

View File

@ -125,7 +125,6 @@ namespace boost { namespace unordered { namespace detail {
template <typename Types>
struct table :
Types::policy,
boost::unordered::detail::functions<
typename Types::hasher,
typename Types::key_equal>
@ -244,6 +243,11 @@ namespace boost { namespace unordered { namespace detail {
link_pointer prev = get_previous_start(bucket_index);
return prev ? iterator(prev->next_) : iterator();
}
std::size_t hash_to_bucket(std::size_t hash) const
{
return policy::to_bucket(bucket_count_, hash);
}
float load_factor() const
{
@ -258,8 +262,7 @@ namespace boost { namespace unordered { namespace detail {
if (!it.node_) return 0;
std::size_t count = 0;
while(it.node_ && policy::to_bucket(
bucket_count_, it.node_->hash_) == index)
while(it.node_ && hash_to_bucket(it.node_->hash_) == index)
{
++count;
++it;
@ -586,7 +589,7 @@ namespace boost { namespace unordered { namespace detail {
if (end)
{
bucket_index2 = policy::to_bucket(bucket_count_,
bucket_index2 = hash_to_bucket(
static_cast<node_pointer>(end)->hash_);
// If begin and end are in the same bucket, then

View File

@ -232,8 +232,7 @@ namespace boost { namespace unordered { namespace detail {
Key const& k,
Pred const& eq) const
{
std::size_t bucket_index =
policy::to_bucket(this->bucket_count_, key_hash);
std::size_t bucket_index = this->hash_to_bucket(key_hash);
iterator n = this->begin(bucket_index);
for (;;)
@ -248,8 +247,7 @@ namespace boost { namespace unordered { namespace detail {
}
else
{
if (policy::to_bucket(this->bucket_count_, node_hash)
!= bucket_index)
if (this->hash_to_bucket(node_hash) != bucket_index)
return iterator();
}
@ -313,15 +311,14 @@ namespace boost { namespace unordered { namespace detail {
node_pointer n = a.release();
n->hash_ = key_hash;
bucket_pointer b = this->get_bucket(
policy::to_bucket(this->bucket_count_, key_hash));
bucket_pointer b = this->get_bucket(this->hash_to_bucket(key_hash));
if (!b->next_)
{
link_pointer start_node = this->get_previous_start();
if (start_node->next_) {
this->get_bucket(policy::to_bucket(this->bucket_count_,
this->get_bucket(this->hash_to_bucket(
static_cast<node_pointer>(start_node->next_)->hash_)
)->next_ = n;
}
@ -519,8 +516,7 @@ namespace boost { namespace unordered { namespace detail {
if(!this->size_) return 0;
std::size_t key_hash = this->hash(k);
std::size_t bucket_index =
policy::to_bucket(this->bucket_count_, key_hash);
std::size_t bucket_index = this->hash_to_bucket(key_hash);
link_pointer prev = this->get_previous_start(bucket_index);
if (!prev) return 0;
@ -529,8 +525,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 (policy::to_bucket(this->bucket_count_, node_hash)
!= bucket_index)
if (this->hash_to_bucket(node_hash) != bucket_index)
return 0;
if (node_hash == key_hash &&
this->key_eq()(k, this->get_key(
@ -564,8 +559,7 @@ namespace boost { namespace unordered { namespace detail {
void erase_nodes(node_pointer begin, node_pointer end)
{
std::size_t bucket_index =
policy::to_bucket(this->bucket_count_, begin->hash_);
std::size_t bucket_index = this->hash_to_bucket(begin->hash_);
// Find the node before begin.
link_pointer prev = this->get_previous_start(bucket_index);
@ -614,8 +608,7 @@ namespace boost { namespace unordered { namespace detail {
static link_pointer place_in_bucket(table& dst, link_pointer prev)
{
node_pointer n = static_cast<node_pointer>(prev->next_);
bucket_pointer b = dst.get_bucket(
table::to_bucket(dst.bucket_count_, n->hash_));
bucket_pointer b = dst.get_bucket(dst.hash_to_bucket(n->hash_));
if (!b->next_) {
b->next_ = prev;

View File

@ -463,8 +463,7 @@ namespace unordered
size_type bucket(const key_type& k) const
{
return table::to_bucket(table_.bucket_count_,
table_.hash(k));
return table_.hash_to_bucket(table_.hash(k));
}
local_iterator begin(size_type n)
@ -942,8 +941,7 @@ namespace unordered
size_type bucket(const key_type& k) const
{
return table::to_bucket(table_.bucket_count_,
table_.hash(k));
return table_.hash_to_bucket(table_.hash(k));
}
local_iterator begin(size_type n)

View File

@ -448,8 +448,7 @@ namespace unordered
size_type bucket(const key_type& k) const
{
return table::to_bucket(table_.bucket_count_,
table_.hash(k));
return table_.hash_to_bucket(table_.hash(k));
}
local_iterator begin(size_type n)
@ -917,8 +916,7 @@ namespace unordered
size_type bucket(const key_type& k) const
{
return table::to_bucket(table_.bucket_count_,
table_.hash(k));
return table_.hash_to_bucket(table_.hash(k));
}
local_iterator begin(size_type n)