annotate DEPENDENCIES/generic/include/boost/intrusive/detail/rbtree_node.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
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@16 17 #include <boost/intrusive/detail/config_begin.hpp>
Chris@16 18 #include <iterator>
Chris@16 19 #include <boost/intrusive/pointer_traits.hpp>
Chris@16 20 #include <boost/intrusive/rbtree_algorithms.hpp>
Chris@16 21 #include <boost/intrusive/pointer_plus_bits.hpp>
Chris@16 22 #include <boost/intrusive/detail/mpl.hpp>
Chris@16 23 #include <boost/intrusive/detail/utilities.hpp>
Chris@16 24 #include <boost/intrusive/detail/tree_node.hpp>
Chris@16 25
Chris@16 26 namespace boost {
Chris@16 27 namespace intrusive {
Chris@16 28
Chris@16 29 /////////////////////////////////////////////////////////////////////////////
Chris@16 30 // //
Chris@16 31 // Generic node_traits for any pointer type //
Chris@16 32 // //
Chris@16 33 /////////////////////////////////////////////////////////////////////////////
Chris@16 34
Chris@16 35 //This is the compact representation: 3 pointers
Chris@16 36 template<class VoidPointer>
Chris@16 37 struct compact_rbtree_node
Chris@16 38 {
Chris@16 39 typedef typename pointer_traits
Chris@16 40 <VoidPointer>::template rebind_pointer
Chris@16 41 <compact_rbtree_node<VoidPointer> >::type node_ptr;
Chris@16 42 enum color { red_t, black_t };
Chris@16 43 node_ptr parent_, left_, right_;
Chris@16 44 };
Chris@16 45
Chris@16 46 //This is the normal representation: 3 pointers + enum
Chris@16 47 template<class VoidPointer>
Chris@16 48 struct rbtree_node
Chris@16 49 {
Chris@16 50 typedef typename pointer_traits
Chris@16 51 <VoidPointer>::template rebind_pointer
Chris@16 52 <rbtree_node<VoidPointer> >::type node_ptr;
Chris@16 53
Chris@16 54 enum color { red_t, black_t };
Chris@16 55 node_ptr parent_, left_, right_;
Chris@16 56 color color_;
Chris@16 57 };
Chris@16 58
Chris@16 59 //This is the default node traits implementation
Chris@16 60 //using a node with 3 generic pointers plus an enum
Chris@16 61 template<class VoidPointer>
Chris@16 62 struct default_rbtree_node_traits_impl
Chris@16 63 {
Chris@16 64 typedef rbtree_node<VoidPointer> node;
Chris@16 65
Chris@16 66 typedef typename pointer_traits
Chris@16 67 <VoidPointer>::template rebind_pointer<node>::type node_ptr;
Chris@16 68 typedef typename pointer_traits
Chris@16 69 <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
Chris@16 70
Chris@16 71 typedef typename node::color color;
Chris@16 72
Chris@16 73 static node_ptr get_parent(const const_node_ptr & n)
Chris@16 74 { return n->parent_; }
Chris@16 75
Chris@16 76 static node_ptr get_parent(const node_ptr & n)
Chris@16 77 { return n->parent_; }
Chris@16 78
Chris@16 79 static void set_parent(const node_ptr & n, const node_ptr & p)
Chris@16 80 { n->parent_ = p; }
Chris@16 81
Chris@16 82 static node_ptr get_left(const const_node_ptr & n)
Chris@16 83 { return n->left_; }
Chris@16 84
Chris@16 85 static node_ptr get_left(const node_ptr & n)
Chris@16 86 { return n->left_; }
Chris@16 87
Chris@16 88 static void set_left(const node_ptr & n, const node_ptr & l)
Chris@16 89 { n->left_ = l; }
Chris@16 90
Chris@16 91 static node_ptr get_right(const const_node_ptr & n)
Chris@16 92 { return n->right_; }
Chris@16 93
Chris@16 94 static node_ptr get_right(const node_ptr & n)
Chris@16 95 { return n->right_; }
Chris@16 96
Chris@16 97 static void set_right(const node_ptr & n, const node_ptr & r)
Chris@16 98 { n->right_ = r; }
Chris@16 99
Chris@16 100 static color get_color(const const_node_ptr & n)
Chris@16 101 { return n->color_; }
Chris@16 102
Chris@16 103 static color get_color(const node_ptr & n)
Chris@16 104 { return n->color_; }
Chris@16 105
Chris@16 106 static void set_color(const node_ptr & n, color c)
Chris@16 107 { n->color_ = c; }
Chris@16 108
Chris@16 109 static color black()
Chris@16 110 { return node::black_t; }
Chris@16 111
Chris@16 112 static color red()
Chris@16 113 { return node::red_t; }
Chris@16 114 };
Chris@16 115
Chris@16 116 //This is the compact node traits implementation
Chris@16 117 //using a node with 3 generic pointers
Chris@16 118 template<class VoidPointer>
Chris@16 119 struct compact_rbtree_node_traits_impl
Chris@16 120 {
Chris@16 121 typedef compact_rbtree_node<VoidPointer> node;
Chris@16 122 typedef typename pointer_traits
Chris@16 123 <VoidPointer>::template rebind_pointer<node>::type node_ptr;
Chris@16 124 typedef typename pointer_traits
Chris@16 125 <VoidPointer>::template rebind_pointer<const node>::type const_node_ptr;
Chris@16 126
Chris@16 127 typedef pointer_plus_bits<node_ptr, 1> ptr_bit;
Chris@16 128
Chris@16 129 typedef typename node::color color;
Chris@16 130
Chris@16 131 static node_ptr get_parent(const const_node_ptr & n)
Chris@16 132 { return ptr_bit::get_pointer(n->parent_); }
Chris@16 133
Chris@16 134 static node_ptr get_parent(const node_ptr & n)
Chris@16 135 { return ptr_bit::get_pointer(n->parent_); }
Chris@16 136
Chris@16 137 static void set_parent(const node_ptr & n, const node_ptr & p)
Chris@16 138 { ptr_bit::set_pointer(n->parent_, p); }
Chris@16 139
Chris@16 140 static node_ptr get_left(const const_node_ptr & n)
Chris@16 141 { return n->left_; }
Chris@16 142
Chris@16 143 static node_ptr get_left(const node_ptr & n)
Chris@16 144 { return n->left_; }
Chris@16 145
Chris@16 146 static void set_left(const node_ptr & n, const node_ptr & l)
Chris@16 147 { n->left_ = l; }
Chris@16 148
Chris@16 149 static node_ptr get_right(const const_node_ptr & n)
Chris@16 150 { return n->right_; }
Chris@16 151
Chris@16 152 static node_ptr get_right(const node_ptr & n)
Chris@16 153 { return n->right_; }
Chris@16 154
Chris@16 155 static void set_right(const node_ptr & n, const node_ptr & r)
Chris@16 156 { n->right_ = r; }
Chris@16 157
Chris@16 158 static color get_color(const const_node_ptr & n)
Chris@16 159 { return (color)ptr_bit::get_bits(n->parent_); }
Chris@16 160
Chris@16 161 static color get_color(const node_ptr & n)
Chris@16 162 { return (color)ptr_bit::get_bits(n->parent_); }
Chris@16 163
Chris@16 164 static void set_color(const node_ptr & n, color c)
Chris@16 165 { ptr_bit::set_bits(n->parent_, c != 0); }
Chris@16 166
Chris@16 167 static color black()
Chris@16 168 { return node::black_t; }
Chris@16 169
Chris@16 170 static color red()
Chris@16 171 { return node::red_t; }
Chris@16 172 };
Chris@16 173
Chris@16 174 //Dispatches the implementation based on the boolean
Chris@16 175 template<class VoidPointer, bool Compact>
Chris@16 176 struct rbtree_node_traits_dispatch
Chris@16 177 : public default_rbtree_node_traits_impl<VoidPointer>
Chris@16 178 {};
Chris@16 179
Chris@16 180 template<class VoidPointer>
Chris@16 181 struct rbtree_node_traits_dispatch<VoidPointer, true>
Chris@16 182 : public compact_rbtree_node_traits_impl<VoidPointer>
Chris@16 183 {};
Chris@16 184
Chris@16 185 //Inherit from the detail::link_dispatch depending on the embedding capabilities
Chris@16 186 template<class VoidPointer, bool OptimizeSize = false>
Chris@16 187 struct rbtree_node_traits
Chris@16 188 : public rbtree_node_traits_dispatch
Chris@16 189 < VoidPointer
Chris@16 190 , OptimizeSize &&
Chris@16 191 (max_pointer_plus_bits
Chris@16 192 < VoidPointer
Chris@16 193 , detail::alignment_of<compact_rbtree_node<VoidPointer> >::value
Chris@16 194 >::value >= 1)
Chris@16 195 >
Chris@16 196 {};
Chris@16 197
Chris@16 198 } //namespace intrusive
Chris@16 199 } //namespace boost
Chris@16 200
Chris@16 201 #include <boost/intrusive/detail/config_end.hpp>
Chris@16 202
Chris@16 203 #endif //BOOST_INTRUSIVE_RBTREE_NODE_HPP