Boost.MultiIndex: How to make an effective set intersection?

隐身守侯 提交于 2019-12-12 11:13:25

问题


assume that we have a data1 and data2. How can I intersect them with std::set_intersect()?

struct pID
{
    int           ID;
    unsigned int  IDf;// postition in the file 
    pID(int id,const unsigned int idf):ID(id),IDf(idf){}
    bool operator<(const pID& p)const { return ID<p.ID;}
};

struct ID{};
struct IDf{};

typedef multi_index_container<
    pID,
    indexed_by<
    ordered_unique<
    tag<IDf>,  BOOST_MULTI_INDEX_MEMBER(pID,unsigned int,IDf)>,
    ordered_non_unique<
    tag<ID>,BOOST_MULTI_INDEX_MEMBER(pID,int,ID)> >
    > pID_set;

ID_set data1, data2; 
Load(data1); Load(data2);

pID_set::index<ID>::type& L1_ID_index=L1.data.get<ID>();
pID_set::index<ID>::type& L2_ID_index=L2.data.get<ID>();
    // How do I use set_intersect?

回答1:


std::set_intersection(
  L1_ID_index.begin(),L1_ID_index.end(),
  L2_ID_index.begin(),L2_ID_index.end(),
  output_iterator,
  L1_ID_index.value_comp());


来源:https://stackoverflow.com/questions/2448058/boost-multiindex-how-to-make-an-effective-set-intersection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!