File indexing completed on 2025-01-18 09:51:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef __BOOST_SORT_PARALLEL_DETAIL_UTIL_MERGE_VECTOR_HPP
0015 #define __BOOST_SORT_PARALLEL_DETAIL_UTIL_MERGE_VECTOR_HPP
0016
0017
0018 #include <ciso646>
0019 #include <functional>
0020 #include <iterator>
0021 #include <memory>
0022 #include <type_traits>
0023 #include <vector>
0024 #include <boost/sort/common/merge_four.hpp>
0025
0026 namespace boost
0027 {
0028 namespace sort
0029 {
0030 namespace common
0031 {
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 template<class Iter1_t, class Iter2_t, class Compare>
0055 void merge_level4(range<Iter1_t> dest, std::vector<range<Iter2_t> > &v_input,
0056 std::vector<range<Iter1_t> > &v_output, Compare comp)
0057 {
0058 typedef range<Iter1_t> range1_t;
0059 typedef util::value_iter<Iter1_t> type1;
0060 typedef util::value_iter<Iter2_t> type2;
0061 static_assert (std::is_same< type1, type2 >::value,
0062 "Incompatible iterators\n");
0063
0064 v_output.clear();
0065 if (v_input.size() == 0) return;
0066 if (v_input.size() == 1)
0067 {
0068 v_output.emplace_back(move_forward(dest, v_input[0]));
0069 return;
0070 };
0071
0072 uint32_t nrange = v_input.size();
0073 uint32_t pos_ini = 0;
0074 while (pos_ini < v_input.size())
0075 {
0076 uint32_t nmerge = (nrange + 3) >> 2;
0077 uint32_t nelem = (nrange + nmerge - 1) / nmerge;
0078 range1_t rz = full_merge4(dest, &v_input[pos_ini], nelem, comp);
0079 v_output.emplace_back(rz);
0080 dest.first = rz.last;
0081 pos_ini += nelem;
0082 nrange -= nelem;
0083 };
0084 return;
0085 };
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 template<class Value_t, class Iter_t, class Compare>
0102 void uninit_merge_level4(range<Value_t *> dest,
0103 std::vector<range<Iter_t> > &v_input,
0104 std::vector <range<Value_t *> > &v_output, Compare comp)
0105 {
0106 typedef range<Value_t *> range1_t;
0107 typedef util::value_iter<Iter_t> type1;
0108 static_assert (std::is_same< type1, Value_t >::value,
0109 "Incompatible iterators\n");
0110
0111 v_output.clear();
0112 if (v_input.size() == 0) return;
0113 if (v_input.size() == 1)
0114 {
0115 v_output.emplace_back(move_construct(dest, v_input[0]));
0116 return;
0117 };
0118
0119 uint32_t nrange = v_input.size();
0120 uint32_t pos_ini = 0;
0121 while (pos_ini < v_input.size())
0122 {
0123 uint32_t nmerge = (nrange + 3) >> 2;
0124 uint32_t nelem = (nrange + nmerge - 1) / nmerge;
0125 range1_t rz = uninit_full_merge4(dest, &v_input[pos_ini], nelem, comp);
0126 v_output.emplace_back(rz);
0127 dest.first = rz.last;
0128 pos_ini += nelem;
0129 nrange -= nelem;
0130 };
0131 return;
0132 };
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 template<class Iter1_t, class Iter2_t, class Compare>
0150 range<Iter2_t> merge_vector4(range<Iter1_t> range_input,
0151 range<Iter2_t> range_output,
0152 std::vector<range<Iter1_t> > &v_input,
0153 std::vector<range<Iter2_t> > &v_output,
0154 Compare comp)
0155 {
0156 typedef range<Iter2_t> range2_t;
0157 typedef util::value_iter<Iter1_t> type1;
0158 typedef util::value_iter<Iter2_t> type2;
0159 static_assert (std::is_same< type1, type2 >::value,
0160 "Incompatible iterators\n");
0161
0162 v_output.clear();
0163 if (v_input.size() == 0)
0164 {
0165 return range2_t(range_output.first, range_output.first);
0166 };
0167 if (v_input.size() == 1)
0168 {
0169 return move_forward(range_output, v_input[0]);
0170 };
0171 bool sw = false;
0172 uint32_t nrange = v_input.size();
0173
0174 while (nrange > 1)
0175 {
0176 if (sw)
0177 {
0178 merge_level4(range_input, v_output, v_input, comp);
0179 sw = false;
0180 nrange = v_input.size();
0181 }
0182 else
0183 {
0184 merge_level4(range_output, v_input, v_output, comp);
0185 sw = true;
0186 nrange = v_output.size();
0187 };
0188 };
0189 return (sw) ? v_output[0] : move_forward(range_output, v_input[0]);
0190 };
0191
0192
0193 };
0194 };
0195 };
0196
0197
0198 #endif