回复: Multi_indexcomposite_key~~

thanks a lot!
now, I have a new problem:
Multi_index example 6: complex searches and forergn keys,
struct car_manufacturer { std::string name; }; struct car_model { std::string model; car_manufacturer* manufacturer; int price; };
I want use "model, name" to query "price", and I maybe to modify "price".
How to do it? thanks.
------------------ 原始邮件 ------------------
发件人: "Joaquin M Lopez Munoz"
hi all,
now,I have a composite_key like this, struct leader_key boost::multi_index::composite_key< channel_info, BOOST_MULTI_INDEX_MEMBER(channel_info, boost::uint64_t, st_md5_), BOOST_MULTI_INDEX_MEMBER(channel_info, boost::uint32_t, st_rank_), BOOST_MULTI_INDEX_MEMBER(channel_info, boost::uint8_t, st_degrees_), BOOST_MULTI_INDEX_MEMBER( channel_info, boost::uint8_t, st_lan_type_)
{};
I used "md5, rank, degrees, lan_type" to query. I want to the result like this, equal to md5, less than rank degrees from small to large equal to lan_type
You can't do this by issuing a single lookup operation. A composite key on keys k1,...,kn allows you to do lookup operations of the form k1==a1, ... , kj==aj, kj+1==aj+1 k1==a1, ... , kj==aj, kj+1< aj+1 k1==a1, ... , kj==aj, kj+1<=aj+1 k1==a1, ... , kj==aj, kj+1> aj+1 k1==a1, ... , kj==aj, kj+1>=aj+1 For any j in the range [1,n], that is, you can query for the exact value of the first j keys and add any type of inequality for the last key being queried. In your particular case you can rearrange the key extractors of your composite key in the following order md5,lan_type,rank,degress then use lower_bound with elements equal to md5 equal to lan_type less than rank (note you've had to rearrange the extractors in leader_key to be able to do this) which gives you some result "it", and finally manually traverse the range [begin,it) to obtain those elements with degrees from small to large. Hope this helps, Joaquín M López Muoz Telefónica, Investigación y Desarrollo _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

isjk
thanks a lot! now, I have a new problem: Multi_index example 6: complex searches and forergn keys, struct car_manufacturer { std::string name; };
struct car_model { std::string model; car_manufacturer* manufacturer; int price; };
I want use "model, name" to query "price", and I maybe to modify "price". How to do it? thanks.
Sorry but your question is not clear to me: what do you mean by querying "price" using "model, name"? If you know the model of a car then you just can use find() in the car_table to locate the element and access the price. As for modifying, there's a tutorial section on updating elements of a multi_index_container at http://www.boost.org/libs/multi_index/doc/tutorial/basics.html#ord_updating Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (2)
-
isjk
-
Joaquin M Lopez Munoz