std::priority_queue的最小堆是我的瓶颈

Min heap with std::priority_queue is my bottleneck

本文关键字:我的 priority queue std      更新时间:2023-10-16

替代标题:

使用比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做什么,但我想它做的远不止优先级队列操作。