1#ifndef __JTOOLS__JMERGESORT__
2#define __JTOOLS__JMERGESORT__
48 template<
class JElement_t,
class JAllocator_t = std::allocator<JElement_t> >
65 template<
class JSuperContainer_t>
69 (*this)(input.begin(), input.end(), output, std::less<JElement_t>());
80 template<
class JSuperContainer_t,
class JComparator_t>
83 const JComparator_t& comparator)
const
85 (*this)(input.begin(), input.end(), output, comparator);
101 (*this)(__begin, __end, output, std::less<JElement_t>());
113 template<
class T,
class JComparator_t>
117 const JComparator_t& comparator)
const
119 if (__begin != __end) {
125 for (
size_t i = std::distance(__begin, __end); i != 0; i >>= 1) {
135 this->
merge(__begin, __end, comparator);
149 template<
class JContainer_t>
150 static inline void copy(
const JContainer_t& input,
153 size_t n = input.size();
155 output.reserve(
n + 1);
156 output.resize (
n + 0);
158 typename JContainer_t::const_iterator in = input .begin();
161 for ( ;
n != 0; --
n) {
181 template<
class JContainer_t,
class JComparator_t>
182 static inline void merge(
const JContainer_t& first,
183 const JContainer_t& second,
185 const JComparator_t& comparator)
187 size_t n = first.size() + second.size();
189 output.reserve(
n + 1);
190 output.resize (
n + 0);
192 typename JContainer_t::const_iterator i = first .begin();
193 typename JContainer_t::const_iterator
j = second.begin();
196 for ( ;
n >= 4;
n -= 4) {
198 if (comparator(*i,*
j))
203 if (comparator(*i,*
j))
208 if (comparator(*i,*
j))
213 if (comparator(*i,*
j))
219 for ( ;
n != 0; --
n) {
221 if (comparator(*i,*
j))
246 return buffer[level - 1].first;
249 return buffer[level - 1].second;
266 template<
class _Iterator_t,
class JComparator_t>
267 inline void merge(_Iterator_t __begin,
269 const JComparator_t& comparator,
270 const size_t level = 0,
273 const size_t N = std::distance(__begin, __end);
292 this->
merge(__begin, __begin + N/2, comparator, level + 1, LEFT);
293 this->
merge(__begin + N/2, __end, comparator, level + 1, RIGHT);
JTwosome
Enumeration for two of a kind.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).