Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 /* Copyright 2003-2005 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_RND_INDEX_OPS_HPP
10 #define BOOST_MULTI_INDEX_DETAIL_RND_INDEX_OPS_HPP
12 #if defined(_MSC_VER)&&(_MSC_VER>=1200)
16 #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
18 #include <boost/multi_index/detail/rnd_index_ptr_array.hpp>
23 namespace multi_index{
27 /* Common code for random_access_index memfuns having templatized and
28 * non-templatized versions.
31 template<typename Node,typename Allocator,typename Predicate>
32 Node* random_access_index_remove(
33 random_access_index_ptr_array<Allocator>& ptrs,Predicate pred
34 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Node))
36 typedef typename Node::value_type value_type;
38 random_access_index_node_impl** first=ptrs.begin(),
41 for(;first!=last;++first){
43 const_cast<const value_type&>(Node::from_impl(*first)->value()))){
45 std::swap(*first,*res);
52 return Node::from_impl(*res);
55 template<typename Node,typename Allocator,class BinaryPredicate>
56 Node* random_access_index_unique(
57 random_access_index_ptr_array<Allocator>& ptrs,BinaryPredicate binary_pred
58 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Node))
60 typedef typename Node::value_type value_type;
62 random_access_index_node_impl** first=ptrs.begin(),
68 const_cast<const value_type&>(Node::from_impl(*res)->value()),
69 const_cast<const value_type&>(Node::from_impl(*first)->value()))){
72 std::swap(*first,*res);
80 return Node::from_impl(*res);
83 template<typename Node,typename Allocator,typename Compare>
84 void random_access_index_inplace_merge(
86 random_access_index_ptr_array<Allocator>& ptrs,
87 random_access_index_node_impl** first1,Compare comp
88 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Node))
90 typedef typename Node::value_type value_type;
92 auto_space<random_access_index_node_impl*,Allocator> spc(al,ptrs.size());
94 random_access_index_node_impl** first0=ptrs.begin(),
98 while(first0!=last0&&first1!=last1){
100 const_cast<const value_type&>(Node::from_impl(*first1)->value()),
101 const_cast<const value_type&>(Node::from_impl(*first0)->value()))){
108 std::copy(first0,last0,out);
109 std::copy(first1,last1,out);
113 while(first1!=last1){
115 (*first1)->up()=first1;
122 /* auxiliary stuff */
124 template<typename Node,typename Compare>
125 struct random_access_index_sort_compare:
126 std::binary_function<
127 const typename Node::value_type*,const typename Node::value_type*,bool>
129 random_access_index_sort_compare(Compare comp_=Compare()):comp(comp_){}
132 random_access_index_node_impl* x,
133 random_access_index_node_impl* y)const
135 typedef typename Node::value_type value_type;
138 const_cast<const value_type&>(Node::from_impl(x)->value()),
139 const_cast<const value_type&>(Node::from_impl(y)->value()));
146 template<typename Node,typename Allocator,class Compare>
147 void random_access_index_sort(
149 random_access_index_ptr_array<Allocator>& ptrs,
151 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Node))
153 /* The implementation is extremely simple: an auxiliary
154 * array of pointers is sorted using stdlib facilities and
155 * then used to rearrange the index. This is suboptimal
156 * in space and time, but has some advantages over other
157 * possible approaches:
158 * - Use std::stable_sort() directly on ptrs using some
159 * special iterator in charge of maintaining pointers
160 * and up() pointers in sync: we cannot guarantee
161 * preservation of the container invariants in the face of
162 * exceptions, if, for instance, std::stable_sort throws
163 * when ptrs transitorily contains duplicate elements.
164 * - Rewrite the internal algorithms of std::stable_sort
165 * adapted for this case: besides being a fair amount of
166 * work, making a stable sort compatible with Boost.MultiIndex
167 * invariants (basically, no duplicates or missing elements
168 * even if an exception is thrown) is complicated, error-prone
169 * and possibly won't perform much better than the
173 typedef typename Node::value_type value_type;
174 typedef random_access_index_sort_compare<
175 Node,Compare> ptr_compare;
177 random_access_index_node_impl** first=ptrs.begin();
178 random_access_index_node_impl** last=ptrs.end();
180 random_access_index_node_impl*,
181 Allocator> spc(al,ptrs.size());
182 random_access_index_node_impl** buf=spc.data();
184 std::copy(first,last,buf);
185 std::stable_sort(buf,buf+ptrs.size(),ptr_compare(comp));
189 (*first)->up()=first;
194 } /* namespace multi_index::detail */
196 } /* namespace multi_index */
198 } /* namespace boost */