Skip to content

Commit 8d5765b

Browse files
authored
Remove bit walk (#239)
* removing lambda bit walk * fixing some tests * fix test * fix docs * update line number
1 parent 087f39e commit 8d5765b

11 files changed

Lines changed: 13 additions & 68 deletions

File tree

library/data_structures_[l,r)/bit.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#pragma once
22
//! @code
33
//! BIT bit(n);
4-
//! bit.walk([&](int r, int64_t sum) -> bool {
5-
//! // sum = a[0] + a[1] + ... + a[r - 1]
6-
//! });
7-
//! int r = bit.walk2(sum);
4+
//! int r = bit.walk(sum);
85
//! // Returns min r s.t. sum of [0,r+1) >= sum
96
//! // Returns n if sum of [0,n) < sum
107
//! // Returns -1 if sum <= 0
@@ -25,6 +22,5 @@ struct BIT {
2522
return res;
2623
}
2724
ll query(int l, int r) { return query(r) - query(l); }
28-
#include "bit_uncommon/walk_lambda.hpp"
2925
#include "bit_uncommon/walk.hpp"
3026
};

library/data_structures_[l,r)/bit_uncommon/walk.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
int walk2(ll sum) {
1+
int walk(ll sum) {
22
if (sum <= 0) return -1;
33
int r = 0;
44
for (int i = bit_floor(size(s)); i; i /= 2)

library/data_structures_[l,r)/bit_uncommon/walk_lambda.hpp

Lines changed: 0 additions & 6 deletions
This file was deleted.

library/data_structures_[l,r]/bit.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#pragma once
22
//! @code
33
//! BIT bit(n);
4-
//! bit.walk([&](int r, int64_t sum) -> bool {
5-
//! // sum = a[0] + a[1] + ... + a[r]
6-
//! });
7-
//! int r = bit.walk2(sum);
4+
//! int r = bit.walk(sum);
85
//! // Returns min r s.t. sum of [0,r] >= sum
96
//! // Returns n if sum of [0,n-1] < sum
107
//! // Returns -1 if sum <= 0
@@ -27,6 +24,5 @@ struct BIT {
2724
ll query(int l, int r) {
2825
return query(r) - query(l - 1);
2926
}
30-
#include "bit_uncommon/walk_lambda.hpp"
3127
#include "../data_structures_[l,r)/bit_uncommon/walk.hpp"
3228
};

library/data_structures_[l,r]/bit_uncommon/walk_lambda.hpp

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/.config/.cppcheck_suppression_list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ unusedFunction:../kactl/content/data-structures/UnionFind.h:14
6060
unusedFunction:../kactl/content/number-theory/ModPow.h:13
6161
unusedFunction:../kactl/stress-tests/utilities/genTree.h:49
6262
containerOutOfBounds:../library/data_structures_[l,r)/uncommon/permutation_tree.hpp:85
63-
ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/bit.hpp:15
63+
ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/bit.hpp:12
6464
ctuOneDefinitionRuleViolation:../library/data_structures_[l,r)/lazy_seg_tree.hpp:4

tests/library_checker_aizu_tests/data_structures/bit.test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int main() {
5858
}
5959
return 1;
6060
};
61-
assert(bit.walk2(sum) == st.find_first(0, n, f));
61+
assert(bit.walk(sum) == st.find_first(0, n, f));
6262
}
6363
return 0;
6464
}

tests/library_checker_aizu_tests/data_structures/bit_inc_walk.test.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,13 @@ int main() {
2323
if (bit.query(k, n - 1) == 0) cout << -1 << '\n';
2424
else {
2525
ll order = bit.query(k - 1);
26-
int res = -1;
27-
bit.walk([&](int r, ll sum) {
28-
if (sum <= order) return 1;
29-
res = r;
30-
return 0;
31-
});
32-
cout << res << '\n';
26+
cout << bit.walk(order + 1) << '\n';
3327
}
3428
} else {
3529
if (bit.query(k) == 0) cout << -1 << '\n';
3630
else {
3731
ll order = bit.query(k);
38-
int res = -1;
39-
bit.walk([&](int r, ll sum) {
40-
if (sum >= order) {
41-
res = r;
42-
return 0;
43-
}
44-
return 1;
45-
});
46-
cout << res << '\n';
32+
cout << bit.walk(order) << '\n';
4733
}
4834
}
4935
}

tests/library_checker_aizu_tests/data_structures/bit_ordered_set.test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int main() {
4040
x = get_compressed_idx(x);
4141
if (bit.query(x, x) == 1) bit.update(x, -1);
4242
} else if (type == 2) {
43-
int res = bit.walk2(x);
43+
int res = bit.walk(x);
4444
if (res == -1 || res == sz(compress))
4545
cout << -1 << '\n';
4646
else cout << compress[res] << '\n';
@@ -49,12 +49,12 @@ int main() {
4949
cout << bit.query(x) << '\n';
5050
} else if (type == 4) {
5151
x = get_compressed_idx(x);
52-
int res = bit.walk2(bit.query(x));
52+
int res = bit.walk(bit.query(x));
5353
if (res == -1) cout << -1 << '\n';
5454
else cout << compress[res] << '\n';
5555
} else {
5656
x = get_compressed_idx(x);
57-
int res = bit.walk2(bit.query(x - 1) + 1);
57+
int res = bit.walk(bit.query(x - 1) + 1);
5858
if (res == sz(bit.s)) cout << -1 << '\n';
5959
else cout << compress[res] << '\n';
6060
}

tests/library_checker_aizu_tests/data_structures/bit_walk.test.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,13 @@ int main() {
4646
}
4747
return 1;
4848
};
49-
int res = bit.walk2(order + 1);
49+
int res = bit.walk(order + 1);
5050
assert(res == st.find_first(0, n, f));
5151
assert(res == st.find_first(k, n,
5252
[&](ll x, int, int) -> bool {
5353
return x > 0;
5454
}));
5555
if (res == n) res = -1;
56-
int res_lambda = -1;
57-
bit.walk([&](int r, ll sum) {
58-
if (sum > order) {
59-
res_lambda = r - 1;
60-
return 0;
61-
}
62-
return 1;
63-
});
64-
assert(res == res_lambda);
6556
cout << res << '\n';
6657
} else {
6758
if (bit.query(k, k + 1) == 1) {
@@ -78,24 +69,12 @@ int main() {
7869
}
7970
return 1;
8071
};
81-
int res = bit.walk2(order);
72+
int res = bit.walk(order);
8273
assert(max(res, 0) == st.find_first(0, n, f));
8374
assert(res == st.find_last(0, k + 1,
8475
[&](ll x, int, int) -> bool {
8576
return x > 0;
8677
}));
87-
int res_lambda = -1;
88-
if (order) {
89-
bit.walk([&](int r, ll sum) {
90-
if (sum < order) {
91-
res_lambda = r;
92-
return 1;
93-
}
94-
res_lambda = r - 1;
95-
return 0;
96-
});
97-
}
98-
assert(res == res_lambda);
9978
cout << res << '\n';
10079
}
10180
}

0 commit comments

Comments
 (0)