Boost logo

Boost Users :

From: Jeffrey Holle (jeffreyholle_at_[hidden])
Date: 2007-10-02 09:59:59


Jeffrey Holle wrote:
> Joaquín Mª López Muñoz wrote:
>> So, instead of using modify_key resort to plain modify instead:
>>
>>
c.get<1>().modify(c.get<1>().find(make_tuple(y,UINT_MAX)),&ll::_1->*&entry::m_x=startIter2->m_x);
>>
>> Is your problem solved now?
>
> This solved my compilation problem, but I ended up with an app than
wants to runs forever.
>
> To be clear, I'm including my entire function. What it is supposed
to do is reorder the x values of the composite_key index of the
multi_index container based on the ordering of a vector<float>
container. It is a swap_sort algorithm because its the only way that
I've imagined how to do this. A better solution would definitely be
entertained.
>
> void sortByBaryCenterValue(Positioner& p, BaryCenterVals& bcv,size_t y)
> {
> Positioner::XYIterator iter,iter_end;
> tie(iter,iter_end)=p.getXYIndex().equal_range(make_tuple(y));
> for (size_t nStartIndex=0;nStartIndex<bcv.size();++nStartIndex) {
> size_t nSmallestIndex=nStartIndex;
> for (size_t
nCurrentIndex=nStartIndex+1;nCurrentIndex<bcv.size();++nCurrentIndex)
> if (bcv[nCurrentIndex]<bcv[nSmallestIndex])
> nSmallestIndex=nCurrentIndex;
> swap(bcv[nStartIndex],bcv[nSmallestIndex]);
> Positioner::XYIterator startIter(iter),smallestIter(iter);
> advance(startIter,nStartIndex);
> size_t x1=startIter->m_x;
> advance(smallestIter,nSmallestIndex);
> size_t x2=smallestIter->m_x;
>
>
p.getXYIndex().modify(p.getXYIndex().find(make_tuple(y,x1)),&ll::_1->*&Positioner::entry::m_x=UINT_MAX);
> //
p.getXYIndex().modify(p.getXYIndex().find(make_tuple(y,x2)),&ll::_1->*&Positioner::entry::m_x=x1);
>
>
p.getXYIndex().modify(p.getXYIndex().find(make_tuple(y,UINT_MAX)),&ll::_1->*&Positioner::entry::m_x=x2);
> }
> }
>
> If I uncomment the middle line of the sort attempt, the application
runs forever.
>
> Do you know what is wrong?
> Thanks in advance.

Found my problem. A sort-swap algorithm has a self-swap "feature".
When x1 and x2 are the same, the above function will lock up (when the
offending line is uncommented.

The solution is to put the swap operation within a conditional clause.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net