boost multi_index partial indexes

Posted by Gokul on Stack Overflow See other posts from Stack Overflow or by Gokul
Published on 2010-12-21T20:26:22Z Indexed on 2010/12/28 3:54 UTC
Read the original article Hit count: 187

Filed under:
|
|

Hi, I want to implement inside boost multi-index two sets of keys with same search criteria but different eviction criteria. Say i have two sets of data with same search condition, but one set needs a MRU(Most Recently Used) list of 100 and the other set requires a MRU of 200. Say the entry is like this

class Student
{
     int student_no;
     char sex;
     std::string address;
};

The search criteria is student_no, but for sex='m', we need MRU of 200 and for sex='f', we need a MRU of 100. Now i have a solution where in i introduce a new ordered index to maintain ordering.

For example the IndexSpecifierList will be something like this

typedef multi_index_container<
  Student,
  indexed_by<
    ordered_unique< member<Student, int, &Student::student_no> >,
    ordered_unique< composite_key<
                    member<Student, char, &Student::sex>,
                    member<Student, int,  &Student::sex_specific_student_counter> > >
  > 
> student_set 

Now everytime, i am inserting a new one, i have to take a equal_range for that using index 2 and remove the oldest one and if something is getting re-used, i have to update it by incrementing the counter.

Is there a better solution to this kind of problem?

Thanks, Gokul.

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost