Boost logo

Boost Users :

Subject: Re: [Boost-users] Multi_indexcomposite_key~~
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2010-07-21 14:08:49


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 Muñoz
Telefónica, Investigación y Desarrollo


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