GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 32 / 0 / 32
Functions: 100.0% 12 / 0 / 12
Branches: 76.9% 20 / 0 / 26

src/ds/rmq/st/lib.hpp
Line Branch Exec Source
1 #pragma once
2
3 #include "../../../util/alias/others/lib.hpp"
4
5 namespace tifa_libs {
6
7 template <class T, auto op>
8 requires std::same_as<std::remove_cvref_t<decltype(op(T(), T()))>, T>
9 class st_array {
10 vvec<T> st;
11
12 public:
13 16 CEXP st_array() = default;
14 374909 CEXPE st_array(spn<T> a) NE { reset(a); }
15
16 374925 CEXP void reset(spn<T> a) NE {
17 374925 cu32 n = (u32)a.size(), lbn = (u32)std::bit_width(n);
18 749850 st = vvec<T>(lbn, vec<T>(n)), copy(a, begin(st[0]));
19
2/2
✓ Branch 0 taken 1500013 times.
✓ Branch 1 taken 374925 times.
1874938 flt_ (u32, j, 1, lbn)
20
2/2
✓ Branch 8 taken 161537715 times.
✓ Branch 9 taken 1500013 times.
163037728 flt_ (u32, i, 0, n) st[j][i] = op(st[j - 1][i], st[j - 1][(u32)max(0, i32(i - (1 << (j - 1))))]);
21 374925 }
22 358578 CEXP void push_back(cT_(T) x) NE {
23
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 358570 times.
358578 if (!height()) {
24
2/2
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 8 times.
24 st = vvec<T>{{x}};
25 8 return;
26 }
27 358570 cu32 n = size() + 1, lbn = (u32)std::bit_width(n);
28
2/2
✓ Branch 3 taken 104 times.
✓ Branch 4 taken 358466 times.
358570 if (st[0].push_back(x); std::has_single_bit(n)) {
29 104 st.emplace_back(n - 1);
30
2/2
✓ Branch 8 taken 476104 times.
✓ Branch 9 taken 104 times.
476208 flt_ (u32, i, 0, n - 1) st.back()[i] = op(st[lbn - 2][i], st[lbn - 2][(u32)max(0, i32(i - (1 << (lbn - 2))))]);
31 }
32
2/2
✓ Branch 7 taken 5055538 times.
✓ Branch 8 taken 358570 times.
5414108 flt_ (u32, j, 1, lbn) st[j].push_back(op(st[j - 1].back(), st[j - 1][n - 1 - (1 << (j - 1))]));
33 24 }
34 35739583 ND CEXP u32 height() CNE { return (u32)st.size(); }
35
2/4
tifa_libs::st_array<int, &(f(int, int))>::size() const:
✓ Branch 1 taken 33514869 times.
✗ Branch 2 not taken.
tifa_libs::st_array<long, &(f(long, long))>::size() const:
✓ Branch 1 taken 1866136 times.
✗ Branch 2 not taken.
35381005 ND CEXP u32 size() CNE { retif_((height()) [[likely]], (u32)st[0].size(), 0); }
36 7503656 CEXP T query(u32 l = 0) CNE { return query(l, size()); }
37 //! 0-indexed, [l, r)
38 27016257 CEXP T query(u32 l, u32 r) CNE {
39
4/8
tifa_libs::st_array<int, &(f(int, int))>::query(unsigned int, unsigned int) const:
✓ Branch 0 taken 26513735 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 26513735 times.
✗ Branch 4 not taken.
tifa_libs::st_array<long, &(f(long, long))>::query(unsigned int, unsigned int) const:
✓ Branch 0 taken 502522 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 502522 times.
✗ Branch 4 not taken.
27016257 assert(l < r && r <= size());
40 27016257 cu32 k = (u32)(std::bit_width(r - l) - 1);
41 27016257 return op(st[k][l + (1 << k) - 1], st[k][r - 1]);
42 }
43 };
44
45 } // namespace tifa_libs
46