Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55524 - in sandbox/SOC/2006/tree/trunk/boost/tree: . detail
From: ockham_at_[hidden]
Date: 2009-08-11 08:17:33


Author: bernhard.reiter
Date: 2009-08-11 08:17:31 EDT (Tue, 11 Aug 2009)
New Revision: 55524
URL: http://svn.boost.org/trac/boost/changeset/55524

Log:
nary_node typedef cleanups, and: make nary_cursor::m_pos an implementation detail
Text files modified:
   sandbox/SOC/2006/tree/trunk/boost/tree/binary_tree.hpp | 14 +++++-----
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/multiway_cursor.hpp | 2
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/nary_cursor.hpp | 50 +++++++++++++++++----------------------
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/nary_node.hpp | 31 +++++++++---------------
   sandbox/SOC/2006/tree/trunk/boost/tree/detail/node_traits.hpp | 15 ++++-------
   5 files changed, 48 insertions(+), 64 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:17:31 EDT (Tue, 11 Aug 2009)
@@ -195,7 +195,7 @@
         //m_node_alloc.construct(p_node, val);
         *p_node = node_type(val);
         
- detail::attach(pos.base_node(), pos.the_node(), p_node, p_node->m_children[pos.m_pos]);
+ detail::attach(pos.parent_node(), pos.child_node(), p_node, p_node->m_children[pos.index()]);
 
         // Readjust begin
 // if ((pos == this->inorder_first()))
@@ -248,7 +248,7 @@
         if (!position.is_leaf()) {
             node_pointer pos_node =
                 static_cast<node_pointer>(
- position.the_node()
+ position.child_node()
                 );
 
             size_type parent_idx = index(position.parent());
@@ -274,7 +274,7 @@
         if (!position.is_leaf()) {
             node_pointer pos_node =
                 static_cast<node_pointer>(
- position.the_node()
+ position.child_node()
                 );
 
             // recurse
@@ -289,7 +289,7 @@
 public:
     void rotate(cursor& pos)
     {
- pos.m_pos = detail::rotate(pos.the_node(), pos.base_node(), pos.m_pos);
+ detail::rotate(pos.child_node(), pos.parent_node(), pos.index());
     }
     
     /**
@@ -380,7 +380,7 @@
     void splice(cursor position, binary_tree& x, cursor root)
     {
         // x isn't actually used currently...
- detail::splice(position.base_node(), position.the_node(), root.the_node());
+ detail::splice(position.parent_node(), position.child_node(), root.child_node());
     }
 
     /**
@@ -391,11 +391,11 @@
     cursor erase(cursor position)
     {
         size_type idx = index(position);
- node_pointer p_node = static_cast<node_pointer>(position.base_node());
+ node_pointer p_node = static_cast<node_pointer>(position.parent_node());
 
         p_node = static_cast<node_pointer>(p_node->detach(idx));
 
- position.base_node() = static_cast<node_base_pointer>(p_node->m_children[idx]);
+ position.parent_node() = static_cast<node_base_pointer>(p_node->m_children[idx]);
 
         m_node_alloc.destroy(p_node);
         m_node_alloc.deallocate(p_node, 1);

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/multiway_cursor.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/multiway_cursor.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/multiway_cursor.hpp 2009-08-11 08:17:31 EDT (Tue, 11 Aug 2009)
@@ -131,7 +131,7 @@
         multiway_tree_cursor<OtherCursor> const& other
       , typename boost::enable_if<
             boost::is_convertible<OtherCursor*,
- typename Cursor::base_pointer> // is that correct?
+ typename Cursor::node_base_type*> // is that correct?
           , enabler
>::type = enabler()
     )

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/nary_cursor.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/nary_cursor.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/nary_cursor.hpp 2009-08-11 08:17:31 EDT (Tue, 11 Aug 2009)
@@ -34,8 +34,8 @@
  : public cursor_adaptor<ascending_nary_cursor<Node>
       , typename mpl::eval_if<
                         is_const<Node>
- , add_const<typename Node::base_type>
- , mpl::identity<typename Node::base_type>
+ , add_const<typename Node::node_base>
+ , mpl::identity<typename Node::node_base>
>::type*
       , typename mpl::eval_if<
                     is_const<Node>
@@ -47,21 +47,17 @@
> {
 
 private:
- typedef typename Node::base_type node_base;
-
- typedef typename mpl::eval_if<
- is_const<Node>
- , add_const<node_base>
- , mpl::identity<node_base>
- >::type base_type;
-
- typedef base_type* base_pointer;
-
     struct enabler {};
-
+
     typedef Node node_type;
     typedef node_type* node_pointer;
-
+
+ typedef typename mpl::eval_if<
+ is_const<Node>
+ , add_const<typename Node::node_base>
+ , mpl::identity<typename Node::node_base>
+ >::type node_base_type;
+
 public:
     typedef typename mpl::eval_if<
                         is_const<Node>
@@ -89,7 +85,7 @@
     ascending_nary_cursor()
       : ascending_nary_cursor::cursor_adaptor_(0), m_pos(0) {}
 
- explicit ascending_nary_cursor(base_pointer p, size_type pos)
+ explicit ascending_nary_cursor(node_base_type* p, size_type pos)
     : ascending_nary_cursor::cursor_adaptor_(p), m_pos(pos) {}
 
     template <class OtherNode>
@@ -102,9 +98,8 @@
     )
     : ascending_nary_cursor::cursor_adaptor_(other.base()), m_pos(other.m_pos) {}
 
- size_type m_pos;
-
-private:
+private:
+ size_type m_pos;
 
     friend class iterator_core_access;
     friend class cursor_core_access;
@@ -173,7 +168,7 @@
     void left()
     {
         this->base_reference() =
- static_cast<node_base*>(this->base_reference()->m_children[m_pos]);
+ static_cast<node_base_type*>(this->base_reference()->m_children[m_pos]);
         m_pos = 0;
         //this->base_reference() = this->base_reference()->operator[0];
     }
@@ -182,7 +177,7 @@
     {
         size_type new_pos = this->base_reference()->m_children.size()-1;
         this->base_reference() =
- static_cast<node_base*>(this->base_reference()->m_children[m_pos]);
+ static_cast<node_base_type*>(this->base_reference()->m_children[m_pos]);
         m_pos = new_pos;
         //this->base_reference() = this->base_reference()->operator[0];
     }
@@ -191,38 +186,37 @@
     void up()
     {
         m_pos = this->base_reference()->get_index();
- this->base_reference() = static_cast<base_pointer>(this->base_reference()->parent());
+ this->base_reference() = static_cast<node_base_type*>(this->base_reference()->parent());
         //this->base_reference() = this->base_reference()->parent();
     }
     
 protected:
     bool is_on_top() const
     {
- base_pointer parent_begin_node =
- static_cast<base_pointer>(this->base_reference()->parent())
+ node_base_type* parent_begin_node =
+ static_cast<node_base_type*>(this->base_reference()->parent())
             ->m_children[this->base_reference()->get_index()];
         return (!m_pos && (this->base_reference() != parent_begin_node));
         // (*this != this->parent().begin())
     }
 
 public:
-
- base_pointer const& base_node() const
+ node_base_type* const& parent_node() const
     {
         return this->base_reference();
     }
 
- base_pointer& base_node()
+ node_base_type*& parent_node()
     {
         return this->base_reference();
     }
 
- typename node_type::node_with_children_base* const& the_node() const
+ typename node_base_type::node_with_children_base* const& child_node() const
     {
         return this->base_reference()->m_children[m_pos];
     }
 
- typename node_type::node_with_children_base*& the_node()
+ typename node_base_type::node_with_children_base*& child_node()
     {
         return this->base_reference()->m_children[m_pos];
     }

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:17:31 EDT (Tue, 11 Aug 2009)
@@ -89,18 +89,13 @@
 
 class node_base
 : public node_with_parent_base, public node_with_children_base {
- typedef node_base self_type;
-
 public:
- typedef self_type* base_pointer;
- typedef self_type const* const_base_pointer;
-
     node_base() : node_with_parent_base(), node_with_children_base() {}
 
     node_base(node_with_parent_base* p)
     : node_with_parent_base(p), node_with_children_base() {}
     
- base_pointer detach(children_type::size_type m_pos)
+ node_base* detach(children_type::size_type m_pos)
     {
         node_with_children_base::children_type::size_type parent_idx = get_index();
 
@@ -116,17 +111,19 @@
     // O(1)
     children_type::size_type const get_index() const
     {
- return (static_cast<base_pointer>(this->m_parent)->m_children[0] == this ? 0 : 1);
+ return (static_cast<node_base*>(this->m_parent)->m_children[0] == this ? 0 : 1);
     }
 };
 
-node_with_children_base::children_type::size_type rotate(node_with_children_base*& child, node_base* parent, node_with_children_base::children_type::size_type const& c)
+//node_with_children_base::children_type::size_type
+void
+rotate(node_with_children_base*& child, node_base* parent
+ , node_with_children_base::children_type::size_type const& c)
 {
     //TODO: Optimise.
- typedef node_base* base_pointer;
- base_pointer q = static_cast<node_base*>(child);
+ node_base* q = static_cast<node_base*>(child);
     
- base_pointer B = static_cast<node_base*>(child->m_children[(c ? 0 : 1)]);
+ node_base* B = static_cast<node_base*>(child->m_children[(c ? 0 : 1)]);
     //pre_rotate();
     
     //B swaps places with its m_parent:
@@ -136,10 +133,10 @@
     q->m_parent = parent->m_parent;
 
     node_with_children_base::children_type::size_type qp = parent->get_index();
- static_cast<base_pointer>(q->m_parent)->m_children[qp] = q;
+ static_cast<node_base*>(q->m_parent)->m_children[qp] = q;
     parent->m_parent = q;
     q->m_children[(c ? 0 : 1)] = parent;
- return qp;
+ //return qp;
     //return (c ? 0 : 1);
 }
 
@@ -173,10 +170,6 @@
     typedef ascending_node<value_type> node_type;
     typedef node_type* node_pointer;
     typedef node_type& node_reference;
-
- typedef node_base base_type;
- typedef base_type* base_pointer;
- typedef base_type const* const_base_pointer;
     
     typedef value_type& reference;
     typedef value_type const& const_reference;
@@ -189,9 +182,9 @@
 
     const_reference operator*() const { return m_data; }
     
- ascending_node(value_type data) : base_type(), m_data(data) {}
+ ascending_node(value_type data) : node_base(), m_data(data) {}
  
- ascending_node(value_type data, base_pointer p) : base_type(p), m_data(data) {}
+ ascending_node(value_type data, node_base* p) : node_base(p), m_data(data) {}
     
 private:
     value_type m_data;

Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/node_traits.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/node_traits.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/node_traits.hpp 2009-08-11 08:17:31 EDT (Tue, 11 Aug 2009)
@@ -17,20 +17,17 @@
     typedef Node node_type;
     
     // Value
- typedef typename node_type::value_type value_type;
- typedef typename node_type::pointer pointer;
- typedef typename node_type::reference reference;
+ typedef typename node_type::value_type value_type;
+ typedef typename node_type::pointer pointer;
+ typedef typename node_type::reference reference;
     //typedef typename node_type::size_type size_type;
     
     // Node
- typedef typename node_type::node_pointer node_pointer;
- typedef typename node_type::node_reference node_reference;
+ typedef typename node_type::node_pointer node_pointer;
+ typedef typename node_type::node_reference node_reference;
     
     // Node base
- typedef typename node_type::base_type node_base_type;
- typedef typename node_type::base_pointer node_base_pointer;
-
- typedef node_base_pointer position_type;
+ typedef typename node_type::node_base node_base_type;
 };
 
 } // namespace detail


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