std::priority_queue的最小堆是我的瓶颈
Min heap with std::priority_queue is my bottleneck
替代标题:
使用比std::priority_queue
更快的实现最小堆。
grpof给了我:
时间秒调用s/调用s/调用名称
84.12 105.54 105.54 320000 0.00 0.00 _ZN3RKDI24分区_Eucledan_spaceIfEE2nnEjRKSt6vectorIfSaIfEERKfRS3_ISt4pairIfiESaIB_EERiiPjRSt14优先级_queueISt5tupleIJfiiEES3_ISJ_SaISJ_EESt7greaterISJ_EES 9_RKjS7_S7\ui
我相信这是我在项目中使用的唯一std::priority_queue
。"Division_Euclidean_space"部分让我感到困惑,因为它是一个在我的项目中不再使用的类/文件。
以下是我确切使用的:
/**
* Min_heap is actually a std::priority_queue,
* with std::greater as a parameter.
*/
typedef std::priority_queue<std::tuple<float, int, int>,
std::vector<std::tuple<float, int, int> >,
std::greater<std::tuple<float, int, int> > > Min_heap;
我使用第一个元素作为比较的关键。
正如人们在我的回购中看到的那样,我只创建了一个Min_heap
,并将其分为两部分:
if(...) {
branch.push(std::make_tuple(new_dist, other_child_i, tree_i));
}
和
while (branch.size()) {
std::tie(new_mindist, node_i, tree_i) = branch.top();
branch.pop();
...
}
我觉得如果我用其他东西替换这个数据结构,我的项目可能会运行得更快(超级傻瓜很棒)。有什么想法吗?
我在堆中推项目一段时间,然后弹出一个项目,我可能会推其他项目,以此类推。大多数时候,我会在另一个条件下停止,而不是在堆变空时。
http://demangler.com将该函数翻译成:(我缩进)
RKD<Division_Euclidean_space<float> >::nn(
unsigned int,
std::vector<float, std::allocator<float> > const&,
float const&,
std::vector<std::pair<float, int>, std::allocator<std::pair<float, int> > >&,
int&,
int,
unsigned int*,
std::priority_queue<std::tuple<float, int, int>,
std::vector<std::tuple<float, int, int>,
std::allocator<std::tuple<float, int, int> > >,
std::greater<std::tuple<float, int, int> > >&,
float const&,
unsigned int const&,
std::vector<float, std::allocator<float> > const&,
std::vector<float, std::allocator<float> > const&,
int)
我不知道nn
做什么,但我想它做的远不止优先级队列操作。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- cmake在我的项目中所需的所有静态库都不成功
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 为什么我的for循环不能正确获取argv
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 0-1背包代码中的错误.我的代码中有什么错误
- 当我的阵列太大时出现分段错误
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 为什么二进制搜索在我的测试中不起作用
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- OpenGL在启用深度测试时不会丢弃我的碎片
- 为什么我的 std::ref 无法按预期工作?
- clang整洁10忽略了我的NOLINT命令
- 为什么我的删除节点函数实际上没有删除节点?