I need to insert an element within a list declared as follows:
list < list <unsigned int> > bucket (16);
I must insert an element into one of the bucket lists as efficiently as possible. I have the position in which I should insert this value, but I can not think of the best way to insert it (preferably, insert should be avoided).
My current code uses, instead of list< list <unsigned int> > bucket (16);
, vector< list <unsigned int> > bucket (16);
, this being the following:
void LSDRadixSortList (list<unsigned int> &v, int m)
{
int logaritmo = (log10(m))/(log10(16));
vector< list <unsigned int> > bucket (16);
for (int i = 0; i <= logaritmo; ++i)
{
for (auto buck : bucket){
buck.clear();
}
for_each(v.begin(),
next(v.begin(),v.size()),
[i,&bucket](unsigned int x){
int digit = x;
int mult = 0xF;
mult <<= 4 * i;
digit = digit & mult;
digit >>= 4 * i;
bucket.at(digit).push_back(x); ///< Esta es la linea a mejorar
});
v.clear();
for (auto buck : bucket){
v.splice(v.end(), move(buck));
}
}
}
I need something that equates to bucket.at(digit).push_back(x);
for lists and without being so expensive (so I know, lists tend to work better than vectors).