1 /* Copyright 2003-2007 Joaquín M López Muñoz.
2 * Distributed under the Boost Software License, Version 1.0.
3 * (See accompanying file LICENSE_1_0.txt or copy at
4 * http://www.boost.org/LICENSE_1_0.txt)
6 * See http://www.boost.org/libs/multi_index for library home page.
9 #ifndef BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_NODE_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_HASH_INDEX_NODE_HPP
12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
17 #include <boost/detail/allocator_utilities.hpp>
18 #include <boost/multi_index/detail/prevent_eti.hpp>
23 namespace multi_index{
27 /* singly-linked node for use by hashed_index */
29 template<typename Allocator>
30 struct hashed_index_node_impl
32 typedef typename prevent_eti<
34 typename boost::detail::allocator::rebind_to<
35 Allocator,hashed_index_node_impl
37 >::type::pointer pointer;
38 typedef typename prevent_eti<
40 typename boost::detail::allocator::rebind_to<
41 Allocator,hashed_index_node_impl
43 >::type::const_pointer const_pointer;
45 pointer& next(){return next_;}
46 pointer next()const{return next_;}
48 /* algorithmic stuff */
50 static void increment(pointer& x,pointer bbegin,pointer bbend)
52 std::less_equal<pointer> leq;
55 if(leq(bbegin,x)&&leq(x,bbend)){ /* bucket node */
63 static void link(pointer x,pointer pos)
65 x->next()=pos->next();
69 static void unlink(pointer x)
72 while(y->next()!=x){y=y->next();}
76 static pointer prev(pointer x)
79 while(y->next()!=x){y=y->next();}
83 static void unlink_next(pointer x)
85 x->next()=x->next()->next();
92 template<typename Super>
93 struct hashed_index_node_trampoline:
96 hashed_index_node_impl<
97 typename boost::detail::allocator::rebind_to<
98 typename Super::allocator_type,
104 typedef typename prevent_eti<
106 hashed_index_node_impl<
107 typename boost::detail::allocator::rebind_to<
108 typename Super::allocator_type,
115 template<typename Super>
116 struct hashed_index_node:Super,hashed_index_node_trampoline<Super>
119 typedef hashed_index_node_trampoline<Super> trampoline;
122 typedef typename trampoline::impl_type impl_type;
123 typedef typename trampoline::pointer impl_pointer;
124 typedef typename trampoline::const_pointer const_impl_pointer;
128 return static_cast<impl_pointer>(
129 static_cast<impl_type*>(static_cast<trampoline*>(this)));
132 const_impl_pointer impl()const
134 return static_cast<const_impl_pointer>(
135 static_cast<const impl_type*>(static_cast<const trampoline*>(this)));
138 static hashed_index_node* from_impl(impl_pointer x)
140 return static_cast<hashed_index_node*>(
141 static_cast<trampoline*>(&*x));
144 static const hashed_index_node* from_impl(const_impl_pointer x)
146 return static_cast<const hashed_index_node*>(
147 static_cast<const trampoline*>(&*x));
150 static void increment(
151 hashed_index_node*& x,impl_pointer bbegin,impl_pointer bend)
153 impl_pointer xi=x->impl();
154 trampoline::increment(xi,bbegin,bend);
159 } /* namespace multi_index::detail */
161 } /* namespace multi_index */
163 } /* namespace boost */