typedef boost::multi_index_container
< Record,
indexed_by
< ordered_non_unique
< tag<ByP>,
composite_key < Record,
const_mem_fun<Record, double, &Record::hit_x>,
const_mem_fun<Record, double, &Record::hit_y>
>
>, // ...
>
ご覧のとおり、Point(x、y)(ByP
)によるインデックスがあります。 は、今は次の関数を使用しています:boost :: multi_index_container:composite_key(x、y)を使用して長方形の検索をサポートする方法は?
size_t adjacencyRectPoints (std::list<Record> &range, const Point &min, const Point &max)
{
MultiIndexMoves::index<ByP>::type &index = store_.get<ByP>();
/* Range searching, i.e.the lookup of all elements in a given interval */
auto itFirstLower = index.lower_bound (boost::tuple<double, double> (min));
auto itFirstUpper = index.upper_bound (boost::tuple<double, double> (max));
size_t count = 0U;
for (auto it = itFirstLower; it != itFirstUpper; ++it)
{
if ((min.x <= it->hit.x && min.y <= it->hit.y)
&& (max.x >= it->hit.x && max.y >= it->hit.y))
{
range.push_back (*it);
++count;
}
}
return count;
}
この関数は、矩形のすべての点を返す:(min.x max.x & & min.y < < X < Y < max.y)。それは働いている。
しかし、コンテナは予想よりも多くのポイントを返し、もう一度それらをフィルタリングする必要があります。 私はその演技が間違っていると思います。
コンパレータを自分で定義して、正しい点だけを取得しなければならないと思っていました。
struct Compare
{
bool operator() (const Point &p, const Point &q) const
{ return (p.x < q.x) && (p.y < q.y); }
};
(最初のコメント@RichardHodges)
と同じ演算子を定義します。それは可逆的ではありません。 xの値が等しく、yの値が異なる場合、他のキーと同じかそれ以上のキーは取得されません。 –
"compare_resultのキー間でAND演算子を取得することは非常に重要です。" - その場合、私は何とかこれがマルチインデックスの仕組みを見失ってしまいます。 – VolkerK
@ VolkerK、コンテナはxとyで独立して検索し、それから交差します。つまり、各キーコンパレータがtrueを返したことを意味します。 –