New version of Boost.Unordered
Merged revisions 55470,55877-55878,55901-55902,55921-55922,55990-55992,56009-56010,56329,56346-56349,56362-56363,56374 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r55470 | danieljames | 2009-08-08 19:50:00 +0100 (Sat, 08 Aug 2009) | 1 line
Remove empty svn:mergeinfo properties. This should reduce the amount of differences between trunk and release.
........
r55877 | danieljames | 2009-08-30 17:33:42 +0100 (Sun, 30 Aug 2009) | 1 line
Remove allocator_constructor since it's never used.
........
r55878 | danieljames | 2009-08-30 17:42:28 +0100 (Sun, 30 Aug 2009) | 6 lines
Initial checkin of new version of Boost.Unordered.
- More template use, less preprocessor use.
- Removed some of the Visual C++ 6 workarounds.
- Reduced memory use of the main object.
- Split into smaller headers.
........
r55901 | danieljames | 2009-08-31 11:39:25 +0100 (Mon, 31 Aug 2009) | 1 line
Detab.
........
r55902 | danieljames | 2009-08-31 11:39:40 +0100 (Mon, 31 Aug 2009) | 1 line
Remove unnecessary BOOST_DEDUCED_TYPENAMEs
........
r55921 | danieljames | 2009-08-31 16:33:28 +0100 (Mon, 31 Aug 2009) | 1 line
Remove a few unused parameters.
........
r55922 | danieljames | 2009-08-31 16:33:49 +0100 (Mon, 31 Aug 2009) | 1 line
Remove 'static' from next_node and node_count. Will hopefully make vacpp happy.
........
r55990 | danieljames | 2009-09-03 08:36:21 +0100 (Thu, 03 Sep 2009) | 1 line
Combine hash_structure and hash_table_manager.
........
r55991 | danieljames | 2009-09-03 08:37:14 +0100 (Thu, 03 Sep 2009) | 1 line
Remove some old Visual C++ workarounds.
........
r55992 | danieljames | 2009-09-03 08:37:30 +0100 (Thu, 03 Sep 2009) | 1 line
Add a small test to see if the tested compilers support out of line template methods.
........
r56009 | danieljames | 2009-09-04 08:02:28 +0100 (Fri, 04 Sep 2009) | 1 line
Fix link to n2691.
........
r56010 | danieljames | 2009-09-04 08:03:04 +0100 (Fri, 04 Sep 2009) | 1 line
Move size_ and cached_begin_bucket_ into table, rename hash_table_manager hash_buckets.
........
r56329 | danieljames | 2009-09-20 22:55:15 +0100 (Sun, 20 Sep 2009) | 2 lines
Since all the compilers support out of line template members use them
and lots of other things.
........
r56346 | danieljames | 2009-09-21 22:17:19 +0100 (Mon, 21 Sep 2009) | 1 line
Slightly more consistent variable names. In detail 'n' is now always a node pointer.
........
r56347 | danieljames | 2009-09-21 22:17:40 +0100 (Mon, 21 Sep 2009) | 1 line
Fix bug where container was reducing the number of buckets.
........
r56348 | danieljames | 2009-09-21 22:18:01 +0100 (Mon, 21 Sep 2009) | 1 line
Fix a bug that was causing unnecessary rehahes.
........
r56349 | danieljames | 2009-09-21 22:18:21 +0100 (Mon, 21 Sep 2009) | 1 line
Use std::max.
........
r56362 | danieljames | 2009-09-22 23:39:00 +0100 (Tue, 22 Sep 2009) | 1 line
Another std::max.
........
r56363 | danieljames | 2009-09-22 23:39:17 +0100 (Tue, 22 Sep 2009) | 1 line
Remove the emplace_hint implementation for unique containers as it isn't really used and seems to be causing sun 5.7 problems.
........
r56374 | danieljames | 2009-09-24 21:42:19 +0100 (Thu, 24 Sep 2009) | 1 line
Remove temporary test.
........
[SVN r56375]
2009-09-24 21:12:46 +00:00
|
|
|
|
|
|
|
|
// Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard.
|
2011-08-21 19:19:12 +00:00
|
|
|
// Copyright (C) 2005-2011 Daniel James
|
New version of Boost.Unordered
Merged revisions 55470,55877-55878,55901-55902,55921-55922,55990-55992,56009-56010,56329,56346-56349,56362-56363,56374 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r55470 | danieljames | 2009-08-08 19:50:00 +0100 (Sat, 08 Aug 2009) | 1 line
Remove empty svn:mergeinfo properties. This should reduce the amount of differences between trunk and release.
........
r55877 | danieljames | 2009-08-30 17:33:42 +0100 (Sun, 30 Aug 2009) | 1 line
Remove allocator_constructor since it's never used.
........
r55878 | danieljames | 2009-08-30 17:42:28 +0100 (Sun, 30 Aug 2009) | 6 lines
Initial checkin of new version of Boost.Unordered.
- More template use, less preprocessor use.
- Removed some of the Visual C++ 6 workarounds.
- Reduced memory use of the main object.
- Split into smaller headers.
........
r55901 | danieljames | 2009-08-31 11:39:25 +0100 (Mon, 31 Aug 2009) | 1 line
Detab.
........
r55902 | danieljames | 2009-08-31 11:39:40 +0100 (Mon, 31 Aug 2009) | 1 line
Remove unnecessary BOOST_DEDUCED_TYPENAMEs
........
r55921 | danieljames | 2009-08-31 16:33:28 +0100 (Mon, 31 Aug 2009) | 1 line
Remove a few unused parameters.
........
r55922 | danieljames | 2009-08-31 16:33:49 +0100 (Mon, 31 Aug 2009) | 1 line
Remove 'static' from next_node and node_count. Will hopefully make vacpp happy.
........
r55990 | danieljames | 2009-09-03 08:36:21 +0100 (Thu, 03 Sep 2009) | 1 line
Combine hash_structure and hash_table_manager.
........
r55991 | danieljames | 2009-09-03 08:37:14 +0100 (Thu, 03 Sep 2009) | 1 line
Remove some old Visual C++ workarounds.
........
r55992 | danieljames | 2009-09-03 08:37:30 +0100 (Thu, 03 Sep 2009) | 1 line
Add a small test to see if the tested compilers support out of line template methods.
........
r56009 | danieljames | 2009-09-04 08:02:28 +0100 (Fri, 04 Sep 2009) | 1 line
Fix link to n2691.
........
r56010 | danieljames | 2009-09-04 08:03:04 +0100 (Fri, 04 Sep 2009) | 1 line
Move size_ and cached_begin_bucket_ into table, rename hash_table_manager hash_buckets.
........
r56329 | danieljames | 2009-09-20 22:55:15 +0100 (Sun, 20 Sep 2009) | 2 lines
Since all the compilers support out of line template members use them
and lots of other things.
........
r56346 | danieljames | 2009-09-21 22:17:19 +0100 (Mon, 21 Sep 2009) | 1 line
Slightly more consistent variable names. In detail 'n' is now always a node pointer.
........
r56347 | danieljames | 2009-09-21 22:17:40 +0100 (Mon, 21 Sep 2009) | 1 line
Fix bug where container was reducing the number of buckets.
........
r56348 | danieljames | 2009-09-21 22:18:01 +0100 (Mon, 21 Sep 2009) | 1 line
Fix a bug that was causing unnecessary rehahes.
........
r56349 | danieljames | 2009-09-21 22:18:21 +0100 (Mon, 21 Sep 2009) | 1 line
Use std::max.
........
r56362 | danieljames | 2009-09-22 23:39:00 +0100 (Tue, 22 Sep 2009) | 1 line
Another std::max.
........
r56363 | danieljames | 2009-09-22 23:39:17 +0100 (Tue, 22 Sep 2009) | 1 line
Remove the emplace_hint implementation for unique containers as it isn't really used and seems to be causing sun 5.7 problems.
........
r56374 | danieljames | 2009-09-24 21:42:19 +0100 (Thu, 24 Sep 2009) | 1 line
Remove temporary test.
........
[SVN r56375]
2009-09-24 21:12:46 +00:00
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
|
|
#ifndef BOOST_UNORDERED_DETAIL_MANAGER_HPP_INCLUDED
|
|
|
|
|
#define BOOST_UNORDERED_DETAIL_MANAGER_HPP_INCLUDED
|
|
|
|
|
|
2011-10-09 18:30:10 +00:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
|
|
|
|
# pragma once
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <boost/unordered/detail/util.hpp>
|
2012-07-15 23:44:41 +00:00
|
|
|
#include <boost/unordered/detail/allocate.hpp>
|
2011-10-09 18:30:10 +00:00
|
|
|
#include <boost/type_traits/aligned_storage.hpp>
|
|
|
|
|
#include <boost/type_traits/alignment_of.hpp>
|
|
|
|
|
#include <boost/swap.hpp>
|
|
|
|
|
#include <boost/assert.hpp>
|
2012-05-03 22:05:21 +00:00
|
|
|
#include <boost/limits.hpp>
|
|
|
|
|
#include <boost/iterator.hpp>
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2011-08-21 19:19:12 +00:00
|
|
|
namespace boost { namespace unordered { namespace detail {
|
2011-10-09 18:30:10 +00:00
|
|
|
|
|
|
|
|
template <typename Types> struct table;
|
|
|
|
|
template <typename NodePointer> struct bucket;
|
|
|
|
|
struct ptr_bucket;
|
2012-05-03 22:05:21 +00:00
|
|
|
template <typename Types> struct table_impl;
|
|
|
|
|
template <typename Types> struct grouped_table_impl;
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-05-03 22:05:21 +00:00
|
|
|
}}}
|
|
|
|
|
|
|
|
|
|
namespace boost { namespace unordered { namespace iterator_detail {
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Iterators
|
|
|
|
|
//
|
|
|
|
|
// all no throw
|
|
|
|
|
|
|
|
|
|
template <typename NodePointer, typename Value> struct iterator;
|
|
|
|
|
template <typename ConstNodePointer, typename NodePointer,
|
|
|
|
|
typename Value> struct c_iterator;
|
|
|
|
|
template <typename NodePointer, typename Value, typename Policy>
|
|
|
|
|
struct l_iterator;
|
|
|
|
|
template <typename ConstNodePointer, typename NodePointer,
|
|
|
|
|
typename Value, typename Policy> struct cl_iterator;
|
|
|
|
|
|
|
|
|
|
// Local Iterators
|
|
|
|
|
//
|
|
|
|
|
// all no throw
|
|
|
|
|
|
|
|
|
|
template <typename NodePointer, typename Value, typename Policy>
|
|
|
|
|
struct l_iterator
|
|
|
|
|
: public boost::iterator<
|
|
|
|
|
std::forward_iterator_tag, Value, std::ptrdiff_t,
|
|
|
|
|
NodePointer, Value&>
|
|
|
|
|
{
|
|
|
|
|
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
|
|
|
|
template <typename ConstNodePointer, typename NodePointer2,
|
|
|
|
|
typename Value2, typename Policy2>
|
|
|
|
|
friend struct boost::unordered::iterator_detail::cl_iterator;
|
|
|
|
|
private:
|
|
|
|
|
#endif
|
|
|
|
|
typedef NodePointer node_pointer;
|
|
|
|
|
typedef boost::unordered::iterator_detail::iterator<NodePointer, Value>
|
|
|
|
|
iterator;
|
|
|
|
|
node_pointer ptr_;
|
|
|
|
|
std::size_t bucket_;
|
|
|
|
|
std::size_t bucket_count_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
l_iterator() : ptr_() {}
|
|
|
|
|
|
|
|
|
|
l_iterator(iterator x, std::size_t b, std::size_t c)
|
|
|
|
|
: ptr_(x.node_), bucket_(b), bucket_count_(c) {}
|
|
|
|
|
|
|
|
|
|
Value& operator*() const {
|
|
|
|
|
return ptr_->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Value* operator->() const {
|
|
|
|
|
return ptr_->value_ptr();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l_iterator& operator++() {
|
|
|
|
|
ptr_ = static_cast<node_pointer>(ptr_->next_);
|
|
|
|
|
if (ptr_ && Policy::to_bucket(bucket_count_, ptr_->hash_)
|
|
|
|
|
!= bucket_)
|
|
|
|
|
ptr_ = node_pointer();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l_iterator operator++(int) {
|
|
|
|
|
l_iterator tmp(*this);
|
|
|
|
|
++(*this);
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator==(l_iterator x) const {
|
|
|
|
|
return ptr_ == x.ptr_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator!=(l_iterator x) const {
|
|
|
|
|
return ptr_ != x.ptr_;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename ConstNodePointer, typename NodePointer, typename Value,
|
|
|
|
|
typename Policy>
|
|
|
|
|
struct cl_iterator
|
|
|
|
|
: public boost::iterator<
|
|
|
|
|
std::forward_iterator_tag, Value, std::ptrdiff_t,
|
|
|
|
|
ConstNodePointer, Value const&>
|
|
|
|
|
{
|
|
|
|
|
friend struct boost::unordered::iterator_detail::l_iterator
|
|
|
|
|
<NodePointer, Value, Policy>;
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
typedef NodePointer node_pointer;
|
|
|
|
|
typedef boost::unordered::iterator_detail::iterator<NodePointer, Value>
|
|
|
|
|
iterator;
|
|
|
|
|
node_pointer ptr_;
|
|
|
|
|
std::size_t bucket_;
|
|
|
|
|
std::size_t bucket_count_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
cl_iterator() : ptr_() {}
|
|
|
|
|
|
|
|
|
|
cl_iterator(iterator x, std::size_t b, std::size_t c) :
|
|
|
|
|
ptr_(x.node_), bucket_(b), bucket_count_(c) {}
|
|
|
|
|
|
|
|
|
|
cl_iterator(boost::unordered::iterator_detail::l_iterator<
|
|
|
|
|
NodePointer, Value, Policy> const& x) :
|
|
|
|
|
ptr_(x.ptr_), bucket_(x.bucket_), bucket_count_(x.bucket_count_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
Value const&
|
|
|
|
|
operator*() const {
|
|
|
|
|
return ptr_->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Value const* operator->() const {
|
|
|
|
|
return ptr_->value_ptr();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cl_iterator& operator++() {
|
|
|
|
|
ptr_ = static_cast<node_pointer>(ptr_->next_);
|
|
|
|
|
if (ptr_ && Policy::to_bucket(bucket_count_, ptr_->hash_)
|
|
|
|
|
!= bucket_)
|
|
|
|
|
ptr_ = node_pointer();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cl_iterator operator++(int) {
|
|
|
|
|
cl_iterator tmp(*this);
|
|
|
|
|
++(*this);
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend bool operator==(cl_iterator const& x, cl_iterator const& y) {
|
|
|
|
|
return x.ptr_ == y.ptr_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend bool operator!=(cl_iterator const& x, cl_iterator const& y) {
|
|
|
|
|
return x.ptr_ != y.ptr_;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename NodePointer, typename Value>
|
|
|
|
|
struct iterator
|
|
|
|
|
: public boost::iterator<
|
|
|
|
|
std::forward_iterator_tag, Value, std::ptrdiff_t,
|
|
|
|
|
NodePointer, Value&>
|
|
|
|
|
{
|
|
|
|
|
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
|
|
|
|
template <typename, typename, typename>
|
|
|
|
|
friend struct boost::unordered::iterator_detail::c_iterator;
|
|
|
|
|
template <typename, typename, typename>
|
|
|
|
|
friend struct boost::unordered::iterator_detail::l_iterator;
|
|
|
|
|
template <typename, typename, typename, typename>
|
|
|
|
|
friend struct boost::unordered::iterator_detail::cl_iterator;
|
|
|
|
|
template <typename>
|
|
|
|
|
friend struct boost::unordered::detail::table;
|
|
|
|
|
template <typename>
|
|
|
|
|
friend struct boost::unordered::detail::table_impl;
|
|
|
|
|
template <typename>
|
|
|
|
|
friend struct boost::unordered::detail::grouped_table_impl;
|
|
|
|
|
private:
|
|
|
|
|
#endif
|
|
|
|
|
typedef NodePointer node_pointer;
|
|
|
|
|
node_pointer node_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
iterator() : node_() {}
|
|
|
|
|
|
|
|
|
|
explicit iterator(node_pointer const& x) : node_(x) {}
|
|
|
|
|
|
|
|
|
|
Value& operator*() const {
|
|
|
|
|
return node_->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Value* operator->() const {
|
|
|
|
|
return &node_->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iterator& operator++() {
|
|
|
|
|
node_ = static_cast<node_pointer>(node_->next_);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iterator operator++(int) {
|
|
|
|
|
iterator tmp(node_);
|
|
|
|
|
node_ = static_cast<node_pointer>(node_->next_);
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator==(iterator const& x) const {
|
|
|
|
|
return node_ == x.node_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool operator!=(iterator const& x) const {
|
|
|
|
|
return node_ != x.node_;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename ConstNodePointer, typename NodePointer, typename Value>
|
|
|
|
|
struct c_iterator
|
|
|
|
|
: public boost::iterator<
|
|
|
|
|
std::forward_iterator_tag, Value, std::ptrdiff_t,
|
|
|
|
|
ConstNodePointer, Value const&>
|
|
|
|
|
{
|
|
|
|
|
friend struct boost::unordered::iterator_detail::iterator<
|
|
|
|
|
NodePointer, Value>;
|
|
|
|
|
|
|
|
|
|
#if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
|
|
|
|
template <typename>
|
|
|
|
|
friend struct boost::unordered::detail::table;
|
|
|
|
|
template <typename>
|
|
|
|
|
friend struct boost::unordered::detail::table_impl;
|
|
|
|
|
template <typename>
|
|
|
|
|
friend struct boost::unordered::detail::grouped_table_impl;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
typedef NodePointer node_pointer;
|
|
|
|
|
typedef boost::unordered::iterator_detail::iterator<NodePointer, Value>
|
|
|
|
|
iterator;
|
|
|
|
|
node_pointer node_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
c_iterator() : node_() {}
|
|
|
|
|
|
|
|
|
|
explicit c_iterator(node_pointer const& x) : node_(x) {}
|
|
|
|
|
|
|
|
|
|
c_iterator(boost::unordered::iterator_detail::iterator<
|
|
|
|
|
NodePointer, Value> const& x) : node_(x.node_) {}
|
|
|
|
|
|
|
|
|
|
Value const& operator*() const {
|
|
|
|
|
return node_->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Value const* operator->() const {
|
|
|
|
|
return &node_->value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c_iterator& operator++() {
|
|
|
|
|
node_ = static_cast<node_pointer>(node_->next_);
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c_iterator operator++(int) {
|
|
|
|
|
c_iterator tmp(node_);
|
|
|
|
|
node_ = static_cast<node_pointer>(node_->next_);
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend bool operator==(c_iterator const& x, c_iterator const& y) {
|
|
|
|
|
return x.node_ == y.node_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
friend bool operator!=(c_iterator const& x, c_iterator const& y) {
|
|
|
|
|
return x.node_ != y.node_;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}}}
|
|
|
|
|
|
|
|
|
|
namespace boost { namespace unordered { namespace detail {
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2012-09-17 18:53:30 +00:00
|
|
|
// Node construction
|
2012-05-03 22:05:21 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename NodeAlloc>
|
|
|
|
|
struct node_constructor
|
2012-05-03 22:05:21 +00:00
|
|
|
{
|
2012-09-17 18:53:30 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
typedef NodeAlloc node_allocator;
|
|
|
|
|
typedef boost::unordered::detail::allocator_traits<NodeAlloc>
|
|
|
|
|
node_allocator_traits;
|
|
|
|
|
typedef typename node_allocator_traits::value_type node;
|
|
|
|
|
typedef typename node_allocator_traits::pointer node_pointer;
|
|
|
|
|
typedef typename node::value_type value_type;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
node_allocator& alloc_;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
node_pointer node_;
|
|
|
|
|
bool node_constructed_;
|
|
|
|
|
bool value_constructed_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
node_constructor(node_allocator& n) :
|
|
|
|
|
alloc_(n),
|
|
|
|
|
node_(),
|
|
|
|
|
node_constructed_(false),
|
|
|
|
|
value_constructed_(false)
|
|
|
|
|
{
|
2012-05-03 22:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
~node_constructor();
|
|
|
|
|
|
|
|
|
|
void construct();
|
|
|
|
|
|
|
|
|
|
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
|
|
|
|
|
void construct_with_value(BOOST_UNORDERED_EMPLACE_ARGS)
|
|
|
|
|
{
|
|
|
|
|
construct();
|
|
|
|
|
boost::unordered::detail::construct_value_impl(
|
|
|
|
|
alloc_, node_->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD);
|
|
|
|
|
value_constructed_ = true;
|
2012-05-03 22:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename A0>
|
|
|
|
|
void construct_with_value2(BOOST_FWD_REF(A0) a0)
|
|
|
|
|
{
|
|
|
|
|
construct();
|
|
|
|
|
boost::unordered::detail::construct_value_impl(
|
|
|
|
|
alloc_, node_->value_ptr(),
|
|
|
|
|
BOOST_UNORDERED_EMPLACE_ARGS1(boost::forward<A0>(a0)));
|
|
|
|
|
value_constructed_ = true;
|
2012-05-03 22:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
value_type const& value() const {
|
|
|
|
|
BOOST_ASSERT(node_ && node_constructed_ && value_constructed_);
|
|
|
|
|
return node_->value();
|
2012-05-03 22:05:21 +00:00
|
|
|
}
|
2012-09-17 18:53:30 +00:00
|
|
|
|
|
|
|
|
// no throw
|
|
|
|
|
node_pointer release()
|
|
|
|
|
{
|
|
|
|
|
BOOST_ASSERT(node_ && node_constructed_);
|
|
|
|
|
node_pointer p = node_;
|
|
|
|
|
node_ = node_pointer();
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
node_constructor(node_constructor const&);
|
|
|
|
|
node_constructor& operator=(node_constructor const&);
|
2012-05-03 22:05:21 +00:00
|
|
|
};
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename Alloc>
|
|
|
|
|
node_constructor<Alloc>::~node_constructor()
|
2012-05-03 22:05:21 +00:00
|
|
|
{
|
2012-09-17 18:53:30 +00:00
|
|
|
if (node_) {
|
|
|
|
|
if (value_constructed_) {
|
|
|
|
|
boost::unordered::detail::destroy_value_impl(alloc_,
|
|
|
|
|
node_->value_ptr());
|
|
|
|
|
}
|
2012-05-03 22:05:21 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
if (node_constructed_) {
|
|
|
|
|
node_allocator_traits::destroy(alloc_,
|
|
|
|
|
boost::addressof(*node_));
|
|
|
|
|
}
|
2012-05-03 22:05:21 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
node_allocator_traits::deallocate(alloc_, node_, 1);
|
2012-05-03 22:05:21 +00:00
|
|
|
}
|
2012-09-17 18:53:30 +00:00
|
|
|
}
|
2012-05-03 22:05:21 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename Alloc>
|
|
|
|
|
void node_constructor<Alloc>::construct()
|
|
|
|
|
{
|
|
|
|
|
if(!node_) {
|
|
|
|
|
node_constructed_ = false;
|
|
|
|
|
value_constructed_ = false;
|
2012-05-03 22:05:21 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
node_ = node_allocator_traits::allocate(alloc_, 1);
|
2012-05-03 22:05:21 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
node_allocator_traits::construct(alloc_,
|
|
|
|
|
boost::addressof(*node_), node());
|
|
|
|
|
node_->init(static_cast<typename node::link_pointer>(node_));
|
|
|
|
|
node_constructed_ = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BOOST_ASSERT(node_constructed_);
|
2012-05-03 22:05:21 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
if (value_constructed_)
|
|
|
|
|
{
|
|
|
|
|
boost::unordered::detail::destroy_value_impl(alloc_,
|
|
|
|
|
node_->value_ptr());
|
|
|
|
|
value_constructed_ = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-10-09 18:30:10 +00:00
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
2011-08-21 19:19:12 +00:00
|
|
|
//
|
2012-09-17 18:53:30 +00:00
|
|
|
// Node Holder
|
|
|
|
|
//
|
|
|
|
|
// Temporary store for nodes. Deletes any that aren't used.
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename NodeAlloc>
|
|
|
|
|
struct node_holder : private node_constructor<NodeAlloc>
|
New version of Boost.Unordered
Merged revisions 55470,55877-55878,55901-55902,55921-55922,55990-55992,56009-56010,56329,56346-56349,56362-56363,56374 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r55470 | danieljames | 2009-08-08 19:50:00 +0100 (Sat, 08 Aug 2009) | 1 line
Remove empty svn:mergeinfo properties. This should reduce the amount of differences between trunk and release.
........
r55877 | danieljames | 2009-08-30 17:33:42 +0100 (Sun, 30 Aug 2009) | 1 line
Remove allocator_constructor since it's never used.
........
r55878 | danieljames | 2009-08-30 17:42:28 +0100 (Sun, 30 Aug 2009) | 6 lines
Initial checkin of new version of Boost.Unordered.
- More template use, less preprocessor use.
- Removed some of the Visual C++ 6 workarounds.
- Reduced memory use of the main object.
- Split into smaller headers.
........
r55901 | danieljames | 2009-08-31 11:39:25 +0100 (Mon, 31 Aug 2009) | 1 line
Detab.
........
r55902 | danieljames | 2009-08-31 11:39:40 +0100 (Mon, 31 Aug 2009) | 1 line
Remove unnecessary BOOST_DEDUCED_TYPENAMEs
........
r55921 | danieljames | 2009-08-31 16:33:28 +0100 (Mon, 31 Aug 2009) | 1 line
Remove a few unused parameters.
........
r55922 | danieljames | 2009-08-31 16:33:49 +0100 (Mon, 31 Aug 2009) | 1 line
Remove 'static' from next_node and node_count. Will hopefully make vacpp happy.
........
r55990 | danieljames | 2009-09-03 08:36:21 +0100 (Thu, 03 Sep 2009) | 1 line
Combine hash_structure and hash_table_manager.
........
r55991 | danieljames | 2009-09-03 08:37:14 +0100 (Thu, 03 Sep 2009) | 1 line
Remove some old Visual C++ workarounds.
........
r55992 | danieljames | 2009-09-03 08:37:30 +0100 (Thu, 03 Sep 2009) | 1 line
Add a small test to see if the tested compilers support out of line template methods.
........
r56009 | danieljames | 2009-09-04 08:02:28 +0100 (Fri, 04 Sep 2009) | 1 line
Fix link to n2691.
........
r56010 | danieljames | 2009-09-04 08:03:04 +0100 (Fri, 04 Sep 2009) | 1 line
Move size_ and cached_begin_bucket_ into table, rename hash_table_manager hash_buckets.
........
r56329 | danieljames | 2009-09-20 22:55:15 +0100 (Sun, 20 Sep 2009) | 2 lines
Since all the compilers support out of line template members use them
and lots of other things.
........
r56346 | danieljames | 2009-09-21 22:17:19 +0100 (Mon, 21 Sep 2009) | 1 line
Slightly more consistent variable names. In detail 'n' is now always a node pointer.
........
r56347 | danieljames | 2009-09-21 22:17:40 +0100 (Mon, 21 Sep 2009) | 1 line
Fix bug where container was reducing the number of buckets.
........
r56348 | danieljames | 2009-09-21 22:18:01 +0100 (Mon, 21 Sep 2009) | 1 line
Fix a bug that was causing unnecessary rehahes.
........
r56349 | danieljames | 2009-09-21 22:18:21 +0100 (Mon, 21 Sep 2009) | 1 line
Use std::max.
........
r56362 | danieljames | 2009-09-22 23:39:00 +0100 (Tue, 22 Sep 2009) | 1 line
Another std::max.
........
r56363 | danieljames | 2009-09-22 23:39:17 +0100 (Tue, 22 Sep 2009) | 1 line
Remove the emplace_hint implementation for unique containers as it isn't really used and seems to be causing sun 5.7 problems.
........
r56374 | danieljames | 2009-09-24 21:42:19 +0100 (Thu, 24 Sep 2009) | 1 line
Remove temporary test.
........
[SVN r56375]
2009-09-24 21:12:46 +00:00
|
|
|
{
|
2011-10-09 18:30:10 +00:00
|
|
|
private:
|
2012-09-17 18:53:30 +00:00
|
|
|
typedef node_constructor<NodeAlloc> base;
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
typedef NodeAlloc node_allocator;
|
|
|
|
|
typedef boost::unordered::detail::allocator_traits<NodeAlloc>
|
|
|
|
|
node_allocator_traits;
|
|
|
|
|
typedef typename node_allocator_traits::value_type node;
|
|
|
|
|
typedef typename node_allocator_traits::pointer node_pointer;
|
|
|
|
|
typedef typename node::value_type value_type;
|
|
|
|
|
typedef typename node::link_pointer link_pointer;
|
2012-05-03 22:05:21 +00:00
|
|
|
typedef boost::unordered::iterator_detail::
|
|
|
|
|
iterator<node_pointer, value_type> iterator;
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
node_pointer nodes_;
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
public:
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename Table>
|
|
|
|
|
explicit node_holder(Table& b) :
|
|
|
|
|
base(b.node_alloc()),
|
|
|
|
|
nodes_()
|
2011-08-21 19:19:12 +00:00
|
|
|
{
|
2012-09-17 18:53:30 +00:00
|
|
|
typename Table::previous_pointer prev = b.get_previous_start();
|
|
|
|
|
nodes_ = static_cast<node_pointer>(prev->next_);
|
|
|
|
|
prev->next_ = link_pointer();
|
|
|
|
|
b.size_ = 0;
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
~node_holder();
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename T>
|
|
|
|
|
inline void assign_impl(T const& v) {
|
|
|
|
|
nodes_->value() = v;
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename T1, typename T2>
|
|
|
|
|
inline void assign_impl(std::pair<T1 const, T2> const& v) {
|
|
|
|
|
const_cast<T1&>(nodes_->value().first) = v.first;
|
|
|
|
|
nodes_->value().second = v.second;
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename T>
|
|
|
|
|
inline void move_assign_impl(T& v) {
|
|
|
|
|
nodes_->value() = boost::move(v);
|
2011-10-09 18:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename T1, typename T2>
|
|
|
|
|
inline void move_assign_impl(std::pair<T1 const, T2>& v) {
|
|
|
|
|
// TODO: Move key as well?
|
|
|
|
|
const_cast<T1&>(nodes_->value().first) =
|
|
|
|
|
boost::move(const_cast<T1&>(v.first));
|
|
|
|
|
nodes_->value().second = boost::move(v.second);
|
2011-10-09 18:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
node_pointer copy_of(value_type const& v)
|
2011-10-09 18:30:10 +00:00
|
|
|
{
|
2012-09-17 18:53:30 +00:00
|
|
|
if (nodes_) {
|
|
|
|
|
assign_impl(v);
|
|
|
|
|
node_pointer p = nodes_;
|
|
|
|
|
nodes_ = static_cast<node_pointer>(p->next_);
|
|
|
|
|
p->init(static_cast<typename node::link_pointer>(p));
|
|
|
|
|
p->next_ = link_pointer();
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this->construct_with_value2(v);
|
|
|
|
|
return base::release();
|
|
|
|
|
}
|
2011-10-09 18:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
node_pointer move_copy_of(value_type& v)
|
2011-10-09 18:30:10 +00:00
|
|
|
{
|
2012-09-17 18:53:30 +00:00
|
|
|
if (nodes_) {
|
|
|
|
|
move_assign_impl(v);
|
|
|
|
|
node_pointer p = nodes_;
|
|
|
|
|
nodes_ = static_cast<node_pointer>(p->next_);
|
|
|
|
|
p->init(static_cast<typename node::link_pointer>(p));
|
|
|
|
|
p->next_ = link_pointer();
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this->construct_with_value2(boost::move(v));
|
|
|
|
|
return base::release();
|
|
|
|
|
}
|
2011-10-09 18:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-03 22:05:21 +00:00
|
|
|
iterator get_start() const
|
2011-10-09 18:30:10 +00:00
|
|
|
{
|
2012-09-17 18:53:30 +00:00
|
|
|
return iterator(nodes_);
|
2011-10-09 18:30:10 +00:00
|
|
|
}
|
2012-09-17 18:53:30 +00:00
|
|
|
};
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename Alloc>
|
|
|
|
|
node_holder<Alloc>::~node_holder()
|
|
|
|
|
{
|
|
|
|
|
while (nodes_) {
|
|
|
|
|
node_pointer p = nodes_;
|
|
|
|
|
nodes_ = static_cast<node_pointer>(p->next_);
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
boost::unordered::detail::destroy_value_impl(this->alloc_,
|
|
|
|
|
p->value_ptr());
|
|
|
|
|
node_allocator_traits::destroy(this->alloc_, boost::addressof(*p));
|
|
|
|
|
node_allocator_traits::deallocate(this->alloc_, p, 1);
|
2011-10-09 18:30:10 +00:00
|
|
|
}
|
2012-09-17 18:53:30 +00:00
|
|
|
}
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Bucket
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename NodePointer>
|
|
|
|
|
struct bucket
|
|
|
|
|
{
|
|
|
|
|
typedef NodePointer previous_pointer;
|
|
|
|
|
previous_pointer next_;
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
bucket() : next_() {}
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
previous_pointer first_from_start()
|
2011-08-21 19:19:12 +00:00
|
|
|
{
|
2012-09-17 18:53:30 +00:00
|
|
|
return next_;
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
enum { extra_node = true };
|
|
|
|
|
};
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
struct ptr_bucket
|
|
|
|
|
{
|
|
|
|
|
typedef ptr_bucket* previous_pointer;
|
|
|
|
|
previous_pointer next_;
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
ptr_bucket() : next_(0) {}
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
previous_pointer first_from_start()
|
2011-08-21 19:19:12 +00:00
|
|
|
{
|
2012-09-17 18:53:30 +00:00
|
|
|
return this;
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
enum { extra_node = false };
|
|
|
|
|
};
|
2011-10-09 18:30:10 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Hash Policy
|
|
|
|
|
//
|
|
|
|
|
// Don't really want table to derive from this, but will for now.
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename SizeT>
|
|
|
|
|
struct prime_policy
|
|
|
|
|
{
|
|
|
|
|
template <typename Hash, typename T>
|
|
|
|
|
static inline SizeT apply_hash(Hash const& hf, T const& x) {
|
|
|
|
|
return hf(x);
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
static inline SizeT to_bucket(SizeT bucket_count, SizeT hash) {
|
|
|
|
|
return hash % bucket_count;
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
static inline SizeT new_bucket_count(SizeT min) {
|
|
|
|
|
return boost::unordered::detail::next_prime(min);
|
2011-10-09 18:30:10 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
static inline SizeT prev_bucket_count(SizeT max) {
|
|
|
|
|
return boost::unordered::detail::prev_prime(max);
|
New version of Boost.Unordered
Merged revisions 55470,55877-55878,55901-55902,55921-55922,55990-55992,56009-56010,56329,56346-56349,56362-56363,56374 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r55470 | danieljames | 2009-08-08 19:50:00 +0100 (Sat, 08 Aug 2009) | 1 line
Remove empty svn:mergeinfo properties. This should reduce the amount of differences between trunk and release.
........
r55877 | danieljames | 2009-08-30 17:33:42 +0100 (Sun, 30 Aug 2009) | 1 line
Remove allocator_constructor since it's never used.
........
r55878 | danieljames | 2009-08-30 17:42:28 +0100 (Sun, 30 Aug 2009) | 6 lines
Initial checkin of new version of Boost.Unordered.
- More template use, less preprocessor use.
- Removed some of the Visual C++ 6 workarounds.
- Reduced memory use of the main object.
- Split into smaller headers.
........
r55901 | danieljames | 2009-08-31 11:39:25 +0100 (Mon, 31 Aug 2009) | 1 line
Detab.
........
r55902 | danieljames | 2009-08-31 11:39:40 +0100 (Mon, 31 Aug 2009) | 1 line
Remove unnecessary BOOST_DEDUCED_TYPENAMEs
........
r55921 | danieljames | 2009-08-31 16:33:28 +0100 (Mon, 31 Aug 2009) | 1 line
Remove a few unused parameters.
........
r55922 | danieljames | 2009-08-31 16:33:49 +0100 (Mon, 31 Aug 2009) | 1 line
Remove 'static' from next_node and node_count. Will hopefully make vacpp happy.
........
r55990 | danieljames | 2009-09-03 08:36:21 +0100 (Thu, 03 Sep 2009) | 1 line
Combine hash_structure and hash_table_manager.
........
r55991 | danieljames | 2009-09-03 08:37:14 +0100 (Thu, 03 Sep 2009) | 1 line
Remove some old Visual C++ workarounds.
........
r55992 | danieljames | 2009-09-03 08:37:30 +0100 (Thu, 03 Sep 2009) | 1 line
Add a small test to see if the tested compilers support out of line template methods.
........
r56009 | danieljames | 2009-09-04 08:02:28 +0100 (Fri, 04 Sep 2009) | 1 line
Fix link to n2691.
........
r56010 | danieljames | 2009-09-04 08:03:04 +0100 (Fri, 04 Sep 2009) | 1 line
Move size_ and cached_begin_bucket_ into table, rename hash_table_manager hash_buckets.
........
r56329 | danieljames | 2009-09-20 22:55:15 +0100 (Sun, 20 Sep 2009) | 2 lines
Since all the compilers support out of line template members use them
and lots of other things.
........
r56346 | danieljames | 2009-09-21 22:17:19 +0100 (Mon, 21 Sep 2009) | 1 line
Slightly more consistent variable names. In detail 'n' is now always a node pointer.
........
r56347 | danieljames | 2009-09-21 22:17:40 +0100 (Mon, 21 Sep 2009) | 1 line
Fix bug where container was reducing the number of buckets.
........
r56348 | danieljames | 2009-09-21 22:18:01 +0100 (Mon, 21 Sep 2009) | 1 line
Fix a bug that was causing unnecessary rehahes.
........
r56349 | danieljames | 2009-09-21 22:18:21 +0100 (Mon, 21 Sep 2009) | 1 line
Use std::max.
........
r56362 | danieljames | 2009-09-22 23:39:00 +0100 (Tue, 22 Sep 2009) | 1 line
Another std::max.
........
r56363 | danieljames | 2009-09-22 23:39:17 +0100 (Tue, 22 Sep 2009) | 1 line
Remove the emplace_hint implementation for unique containers as it isn't really used and seems to be causing sun 5.7 problems.
........
r56374 | danieljames | 2009-09-24 21:42:19 +0100 (Thu, 24 Sep 2009) | 1 line
Remove temporary test.
........
[SVN r56375]
2009-09-24 21:12:46 +00:00
|
|
|
}
|
2012-09-17 18:53:30 +00:00
|
|
|
};
|
New version of Boost.Unordered
Merged revisions 55470,55877-55878,55901-55902,55921-55922,55990-55992,56009-56010,56329,56346-56349,56362-56363,56374 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r55470 | danieljames | 2009-08-08 19:50:00 +0100 (Sat, 08 Aug 2009) | 1 line
Remove empty svn:mergeinfo properties. This should reduce the amount of differences between trunk and release.
........
r55877 | danieljames | 2009-08-30 17:33:42 +0100 (Sun, 30 Aug 2009) | 1 line
Remove allocator_constructor since it's never used.
........
r55878 | danieljames | 2009-08-30 17:42:28 +0100 (Sun, 30 Aug 2009) | 6 lines
Initial checkin of new version of Boost.Unordered.
- More template use, less preprocessor use.
- Removed some of the Visual C++ 6 workarounds.
- Reduced memory use of the main object.
- Split into smaller headers.
........
r55901 | danieljames | 2009-08-31 11:39:25 +0100 (Mon, 31 Aug 2009) | 1 line
Detab.
........
r55902 | danieljames | 2009-08-31 11:39:40 +0100 (Mon, 31 Aug 2009) | 1 line
Remove unnecessary BOOST_DEDUCED_TYPENAMEs
........
r55921 | danieljames | 2009-08-31 16:33:28 +0100 (Mon, 31 Aug 2009) | 1 line
Remove a few unused parameters.
........
r55922 | danieljames | 2009-08-31 16:33:49 +0100 (Mon, 31 Aug 2009) | 1 line
Remove 'static' from next_node and node_count. Will hopefully make vacpp happy.
........
r55990 | danieljames | 2009-09-03 08:36:21 +0100 (Thu, 03 Sep 2009) | 1 line
Combine hash_structure and hash_table_manager.
........
r55991 | danieljames | 2009-09-03 08:37:14 +0100 (Thu, 03 Sep 2009) | 1 line
Remove some old Visual C++ workarounds.
........
r55992 | danieljames | 2009-09-03 08:37:30 +0100 (Thu, 03 Sep 2009) | 1 line
Add a small test to see if the tested compilers support out of line template methods.
........
r56009 | danieljames | 2009-09-04 08:02:28 +0100 (Fri, 04 Sep 2009) | 1 line
Fix link to n2691.
........
r56010 | danieljames | 2009-09-04 08:03:04 +0100 (Fri, 04 Sep 2009) | 1 line
Move size_ and cached_begin_bucket_ into table, rename hash_table_manager hash_buckets.
........
r56329 | danieljames | 2009-09-20 22:55:15 +0100 (Sun, 20 Sep 2009) | 2 lines
Since all the compilers support out of line template members use them
and lots of other things.
........
r56346 | danieljames | 2009-09-21 22:17:19 +0100 (Mon, 21 Sep 2009) | 1 line
Slightly more consistent variable names. In detail 'n' is now always a node pointer.
........
r56347 | danieljames | 2009-09-21 22:17:40 +0100 (Mon, 21 Sep 2009) | 1 line
Fix bug where container was reducing the number of buckets.
........
r56348 | danieljames | 2009-09-21 22:18:01 +0100 (Mon, 21 Sep 2009) | 1 line
Fix a bug that was causing unnecessary rehahes.
........
r56349 | danieljames | 2009-09-21 22:18:21 +0100 (Mon, 21 Sep 2009) | 1 line
Use std::max.
........
r56362 | danieljames | 2009-09-22 23:39:00 +0100 (Tue, 22 Sep 2009) | 1 line
Another std::max.
........
r56363 | danieljames | 2009-09-22 23:39:17 +0100 (Tue, 22 Sep 2009) | 1 line
Remove the emplace_hint implementation for unique containers as it isn't really used and seems to be causing sun 5.7 problems.
........
r56374 | danieljames | 2009-09-24 21:42:19 +0100 (Thu, 24 Sep 2009) | 1 line
Remove temporary test.
........
[SVN r56375]
2009-09-24 21:12:46 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <typename SizeT>
|
|
|
|
|
struct mix64_policy
|
|
|
|
|
{
|
|
|
|
|
template <typename Hash, typename T>
|
|
|
|
|
static inline SizeT apply_hash(Hash const& hf, T const& x) {
|
|
|
|
|
SizeT key = hf(x);
|
|
|
|
|
key = (~key) + (key << 21); // key = (key << 21) - key - 1;
|
|
|
|
|
key = key ^ (key >> 24);
|
|
|
|
|
key = (key + (key << 3)) + (key << 8); // key * 265
|
|
|
|
|
key = key ^ (key >> 14);
|
|
|
|
|
key = (key + (key << 2)) + (key << 4); // key * 21
|
|
|
|
|
key = key ^ (key >> 28);
|
|
|
|
|
key = key + (key << 31);
|
|
|
|
|
return key;
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
static inline SizeT to_bucket(SizeT bucket_count, SizeT hash) {
|
|
|
|
|
return hash & (bucket_count - 1);
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
static inline SizeT new_bucket_count(SizeT min) {
|
|
|
|
|
if (min <= 4) return 4;
|
|
|
|
|
--min;
|
|
|
|
|
min |= min >> 1;
|
|
|
|
|
min |= min >> 2;
|
|
|
|
|
min |= min >> 4;
|
|
|
|
|
min |= min >> 8;
|
|
|
|
|
min |= min >> 16;
|
|
|
|
|
min |= min >> 32;
|
|
|
|
|
return min + 1;
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
static inline SizeT prev_bucket_count(SizeT max) {
|
|
|
|
|
max |= max >> 1;
|
|
|
|
|
max |= max >> 2;
|
|
|
|
|
max |= max >> 4;
|
|
|
|
|
max |= max >> 8;
|
|
|
|
|
max |= max >> 16;
|
|
|
|
|
max |= max >> 32;
|
|
|
|
|
return (max >> 1) + 1;
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
2012-09-17 18:53:30 +00:00
|
|
|
};
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <int digits, int radix>
|
|
|
|
|
struct pick_policy_impl {
|
|
|
|
|
typedef prime_policy<std::size_t> type;
|
|
|
|
|
};
|
2011-08-21 19:19:12 +00:00
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
template <>
|
|
|
|
|
struct pick_policy_impl<64, 2> {
|
|
|
|
|
typedef mix64_policy<std::size_t> type;
|
2011-08-21 19:19:12 +00:00
|
|
|
};
|
|
|
|
|
|
2012-09-17 18:53:30 +00:00
|
|
|
struct pick_policy :
|
|
|
|
|
pick_policy_impl<
|
|
|
|
|
std::numeric_limits<std::size_t>::digits,
|
|
|
|
|
std::numeric_limits<std::size_t>::radix> {};
|
|
|
|
|
|
2011-10-09 18:30:10 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Functions
|
|
|
|
|
|
2011-08-21 19:19:12 +00:00
|
|
|
// Assigning and swapping the equality and hash function objects
|
|
|
|
|
// needs strong exception safety. To implement that normally we'd
|
|
|
|
|
// require one of them to be known to not throw and the other to
|
|
|
|
|
// guarantee strong exception safety. Unfortunately they both only
|
|
|
|
|
// have basic exception safety. So to acheive strong exception
|
|
|
|
|
// safety we have storage space for two copies, and assign the new
|
|
|
|
|
// copies to the unused space. Then switch to using that to use
|
|
|
|
|
// them. This is implemented in 'set_hash_functions' which
|
|
|
|
|
// atomically assigns the new function objects in a strongly
|
|
|
|
|
// exception safe manner.
|
|
|
|
|
|
|
|
|
|
template <class H, class P> class set_hash_functions;
|
|
|
|
|
|
|
|
|
|
template <class H, class P>
|
|
|
|
|
class functions
|
New version of Boost.Unordered
Merged revisions 55470,55877-55878,55901-55902,55921-55922,55990-55992,56009-56010,56329,56346-56349,56362-56363,56374 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r55470 | danieljames | 2009-08-08 19:50:00 +0100 (Sat, 08 Aug 2009) | 1 line
Remove empty svn:mergeinfo properties. This should reduce the amount of differences between trunk and release.
........
r55877 | danieljames | 2009-08-30 17:33:42 +0100 (Sun, 30 Aug 2009) | 1 line
Remove allocator_constructor since it's never used.
........
r55878 | danieljames | 2009-08-30 17:42:28 +0100 (Sun, 30 Aug 2009) | 6 lines
Initial checkin of new version of Boost.Unordered.
- More template use, less preprocessor use.
- Removed some of the Visual C++ 6 workarounds.
- Reduced memory use of the main object.
- Split into smaller headers.
........
r55901 | danieljames | 2009-08-31 11:39:25 +0100 (Mon, 31 Aug 2009) | 1 line
Detab.
........
r55902 | danieljames | 2009-08-31 11:39:40 +0100 (Mon, 31 Aug 2009) | 1 line
Remove unnecessary BOOST_DEDUCED_TYPENAMEs
........
r55921 | danieljames | 2009-08-31 16:33:28 +0100 (Mon, 31 Aug 2009) | 1 line
Remove a few unused parameters.
........
r55922 | danieljames | 2009-08-31 16:33:49 +0100 (Mon, 31 Aug 2009) | 1 line
Remove 'static' from next_node and node_count. Will hopefully make vacpp happy.
........
r55990 | danieljames | 2009-09-03 08:36:21 +0100 (Thu, 03 Sep 2009) | 1 line
Combine hash_structure and hash_table_manager.
........
r55991 | danieljames | 2009-09-03 08:37:14 +0100 (Thu, 03 Sep 2009) | 1 line
Remove some old Visual C++ workarounds.
........
r55992 | danieljames | 2009-09-03 08:37:30 +0100 (Thu, 03 Sep 2009) | 1 line
Add a small test to see if the tested compilers support out of line template methods.
........
r56009 | danieljames | 2009-09-04 08:02:28 +0100 (Fri, 04 Sep 2009) | 1 line
Fix link to n2691.
........
r56010 | danieljames | 2009-09-04 08:03:04 +0100 (Fri, 04 Sep 2009) | 1 line
Move size_ and cached_begin_bucket_ into table, rename hash_table_manager hash_buckets.
........
r56329 | danieljames | 2009-09-20 22:55:15 +0100 (Sun, 20 Sep 2009) | 2 lines
Since all the compilers support out of line template members use them
and lots of other things.
........
r56346 | danieljames | 2009-09-21 22:17:19 +0100 (Mon, 21 Sep 2009) | 1 line
Slightly more consistent variable names. In detail 'n' is now always a node pointer.
........
r56347 | danieljames | 2009-09-21 22:17:40 +0100 (Mon, 21 Sep 2009) | 1 line
Fix bug where container was reducing the number of buckets.
........
r56348 | danieljames | 2009-09-21 22:18:01 +0100 (Mon, 21 Sep 2009) | 1 line
Fix a bug that was causing unnecessary rehahes.
........
r56349 | danieljames | 2009-09-21 22:18:21 +0100 (Mon, 21 Sep 2009) | 1 line
Use std::max.
........
r56362 | danieljames | 2009-09-22 23:39:00 +0100 (Tue, 22 Sep 2009) | 1 line
Another std::max.
........
r56363 | danieljames | 2009-09-22 23:39:17 +0100 (Tue, 22 Sep 2009) | 1 line
Remove the emplace_hint implementation for unique containers as it isn't really used and seems to be causing sun 5.7 problems.
........
r56374 | danieljames | 2009-09-24 21:42:19 +0100 (Thu, 24 Sep 2009) | 1 line
Remove temporary test.
........
[SVN r56375]
2009-09-24 21:12:46 +00:00
|
|
|
{
|
2011-10-09 18:30:10 +00:00
|
|
|
friend class boost::unordered::detail::set_hash_functions<H, P>;
|
2011-08-21 19:19:12 +00:00
|
|
|
functions& operator=(functions const&);
|
|
|
|
|
|
2011-10-09 18:30:10 +00:00
|
|
|
typedef compressed<H, P> function_pair;
|
|
|
|
|
|
|
|
|
|
typedef typename boost::aligned_storage<
|
2011-08-21 19:19:12 +00:00
|
|
|
sizeof(function_pair),
|
2011-10-09 18:30:10 +00:00
|
|
|
boost::alignment_of<function_pair>::value>::type aligned_function;
|
2011-08-21 19:19:12 +00:00
|
|
|
|
|
|
|
|
bool current_; // The currently active functions.
|
|
|
|
|
aligned_function funcs_[2];
|
|
|
|
|
|
|
|
|
|
function_pair const& current() const {
|
|
|
|
|
return *static_cast<function_pair const*>(
|
|
|
|
|
static_cast<void const*>(&funcs_[current_]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void construct(bool which, H const& hf, P const& eq)
|
|
|
|
|
{
|
|
|
|
|
new((void*) &funcs_[which]) function_pair(hf, eq);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void construct(bool which, function_pair const& f)
|
|
|
|
|
{
|
|
|
|
|
new((void*) &funcs_[which]) function_pair(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void destroy(bool which)
|
|
|
|
|
{
|
2011-10-09 18:30:10 +00:00
|
|
|
boost::unordered::detail::destroy((function_pair*)(&funcs_[which]));
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
functions(H const& hf, P const& eq)
|
|
|
|
|
: current_(false)
|
|
|
|
|
{
|
|
|
|
|
construct(current_, hf, eq);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
functions(functions const& bf)
|
|
|
|
|
: current_(false)
|
|
|
|
|
{
|
|
|
|
|
construct(current_, bf.current());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~functions() {
|
2011-10-09 18:30:10 +00:00
|
|
|
this->destroy(current_);
|
2011-08-21 19:19:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
H const& hash_function() const {
|
|
|
|
|
return current().first();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
P const& key_eq() const {
|
|
|
|
|
return current().second();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <class H, class P>
|
|
|
|
|
class set_hash_functions
|
|
|
|
|
{
|
|
|
|
|
set_hash_functions(set_hash_functions const&);
|
|
|
|
|
set_hash_functions& operator=(set_hash_functions const&);
|
|
|
|
|
|
|
|
|
|
functions<H,P>& functions_;
|
|
|
|
|
bool tmp_functions_;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
set_hash_functions(functions<H,P>& f, H const& h, P const& p)
|
|
|
|
|
: functions_(f),
|
|
|
|
|
tmp_functions_(!f.current_)
|
|
|
|
|
{
|
|
|
|
|
f.construct(tmp_functions_, h, p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_hash_functions(functions<H,P>& f, functions<H,P> const& other)
|
|
|
|
|
: functions_(f),
|
|
|
|
|
tmp_functions_(!f.current_)
|
|
|
|
|
{
|
|
|
|
|
f.construct(tmp_functions_, other.current());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~set_hash_functions()
|
|
|
|
|
{
|
|
|
|
|
functions_.destroy(tmp_functions_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void commit()
|
|
|
|
|
{
|
|
|
|
|
functions_.current_ = tmp_functions_;
|
|
|
|
|
tmp_functions_ = !tmp_functions_;
|
|
|
|
|
}
|
|
|
|
|
};
|
2012-09-01 15:50:36 +00:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// rvalue parameters when type can't be a BOOST_RV_REF(T) parameter
|
|
|
|
|
// e.g. for int
|
|
|
|
|
|
|
|
|
|
#if !defined(BOOST_NO_RVALUE_REFERENCES)
|
|
|
|
|
# define BOOST_UNORDERED_RV_REF(T) BOOST_RV_REF(T)
|
|
|
|
|
#else
|
|
|
|
|
struct please_ignore_this_overload {
|
|
|
|
|
typedef please_ignore_this_overload type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct rv_ref_impl {
|
|
|
|
|
typedef BOOST_RV_REF(T) type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
struct rv_ref :
|
|
|
|
|
boost::detail::if_true<
|
|
|
|
|
boost::is_class<T>::value
|
|
|
|
|
>::BOOST_NESTED_TEMPLATE then <
|
|
|
|
|
boost::unordered::detail::rv_ref_impl<T>,
|
|
|
|
|
please_ignore_this_overload
|
|
|
|
|
>::type
|
|
|
|
|
{};
|
|
|
|
|
|
|
|
|
|
# define BOOST_UNORDERED_RV_REF(T) \
|
|
|
|
|
typename boost::unordered::detail::rv_ref<T>::type
|
|
|
|
|
#endif
|
2011-10-09 18:30:10 +00:00
|
|
|
}}}
|
New version of Boost.Unordered
Merged revisions 55470,55877-55878,55901-55902,55921-55922,55990-55992,56009-56010,56329,56346-56349,56362-56363,56374 via svnmerge from
https://svn.boost.org/svn/boost/trunk
........
r55470 | danieljames | 2009-08-08 19:50:00 +0100 (Sat, 08 Aug 2009) | 1 line
Remove empty svn:mergeinfo properties. This should reduce the amount of differences between trunk and release.
........
r55877 | danieljames | 2009-08-30 17:33:42 +0100 (Sun, 30 Aug 2009) | 1 line
Remove allocator_constructor since it's never used.
........
r55878 | danieljames | 2009-08-30 17:42:28 +0100 (Sun, 30 Aug 2009) | 6 lines
Initial checkin of new version of Boost.Unordered.
- More template use, less preprocessor use.
- Removed some of the Visual C++ 6 workarounds.
- Reduced memory use of the main object.
- Split into smaller headers.
........
r55901 | danieljames | 2009-08-31 11:39:25 +0100 (Mon, 31 Aug 2009) | 1 line
Detab.
........
r55902 | danieljames | 2009-08-31 11:39:40 +0100 (Mon, 31 Aug 2009) | 1 line
Remove unnecessary BOOST_DEDUCED_TYPENAMEs
........
r55921 | danieljames | 2009-08-31 16:33:28 +0100 (Mon, 31 Aug 2009) | 1 line
Remove a few unused parameters.
........
r55922 | danieljames | 2009-08-31 16:33:49 +0100 (Mon, 31 Aug 2009) | 1 line
Remove 'static' from next_node and node_count. Will hopefully make vacpp happy.
........
r55990 | danieljames | 2009-09-03 08:36:21 +0100 (Thu, 03 Sep 2009) | 1 line
Combine hash_structure and hash_table_manager.
........
r55991 | danieljames | 2009-09-03 08:37:14 +0100 (Thu, 03 Sep 2009) | 1 line
Remove some old Visual C++ workarounds.
........
r55992 | danieljames | 2009-09-03 08:37:30 +0100 (Thu, 03 Sep 2009) | 1 line
Add a small test to see if the tested compilers support out of line template methods.
........
r56009 | danieljames | 2009-09-04 08:02:28 +0100 (Fri, 04 Sep 2009) | 1 line
Fix link to n2691.
........
r56010 | danieljames | 2009-09-04 08:03:04 +0100 (Fri, 04 Sep 2009) | 1 line
Move size_ and cached_begin_bucket_ into table, rename hash_table_manager hash_buckets.
........
r56329 | danieljames | 2009-09-20 22:55:15 +0100 (Sun, 20 Sep 2009) | 2 lines
Since all the compilers support out of line template members use them
and lots of other things.
........
r56346 | danieljames | 2009-09-21 22:17:19 +0100 (Mon, 21 Sep 2009) | 1 line
Slightly more consistent variable names. In detail 'n' is now always a node pointer.
........
r56347 | danieljames | 2009-09-21 22:17:40 +0100 (Mon, 21 Sep 2009) | 1 line
Fix bug where container was reducing the number of buckets.
........
r56348 | danieljames | 2009-09-21 22:18:01 +0100 (Mon, 21 Sep 2009) | 1 line
Fix a bug that was causing unnecessary rehahes.
........
r56349 | danieljames | 2009-09-21 22:18:21 +0100 (Mon, 21 Sep 2009) | 1 line
Use std::max.
........
r56362 | danieljames | 2009-09-22 23:39:00 +0100 (Tue, 22 Sep 2009) | 1 line
Another std::max.
........
r56363 | danieljames | 2009-09-22 23:39:17 +0100 (Tue, 22 Sep 2009) | 1 line
Remove the emplace_hint implementation for unique containers as it isn't really used and seems to be causing sun 5.7 problems.
........
r56374 | danieljames | 2009-09-24 21:42:19 +0100 (Thu, 24 Sep 2009) | 1 line
Remove temporary test.
........
[SVN r56375]
2009-09-24 21:12:46 +00:00
|
|
|
|
|
|
|
|
#endif
|