Replace several uses of iterators with node pointers.

Which is to some extent going in circles, as this is how the containers
were originally implemented. But I think this is cleaner. It also fixes
a minor problem where the internal and external iterator types are
different for some containers, as the external iterators are all const.
This commit is contained in:
Daniel James
2016-10-22 10:04:36 +01:00
parent 6071f9a08b
commit 9772c01161
6 changed files with 196 additions and 183 deletions

View File

@@ -130,6 +130,13 @@ namespace boost { namespace unordered { namespace detail {
std::size_t max_load_;
bucket_pointer buckets_;
////////////////////////////////////////////////////////////////////////
// Node functions
static inline node_pointer next_node(link_pointer n) {
return static_cast<node_pointer>(n->next_);
}
////////////////////////////////////////////////////////////////////////
// Data access
@@ -176,16 +183,16 @@ namespace boost { namespace unordered { namespace detail {
return get_bucket(bucket_index)->next_;
}
iterator begin() const
node_pointer begin() const
{
return size_ ? iterator(get_previous_start()->next_) : iterator();
return size_ ? next_node(get_previous_start()) : node_pointer();
}
iterator begin(std::size_t bucket_index) const
node_pointer begin(std::size_t bucket_index) const
{
if (!size_) return iterator();
if (!size_) return node_pointer();
link_pointer prev = get_previous_start(bucket_index);
return prev ? iterator(prev->next_) : iterator();
return prev ? next_node(prev) : node_pointer();
}
std::size_t hash_to_bucket(std::size_t hash_value) const
@@ -202,14 +209,14 @@ namespace boost { namespace unordered { namespace detail {
std::size_t bucket_size(std::size_t index) const
{
iterator it = begin(index);
if (!it.node_) return 0;
node_pointer n = begin(index);
if (!n) return 0;
std::size_t count = 0;
while(it.node_ && hash_to_bucket(it.node_->hash_) == index)
while(n && hash_to_bucket(n->hash_) == index)
{
++count;
++it;
n = next_node(n);
}
return count;
@@ -698,7 +705,7 @@ namespace boost { namespace unordered { namespace detail {
// Find Node
template <typename Key, typename Hash, typename Pred>
iterator generic_find_node(
node_pointer generic_find_node(
Key const& k,
Hash const& hf,
Pred const& eq) const
@@ -707,7 +714,7 @@ namespace boost { namespace unordered { namespace detail {
find_node_impl(policy::apply_hash(hf, k), k, eq);
}
iterator find_node(
node_pointer find_node(
std::size_t key_hash,
key_type const& k) const
{
@@ -715,13 +722,13 @@ namespace boost { namespace unordered { namespace detail {
find_node_impl(key_hash, k, this->key_eq());
}
iterator find_node(key_type const& k) const
node_pointer find_node(key_type const& k) const
{
return static_cast<table_impl const*>(this)->
find_node_impl(hash(k), k, this->key_eq());
}
iterator find_matching_node(iterator n) const
node_pointer find_matching_node(iterator n) const
{
// TODO: Does this apply to C++11?
//