Let say I have a class to hold the sensor measurements, and I created a boost multi-index container with composite key of time and id of each measurement:
namespace {
struct ValueUpdateMsg {
double value;
uint64_t time;
int id;
};
struct time_id {
};
struct id_time {
};
using value_set_t = bmi::multi_index_container<
ValueUpdateMsg,
bmi::indexed_by<
bmi::ordered_unique<
bmi::tag<struct id_time>,
bmi::composite_key<ValueUpdateMsg,
bmi::member<ValueUpdateMsg, decltype(ValueUpdateMsg::id), &ValueUpdateMsg::id>,
bmi::member<ValueUpdateMsg, uint64_t, &ValueUpdateMsg::time>
>
>,
bmi::ordered_unique<
bmi::tag<struct time_id>,
bmi::composite_key<ValueUpdateMsg,
bmi::member<ValueUpdateMsg, uint64_t, &ValueUpdateMsg::time>,
bmi::member<ValueUpdateMsg, decltype(ValueUpdateMsg::id), &ValueUpdateMsg::id>
>
>
>
>;
}
value_set_t container;
container.insert(ValueUpdateMsg{1, 0, 1.0});
container.insert(ValueUpdateMsg{1, 1, 2.0});
container.insert(ValueUpdateMsg{3, 0, 3.0});
container.insert(ValueUpdateMsg{3, 2, 4.0});
container.insert(ValueUpdateMsg{5, 0, 5.0});
container.insert(ValueUpdateMsg{5, 1, 6.0});
I would like to find the node whose id=2
and the update time less that to equal to 4. How can I do that in the boost-multi-index container?
I can perform the following:
auto id2_range = boost::make_iterator_range(container.get<id_time>().equal_range(std::make_tuple(2)));
To get a range of values whose id == 2
and perform a linear( or binary) search to find the node whose time matches the query. Is there is a better way of doing it in boost multi-index?