boost multi_index 部分索引

发布于 2024-10-08 20:00:05 字数 901 浏览 0 评论 0原文

我想在 boost 多索引内部实现两组具有相同搜索条件但不同驱逐标准的键。假设我有两组具有相同搜索条件的数据,但一组需要 100 的 MRU(最近使用)列表,另一组需要 200 的 MRU。假设条目是这样的

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

搜索条件是 Student_no,但是对于sex='m',我们需要 200 的 MRU,对于 sex='f',我们需要 100 的 MRU。 现在我有一个解决方案,其中引入一个新的有序索引来维护排序。

例如 IndexSpecifierList 将是这样的

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 

现在每次,我插入一个新的,我必须使用索引 2 为其获取一个 equal_range 并删除最旧的一个,如果某些东西被重新使用,我必须通过以下方式更新它递增计数器。

对于此类问题有更好的解决方案吗?

谢谢, 戈库尔。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Saygoodbye 2024-10-15 20:00:05

可以用排序代替第二个索引来执行相同的操作,并将将男性和女性分开的迭代器保存为缓存的迭代器。这有助于相同的行为。

It is possible to do the same with sequenced in place of the second index and holding the iterator which splits the male and female as a cached one. This helps is with the same behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文