15 #include <type_traits>
26 template<
class T>
inline
33 if(((p = P[0]) & s) != 0)
break;
38 if(((q = Q[-1]) & s) == 0)
break;
45 while(((p = P[0]) & s) == 0) P++;
46 while(((q = Q[-1]) & s) != 0) Q--;
59 template<
class T,
class S>
inline
67 if(((p = P[0]) & s) != 0)
break;
73 if(((q = Q[-1]) & s) == 0)
break;
86 while(((p = P[0]) & s) == 0) P++, U++;
87 while(((q = Q[-1]) & s) != 0) Q--, V--;
100 template<
class T,
class S,
class R>
inline
109 if(((p = P[0]) & s) != 0)
break;
116 if(((q = Q[-1]) & s) == 0)
break;
135 while(((p = P[0]) & s) == 0) P++, A++, U++;
136 while(((q = Q[-1]) & s) != 0) Q--, B--, V--;
149 template<
class T>
inline
152 T *P = _P, *Q = _Q, *A = _A, *B = _B;
156 if(((p = P[0]) & s) != 0)
break;
162 if(((q = Q[-1]) & s) == 0)
break;
175 while(((p = P[0]) & s) == 0) P++, A++;
176 while(((q = Q[-1]) & s) != 0) Q--, B--;
194 template<
class T,
class S>
inline
197 T *P = _P, *Q = _Q, *A = _A, *B = _B;
202 if(((p = P[0]) & s) != 0)
break;
209 if(((q = Q[-1]) & s) == 0)
break;
228 while(((p = P[0]) & s) == 0) P++, A++, U++;
229 while(((q = Q[-1]) & s) != 0) Q--, B--, V--;
248 template<
class T>
inline
252 using mask_t =
typename std::make_unsigned<T>::type;
259 mask_t t = ~mask_t(0);
273 template<
class T>
inline
276 if(_V.
size() < 2)
return;
285 template<
class T,
class S>
inline
288 if(_V.
size() < 2)
return;
298 template<
class T,
class S,
class R>
inline
301 if(_V.
size() < 2)
return;
310 template<
class T>
inline
313 if(_V.
size() < 2)
return;
324 template<
class T,
class S>
inline
327 if(_V.
size() < 2)
return;
337 template<
class T>
inline
340 if(_P.
size() < 2)
return;
341 T *P = &_P[0], *Q = &_P[0] + _P.
size();
356 _P.
resize(
int(R - &_P[0]));
365 template<
class T>
inline
368 if(_P.
size() < 2)
return;
369 T *P = &_P[0], *Q = &_P[0] + _P.
size();
379 if ((*R != *P) || (*W != *U))
388 _P.
resize(
int(R - &_P[0]));
389 _U.
resize(
int(W - &_U[0]));
398 template<
class T,
class S>
inline
401 if(_P.
size() < 2)
return;
402 T *P = &_P[0], *Q = &_P[0] + _P.
size();
425 _P.
resize(
int(R - &_P[0]));
426 _A.
resize(
int(C - &_A[0]));
436 template<
class T,
class S>
inline
439 if(_P.
size() < 2)
return;
440 T *P = &_P[0], *Q = &_P[0] + _P.
size();
452 if ((*R == *P) && (*W == *U))
467 _P.
resize(
int(R - &_P[0]));
468 _U.
resize(
int(W - &_U[0]));
469 _A.
resize(
int(C - &_A[0]));
483 template<
class T>
inline
486 size_t dsize = data.
size(), gsize = glob.
size();
496 size_t cidx, ridx, widx=0;
497 for (ridx=0, cidx=0; ridx<dsize; ridx++)
499 while (glob[cidx] < data[ridx] && cidx < (gsize-1)) cidx++;
500 if(data[ridx] == glob[cidx]) {
510 fprintf(stderr,
"global_to_local warning: Not all indices could be mapped!\n");
529 template<
class T>
inline
532 size_t dsize = data.
size(), gsize = glob.
size();
545 size_t cidx, ridx, widx=0;
546 for (ridx=0, cidx=0; ridx<dsize; ridx++)
548 while (_glob[cidx] < data[ridx] && cidx < (gsize-1)) cidx++;
549 if(data[ridx] == _glob[cidx]) {
550 data[widx] = perm_glob[cidx];
559 fprintf(stderr,
"global_to_local warning: Not all indices could be mapped!\n");
576 template<
class T>
inline
580 for(
size_t i=0; i<data.
size(); i++) {
581 auto it = g2l.
find(data[i]);
582 if(it != g2l.
end()) {
583 data[widx++] = it->second;
588 if(widx < data.
size()) {
591 fprintf(stderr,
"%s warning: Not all indices could be mapped!\n", __func__);
The vector class and related algorithms.
A vector storing arbitrary data.
size_t size() const
The current size of the vector.
void resize(size_t n)
Resize a vector.
iterator find(const K &key)
Search for key. Return iterator.
Classes similar to unordered_set and unordered_map, but with better performance.
void _binary_sort_copy_copy(T *_P, T *_Q, S *_A, S *_B, R *_U, R *_V, T s)
void interval(vector< T > &vec, size_t start, size_t end)
Create an integer interval between start and end.
void binary_sort_copy_copy(vector< T > &_V, vector< S > &_W, vector< R > &_A)
void unique_accumulate(vector< T > &_P, vector< S > &_A)
void binary_sort_copy(vector< T > &_V, vector< S > &_W)
void unique_resize(vector< T > &_P)
void _binary_sort(T *_P, T *_Q, T s)
T _binary_log(const T *P, const T *Q)
void _binary_sort_sort(T *_P, T *_Q, T *_A, T *_B, T s, T t)
void _binary_sort_sort_copy(T *_P, T *_Q, T *_A, T *_B, S *_U, S *_V, T s, T t)
void _binary_sort_copy(T *_P, T *_Q, S *_U, S *_V, T s)
void global_to_local(const vector< T > &glob, vector< T > &data, bool sortedData, bool doWarn)
void binary_sort(vector< T > &_V)
void binary_sort_sort_copy(vector< T > &_V, vector< T > &_W, vector< S > &_A)
void binary_sort_sort(vector< T > &_V, vector< T > &_W)
void global_to_local_sorted(const vector< T > &glob, vector< T > &data, bool sortedData, bool doWarn)