|
Boost Users : |
Subject: [Boost-users] »Ø¸´£º Multi_indexcomposite_key~~
From: isjk (isjk_at_[hidden])
Date: 2010-07-24 10:09:16
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"<joaquin_at_[hidden]>;
·¢ËÍʱ¼ä: 2010Äê7ÔÂ22ÈÕ(ÐÇÆÚËÄ) Á賿2:08
ÊÕ¼þÈË: "boost-users"<boost-users_at_[hidden]>;
Ö÷Ìâ: Re: [Boost-users] Multi_indexcomposite_key~~
isjk <isjk <at> foxmail.com> writes:
>
> 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_at_[hidden]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
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