|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55525 - in sandbox/SOC/2006/tree/trunk/boost/tree: . detail
From: ockham_at_[hidden]
Date: 2009-08-11 08:42:10
Author: bernhard.reiter
Date: 2009-08-11 08:42:07 EDT (Tue, 11 Aug 2009)
New Revision: 55525
URL: http://svn.boost.org/trac/boost/changeset/55525
Log:
Move swap implementation to nary_node.hpp
Text files modified:
sandbox/SOC/2006/tree/trunk/boost/tree/binary_tree.hpp | 40 +---------------------------------------
sandbox/SOC/2006/tree/trunk/boost/tree/detail/nary_node.hpp | 18 ++++++++++++++++++
2 files changed, 19 insertions(+), 39 deletions(-)
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/binary_tree.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/binary_tree.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/binary_tree.hpp 2009-08-11 08:42:07 EDT (Tue, 11 Aug 2009)
@@ -297,48 +297,10 @@
* @param x A %binary_tree of the same element and allocator types.
*
* This exchanges the elements between two binary trees in constant time.
- * (Four pointers, so it should be quite fast.)
*/
void swap(self_type& other)
{
- using std::swap;
- if (empty()) {
- if (other.empty())
- return;
-
- m_header.m_children[0] = other.m_header.m_children[0];
- static_cast<node_base_pointer>(m_header.m_children[0])->m_parent = &m_header;
-
- m_header.m_children[1] = other.m_header.m_children[1];
- //m_header.m_parent = other.m_header.m_parent;
-
- other.m_header.m_children[0] = 0;
- other.m_header.m_children[1] = &other.m_header;
- //other.m_header.m_parent = &other.m_header;
-
- return;
- }
-
- if (other.empty()) {
- other.m_header.m_children[0] = m_header.m_children[0];
- static_cast<node_base_pointer>(other.m_header.m_children[0])->m_parent = &other.m_header;
-
- other.m_header.m_children[1] = m_header.m_children[1];
- //other.m_header.m_parent = m_header.m_parent;
-
- m_header.m_children[0] = 0;
- m_header.m_children[1] = &m_header;
- //m_header.m_parent = &m_header;
-
- return;
- }
-
- swap(m_header, other.m_header);
- //swap(m_header.m_children[0]->m_parent, other.m_header.m_children[0]->m_parent);
- static_cast<node_base_pointer>(m_header.m_children[0])->m_parent = &m_header;
- static_cast<node_base_pointer>(other.m_header.m_children[0])->m_parent = &other.m_header;
-
- return;
+ detail::swap_trees(m_header, other.m_header);
}
/**
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/nary_node.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/nary_node.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/nary_node.hpp 2009-08-11 08:42:07 EDT (Tue, 11 Aug 2009)
@@ -158,6 +158,24 @@
splice(to, from);
}
+// Currently only suitable for trees, not subtrees!
+// Otherwise we'd need also to take care of m_children[1] and m_parent
+void swap_trees(node_base& x, node_base& y)
+{
+ using std::swap;
+
+ swap(x, y);
+
+ if (x.m_children[0])
+ static_cast<node_base*>(x.m_children[0])->m_parent
+ = &x;
+
+ if (y.m_children[0])
+ static_cast<node_base*>(
+ y.m_children[0]
+ )->m_parent = &y;
+}
+
class descending_node_base
: public node_with_children_base {
};
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk