File indexing completed on 2025-01-18 09:38:36
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_INTRUSIVE_BSTREE_ALGORITHMS_BASE_HPP
0014 #define BOOST_INTRUSIVE_BSTREE_ALGORITHMS_BASE_HPP
0015
0016 #ifndef BOOST_CONFIG_HPP
0017 # include <boost/config.hpp>
0018 #endif
0019
0020 #if defined(BOOST_HAS_PRAGMA_ONCE)
0021 # pragma once
0022 #endif
0023
0024 #include <boost/intrusive/detail/uncast.hpp>
0025
0026 namespace boost {
0027 namespace intrusive {
0028
0029 template<class NodeTraits>
0030 class bstree_algorithms_base
0031 {
0032 public:
0033 typedef typename NodeTraits::node node;
0034 typedef NodeTraits node_traits;
0035 typedef typename NodeTraits::node_ptr node_ptr;
0036 typedef typename NodeTraits::const_node_ptr const_node_ptr;
0037
0038
0039
0040
0041
0042
0043
0044
0045 static node_ptr next_node(node_ptr n) BOOST_NOEXCEPT
0046 {
0047 node_ptr const n_right(NodeTraits::get_right(n));
0048 if(n_right){
0049 return minimum(n_right);
0050 }
0051 else {
0052 node_ptr p(NodeTraits::get_parent(n));
0053 while(n == NodeTraits::get_right(p)){
0054 n = p;
0055 p = NodeTraits::get_parent(p);
0056 }
0057 return NodeTraits::get_right(n) != p ? p : n;
0058 }
0059 }
0060
0061
0062
0063
0064
0065
0066
0067
0068 static node_ptr prev_node(node_ptr n) BOOST_NOEXCEPT
0069 {
0070 if(is_header(n)){
0071 return NodeTraits::get_right(n);
0072 }
0073 else if(NodeTraits::get_left(n)){
0074 return maximum(NodeTraits::get_left(n));
0075 }
0076 else {
0077 node_ptr p(n);
0078 node_ptr x = NodeTraits::get_parent(p);
0079 while(p == NodeTraits::get_left(x)){
0080 p = x;
0081 x = NodeTraits::get_parent(x);
0082 }
0083 return x;
0084 }
0085 }
0086
0087
0088
0089
0090
0091
0092
0093
0094 static node_ptr minimum(node_ptr n)
0095 {
0096 for(node_ptr p_left = NodeTraits::get_left(n)
0097 ;p_left
0098 ;p_left = NodeTraits::get_left(n)){
0099 n = p_left;
0100 }
0101 return n;
0102 }
0103
0104
0105
0106
0107
0108
0109
0110
0111 static node_ptr maximum(node_ptr n)
0112 {
0113 for(node_ptr p_right = NodeTraits::get_right(n)
0114 ;p_right
0115 ;p_right = NodeTraits::get_right(n)){
0116 n = p_right;
0117 }
0118 return n;
0119 }
0120
0121
0122
0123
0124
0125
0126
0127
0128 static bool is_header(const_node_ptr p) BOOST_NOEXCEPT
0129 {
0130 node_ptr p_left (NodeTraits::get_left(p));
0131 node_ptr p_right(NodeTraits::get_right(p));
0132 if(!NodeTraits::get_parent(p) ||
0133 (p_left && p_right &&
0134 (p_left == p_right ||
0135 (NodeTraits::get_parent(p_left) != p ||
0136 NodeTraits::get_parent(p_right) != p ))
0137
0138
0139 )){
0140 return true;
0141 }
0142 return false;
0143 }
0144
0145
0146
0147
0148
0149
0150
0151
0152 static node_ptr get_header(const_node_ptr n)
0153 {
0154 node_ptr nn(detail::uncast(n));
0155 node_ptr p(NodeTraits::get_parent(n));
0156
0157 if(p){
0158
0159 node_ptr pp(NodeTraits::get_parent(p));
0160
0161
0162 if(nn != pp){
0163 do{
0164 nn = p;
0165 p = pp;
0166 pp = NodeTraits::get_parent(pp);
0167 }while(nn != pp);
0168 nn = p;
0169 }
0170
0171 else if(!bstree_algorithms_base::is_header(nn)){
0172 nn = p;
0173 }
0174 }
0175 return nn;
0176 }
0177 };
0178
0179 }
0180 }
0181
0182 #endif