繁体   English   中英

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 _ZN3RKDI24Division_Euclidean_spaceIfEE2nnEjRKSt6vectorIfSaIfEERKfRS3_ISt4pairIfiESaISB_EERiiPjRSt14priority_queueISt5tupleIJfiiEES3_ISJ_SaISJ_ES7_S7S

我相信这是我在项目中使用的唯一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会做什么,但是我想它比优先级队列操作做的更多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM