boost multi_multi 索引的使用
Usage of boost multi_multi index
我的代码(不是我写的)使用多索引容器。
typedef boost::multi_index_container<
Block*,
boost::multi_index::indexed_by<
boost::multi_index::random_access<>,
boost::multi_index::ordered_non_unique<BOOST_MULTI_INDEX_MEMBER(Block,uint,pages_invalid) >
>
> active_set;
typedef active_set::nth_index<0>::type ActiveBySeq;
typedef active_set::nth_index<1>::type ActiveByCost;
active_set active_cost;
"Block" 是 class 之一。
此容器用作优先队列。
ActiveByCost::iterator it = active_cost.get<1>().end();
--it;
我想搜索一个有变量 A=="specific value" 的成员。
(不适用于优先队列)
A是Class块的成员变量之一。
有什么办法吗?
I'd like to search a member which have variable A=="specific value"
如果该成员没有索引,则需要在随机访问索引中进行线性搜索:
auto pos = std::find_if(active_cost.begin(), active_cost.end(),
[](Block const* p) { return p->A == "specific value"; }
if(pos == active_cost.end())
// Not found.
我的代码(不是我写的)使用多索引容器。
typedef boost::multi_index_container<
Block*,
boost::multi_index::indexed_by<
boost::multi_index::random_access<>,
boost::multi_index::ordered_non_unique<BOOST_MULTI_INDEX_MEMBER(Block,uint,pages_invalid) >
>
> active_set;
typedef active_set::nth_index<0>::type ActiveBySeq;
typedef active_set::nth_index<1>::type ActiveByCost;
active_set active_cost;
"Block" 是 class 之一。
此容器用作优先队列。
ActiveByCost::iterator it = active_cost.get<1>().end();
--it;
我想搜索一个有变量 A=="specific value" 的成员。 (不适用于优先队列)
A是Class块的成员变量之一。
有什么办法吗?
I'd like to search a member which have variable A=="specific value"
如果该成员没有索引,则需要在随机访问索引中进行线性搜索:
auto pos = std::find_if(active_cost.begin(), active_cost.end(),
[](Block const* p) { return p->A == "specific value"; }
if(pos == active_cost.end())
// Not found.