如何获得boost::multiindex容器的交集
how to get an intersection of a boost::multi_index container
我想以最快的方式获得ordered_non_unique
类型的4个索引的交集。这样的multi_index
-交集是否比嵌套4倍的std::map
更快?是否有可能使用类似std::map().templace().的东西
这是我的密码。
#include <iostream>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
using boost::multi_index_container;
using namespace boost::multi_index;
struct Kpt {
Kpt(float _x0, float _x1, float _y0, float _y1)
: x0_(_x0),x1_(_x1),y0_(_y0),y1_(_y1) {
}
friend std::ostream& operator<<(std::ostream & _os, Kpt const & _kpt) {
_os
<< "nx0 " << _kpt.x0_ << ","
<< " y0 " << _kpt.y0_ << ","
<< " x1 " << _kpt.x1_ << ","
<< " y1 " << _kpt.y1_ << std::endl
;
return _os;
}
float x0_;
float x1_;
float y0_;
float y1_;
};
struct x0_{};
struct x1_{};
struct y0_{};
struct y1_{};
typedef multi_index_container <
Kpt
, indexed_by <
ordered_non_unique <
tag<x0_>,BOOST_MULTI_INDEX_MEMBER(Kpt,float,x0_)
>
, ordered_non_unique <
tag<x1_>,BOOST_MULTI_INDEX_MEMBER(Kpt,float,x1_)
>
, ordered_non_unique <
tag<y0_>,BOOST_MULTI_INDEX_MEMBER(Kpt,float,y0_)
>
, ordered_non_unique <
tag<y1_>,BOOST_MULTI_INDEX_MEMBER(Kpt,float,y1_)
>
>
> Kpts;
int main() {
Kpts kpts;
for (int i=0; i<1000000; ++i) {
if (i%10000==0) std::cout << "." << std::flush;
kpts.insert(Kpt(0.1,0.1,0.1,0.1));
}
}
好的,现在我知道你想在区域[x0,x0+d]×[x1,x1+d]×[y0,y0+d]×[y1,y1+d]
中搜索4维点,对吧?
好吧,我恐怕要说Boost.MultiIndex不是正确的工具,因为它可以获得索引#0、#1、#2中范围的交集,#3只能通过扫描其中一个范围(比如#0)并手动验证遍历点的剩余坐标(x1, y0, y1)
是否位于感兴趣区域内来完成(std::set_intersection
在这里甚至不适用,因为它要求通过相同的标准对比较的范围进行排序,而我们的索引不是这样)。
正如你所指出的,boost::geometry::index::rtree
或一些类似的空间数据结构可能更适合这份工作。
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 如何从C++中的依赖类型中获得它所依赖的类型
- 欧拉项目#8答案是大以获得有效答案
- 如何使用C/C++在MacOSX中获得键盘布局
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 如何在不产生任何垃圾的情况下获得C中的像素
- 有没有一种方法可以在编译时获得作用域类名
- 如何在C++中获得"静态纯虚拟"功能?
- Python中的for循环与C++有何不同
- 如何设置一个范围来提取我想要获得的信息
- 在多次运行中获得一致的callgrind输出
- 通过错误处理,在C++中可靠地获得用户十六进制输入
- 如何在Directwrite中获得给定字体的可用OpenType功能
- 在我的代码中,获得最大的Pair Wise产品C++和输出并不总是正确的
- 当用户在qtablewidget中输入单元格时,如何获得信号?C++
- 未获得字符串中的预期输出
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- Qt:当QListView获得新条目时,如何更新QStringList
- 如何在卷曲中获得卷曲/卷曲.h?
- 如何获得boost::multiindex容器的交集