boost::multi_index_container:如何使用composite_key (x,y) 支持矩形搜索
boost::multi_index_container: How to use composite_key (x,y) to support rectangular search?
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>
>
>, // ...
>
如您所见,有按点(x,y((ByP
(的索引。现在我正在使用下一个函数:
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 (第一条评论@RichardHodges( struct Compare
{
bool operator() (const Point &p, const Point &q) const
{ return (p.x < q.x) && (p.y < q.y); }
};
首先,比较器对我来说似乎是错误的(看起来它并没有根据需要定义一个完全弱的排序(。
其次,组合键上的键类型在逻辑上是组成部分的元组。默认比较实现由 boost 提供(作为字典编纂成员比较¹(。
这更有可能是你想要的。如果必须以某种方式覆盖它,请使用:http://www.boost.org/doc/libs/1_60_0/libs/multi_index/doc/reference/key_extraction.html#composite_key_compare
¹ <boost/tuple/tuple_comparison.hpp>
和 C++11 的 std::tuple 也定义了相同的运算符
相关文章:
- 编译时未启用intel oneApi CUDA支持
- 有根的二进制搜索树.保留与其父级的链接
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 使用CMake检测支持的C++标准
- 为什么istream不支持右值提取
- 在C++中搜索嵌套多映射值
- 当我编译webrtc服务器时,Windows上只支持clang-cl
- 扩展光电二极管探测器以支持多个传感器
- cpp二进制搜索问题,计算给定数组中输入元素的出现次数
- MSVC是否支持C++11样式的属性而不是__declspec
- 二进制搜索树叶数问题
- 为什么二进制搜索在我的测试中不起作用
- 正在尝试重载二进制搜索树分配运算符
- c++binary_search函数排序数组(流行名称搜索)出现问题
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 向量上的线性搜索
- 如何在动态数组上使用搜索函数
- 如何打开全文搜索支持
- boost::multi_index_container:如何使用composite_key (x,y) 支持矩形搜索
- 现有的数据库(最好是嵌入式数据库)是否支持大型小型多维搜索?