1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
#ifndef __PHOENIX_VECTOR_SPLIT_H__ |
8 |
|
|
#define __PHOENIX_VECTOR_SPLIT_H__ |
9 |
|
|
|
10 |
|
|
#include <string> |
11 |
|
|
#include <vector> |
12 |
|
|
|
13 |
|
|
///Split a list in a list of lists, keep the order of the input file if the output is used for std::thread |
14 |
|
|
/** @param[out] vecVecOutput : output list of list of nbPart parts |
15 |
|
|
* @param vecInput : input list to be split |
16 |
|
|
* @param nbPart : number of part in which to split the vecInput |
17 |
|
|
*/ |
18 |
|
|
template <typename T> |
19 |
|
2 |
void phoenix_vector_split(std::vector<std::vector<T> > & vecVecOutput, const std::vector<T> & vecInput, size_t nbPart){ |
20 |
✗✓ |
2 |
if(vecInput.size() == 0lu) return; |
21 |
|
2 |
size_t i(0lu); |
22 |
✓✓ |
14 |
for(typename std::vector<T>::const_iterator it(vecInput.begin()); it != vecInput.end(); ++it){ |
23 |
✓✓ |
12 |
if(vecVecOutput.size() <= i){ |
24 |
|
8 |
std::vector<T> vecTmp; |
25 |
✓ |
4 |
vecTmp.push_back(*it); |
26 |
✓ |
4 |
vecVecOutput.push_back(vecTmp); |
27 |
|
|
}else{ |
28 |
✓ |
8 |
vecVecOutput[i].push_back(*it); |
29 |
|
|
} |
30 |
|
12 |
++i; |
31 |
✓✓ |
12 |
if(i >= nbPart){i = 0lu;} |
32 |
|
|
} |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
#endif |
36 |
|
|
|