summaryrefslogtreecommitdiff
path: root/boost/intrusive/circular_slist_algorithms.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/intrusive/circular_slist_algorithms.hpp')
-rw-r--r--boost/intrusive/circular_slist_algorithms.hpp68
1 files changed, 35 insertions, 33 deletions
diff --git a/boost/intrusive/circular_slist_algorithms.hpp b/boost/intrusive/circular_slist_algorithms.hpp
index c39b3d0c5a..3dd561df50 100644
--- a/boost/intrusive/circular_slist_algorithms.hpp
+++ b/boost/intrusive/circular_slist_algorithms.hpp
@@ -1,7 +1,7 @@
/////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Olaf Krzikalla 2004-2006.
-// (C) Copyright Ion Gaztanaga 2006-2012
+// (C) Copyright Ion Gaztanaga 2006-2014
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -14,11 +14,16 @@
#ifndef BOOST_INTRUSIVE_CIRCULAR_SLIST_ALGORITHMS_HPP
#define BOOST_INTRUSIVE_CIRCULAR_SLIST_ALGORITHMS_HPP
+#if defined(_MSC_VER)
+# pragma once
+#endif
+
+#include <cstddef>
#include <boost/intrusive/detail/config_begin.hpp>
#include <boost/intrusive/intrusive_fwd.hpp>
#include <boost/intrusive/detail/common_slist_algorithms.hpp>
-#include <boost/intrusive/detail/assert.hpp>
-#include <cstddef>
+#include <boost/intrusive/detail/algo_type.hpp>
+
namespace boost {
namespace intrusive {
@@ -172,18 +177,17 @@ class circular_slist_algorithms
static node_ptr get_previous_previous_node(const node_ptr & this_node)
{ return get_previous_previous_node(this_node, this_node); }
- //! <b>Requires</b>: this_node and prev_prev_init_node must be in the same circular list.
+ //! <b>Requires</b>: this_node and p must be in the same circular list.
//!
//! <b>Effects</b>: Returns the previous node of the previous node of this_node in the
- //! circular list starting. the search from prev_init_node. The first node checked
- //! for equality is NodeTraits::get_next((NodeTraits::get_next(prev_prev_init_node)).
+ //! circular list starting. the search from p. The first node checked
+ //! for equality is NodeTraits::get_next((NodeTraits::get_next(p)).
//!
//! <b>Complexity</b>: Linear to the number of elements in the circular list.
//!
//! <b>Throws</b>: Nothing.
- static node_ptr get_previous_previous_node(const node_ptr & prev_prev_init_node, const node_ptr & this_node)
+ static node_ptr get_previous_previous_node(node_ptr p, const node_ptr & this_node)
{
- node_ptr p = prev_prev_init_node;
node_ptr p_next = NodeTraits::get_next(p);
node_ptr p_next_next = NodeTraits::get_next(p_next);
while (this_node != p_next_next){
@@ -250,33 +254,21 @@ class circular_slist_algorithms
{
if (other_node == this_node)
return;
- bool this_inited = base_t::inited(this_node);
- bool other_inited = base_t::inited(other_node);
- if(this_inited){
- base_t::init_header(this_node);
+ const node_ptr this_next = NodeTraits::get_next(this_node);
+ const node_ptr other_next = NodeTraits::get_next(other_node);
+ const bool this_null = !this_next;
+ const bool other_null = !other_next;
+ const bool this_empty = this_next == this_node;
+ const bool other_empty = other_next == other_node;
+
+ if(!(other_null || other_empty)){
+ NodeTraits::set_next(this_next == other_node ? other_node : get_previous_node(other_node), this_node );
}
- if(other_inited){
- base_t::init_header(other_node);
- }
-
- bool empty1 = base_t::unique(this_node);
- bool empty2 = base_t::unique(other_node);
- node_ptr prev_this (get_previous_node(this_node));
- node_ptr prev_other(get_previous_node(other_node));
-
- node_ptr this_next (NodeTraits::get_next(this_node));
- node_ptr other_next(NodeTraits::get_next(other_node));
- NodeTraits::set_next(this_node, other_next);
- NodeTraits::set_next(other_node, this_next);
- NodeTraits::set_next(empty1 ? other_node : prev_this, other_node);
- NodeTraits::set_next(empty2 ? this_node : prev_other, this_node);
-
- if(this_inited){
- base_t::init(other_node);
- }
- if(other_inited){
- base_t::init(this_node);
+ if(!(this_null | this_empty)){
+ NodeTraits::set_next(other_next == this_node ? this_node : get_previous_node(this_node), other_node );
}
+ NodeTraits::set_next(this_node, other_empty ? this_node : (other_next == this_node ? other_node : other_next) );
+ NodeTraits::set_next(other_node, this_empty ? other_node : (this_next == other_node ? this_node : this_next ) );
}
//! <b>Effects</b>: Reverses the order of elements in the list.
@@ -397,6 +389,16 @@ class circular_slist_algorithms
}
};
+/// @cond
+
+template<class NodeTraits>
+struct get_algo<CircularSListAlgorithms, NodeTraits>
+{
+ typedef circular_slist_algorithms<NodeTraits> type;
+};
+
+/// @endcond
+
} //namespace intrusive
} //namespace boost