@@ -660,7 +660,7 @@ void bfs(const std::function<void(std::unique_ptr<PRTreeLeaf<T, B, D>> &)> &func
660660 queue<size_t > que;
661661 auto qpush_if_intersect = [&](const size_t &i)
662662 {
663- PRTreeElement<T, B, D> &r = flat_tree. at (i) ;
663+ PRTreeElement<T, B, D> &r = flat_tree[i] ;
664664 // std::cout << "i " << (long int) i << " : " << (bool) r.leaf << std::endl;
665665 if (r (target))
666666 {
@@ -676,7 +676,7 @@ void bfs(const std::function<void(std::unique_ptr<PRTreeLeaf<T, B, D>> &)> &func
676676 size_t idx = que.front ();
677677 // std::cout << "idx: " << (long int) idx << std::endl;
678678 que.pop ();
679- PRTreeElement<T, B, D> &elem = flat_tree. at ( idx) ;
679+ PRTreeElement<T, B, D> &elem = flat_tree[ idx] ;
680680
681681 if (elem.leaf )
682682 {
@@ -880,7 +880,7 @@ class PRTree
880880 queue<size_t > que;
881881 auto qpush_if_intersect = [&](const size_t &i)
882882 {
883- if (flat_tree. at (i) (bb))
883+ if (flat_tree[i] (bb))
884884 {
885885 que.emplace (i);
886886 }
@@ -891,7 +891,7 @@ class PRTree
891891 {
892892 size_t i = que.front ();
893893 que.pop ();
894- PRTreeElement<T, B, D> &elem = flat_tree. at (i) ;
894+ PRTreeElement<T, B, D> &elem = flat_tree[i] ;
895895
896896 if (elem.leaf && elem.leaf ->mbb (bb))
897897 {
@@ -924,7 +924,7 @@ class PRTree
924924 Real min_diff_area = 1e100 ;
925925 for (const auto &i : cands)
926926 {
927- PRTreeLeaf<T, B, D> *leaf = flat_tree. at (i) .leaf .get ();
927+ PRTreeLeaf<T, B, D> *leaf = flat_tree[i] .leaf .get ();
928928 PRTreeLeaf<T, B, D> tmp_leaf = PRTreeLeaf<T, B, D>(*leaf);
929929 Real diff_area = -tmp_leaf.area ();
930930 tmp_leaf.push (idx, bb);
@@ -936,20 +936,20 @@ class PRTree
936936 }
937937 }
938938 }
939- flat_tree. at ( min_leaf) .leaf ->push (idx, bb);
939+ flat_tree[ min_leaf] .leaf ->push (idx, bb);
940940 // update mbbs of all cands and their parents
941941 size_t i = min_leaf;
942942 while (true )
943943 {
944- PRTreeElement<T, B, D> &elem = flat_tree. at (i) ;
944+ PRTreeElement<T, B, D> &elem = flat_tree[i] ;
945945
946946 if (elem.leaf )
947947 elem.mbb += elem.leaf ->mbb ;
948948
949949 if (i > 0 )
950950 {
951951 size_t j = (i - 1 ) / B;
952- flat_tree. at (j) .mbb += flat_tree. at (i) .mbb ;
952+ flat_tree[j] .mbb += flat_tree[i] .mbb ;
953953 }
954954 if (i == 0 )
955955 break ;
@@ -983,7 +983,7 @@ class PRTree
983983 size_t idx = sta.top ();
984984 sta.pop ();
985985
986- PRTreeElement<T, B, D> &elem = flat_tree. at ( idx) ;
986+ PRTreeElement<T, B, D> &elem = flat_tree[ idx] ;
987987
988988 if (elem.leaf )
989989 {
@@ -998,7 +998,7 @@ class PRTree
998998 for (size_t offset = 0 ; offset < B; offset++)
999999 {
10001000 size_t jdx = idx * B + offset + 1 ;
1001- if (flat_tree. at ( jdx) .is_used )
1001+ if (likely (flat_tree[ jdx] .is_used ) )
10021002 {
10031003 sta.push (jdx);
10041004 }
@@ -1098,10 +1098,11 @@ class PRTree
10981098 // resize
10991099 {
11001100 flat_tree.clear ();
1101- size_t count = 1 ;
1102- for (int i = 0 ; i < depth; i++)
1101+ flat_tree.shrink_to_fit ();
1102+ size_t count = 0 ;
1103+ for (int i = 0 ; i <= depth; i++)
11031104 {
1104- count += B * std::pow (B, depth);
1105+ count += std::pow (B, depth);
11051106 }
11061107 flat_tree.resize (count);
11071108 }
@@ -1115,12 +1116,7 @@ class PRTree
11151116 p = tmp.first ;
11161117 size_t idx = tmp.second ;
11171118
1118- if (unlikely (flat_tree.at (idx).is_used ))
1119- {
1120- throw std::runtime_error (" alreadly set" );
1121- }
1122-
1123- flat_tree.at (idx) = PRTreeElement (*p);
1119+ flat_tree[idx] = PRTreeElement (*p);
11241120 size_t child_idx = 0 ;
11251121 if (p->head )
11261122 {
0 commit comments