Merge unordered.

[SVN r58605]
This commit is contained in:
Daniel James
2009-12-30 22:17:48 +00:00
parent 02bf8f288e
commit f962857e68
11 changed files with 505 additions and 11 deletions
+1 -1
View File
@@ -148,7 +148,7 @@ namespace boost { namespace unordered_detail {
// Set up the sentinel (node_ptr cast)
bucket_ptr sentinel = constructor.get() +
static_cast<ptrdiff_t>(this->bucket_count_);
static_cast<std::ptrdiff_t>(this->bucket_count_);
sentinel->next_ = sentinel;
// Only release the buckets once everything is successfully
+7 -1
View File
@@ -466,6 +466,9 @@ namespace boost { namespace unordered_detail {
return extractor::extract(node::get_value(n));
}
bool equal(key_type const& k, value_type const& v) const;
template <class Key, class Pred>
node_ptr find_iterator(bucket_ptr bucket, Key const& k,
Pred const&) const;
node_ptr find_iterator(bucket_ptr bucket, key_type const& k) const;
node_ptr find_iterator(key_type const& k) const;
node_ptr* find_for_erase(bucket_ptr bucket, key_type const& k) const;
@@ -523,6 +526,8 @@ namespace boost { namespace unordered_detail {
std::size_t count(key_type const& k) const;
iterator_base find(key_type const& k) const;
template <class Key, class Hash, class Pred>
iterator_base find(Key const& k, Hash const& h, Pred const& eq) const;
value_type& at(key_type const& k) const;
iterator_pair equal_range(key_type const& k) const;
@@ -532,7 +537,8 @@ namespace boost { namespace unordered_detail {
void clear();
std::size_t erase_key(key_type const& k);
iterator_base erase(iterator_base r);
iterator_base erase_return_iterator(iterator_base r);
void erase(iterator_base r);
std::size_t erase_group(node_ptr* it, bucket_ptr bucket);
iterator_base erase_range(iterator_base r1, iterator_base r2);
+44 -1
View File
@@ -28,6 +28,23 @@ namespace boost { namespace unordered_detail {
return this->key_eq()(k, get_key(v));
}
// strong exception safety, no side effects
template <class T>
template <class Key, class Pred>
inline BOOST_DEDUCED_TYPENAME T::node_ptr
hash_table<T>::find_iterator(bucket_ptr bucket, Key const& k,
Pred const& eq) const
{
node_ptr it = bucket->next_;
while (BOOST_UNORDERED_BORLAND_BOOL(it) &&
!eq(k, get_key(node::get_value(it))))
{
it = node::next_group(it);
}
return it;
}
// strong exception safety, no side effects
template <class T>
inline BOOST_DEDUCED_TYPENAME T::node_ptr
@@ -570,6 +587,22 @@ namespace boost { namespace unordered_detail {
return this->end();
}
template <class T>
template <class Key, class Hash, class Pred>
BOOST_DEDUCED_TYPENAME T::iterator_base hash_table<T>::find(Key const& k,
Hash const& h, Pred const& eq) const
{
if(!this->size_) return this->end();
bucket_ptr bucket = this->get_bucket(h(k) % this->bucket_count_);
node_ptr it = find_iterator(bucket, k, eq);
if (BOOST_UNORDERED_BORLAND_BOOL(it))
return iterator_base(bucket, it);
else
return this->end();
}
template <class T>
BOOST_DEDUCED_TYPENAME T::value_type&
hash_table<T>::at(key_type const& k) const
@@ -652,10 +685,20 @@ namespace boost { namespace unordered_detail {
return *it ? this->erase_group(it, bucket) : 0;
}
template <class T>
void hash_table<T>::erase(iterator_base r)
{
BOOST_ASSERT(r.node_);
--this->size_;
node::unlink_node(*r.bucket_, r.node_);
this->delete_node(r.node_);
// r has been invalidated but its bucket is still valid
this->recompute_begin_bucket(r.bucket_);
}
template <class T>
BOOST_DEDUCED_TYPENAME T::iterator_base
hash_table<T>::erase(iterator_base r)
hash_table<T>::erase_return_iterator(iterator_base r)
{
BOOST_ASSERT(r.node_);
iterator_base next = r;
+52 -2
View File
@@ -355,7 +355,7 @@ namespace boost
iterator erase(const_iterator position)
{
return iterator(table_.erase(get(position)));
return iterator(table_.erase_return_iterator(get(position)));
}
size_type erase(const key_type& k)
@@ -368,6 +368,11 @@ namespace boost
return iterator(table_.erase_range(get(first), get(last)));
}
void erase_return_void(const_iterator position)
{
table_.erase(get(position));
}
void clear()
{
table_.clear();
@@ -417,6 +422,26 @@ namespace boost
return const_iterator(table_.find(k));
}
template <class CompatibleKey, class CompatibleHash,
class CompatiblePredicate>
iterator find(
CompatibleKey const& k,
CompatibleHash const& hash,
CompatiblePredicate const& eq)
{
return iterator(table_.find(k, hash, eq));
}
template <class CompatibleKey, class CompatibleHash,
class CompatiblePredicate>
const_iterator find(
CompatibleKey const& k,
CompatibleHash const& hash,
CompatiblePredicate const& eq) const
{
return iterator(table_.find(k, hash, eq));
}
size_type count(const key_type& k) const
{
return table_.count(k);
@@ -868,7 +893,7 @@ namespace boost
iterator erase(const_iterator position)
{
return iterator(table_.erase(get(position)));
return iterator(table_.erase_return_iterator(get(position)));
}
size_type erase(const key_type& k)
@@ -881,6 +906,11 @@ namespace boost
return iterator(table_.erase_range(get(first), get(last)));
}
void erase_return_void(const_iterator position)
{
table_.erase(get(position));
}
void clear()
{
table_.clear();
@@ -915,6 +945,26 @@ namespace boost
return const_iterator(table_.find(k));
}
template <class CompatibleKey, class CompatibleHash,
class CompatiblePredicate>
iterator find(
CompatibleKey const& k,
CompatibleHash const& hash,
CompatiblePredicate const& eq)
{
return iterator(table_.find(k, hash, eq));
}
template <class CompatibleKey, class CompatibleHash,
class CompatiblePredicate>
const_iterator find(
CompatibleKey const& k,
CompatibleHash const& hash,
CompatiblePredicate const& eq) const
{
return iterator(table_.find(k, hash, eq));
}
size_type count(const key_type& k) const
{
return table_.count(k);
+31 -2
View File
@@ -348,7 +348,7 @@ namespace boost
iterator erase(const_iterator position)
{
return iterator(table_.erase(get(position)));
return iterator(table_.erase_return_iterator(get(position)));
}
size_type erase(const key_type& k)
@@ -361,6 +361,11 @@ namespace boost
return iterator(table_.erase_range(get(first), get(last)));
}
void erase_return_void(const_iterator position)
{
table_.erase(get(position));
}
void clear()
{
table_.clear();
@@ -390,6 +395,15 @@ namespace boost
return const_iterator(table_.find(k));
}
template <class CompatibleKey, class CompatibleHash,
class CompatiblePredicate>
const_iterator find(
CompatibleKey const& k,
CompatibleHash const& hash,
CompatiblePredicate const& eq) const
{
return iterator(table_.find(k, hash, eq));
}
size_type count(const key_type& k) const
{
return table_.count(k);
@@ -822,7 +836,7 @@ namespace boost
iterator erase(const_iterator position)
{
return iterator(table_.erase(get(position)));
return iterator(table_.erase_return_iterator(get(position)));
}
size_type erase(const key_type& k)
@@ -835,6 +849,11 @@ namespace boost
return iterator(table_.erase_range(get(first), get(last)));
}
void erase_return_void(const_iterator position)
{
table_.erase(get(position));
}
void clear()
{
table_.clear();
@@ -864,6 +883,16 @@ namespace boost
return const_iterator(table_.find(k));
}
template <class CompatibleKey, class CompatibleHash,
class CompatiblePredicate>
const_iterator find(
CompatibleKey const& k,
CompatibleHash const& hash,
CompatiblePredicate const& eq) const
{
return iterator(table_.find(k, hash, eq));
}
size_type count(const key_type& k) const
{
return table_.count(k);