簡體   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