Skip to content

Commit eeb6c6b

Browse files
authored
Naming nit (#175)
* Refactor lazy segment tree apply and update methods * Refactor update method for lazy segment tree * Move operation function inside seg_tree struct * Update lazy_seg_tree.hpp * Fix cppcheck suppression for lazy_seg_tree.hpp * Refactor operation function in lazy segment tree * Update lazy_seg_tree.hpp * Update cppcheck suppression for lazy_seg_tree.hpp
1 parent f7a8295 commit eeb6c6b

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ struct seg_tree {
1111
for (int i = n - 1; i >= 1; i--)
1212
tree[i] = op(tree[2 * i], tree[2 * i + 1]);
1313
}
14-
void apply(ll change, int tl, int tr, int v) {
15-
tree[v] += (tr - tl) * change;
16-
if (v < n) lazy[v] += change;
14+
void apply(ll d, int tl, int tr, int v) {
15+
tree[v] += (tr - tl) * d;
16+
if (v < n) lazy[v] += d;
1717
}
1818
void push(int tl, int tm, int tr, int v) {
1919
if (lazy[v]) {
@@ -22,18 +22,16 @@ struct seg_tree {
2222
lazy[v] = 0;
2323
}
2424
}
25-
void update(int l, int r, ll change) {
26-
update(l, r, change, 0, n, 1);
25+
void update(int l, int r, ll d) {
26+
update(l, r, d, 0, n, 1);
2727
}
28-
void update(int l, int r, ll change, int tl, int tr,
29-
int v) {
28+
void update(int l, int r, ll d, int tl, int tr, int v) {
3029
if (r <= tl || tr <= l) return;
31-
if (l <= tl && tr <= r)
32-
return apply(change, tl, tr, v);
30+
if (l <= tl && tr <= r) return apply(d, tl, tr, v);
3331
int tm = split(tl, tr);
3432
push(tl, tm, tr, v);
35-
update(l, r, change, tl, tm, 2 * v);
36-
update(l, r, change, tm, tr, 2 * v + 1);
33+
update(l, r, d, tl, tm, 2 * v);
34+
update(l, r, d, tm, tr, 2 * v + 1);
3735
tree[v] = op(tree[2 * v], tree[2 * v + 1]);
3836
}
3937
ll query(int l, int r) { return query(l, r, 0, n, 1); }

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ struct seg_tree {
1111
for (int i = n - 1; i >= 1; i--)
1212
tree[i] = op(tree[2 * i], tree[2 * i + 1]);
1313
}
14-
void apply(ll change, int tl, int tr, int v) {
15-
tree[v] += (tr - tl + 1) * change;
16-
if (v < n) lazy[v] += change;
14+
void apply(ll d, int tl, int tr, int v) {
15+
tree[v] += (tr - tl + 1) * d;
16+
if (v < n) lazy[v] += d;
1717
}
1818
void push(int tl, int tm, int tr, int v) {
1919
if (lazy[v]) {
@@ -22,18 +22,16 @@ struct seg_tree {
2222
lazy[v] = 0;
2323
}
2424
}
25-
void update(int l, int r, ll change) {
26-
update(l, r, change, 0, n - 1, 1);
25+
void update(int l, int r, ll d) {
26+
update(l, r, d, 0, n - 1, 1);
2727
}
28-
void update(int l, int r, ll change, int tl, int tr,
29-
int v) {
28+
void update(int l, int r, ll d, int tl, int tr, int v) {
3029
if (r < tl || tr < l) return;
31-
if (l <= tl && tr <= r)
32-
return apply(change, tl, tr, v);
30+
if (l <= tl && tr <= r) return apply(d, tl, tr, v);
3331
int tm = split(tl, tr);
3432
push(tl, tm, tr, v);
35-
update(l, r, change, tl, tm, 2 * v);
36-
update(l, r, change, tm + 1, tr, 2 * v + 1);
33+
update(l, r, d, tl, tm, 2 * v);
34+
update(l, r, d, tm + 1, tr, 2 * v + 1);
3735
tree[v] = op(tree[2 * v], tree[2 * v + 1]);
3836
}
3937
ll query(int l, int r) {

0 commit comments

Comments
 (0)