Skip to content

Commit 962f6a6

Browse files
cameroncusterCameron Custer
andauthored
make variable naming consistent across library (#223)
* make variable naming consistent across library * apply naming conventions to doc examples --------- Co-authored-by: Cameron Custer <cam@augmentcode.com>
1 parent 29d8d92 commit 962f6a6

16 files changed

Lines changed: 78 additions & 80 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ struct BIT {
2020
for (; i < sz(s); i |= i + 1) s[i] += d;
2121
}
2222
ll query(int r) {
23-
ll ret = 0;
24-
for (; r > 0; r &= r - 1) ret += s[r - 1];
25-
return ret;
23+
ll res = 0;
24+
for (; r > 0; r &= r - 1) res += s[r - 1];
25+
return res;
2626
}
2727
ll query(int l, int r) { return query(r) - query(l); }
2828
#include "bit_uncommon/walk_lambda.hpp"

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ template<int K> struct KD_BIT {
1919
for (; i < sz(s); i |= i + 1) s[i].update(a...);
2020
}
2121
ll query(int l, int r, auto... a) {
22-
ll ans = 0;
23-
for (; l < r; r &= r - 1) ans += s[r - 1].query(a...);
24-
for (; r < l; l &= l - 1) ans -= s[l - 1].query(a...);
25-
return ans;
22+
ll res = 0;
23+
for (; l < r; r &= r - 1) res += s[r - 1].query(a...);
24+
for (; r < l; l &= l - 1) res -= s[l - 1].query(a...);
25+
return res;
2626
}
2727
};
2828
template<> struct KD_BIT<0> {

library/data_structures_[l,r)/seg_tree_uncommon/kth_smallest_query.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ struct kth_smallest {
2626
int query(int k, int tl, int tr, int vl, int vr) {
2727
if (tr - tl == 1) return tl;
2828
int tm = tl + (tr - tl) / 2;
29-
int left_count = pst.tree[pst.tree[vr].lch].sum -
30-
pst.tree[pst.tree[vl].lch].sum;
31-
if (left_count >= k)
29+
int cnt_l = pst.tree[pst.tree[vr].lch].sum -
30+
pst.tree[pst.tree[vl].lch].sum;
31+
if (cnt_l >= k)
3232
return query(k, tl, tm, pst.tree[vl].lch,
3333
pst.tree[vr].lch);
34-
return query(k - left_count, tm, tr, pst.tree[vl].rch,
34+
return query(k - cnt_l, tm, tr, pst.tree[vl].rch,
3535
pst.tree[vr].rch);
3636
}
3737
};

library/data_structures_[l,r)/uncommon/deque_op.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ template<class T, class F> struct deq {
2424
T front() { return (empty(l) ? r[0] : l.back())[0]; }
2525
T back() { return (empty(r) ? l[0] : r.back())[0]; }
2626
int siz() { return sz(l) + sz(r); }
27-
void push_back(T elem) {
27+
void push_back(T val) {
2828
r.push_back(
29-
{elem, empty(r) ? elem : op(r.back()[1], elem)});
29+
{val, empty(r) ? val : op(r.back()[1], val)});
3030
}
3131
void pop_back() {
3232
if (empty(r)) {
@@ -37,9 +37,9 @@ template<class T, class F> struct deq {
3737
}
3838
r.pop_back();
3939
}
40-
void push_front(T elem) {
40+
void push_front(T val) {
4141
l.push_back(
42-
{elem, empty(l) ? elem : op(elem, l.back()[1])});
42+
{val, empty(l) ? val : op(val, l.back()[1])});
4343
}
4444
void pop_front() {
4545
if (empty(l)) {

library/data_structures_[l,r)/uncommon/mode_query.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ const int b = 318; //!< sqrt(1e5)
33
//! https://noshi91.hatenablog.com/entry/2020/10/26/140105
44
struct mode_query {
55
int n;
6-
vi a, cnt, index_into_index;
7-
vector<vi> index;
6+
vi a, cnt, pos_idx;
7+
vector<vi> pos;
88
vector<vector<pii>>
99
mode_blocks; //!< {mode, cnt} of range of blocks
1010
//! @param a compressed array: 0 <= a[i] < n
1111
//! @time O(n * sqrt(n))
1212
//! @space O(n)
1313
mode_query(const vi& a):
14-
n(sz(a)), a(a), cnt(n), index_into_index(n), index(n),
14+
n(sz(a)), a(a), cnt(n), pos_idx(n), pos(n),
1515
mode_blocks((n + b - 1) / b,
1616
vector<pii>((n + b - 1) / b)) {
1717
rep(i, 0, n) {
18-
index_into_index[i] = sz(index[a[i]]);
19-
index[a[i]].push_back(i);
18+
pos_idx[i] = sz(pos[a[i]]);
19+
pos[a[i]].push_back(i);
2020
}
2121
for (int start = 0; start < n; start += b) {
2222
int mode = a[start];
@@ -51,17 +51,17 @@ struct mode_query {
5151
for (int i = l / b * b + b - 1; i >= l; i--)
5252
cnt[a[i]]++;
5353
for (int i = l / b * b + b - 1; i >= l; i--) {
54-
int idx = index_into_index[i];
55-
if (idx + res.second < sz(index[a[i]]) &&
56-
index[a[i]][idx + res.second] < r)
54+
int idx = pos_idx[i];
55+
if (idx + res.second < sz(pos[a[i]]) &&
56+
pos[a[i]][idx + res.second] < r)
5757
res = {a[i], cnt[a[i]] + res.second};
5858
cnt[a[i]]--;
5959
}
6060
rep(i, (r - 1) / b * b, r) cnt[a[i]]++;
6161
rep(i, (r - 1) / b * b, r) {
62-
int idx = index_into_index[i];
62+
int idx = pos_idx[i];
6363
if (idx >= res.second &&
64-
index[a[i]][idx - res.second] >= l)
64+
pos[a[i]][idx - res.second] >= l)
6565
res = {a[i], cnt[a[i]] + res.second};
6666
cnt[a[i]]--;
6767
}

library/data_structures_[l,r)/uncommon/priority_queue_of_updates.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! DS ds;
66
//! // int = argument type of DS::join
77
//! pq_updates<DS, int> pq(ds);
8-
//! pq.push_update(val, priority);
8+
//! pq.push_update(val, pri);
99
//! pq.pop_update();
1010
//! @endcode
1111
//! @time n interweaved calls to pop_update, push_update
@@ -38,10 +38,9 @@ template<class DS, class... ARGS> struct pq_updates {
3838
extra.push_back(upd_st[idx_sk]);
3939
idx = min(idx, idx_sk), lowest_pri = pri;
4040
}
41-
auto it =
42-
remove_if(idx + all(upd_st), [&](auto& curr) {
43-
return curr.second->first >= lowest_pri;
44-
});
41+
auto it = remove_if(idx + all(upd_st), [&](auto& cur) {
42+
return cur.second->first >= lowest_pri;
43+
});
4544
reverse_copy(all(extra), it);
4645
rep(i, idx, sz(upd_st)) ds.undo();
4746
upd_st.pop_back();
@@ -53,13 +52,13 @@ template<class DS, class... ARGS> struct pq_updates {
5352
}
5453
}
5554
//! @param args arguments to DS::join
56-
//! @param priority must be distinct, can be negative
55+
//! @param pri must be distinct, can be negative
5756
//! @time O(log(n) + T(n))
5857
//! @space an new update is allocated, inserted into
5958
//! `upd_st`, `mp` member variables
60-
void push_update(ARGS... args, int priority) {
59+
void push_update(ARGS... args, int pri) {
6160
ds.join(args...);
62-
auto [it, ins] = mp.emplace(priority, sz(upd_st));
61+
auto [it, ins] = mp.emplace(pri, sz(upd_st));
6362
assert(ins);
6463
upd_st.emplace_back(make_tuple(args...), it);
6564
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ struct BIT {
2020
for (; i < sz(s); i |= i + 1) s[i] += d;
2121
}
2222
ll query(int i) {
23-
ll ret = 0;
24-
for (; i >= 0; (i &= i + 1)--) ret += s[i];
25-
return ret;
23+
ll res = 0;
24+
for (; i >= 0; (i &= i + 1)--) res += s[i];
25+
return res;
2626
}
2727
ll query(int l, int r) {
2828
return query(r) - query(l - 1);

library/dsu/line_tree.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
//! line_tree lt(n);
66
//! for (auto [w, u, v] : w_eds) lt.join(u, v);
77
//! for (int v = lt.f(0); v != -1;) {
8-
//! auto [next, e_id] = lt.edge[v];
8+
//! auto [nxt, e_id] = lt.edge[v];
99
//! int w = w_eds[e_id][0];
1010
//! //
11-
//! v = next;
11+
//! v = nxt;
1212
//! }
1313
//! @endcode
1414
//! lt.f(v) = head of linked list

library/flow/hungarian.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ pair<ll, vi> hungarian(const vector<vector<ll>>& cost) {
1818
p[0] = i;
1919
int j0 = 0;
2020
vector minv(m, LLONG_MAX);
21-
vi used(m);
21+
vi vis(m);
2222
do {
23-
used[j0] = 1;
23+
vis[j0] = 1;
2424
int i0 = p[j0], j1 = 0;
2525
ll delta = LLONG_MAX;
26-
rep(j, 1, m) if (!used[j]) {
26+
rep(j, 1, m) if (!vis[j]) {
2727
ll cur = cost[i0][j] - u[i0] - v[j];
2828
if (cur < minv[j]) minv[j] = cur, way[j] = j0;
2929
if (minv[j] < delta) delta = minv[j], j1 = j;
3030
}
3131
rep(j, 0, m) {
32-
if (used[j]) u[p[j]] += delta, v[j] -= delta;
32+
if (vis[j]) u[p[j]] += delta, v[j] -= delta;
3333
else minv[j] -= delta;
3434
}
3535
j0 = j1;

library/graphs/bcc_callback.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
//! {
55
//! vector<vi> g(n);
66
//! DSU dsu(n);
7-
//! vector<bool> seen(n);
7+
//! vector<bool> vis(n);
88
//! bcc(g, [&](const vi& nodes) {
9-
//! int count_edges = 0;
9+
//! int cnt_edges = 0;
1010
//! rep (i, 0, sz(nodes) - 1) {
11-
//! seen[nodes[i]] = 1;
12-
//! for (int u : g[nodes[i]]) if (!seen[u]) {
11+
//! vis[nodes[i]] = 1;
12+
//! for (int u : g[nodes[i]]) if (!vis[u]) {
1313
//! // edge nodes[i] <=> u is in current BCC
14-
//! count_edges++;
14+
//! cnt_edges++;
1515
//! }
1616
//! }
17-
//! if (count_edges == 1) {
17+
//! if (cnt_edges == 1) {
1818
//! // nodes[0] <=> nodes[1] is a bridge
1919
//! return;
2020
//! }

0 commit comments

Comments
 (0)