123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #ifndef BOOST_INTRUSIVE_BSTREE_ALGORITHMS_BASE_HPP
- #define BOOST_INTRUSIVE_BSTREE_ALGORITHMS_BASE_HPP
- #ifndef BOOST_CONFIG_HPP
- # include <boost/config.hpp>
- #endif
- #if defined(BOOST_HAS_PRAGMA_ONCE)
- # pragma once
- #endif
- #include <boost/intrusive/detail/uncast.hpp>
- namespace boost {
- namespace intrusive {
- template<class NodeTraits>
- class bstree_algorithms_base
- {
- public:
- typedef typename NodeTraits::node node;
- typedef NodeTraits node_traits;
- typedef typename NodeTraits::node_ptr node_ptr;
- typedef typename NodeTraits::const_node_ptr const_node_ptr;
-
-
-
-
-
-
-
- static node_ptr next_node(node_ptr n) BOOST_NOEXCEPT
- {
- node_ptr const n_right(NodeTraits::get_right(n));
- if(n_right){
- return minimum(n_right);
- }
- else {
- node_ptr p(NodeTraits::get_parent(n));
- while(n == NodeTraits::get_right(p)){
- n = p;
- p = NodeTraits::get_parent(p);
- }
- return NodeTraits::get_right(n) != p ? p : n;
- }
- }
-
-
-
-
-
-
-
- static node_ptr prev_node(node_ptr n) BOOST_NOEXCEPT
- {
- if(is_header(n)){
- return NodeTraits::get_right(n);
- }
- else if(NodeTraits::get_left(n)){
- return maximum(NodeTraits::get_left(n));
- }
- else {
- node_ptr p(n);
- node_ptr x = NodeTraits::get_parent(p);
- while(p == NodeTraits::get_left(x)){
- p = x;
- x = NodeTraits::get_parent(x);
- }
- return x;
- }
- }
-
-
-
-
-
-
-
- static node_ptr minimum(node_ptr n)
- {
- for(node_ptr p_left = NodeTraits::get_left(n)
- ;p_left
- ;p_left = NodeTraits::get_left(n)){
- n = p_left;
- }
- return n;
- }
-
-
-
-
-
-
-
- static node_ptr maximum(node_ptr n)
- {
- for(node_ptr p_right = NodeTraits::get_right(n)
- ;p_right
- ;p_right = NodeTraits::get_right(n)){
- n = p_right;
- }
- return n;
- }
-
-
-
-
-
-
-
- static bool is_header(const_node_ptr p) BOOST_NOEXCEPT
- {
- node_ptr p_left (NodeTraits::get_left(p));
- node_ptr p_right(NodeTraits::get_right(p));
- if(!NodeTraits::get_parent(p) ||
- (p_left && p_right &&
- (p_left == p_right ||
- (NodeTraits::get_parent(p_left) != p ||
- NodeTraits::get_parent(p_right) != p ))
-
-
- )){
- return true;
- }
- return false;
- }
-
-
-
-
-
-
-
- static node_ptr get_header(const_node_ptr n)
- {
- node_ptr nn(detail::uncast(n));
- node_ptr p(NodeTraits::get_parent(n));
-
- if(p){
-
- node_ptr pp(NodeTraits::get_parent(p));
-
-
- if(nn != pp){
- do{
- nn = p;
- p = pp;
- pp = NodeTraits::get_parent(pp);
- }while(nn != pp);
- nn = p;
- }
-
- else if(!bstree_algorithms_base::is_header(nn)){
- nn = p;
- }
- }
- return nn;
- }
- };
- }
- }
- #endif
|