Skip to content

Commit

Permalink
fix: tiny change
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiphereth-A committed Feb 19, 2024
1 parent a676fea commit 0a184e0
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/code/util/blocking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class blocking {
vec<T> dt, bs;

constexpr auto block_l(u32 id) { return dt.begin() + std::min((u32)dt.size(), id * bsz); }
constexpr u32 block_id(u32 idx) const { return idx / bsz; }

public:
// @param block_func init function for block: block_func(block, data.begin() + xl, data.begin() + xr); change value of block with range [xl, xr)
Expand All @@ -34,14 +35,10 @@ class blocking {
}
constexpr void run(u32 l, u32 r, FD&& upd, FDB&& updb) {
assert(l < r);
u32 bl = (l + bsz - 1) / bsz, br = (r + bsz - 1) / bsz;
for (u32 i = bl; i < br; ++i) updb(bs[i], block_l(i), block_l(i + 1));
if (r <= bl * bsz) {
if (bl) upd(bs[bl - 1], dt.begin() + l, dt.begin() + r);
} else {
if (l < bl * bsz) upd(bs[bl - 1], dt.begin() + l, block_l(bl));
if (br * bsz < r) upd(bs[br + 1], block_l(br), dt.begin() + r);
}
u32 bl = block_id(l), br = block_id(r - 1);
for (u32 i = bl; i <= br; ++i) updb(bs[i], block_l(i), block_l(i + 1));
if (auto L = dt.begin() + l, R = block_l(bl); L < R) upd(bs[bl - 1], L, R);
if (auto L = block_l(br + 1), R = dt.begin() + r; L < R) upd(bs[br + 1], L, R);
}
};

Expand Down

0 comments on commit 0a184e0

Please sign in to comment.