[multi_key] problems using modify_key with a composite_key index
Once again, I've run into a compilation problem that I can't seem to fix and I wish some help. My multi_index container looks like: typedef multi_index_container< entry, indexed_by< ordered_unique<member<entry,DataVertex,&entry::m_vertex> >, ordered_non_unique< composite_key< entry, member<entry,size_t,&entry::m_y>, member<entry,size_t,&entry::m_x> > > >
C;
I now have to swap values via the composite_key. To simplify things, I'll just express the last of three lines that would do this job if it compiles (and the lines needed to understand it). c.get<1>().modify_key(c.get<1>().find(make_tuple(y,UINT_MAX)),ll::_1=make_tuple(y,startIter2->m_x)); where startIter2 type is: nth_index<C,1>::type::iterator and y is just an int. The compiler error that I get is: $BOOST_ROOT/boost/multi_index/detail/modify_key_adaptor.hpp: In member function 'void boost::multi_index::detail::modify_key_adaptor<Modifier, Value, KeyFromValue>::operator()(Value&) [with Modifier = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1>
, const boost::tuples::tuple<int, unsigned int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, Value = Positioner::entry, KeyFromValue = boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>]': $BOOST_ROOT/boost/multi_index_container.hpp:543: instantiated from 'bool boost::multi_index::multi_index_container<Value, IndexSpecifierList, Allocator>::modify_(Modifier, typename boost::multi_index::detail::multi_index_base_type<Value, IndexSpecifierList, Allocator>::type::node_type*) [with Modifier = boost::multi_index::detail::modify_key_adaptor<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> , const boost::tuples::tuple<int, unsigned int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, Positioner::entry, boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, Value = Positioner::entry, IndexSpecifierList = boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_vertex>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, Allocator = std::allocator<Positioner::entry>]' $BOOST_ROOT/boost/multi_index/detail/index_base.hpp:166: instantiated from 'bool boost::multi_index::detail::index_base<Value, IndexSpecifierList, Allocator>::final_modify_(Modifier, typename boost::multi_index::detail::multi_index_node_type<Value, IndexSpecifierList, Allocator>::type*) [with Modifier = boost::multi_index::detail::modify_key_adaptor<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> , const boost::tuples::tuple<int, unsigned int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, Positioner::entry, boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, Value = Positioner::entry, IndexSpecifierList = boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_vertex>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, Allocator = std::allocator<Positioner::entry>]' $BOOST_ROOT/boost/multi_index/ordered_index.hpp:338: instantiated from 'bool boost::multi_index::detail::ordered_index<KeyFromValue, Compare, SuperMeta, TagList, Category>::modify(boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<typename SuperMeta::type::node_type>, mpl_::na>, Modifier) [with Modifier = boost::multi_index::detail::modify_key_adaptor<boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> , const boost::tuples::tuple<int, unsigned int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, Positioner::entry, boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, KeyFromValue = boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, Compare = std::less<boost::multi_index::composite_key_result<boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, SuperMeta = boost::multi_index::detail::nth_layer<2, Positioner::entry, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_vertex>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<Positioner::entry> >, TagList = boost::mpl::vector0<mpl_::na>, Category = boost::multi_index::detail::ordered_non_unique_tag]' $BOOST_ROOT/boost/multi_index/ordered_index.hpp:349: instantiated from 'bool boost::multi_index::detail::ordered_index<KeyFromValue, Compare, SuperMeta, TagList, Category>::modify_key(boost::multi_index::detail::bidir_node_iterator<boost::multi_index::detail::ordered_index_node<typename SuperMeta::type::node_type>, mpl_::na>, Modifier) [with Modifier = boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::other_action<boost::lambda::assignment_action>, boost::tuples::tuple<boost::lambda::lambda_functor<boost::lambda::placeholder<1> , const boost::tuples::tuple<int, unsigned int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, KeyFromValue = boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, Compare = std::less<boost::multi_index::composite_key_result<boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >, SuperMeta = boost::multi_index::detail::nth_layer<2, Positioner::entry, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_vertex>, mpl_::na, mpl_::na>, boost::multi_index::ordered_non_unique<boost::multi_index::composite_key<Positioner::entry, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_y>, boost::multi_index::member<Positioner::entry, unsigned int, &Positioner::entry::m_x>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<Positioner::entry> >, TagList = boost::mpl::vector0<mpl_::na>, Category = boost::multi_index::detail::ordered_non_unique_tag]'
Can somebody point out whats wrong?
Hello all, in the following little program: using namespace boost::archive; int main () { std::wostringstream lOSS; lOSS << __FUNCTION__; return 0; } for the operator<<() statement is called the following operator<<() (in file boost_1_34_1\libs\serialization\src\xml_woarchive.cpp): std::wostream & operator<<(std::wostream &os, const char *t) . Instead I expected that it would be called the one defined in "ostream" file, i.e. basic_ostream<_Elem, _Traits>& __CLRCALL_OR_CDECL operator<<( basic_ostream<_Elem, _Traits>& _Ostr, const char *_Val) . Notice that the fault is of the "using namespace boost::archive;" directive: in fact when it is removed it happens what I expected. Why does this happen? Is it forbidden to use "using namespace boost::archive;" in application's code? The problem with calling the wrong operator<<() with a string is that the implementation in the boost::archive namespace ends up in an infinite loop as it does: std::wostream & operator<<(std::wostream &os, const char *t){ for(;;){ wchar_t wc; int result = std::mbtowc(&wc, t, 10 /* max number */); if(0 < result) os.put(wc); else if(0 == result) break; else boost::throw_exception( iterators::dataflow_exception( iterators::dataflow_exception::invalid_conversion ) ); } return os; } Thanks in advance, Luca
Looks like a problem to me. I'll look into it. Robert Ramey Luca Cappa wrote:
Hello all, in the following little program:
using namespace boost::archive; int main () { std::wostringstream lOSS; lOSS << __FUNCTION__;
return 0; }
Hello Jeff, Jeff Holle ha escrito:
Once again, I've run into a compilation problem that I can't seem to fix and I wish some help.
My multi_index container looks like:
typedef multi_index_container< entry, indexed_by< ordered_unique<member<entry,DataVertex,&entry::m_vertex> >, ordered_non_unique< composite_key< entry, member<entry,size_t,&entry::m_y>, member<entry,size_t,&entry::m_x> > > >
C;
I now have to swap values via the composite_key. To simplify things, I'll just express the last of three lines that would do this job if it compiles (and the lines needed to understand it).
c.get<1>().modify_key(c.get<1>().find(make_tuple(y,UINT_MAX)), ll::_1=make_tuple(y,startIter2->m_x));
This reason why this does not compile as you expect is because the key type of index #1 in your example is *not* tuple(size_t,size_t), as the code seems to be asuming. Actually, the key is an instantiation of an opaque template class called composite_key_result: http://boost.org/libs/multi_index/doc/reference/key_extraction.html#composit... As explained in the docs, there is little you can assume about this composite_key_result, except that B.MI correctly handles it internally. In particular, you cannot assign it a tuple as you're trying to do, although this operation might seem reasonable at first sight given that you can look for a tuple in a composite_key-powered index. 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? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
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.
Jeffrey Holle ha escrito: [...]
This solved my compilation problem, but I ended up with an app than wants to runs forever.
[...]
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?
Most likely, you're calling modify() on a end iterator; check this in your code. Also, remember this kind of errors can be detected by using B.MI safe mode: http://boost.org/libs/multi_index/doc/tutorial/debug.html#safe_mode Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
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.
While my swap method is now working correctly, I have found the the use of modify on a composite_key in order to preform a swap has corrupted the index. The very next time I attempt to use it in a statement like this: for (tie(iter,iter_end)=xyIndex.equal_range(make_tuple(i)); iter!=iter_end;++iter) The for loop runs forever. I also attempted to print the distance(iter,iter_end) and this function never returns. Note that it happens that the one time my sort function executed, only a single swap was preformed. Is there a way to fix this?
----- Mensaje original ----- De: Jeffrey Holle <jeffreyholle@bellsouth.net> Fecha: Martes, Octubre 2, 2007 11:08 pm Asunto: Re: [Boost-users] [multi_key] problems using modify_key with a composite_key index Para: Boost Users mailing list <boost-users@lists.boost.org>
While my swap method is now working correctly, I have found the the use of modify on a composite_key in order to preform a swap has corrupted the index.
The very next time I attempt to use it in a statement like this:
for (tie(iter,iter_end)=xyIndex.equal_range(make_tuple(i)); iter!=iter_end;++iter)
The for loop runs forever. I also attempted to print the distance(iter,iter_end) and this function never returns.
Note that it happens that the one time my sort function executed, only a single swap was preformed.
Is there a way to fix this?
I lack the context to give a more informed opinion, so the following is mere speculation: take into account that in a expression of the form c.modify(it,f); f is *not* allowed to modify any other element of c except *it. Maybe you are violating this rule in some of your calls to modify()? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
JOAQUIN LOPEZ MU?Z wrote:
----- Mensaje original ----- De: Jeffrey Holle <jeffreyholle@bellsouth.net> Fecha: Martes, Octubre 2, 2007 11:08 pm Asunto: Re: [Boost-users] [multi_key] problems using modify_key with a composite_key index Para: Boost Users mailing list <boost-users@lists.boost.org>
While my swap method is now working correctly, I have found the the use of modify on a composite_key in order to preform a swap has corrupted the index.
The very next time I attempt to use it in a statement like this:
for (tie(iter,iter_end)=xyIndex.equal_range(make_tuple(i)); iter!=iter_end;++iter)
The for loop runs forever. I also attempted to print the distance(iter,iter_end) and this function never returns.
Note that it happens that the one time my sort function executed, only a single swap was preformed.
Is there a way to fix this?
I lack the context to give a more informed opinion, so the following is mere speculation: take into account that in a expression of the form
c.modify(it,f);
f is *not* allowed to modify any other element of c except *it. Maybe you are violating this rule in some of your calls to modify()?
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
I actually coded my sort function with iterators the first time and found out that it was a no no. Presently, I produce the iterator that modify needs "on-the-fly" using the xyIndex's find method. The situation that I described above is considerable more complicated. By the time my app hangs up in the iteration loop through the elements in row 2, my sort function has executed 4 times, producing a sum of 2 swaps. The arrant behavior of the composite_key index starts appearing at the end of the 3rd sort operation. Then I see that a vertex order of "7,10,9,11" get changed to "11,7". This makes no sense to me, swapping elements shouldn't reduce the number of elements in a row. I'm going to do some experimenting with different types of indexes next. I'm also going to contemplate if the boost::zip_iterator might assist me in this problem.
Jeffrey Holle ha escrito:
JOAQUIN LOPEZ MU?Z wrote:
----- Mensaje original ----- De: Jeffrey Holle <jeffreyholle@bellsouth.net> Fecha: Martes, Octubre 2, 2007 11:08 pm Asunto: Re: [Boost-users] [multi_key] problems using modify_key with a composite_key index Para: Boost Users mailing list <boost-users@lists.boost.org>
While my swap method is now working correctly, I have found the the use of modify on a composite_key in order to preform a swap has corrupted the index.
[...]
The situation that I described above is considerable more complicated. By the time my app hangs up in the iteration loop through the elements in row 2, my sort function has executed 4 times, producing a sum of 2 swaps. The arrant behavior of the composite_key index starts appearing at the end of the 3rd sort operation. Then I see that a vertex order of "7,10,9,11" get changed to "11,7". This makes no sense to me, swapping elements shouldn't reduce the number of elements in a row.
There is a situation in which you can see such reduction of elements: modify() will *erase* the element if the modification has resulted in a collision for some index with unique keys. In your particular case, index #0 is unique on entry::m_vertex, so you might want to check whether your procedure somehow can change this member so that it becomes a duplicate of a preexisting value. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Problem with boost::multi_index fixed. It was caused by not refreshing iterators after modifying the container.
on Mon Oct 01 2007, Jeffrey Holle <jeffreyholle-AT-bellsouth.net> wrote:
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?
Does this question have anything to do with Boost? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
David Abrahams ha escrito:
on Mon Oct 01 2007, Jeffrey Holle <jeffreyholle-AT-bellsouth.net> wrote:
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?
Does this question have anything to do with Boost?
The question is about problems in some code of the OP's heavily dependent on a Boost library: is this an acceptable topic for Boost-users? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (7)
-
"JOAQUIN LOPEZ MU?Z"
-
David Abrahams
-
Jeff Holle
-
Jeffrey Holle
-
Joaquín Mª López Muñoz
-
Luca Cappa
-
Robert Ramey