使用Boost多索引搜索多个不良事件 [英] search for multiple indecies with Boost Multi-Index
问题描述
如何通过上一次搜索的结果限制在 boost :: multi_index
中的搜索?
举个例子:假设我有一个内部值为这样的矩形类:
how do I limit the search in a boost::multi_index
by the result of a previous search?
As an example: suppose I have a rectangle class with an internal value like this:
class MyRect
{
public:
int width;
int height;
double value;
}
我需要这种对象的数据结构来回答查询, input_rectangle
- 该对象 MyRect
包含在该矩形中并且具有最高值?
and I need a data structure of such object to answer queries like "given an input_rectangle
- which object MyRect
is contained in that rectangle and has the highest value?"
我可以这样使用一个'multi_index':
I could use a 'multi_index' like this:
struct given_value{};
struct given_width{};
struct given_height{};
typedef multi_index_container<MyRect,
indexed_by<
ordered_non_unique< tag<given_value>,
member<MyRect, double, &MyRect::value>,
ordered_non_unique< tag<given_width>,
member<MyRect, int, &MyRect::width>,
ordered_non_unique< tag<given_height>,
member<MyRect, int, &MyRect::height>, >
>
> MyDataStructure;
typedef MyDataStructure::index<given_width>::type MyDataStructureGivenWidth;
typedef MyDataStructureGivenWidth::iterator WidthIterator;
如果我的 input_rectangle
$ c> input_width 我可以使用这样的:
If my input_rectangle
has width input_width
I could use something like this:
WidthIterator start_iter = data_object.get<given_width>().begin();
WidthIterator end_iter = data_object.get<given_width>().upper_bound(input_width);
但是如何通过两个给定的迭代器限制对coresp高度的搜索?
(然后找到该结果中值最高的对象?)
But how do I limit the search for the coresp height by the two given iterators? (And after that find the object with the highest value in that result?)
推荐答案
您可以执行inplace限制。
将匹配宽度查询的结果迭代器存储在另一个容器中,并使用该容器与remove_if查找匹配的高度。
I don't think you can do an inplace limitation.
Store the resulting iterators of the matching widths query in another container and use that container to find the matching heights with remove_if. Then use max_element to find the largest.
如果将元素存储为指针,则可以使用相同的MIC来存储结果。
If you store the elements as pointers, you could use the same MIC to store the results.
这篇关于使用Boost多索引搜索多个不良事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!