Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
atksh committed May 16, 2022
1 parent ebe8f9e commit 7e340c4
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions cpp/prtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ void bfs(const std::function<void(std::unique_ptr<PRTreeLeaf<T, B, D>> &)> &func
queue<size_t> que;
auto qpush_if_intersect = [&](const size_t &i)
{
PRTreeElement<T, B, D> &r = flat_tree.at(i);
PRTreeElement<T, B, D> &r = flat_tree[i];
// std::cout << "i " << (long int) i << " : " << (bool) r.leaf << std::endl;
if (r(target))
{
Expand All @@ -676,7 +676,7 @@ void bfs(const std::function<void(std::unique_ptr<PRTreeLeaf<T, B, D>> &)> &func
size_t idx = que.front();
// std::cout << "idx: " << (long int) idx << std::endl;
que.pop();
PRTreeElement<T, B, D> &elem = flat_tree.at(idx);
PRTreeElement<T, B, D> &elem = flat_tree[idx];

if (elem.leaf)
{
Expand Down Expand Up @@ -880,7 +880,7 @@ class PRTree
queue<size_t> que;
auto qpush_if_intersect = [&](const size_t &i)
{
if (flat_tree.at(i)(bb))
if (flat_tree[i](bb))
{
que.emplace(i);
}
Expand All @@ -891,7 +891,7 @@ class PRTree
{
size_t i = que.front();
que.pop();
PRTreeElement<T, B, D> &elem = flat_tree.at(i);
PRTreeElement<T, B, D> &elem = flat_tree[i];

if (elem.leaf && elem.leaf->mbb(bb))
{
Expand Down Expand Up @@ -924,7 +924,7 @@ class PRTree
Real min_diff_area = 1e100;
for (const auto &i : cands)
{
PRTreeLeaf<T, B, D> *leaf = flat_tree.at(i).leaf.get();
PRTreeLeaf<T, B, D> *leaf = flat_tree[i].leaf.get();
PRTreeLeaf<T, B, D> tmp_leaf = PRTreeLeaf<T, B, D>(*leaf);
Real diff_area = -tmp_leaf.area();
tmp_leaf.push(idx, bb);
Expand All @@ -936,20 +936,20 @@ class PRTree
}
}
}
flat_tree.at(min_leaf).leaf->push(idx, bb);
flat_tree[min_leaf].leaf->push(idx, bb);
// update mbbs of all cands and their parents
size_t i = min_leaf;
while (true)
{
PRTreeElement<T, B, D> &elem = flat_tree.at(i);
PRTreeElement<T, B, D> &elem = flat_tree[i];

if (elem.leaf)
elem.mbb += elem.leaf->mbb;

if (i > 0)
{
size_t j = (i - 1) / B;
flat_tree.at(j).mbb += flat_tree.at(i).mbb;
flat_tree[j].mbb += flat_tree[i].mbb;
}
if (i == 0)
break;
Expand Down Expand Up @@ -983,7 +983,7 @@ class PRTree
size_t idx = sta.top();
sta.pop();

PRTreeElement<T, B, D> &elem = flat_tree.at(idx);
PRTreeElement<T, B, D> &elem = flat_tree[idx];

if (elem.leaf)
{
Expand All @@ -998,7 +998,7 @@ class PRTree
for (size_t offset = 0; offset < B; offset++)
{
size_t jdx = idx * B + offset + 1;
if (flat_tree.at(jdx).is_used)
if (likely(flat_tree[jdx].is_used))
{
sta.push(jdx);
}
Expand Down Expand Up @@ -1098,10 +1098,11 @@ class PRTree
// resize
{
flat_tree.clear();
size_t count = 1;
for (int i = 0; i < depth; i++)
flat_tree.shrink_to_fit();
size_t count = 0;
for (int i = 0; i <= depth; i++)
{
count += B * std::pow(B, depth);
count += std::pow(B, depth);
}
flat_tree.resize(count);
}
Expand All @@ -1115,12 +1116,7 @@ class PRTree
p = tmp.first;
size_t idx = tmp.second;

if (unlikely(flat_tree.at(idx).is_used))
{
throw std::runtime_error("alreadly set");
}

flat_tree.at(idx) = PRTreeElement(*p);
flat_tree[idx] = PRTreeElement(*p);
size_t child_idx = 0;
if (p->head)
{
Expand Down

0 comments on commit 7e340c4

Please sign in to comment.