forked from boostorg/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]
227 lines
6.5 KiB
C++
227 lines
6.5 KiB
C++
|
|
// Copyright (C) 2003-2004 Jeremy B. Maitin-Shepard.
|
|
// Copyright (C) 2005-2009 Daniel James
|
|
// 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)
|
|
|
|
// This contains the basic data structure, apart from the actual values. There's
|
|
// no construction or deconstruction here. So this only depends on the pointer
|
|
// type.
|
|
|
|
#ifndef BOOST_UNORDERED_DETAIL_NODE_HPP_INCLUDED
|
|
#define BOOST_UNORDERED_DETAIL_NODE_HPP_INCLUDED
|
|
|
|
#include <boost/config.hpp>
|
|
#include <boost/assert.hpp>
|
|
#include <boost/detail/workaround.hpp>
|
|
#include <boost/unordered/detail/fwd.hpp>
|
|
|
|
#if BOOST_WORKAROUND(__BORLANDC__, <= 0X0582)
|
|
#define BOOST_UNORDERED_BORLAND_BOOL(x) (bool)(x)
|
|
#else
|
|
#define BOOST_UNORDERED_BORLAND_BOOL(x) x
|
|
#endif
|
|
|
|
namespace boost { namespace unordered_detail {
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
// ungrouped node implementation
|
|
|
|
template <class A>
|
|
inline BOOST_DEDUCED_TYPENAME ungrouped_node_base<A>::node_ptr&
|
|
ungrouped_node_base<A>::next_group(node_ptr ptr)
|
|
{
|
|
return ptr->next_;
|
|
}
|
|
|
|
template <class A>
|
|
inline std::size_t ungrouped_node_base<A>::group_count(node_ptr)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
template <class A>
|
|
inline void ungrouped_node_base<A>::add_to_bucket(node_ptr n, bucket& b)
|
|
{
|
|
n->next_ = b.next_;
|
|
b.next_ = n;
|
|
}
|
|
|
|
template <class A>
|
|
inline void ungrouped_node_base<A>::add_after_node(node_ptr n,
|
|
node_ptr position)
|
|
{
|
|
n->next_ = position->next_;
|
|
position->next_ = position;
|
|
}
|
|
|
|
template <class A>
|
|
inline void ungrouped_node_base<A>::unlink_nodes(bucket& b,
|
|
node_ptr begin, node_ptr end)
|
|
{
|
|
node_ptr* pos = &b.next_;
|
|
while(*pos != begin) pos = &(*pos)->next_;
|
|
*pos = end;
|
|
}
|
|
|
|
template <class A>
|
|
inline void ungrouped_node_base<A>::unlink_nodes(bucket& b, node_ptr end)
|
|
{
|
|
b.next_ = end;
|
|
}
|
|
|
|
template <class A>
|
|
inline void ungrouped_node_base<A>::unlink_node(bucket& b, node_ptr n)
|
|
{
|
|
unlink_nodes(b, n, n->next_);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
// grouped node implementation
|
|
|
|
// If ptr is the first element in a group, return pointer to next group.
|
|
// Otherwise returns a pointer to ptr.
|
|
template <class A>
|
|
inline BOOST_DEDUCED_TYPENAME grouped_node_base<A>::node_ptr&
|
|
grouped_node_base<A>::next_group(node_ptr ptr)
|
|
{
|
|
return get(ptr).group_prev_->next_;
|
|
}
|
|
|
|
template <class A>
|
|
inline BOOST_DEDUCED_TYPENAME grouped_node_base<A>::node_ptr
|
|
grouped_node_base<A>::first_in_group(node_ptr ptr)
|
|
{
|
|
while(next_group(ptr) == ptr)
|
|
ptr = get(ptr).group_prev_;
|
|
return ptr;
|
|
}
|
|
|
|
template <class A>
|
|
inline std::size_t grouped_node_base<A>::group_count(node_ptr ptr)
|
|
{
|
|
node_ptr start = ptr;
|
|
std::size_t size = 0;
|
|
do {
|
|
++size;
|
|
ptr = get(ptr).group_prev_;
|
|
} while(ptr != start);
|
|
return size;
|
|
}
|
|
|
|
template <class A>
|
|
inline void grouped_node_base<A>::add_to_bucket(node_ptr n, bucket& b)
|
|
{
|
|
n->next_ = b.next_;
|
|
get(n).group_prev_ = n;
|
|
b.next_ = n;
|
|
}
|
|
|
|
template <class A>
|
|
inline void grouped_node_base<A>::add_after_node(node_ptr n, node_ptr pos)
|
|
{
|
|
n->next_ = next_group(pos);
|
|
get(n).group_prev_ = get(pos).group_prev_;
|
|
next_group(pos) = n;
|
|
get(pos).group_prev_ = n;
|
|
}
|
|
|
|
// Break a ciruclar list into two, with split as the beginning
|
|
// of the second group (if split is at the beginning then don't
|
|
// split).
|
|
template <class A>
|
|
inline BOOST_DEDUCED_TYPENAME grouped_node_base<A>::node_ptr
|
|
grouped_node_base<A>::split_group(node_ptr split)
|
|
{
|
|
node_ptr first = first_in_group(split);
|
|
if(first == split) return split;
|
|
|
|
node_ptr last = get(first).group_prev_;
|
|
get(first).group_prev_ = get(split).group_prev_;
|
|
get(split).group_prev_ = last;
|
|
|
|
return first;
|
|
}
|
|
|
|
template <class A>
|
|
void grouped_node_base<A>::unlink_node(bucket& b, node_ptr n)
|
|
{
|
|
node_ptr next = n->next_;
|
|
node_ptr* pos = &next_group(n);
|
|
|
|
if(*pos != n) {
|
|
// The node is at the beginning of a group.
|
|
|
|
// Find the previous node pointer:
|
|
pos = &b.next_;
|
|
while(*pos != n) pos = &next_group(*pos);
|
|
|
|
// Remove from group
|
|
if(BOOST_UNORDERED_BORLAND_BOOL(next) &&
|
|
get(next).group_prev_ == n)
|
|
{
|
|
get(next).group_prev_ = get(n).group_prev_;
|
|
}
|
|
}
|
|
else if(BOOST_UNORDERED_BORLAND_BOOL(next) &&
|
|
get(next).group_prev_ == n)
|
|
{
|
|
// The deleted node is not at the end of the group, so
|
|
// change the link from the next node.
|
|
get(next).group_prev_ = get(n).group_prev_;
|
|
}
|
|
else {
|
|
// The deleted node is at the end of the group, so the
|
|
// first node in the group is pointing to it.
|
|
// Find that to change its pointer.
|
|
node_ptr x = get(n).group_prev_;
|
|
while(get(x).group_prev_ != n) {
|
|
x = get(x).group_prev_;
|
|
}
|
|
get(x).group_prev_ = get(n).group_prev_;
|
|
}
|
|
*pos = next;
|
|
}
|
|
|
|
template <class A>
|
|
void grouped_node_base<A>::unlink_nodes(bucket& b,
|
|
node_ptr begin, node_ptr end)
|
|
{
|
|
node_ptr* pos = &next_group(begin);
|
|
|
|
if(*pos != begin) {
|
|
// The node is at the beginning of a group.
|
|
|
|
// Find the previous node pointer:
|
|
pos = &b.next_;
|
|
while(*pos != begin) pos = &next_group(*pos);
|
|
|
|
// Remove from group
|
|
if(BOOST_UNORDERED_BORLAND_BOOL(end)) split_group(end);
|
|
}
|
|
else {
|
|
node_ptr group1 = split_group(begin);
|
|
if(BOOST_UNORDERED_BORLAND_BOOL(end)) {
|
|
node_ptr group2 = split_group(end);
|
|
|
|
if(begin == group2) {
|
|
node_ptr end1 = get(group1).group_prev_;
|
|
node_ptr end2 = get(group2).group_prev_;
|
|
get(group1).group_prev_ = end2;
|
|
get(group2).group_prev_ = end1;
|
|
}
|
|
}
|
|
}
|
|
*pos = end;
|
|
}
|
|
|
|
template <class A>
|
|
void grouped_node_base<A>::unlink_nodes(bucket& b, node_ptr end)
|
|
{
|
|
split_group(end);
|
|
b.next_ = end;
|
|
}
|
|
}}
|
|
|
|
#endif
|