annotate DEPENDENCIES/generic/include/boost/intrusive/detail/rbtree_node.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /////////////////////////////////////////////////////////////////////////////
Chris@16 2 //
Chris@16 3 // (C) Copyright Olaf Krzikalla 2004-2006.
Chris@16 4 // (C) Copyright Ion Gaztanaga 2006-2013.
Chris@16 5 //
Chris@16 6 // Distributed under the Boost Software License, Version 1.0.
Chris@16 7 // (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 8 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //
Chris@16 10 // See http://www.boost.org/libs/intrusive for documentation.
Chris@16 11 //
Chris@16 12 /////////////////////////////////////////////////////////////////////////////
Chris@16 13
Chris@16 14 #ifndef BOOST_INTRUSIVE_RBTREE_NODE_HPP
Chris@16 15 #define BOOST_INTRUSIVE_RBTREE_NODE_HPP
Chris@16 16
Chris@101 17 #ifndef BOOST_CONFIG_HPP
Chris@101 18 # include <boost/config.hpp>
Chris@101 19 #endif
Chris@101 20
Chris@101 21 #if defined(BOOST_HAS_PRAGMA_ONCE)
Chris@101 22 # pragma once
Chris@101 23 #endif
Chris@101 24
Chris@16 25 #include <boost/intrusive/detail/config_begin.hpp>
Chris@101 26 #include <boost/intrusive/pointer_rebind.hpp>
Chris@16 27 #include <boost/intrusive/rbtree_algorithms.hpp>
Chris@16 28 #include <boost/intrusive/pointer_plus_bits.hpp>
Chris@16 29 #include <boost/intrusive/detail/mpl.hpp>
Chris@16 30 #include <boost/intrusive/detail/tree_node.hpp>
Chris@16 31
Chris@16 32 namespace boost {
Chris@16 33 namespace intrusive {
Chris@16 34
Chris@16 35 /////////////////////////////////////////////////////////////////////////////
Chris@16 36 // //
Chris@16 37 // Generic node_traits for any pointer type //
Chris@16 38 // //
Chris@16 39 /////////////////////////////////////////////////////////////////////////////
Chris@16 40
Chris@16 41 //This is the compact representation: 3 pointers
Chris@16 42 template<class VoidPointer>
Chris@16 43 struct compact_rbtree_node
Chris@16 44 {
Chris@101 45 typedef compact_rbtree_node<VoidPointer> node;
Chris@101 46 typedef typename pointer_rebind<VoidPointer, node >::type node_ptr;
Chris@101 47 typedef typename pointer_rebind<VoidPointer, const node >::type const_node_ptr;
Chris@16 48 enum color { red_t, black_t };
Chris@16 49 node_ptr parent_, left_, right_;
Chris@16 50 };
Chris@16 51
Chris@16 52 //This is the normal representation: 3 pointers + enum
Chris@16 53 template<class VoidPointer>
Chris@16 54 struct rbtree_node
Chris@16 55 {
Chris@101 56 typedef rbtree_node<VoidPointer> node;
Chris@101 57 typedef typename pointer_rebind<VoidPointer, node >::type node_ptr;
Chris@101 58 typedef typename pointer_rebind<VoidPointer, const node >::type const_node_ptr;
Chris@16 59
Chris@16 60 enum color { red_t, black_t };
Chris@16 61 node_ptr parent_, left_, right_;
Chris@16 62 color color_;
Chris@16 63 };
Chris@16 64
Chris@16 65 //This is the default node traits implementation
Chris@16 66 //using a node with 3 generic pointers plus an enum
Chris@16 67 template<class VoidPointer>
Chris@16 68 struct default_rbtree_node_traits_impl
Chris@16 69 {
Chris@16 70 typedef rbtree_node<VoidPointer> node;
Chris@101 71 typedef typename node::node_ptr node_ptr;
Chris@101 72 typedef typename node::const_node_ptr const_node_ptr;
Chris@16 73
Chris@16 74 typedef typename node::color color;
Chris@16 75
Chris@16 76 static node_ptr get_parent(const const_node_ptr & n)
Chris@16 77 { return n->parent_; }
Chris@16 78
Chris@16 79 static node_ptr get_parent(const node_ptr & n)
Chris@16 80 { return n->parent_; }
Chris@16 81
Chris@16 82 static void set_parent(const node_ptr & n, const node_ptr & p)
Chris@16 83 { n->parent_ = p; }
Chris@16 84
Chris@16 85 static node_ptr get_left(const const_node_ptr & n)
Chris@16 86 { return n->left_; }
Chris@16 87
Chris@16 88 static node_ptr get_left(const node_ptr & n)
Chris@16 89 { return n->left_; }
Chris@16 90
Chris@16 91 static void set_left(const node_ptr & n, const node_ptr & l)
Chris@16 92 { n->left_ = l; }
Chris@16 93
Chris@16 94 static node_ptr get_right(const const_node_ptr & n)
Chris@16 95 { return n->right_; }
Chris@16 96
Chris@16 97 static node_ptr get_right(const node_ptr & n)
Chris@16 98 { return n->right_; }
Chris@16 99
Chris@16 100 static void set_right(const node_ptr & n, const node_ptr & r)
Chris@16 101 { n->right_ = r; }
Chris@16 102
Chris@16 103 static color get_color(const const_node_ptr & n)
Chris@16 104 { return n->color_; }
Chris@16 105
Chris@16 106 static color get_color(const node_ptr & n)
Chris@16 107 { return n->color_; }
Chris@16 108
Chris@16 109 static void set_color(const node_ptr & n, color c)
Chris@16 110 { n->color_ = c; }
Chris@16 111
Chris@16 112 static color black()
Chris@16 113 { return node::black_t; }
Chris@16 114
Chris@16 115 static color red()
Chris@16 116 { return node::red_t; }
Chris@16 117 };
Chris@16 118
Chris@16 119 //This is the compact node traits implementation
Chris@16 120 //using a node with 3 generic pointers
Chris@16 121 template<class VoidPointer>
Chris@16 122 struct compact_rbtree_node_traits_impl
Chris@16 123 {
Chris@16 124 typedef compact_rbtree_node<VoidPointer> node;
Chris@101 125 typedef typename node::node_ptr node_ptr;
Chris@101 126 typedef typename node::const_node_ptr const_node_ptr;
Chris@16 127
Chris@16 128 typedef pointer_plus_bits<node_ptr, 1> ptr_bit;
Chris@16 129
Chris@16 130 typedef typename node::color color;
Chris@16 131
Chris@16 132 static node_ptr get_parent(const const_node_ptr & n)
Chris@16 133 { return ptr_bit::get_pointer(n->parent_); }
Chris@16 134
Chris@16 135 static node_ptr get_parent(const node_ptr & n)
Chris@16 136 { return ptr_bit::get_pointer(n->parent_); }
Chris@16 137
Chris@16 138 static void set_parent(const node_ptr & n, const node_ptr & p)
Chris@16 139 { ptr_bit::set_pointer(n->parent_, p); }
Chris@16 140
Chris@16 141 static node_ptr get_left(const const_node_ptr & n)
Chris@16 142 { return n->left_; }
Chris@16 143
Chris@16 144 static node_ptr get_left(const node_ptr & n)
Chris@16 145 { return n->left_; }
Chris@16 146
Chris@16 147 static void set_left(const node_ptr & n, const node_ptr & l)
Chris@16 148 { n->left_ = l; }
Chris@16 149
Chris@16 150 static node_ptr get_right(const const_node_ptr & n)
Chris@16 151 { return n->right_; }
Chris@16 152
Chris@16 153 static node_ptr get_right(const node_ptr & n)
Chris@16 154 { return n->right_; }
Chris@16 155
Chris@16 156 static void set_right(const node_ptr & n, const node_ptr & r)
Chris@16 157 { n->right_ = r; }
Chris@16 158
Chris@16 159 static color get_color(const const_node_ptr & n)
Chris@16 160 { return (color)ptr_bit::get_bits(n->parent_); }
Chris@16 161
Chris@16 162 static color get_color(const node_ptr & n)
Chris@16 163 { return (color)ptr_bit::get_bits(n->parent_); }
Chris@16 164
Chris@16 165 static void set_color(const node_ptr & n, color c)
Chris@16 166 { ptr_bit::set_bits(n->parent_, c != 0); }
Chris@16 167
Chris@16 168 static color black()
Chris@16 169 { return node::black_t; }
Chris@16 170
Chris@16 171 static color red()
Chris@16 172 { return node::red_t; }
Chris@16 173 };
Chris@16 174
Chris@16 175 //Dispatches the implementation based on the boolean
Chris@16 176 template<class VoidPointer, bool Compact>
Chris@16 177 struct rbtree_node_traits_dispatch
Chris@16 178 : public default_rbtree_node_traits_impl<VoidPointer>
Chris@16 179 {};
Chris@16 180
Chris@16 181 template<class VoidPointer>
Chris@16 182 struct rbtree_node_traits_dispatch<VoidPointer, true>
Chris@16 183 : public compact_rbtree_node_traits_impl<VoidPointer>
Chris@16 184 {};
Chris@16 185
Chris@101 186 //Inherit from rbtree_node_traits_dispatch depending on the embedding capabilities
Chris@16 187 template<class VoidPointer, bool OptimizeSize = false>
Chris@16 188 struct rbtree_node_traits
Chris@16 189 : public rbtree_node_traits_dispatch
Chris@16 190 < VoidPointer
Chris@16 191 , OptimizeSize &&
Chris@16 192 (max_pointer_plus_bits
Chris@16 193 < VoidPointer
Chris@16 194 , detail::alignment_of<compact_rbtree_node<VoidPointer> >::value
Chris@16 195 >::value >= 1)
Chris@16 196 >
Chris@16 197 {};
Chris@16 198
Chris@16 199 } //namespace intrusive
Chris@16 200 } //namespace boost
Chris@16 201
Chris@16 202 #include <boost/intrusive/detail/config_end.hpp>
Chris@16 203
Chris@16 204 #endif //BOOST_INTRUSIVE_RBTREE_NODE_HPP