11 s <<
"0x" << std::hex <<
i;
16 template<
typename INT>
21 s <<
"0b" <<
b.to_string().substr(32-n,32);
22 }
else if (
sizeof(i) <= 8) {
24 s <<
"0b" <<
b.to_string().substr(64-n,64);
30 template<
typename T,
size_t N>
34 template<
typename T,
size_t N>
38 for (
size_t i=0; i<
N; ++
i) {
52 template <
class T>
struct _reversed {
53 T&
t; _reversed(
T& _t): t(_t) {}
54 decltype(t.rbegin())
begin() {
return t.rbegin(); }
55 decltype(t.rend())
end() {
return t.rend(); }
58 template <
class T> details::_reversed<T> reversed(
T& t) {
return details::_reversed<T>(
t); }
62 template <
class STR=std::
string>
63 std::vector<STR> split_string(
const std::string& s,
char c =
' ',
char d =
' ') {
65 const char*
str = s.c_str();
68 while(*str !=
c && *str !=
d && *str)
70 result.emplace_back(begin, str);
71 }
while (0 != *str++);
77 template <
class T1,
class T2>
78 void flatten_container(
const T1&
input, T2&
output) {
79 typename T1::const_iterator it;
80 for (it = input.begin(); it != input.end(); ++it) {
81 output.insert(output.end(), it->begin(), it->end());
87 struct is_map_of_vectors :
public std::false_type { };
89 template<
typename T1,
typename T2>
90 struct is_map_of_vectors<
std::
map<T1, std::vector<T2> > > :
public std::true_type { };
93 template<
typename Map>
94 void merge_map_into_map(Map& map1, Map& map2) {
96 typedef typename Map::iterator
Iterator;
97 typedef typename Map::mapped_type
Container;
99 Iterator
first = map1.begin();
100 Iterator
last = map1.end();
102 std::pair<Iterator,bool>
ins = map2.insert(*first);
105 Container* container1 = &(first->second);
106 Container* container2 = &(ins.first->second);
107 container2->insert(container2->end(), container1->begin(), container1->end());
117 template <
class ForwardIt,
class BinaryPredicate,
class BinaryOp>
118 ForwardIt adjacent_cluster(ForwardIt first, ForwardIt last, BinaryPredicate adjacent, BinaryOp cluster) {
119 if (first == last)
return last;
121 ForwardIt result =
first;
122 while (++first != last) {
123 if (!adjacent(*result, *first)) {
126 cluster(*result, *first);
134 template<
typename RandomAccessIterator,
typename Compare = std::less<> >
135 void merge_sort_merge(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare cmp)
139 typedef typename std::iterator_traits<RandomAccessIterator>::pointer pointer;
140 std::pair<pointer, std::ptrdiff_t>
p = std::get_temporary_buffer<value_type>(len);
141 pointer buf = p.first;
142 pointer buf_end =
std::next(p.first, p.second);
144 RandomAccessIterator first1 =
first;
145 RandomAccessIterator last1 = middle;
146 RandomAccessIterator first2 = middle;
147 RandomAccessIterator last2 =
last;
149 while (first1 != last1 && first2 != last2) {
150 if (cmp(*first2, *first1)) {
156 while (first1 != last1) {
159 while (first2 != last2) {
165 std::return_temporary_buffer(p.first);
169 template<
typename RandomAccessIterator,
typename Compare = std::less<> >
170 void merge_sort(RandomAccessIterator first, RandomAccessIterator last, Compare cmp)
174 RandomAccessIterator middle =
std::next(first, len / 2);
175 merge_sort(first, middle, cmp);
176 merge_sort(middle, last, cmp);
177 merge_sort_merge(first, middle, last, cmp);
184 template<
typename RandomAccessIterator,
typename Compare,
typename Compare3>
185 void merge_sort_merge3(RandomAccessIterator first, RandomAccessIterator one_third, RandomAccessIterator two_third, RandomAccessIterator last, Compare cmp, Compare3 cmp3)
189 typedef typename std::iterator_traits<RandomAccessIterator>::pointer pointer;
190 std::pair<pointer, std::ptrdiff_t> p = std::get_temporary_buffer<value_type>(len);
191 pointer buf = p.first;
192 pointer buf_end =
std::next(p.first, p.second);
194 RandomAccessIterator first1 =
first;
195 RandomAccessIterator last1 = one_third;
196 RandomAccessIterator first2 = one_third;
197 RandomAccessIterator last2 = two_third;
198 RandomAccessIterator first3 = two_third;
199 RandomAccessIterator last3 =
last;
201 while (first1 != last1 && first2 != last2 && first3 != last3) {
202 int rr = cmp3(*first1, *first2, *first3);
205 }
else if (rr == 1) {
207 }
else if (rr == 2) {
212 if (first3 == last3) {
214 }
else if (first2 == last2) {
217 }
else if (first1 == last1) {
224 while (first1 != last1 && first2 != last2) {
225 if (cmp(*first2, *first1)) {
231 while (first1 != last1) {
234 while (first2 != last2) {
240 std::return_temporary_buffer(p.first);
244 template<
typename RandomAccessIterator,
typename Compare,
typename Compare3>
245 void merge_sort3(RandomAccessIterator first, RandomAccessIterator last, Compare cmp, Compare3 cmp3)
249 RandomAccessIterator one_third =
std::next(first, (len+2) / 3);
250 RandomAccessIterator two_third =
std::next(first, (len+2) / 3 * 2);
251 merge_sort3(first, one_third, cmp, cmp3);
252 merge_sort3(one_third, two_third, cmp, cmp3);
253 merge_sort3(two_third, last, cmp, cmp3);
254 merge_sort_merge3(first, one_third, two_third, last, cmp, cmp3);
259 template<
typename RandomAccessIterator,
typename Compare,
typename Compare3>
260 void merge_sort3_with_hint(RandomAccessIterator first, RandomAccessIterator last, Compare cmp, Compare3 cmp3, std::ptrdiff_t
d)
264 RandomAccessIterator one_third =
std::next(first, d);
265 RandomAccessIterator two_third =
std::next(first, d * 2);
266 merge_sort3(first, one_third, cmp, cmp3);
267 merge_sort3(one_third, two_third, cmp, cmp3);
268 merge_sort3(two_third, last, cmp, cmp3);
269 merge_sort_merge3(first, one_third, two_third, last, cmp, cmp3);
static char to_hex(unsigned int i)
static std::string const input
Container::value_type value_type
edm::AssociationVector< reco::JetRefBaseProd, Values > Container