Boost logo

Boost Users :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2006-08-08 14:55:41


Sebastien Fortier ha escrito:

> I will try to make this as simple as possible,
> I have the following struct
>
> struct meteo_record {
> public:
> [...ctor...]
> [...getters and setters...]
> private:
> string var_name;
> string grid_type;
> float ip1;
> float ip2;
> float ip3;
> float ig1;
> float ig2;
> float ig3;
> int ip1Kind;
> int data_key;
> };
>
> All these attributes are non-unique except for the data_key
> which is not a sorting criteria.
>
> What I need to do is to be able to iterate over the whole
> set by certain criteria.
[...]
> my criterias are
> sort by same gryd_type group by var_name with same ip2 and
> same ip1kind ordered on ip1
[...]

Hello Sebastien,

I'm not sure I've fully understood all the details of your problem,
but seems to me that composite keys ( http://tinyurl.com/hdf3q )
might be of help here. A composite key accepts several attributes
and presents the records sorted in lexicographical order
with respect to them. In your particular case, suppose you've
got an index (non-unique) whose key is

composite_key<
  meteo_record,
  const_mem_fun<meteo_record,const
string&,&meteo_record::get_grid_type>,
  const_mem_fun<meteo_record,const
string&,&meteo_record::get_var_name>,
  const_mem_fun<meteo_record,float,&meteo_record::get_ip2>,
  const_mem_fun<meteo_record,int,&meteo_record::get_ip1Kind>,
  const_mem_fun<meteo_record,float,&meteo_record::get_ip1>
>

(where I've used some imaginary names for the attribute getters).
This index sorts records lexicographically by

  grid_type,var_name,ip2,ip1Kind,ip1

which looks like what you're after, from what I understand about
the description of your current query process. The different
groups can be then traversed like follows (for simplicity I
assume the composite key is used in index #0, you'll probably want
to have it in an additional index):

for(recordIter=set.begin();recordIter!=set.end();)
{
  recordIter2=set.upper_range(
    boost::make_tuple(
      it->get_grid_type(),
      it->get_var_name(),
      it->get_ip2(),
      it->get_ipKind(),
    )
  );

  // [recorditer1,recorditer2) is a range of elements with equal
  // grid_type,var_name,ip2 and ipKind, sorted by ip1
  process(recordIter1,recordIter2);
  
  recordIter1=recordIter2;
}

Is this what you were looking for? Thank you for using
Boost.MultiIndex,

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