Skip to content

Commit 3b77fdc

Browse files
refactor: improve API name consistency (#49)
1 parent 6de3e5c commit 3b77fdc

22 files changed

+51
-51
lines changed

src/1-ds/ds_segtree.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ struct seg_2d { // 1-indexed
235235

236236
// what: 2D segment tree with coordinate compression for sparse updates/queries.
237237
// time: prep O(q log q), update/query O(log^2 n); memory: O(q log q)
238-
// constraint: x is 1-indexed [1..n]; y is coordinate value; call mark_set/mark_qry first, then prep, then set/query.
239-
// usage: seg2d_comp st(n); st.mark_set(x, y); st.mark_qry(x1, x2, y1, y2); st.prep(); st.set(x, y, v); st.query(x1, x2, y1, y2);
238+
// constraint: x is 1-indexed [1..n]; y is coordinate value; call mark_set/mark_query first, then prep, then set/query.
239+
// usage: seg2d_comp st(n); st.mark_set(x, y); st.mark_query(x1, x2, y1, y2); st.prep(); st.set(x, y, v); st.query(x1, x2, y1, y2);
240240
struct seg2d_comp { // x: 1-indexed
241241
int n;
242242
vector<vector<ll>> a;
@@ -247,7 +247,7 @@ struct seg2d_comp { // x: 1-indexed
247247
// goal: record y-coordinates that will be updated.
248248
for (x += n - 1; x >= 1; x >>= 1) used[x].push_back(y);
249249
}
250-
void mark_qry(int x1, int x2, int y1, int y2) {
250+
void mark_query(int x1, int x2, int y1, int y2) {
251251
// goal: record y-coordinates needed for queries.
252252
for (x1 += n - 1, x2 += n; x1 < x2; x1 >>= 1, x2 >>= 1) {
253253
if (x1 & 1) {

src/2-graph/cc_bcc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// what: find biconnected components and articulation points/bridges in an undirected graph.
44
// time: O(n+m); memory: O(n+m)
55
// constraint: 1-indexed; no self-loops; recursion depth O(n).
6-
// usage: bcc_graph g; g.init(n); g.add(u,v); g.run(); // g.bccs, g.ap, g.ae
6+
// usage: bcc_graph g; g.init(n); g.add_edge(u,v); g.run(); // g.bccs, g.ap, g.ae
77
struct bcc_graph {
88
int n, tim;
99
vector<vector<pii>> adj;
@@ -23,7 +23,7 @@ struct bcc_graph {
2323
ed.clear();
2424
bccs.clear();
2525
}
26-
void add(int u, int v) {
26+
void add_edge(int u, int v) {
2727
int id = sz(ed);
2828
ed.push_back({u, v});
2929
adj[u].push_back({v, id});

src/2-graph/cc_scc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// what: compute SCCs in a directed graph using Kosaraju's algorithm.
44
// time: O(n+m); memory: O(n+m)
55
// constraint: directed; 1-indexed; recursion depth O(n).
6-
// usage: scc_kosa s; s.init(n); s.add(u,v); int c=s.run();
6+
// usage: scc_kosa s; s.init(n); s.add_edge(u,v); int c=s.run();
77
struct scc_kosa {
88
int n;
99
vector<vector<int>> g, rg, sccs;
@@ -18,7 +18,7 @@ struct scc_kosa {
1818
comp.assign(n + 1, -1);
1919
ord.clear();
2020
}
21-
void add(int u, int v) {
21+
void add_edge(int u, int v) {
2222
g[u].push_back(v);
2323
rg[v].push_back(u);
2424
}
@@ -50,7 +50,7 @@ struct scc_kosa {
5050
// what: compute SCCs in a directed graph using Tarjan's algorithm.
5151
// time: O(n+m); memory: O(n+m)
5252
// constraint: directed; 1-indexed; recursion depth O(n).
53-
// usage: scc_tarjan s; s.init(n); s.add(u,v); int c=s.run();
53+
// usage: scc_tarjan s; s.init(n); s.add_edge(u,v); int c=s.run();
5454
struct scc_tarjan {
5555
int n, tim;
5656
vector<vector<int>> g, sccs;
@@ -67,7 +67,7 @@ struct scc_tarjan {
6767
ins.assign(n + 1, 0);
6868
st.clear();
6969
}
70-
void add(int u, int v) { g[u].push_back(v); }
70+
void add_edge(int u, int v) { g[u].push_back(v); }
7171
void dfs(int v) {
7272
dfn[v] = low[v] = ++tim;
7373
st.push_back(v);

src/2-graph/euler_circ.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// what: build an Eulerian circuit in an undirected multigraph (adjacency matrix).
44
// time: O(n^2+m); memory: O(n^2)
55
// constraint: 1-indexed; all nonzero-degree nodes connected.
6-
// usage: euler_cir g; g.init(n); g.add(u,v); if (g.can()) auto path=g.run(1);
6+
// usage: euler_cir g; g.init(n); g.add_edge(u,v); if (g.can()) auto path=g.run(1);
77
struct euler_cir {
88
int n;
99
vector<vector<int>> adj;
@@ -16,7 +16,7 @@ struct euler_cir {
1616
nxt.assign(n + 1, 1);
1717
path.clear();
1818
}
19-
void add(int u, int v, int c = 1) {
19+
void add_edge(int u, int v, int c = 1) {
2020
// goal: add c parallel edges between u and v.
2121
if (u == v) adj[u][u] += 2 * c;
2222
else adj[u][v] += c, adj[v][u] += c;

src/2-graph/sp_basic.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// what: compute single-source shortest paths with non-negative edges (Dijkstra).
44
// time: O((n+m)log n); memory: O(n+m)
55
// constraint: directed; 1-indexed; w >= 0.
6-
// usage: dijkstra g; g.init(n); g.add(u,v,w); auto dist=g.run(s);
6+
// usage: dijkstra g; g.init(n); g.add_edge(u,v,w); auto dist=g.run(s);
77
struct dijkstra {
88
static const ll INF = (1LL << 62);
99
int n;
@@ -14,7 +14,7 @@ struct dijkstra {
1414
n = n_;
1515
adj.assign(n + 1, {});
1616
}
17-
void add(int u, int v, ll w) { adj[u].push_back({w, v}); }
17+
void add_edge(int u, int v, ll w) { adj[u].push_back({w, v}); }
1818
vector<ll> run(int s) {
1919
// result: dist[i] = shortest distance from s to i.
2020
vector<ll> dist(n + 1, INF);
@@ -39,7 +39,7 @@ struct dijkstra {
3939
// what: compute single-source shortest paths with possible negative edges.
4040
// time: O(nm); memory: O(n+m)
4141
// constraint: directed; 1-indexed; detects negative cycle reachable from s.
42-
// usage: bell_ford g; g.init(n); g.add(u,v,w); bool ok=g.run(s, dist);
42+
// usage: bell_ford g; g.init(n); g.add_edge(u,v,w); bool ok=g.run(s, dist);
4343
struct bell_ford {
4444
static const ll INF = (1LL << 62);
4545
int n;
@@ -50,7 +50,7 @@ struct bell_ford {
5050
n = n_;
5151
ed.clear();
5252
}
53-
void add(int u, int v, ll w) { ed.push_back({u, v, w}); }
53+
void add_edge(int u, int v, ll w) { ed.push_back({u, v, w}); }
5454
bool run(int s, vector<ll> &dist) {
5555
// result: false if a negative cycle is reachable.
5656
dist.assign(n + 1, INF);
@@ -74,7 +74,7 @@ struct bell_ford {
7474
// what: compute all-pairs shortest paths with dynamic programming.
7575
// time: O(n^3); memory: O(n^2)
7676
// constraint: directed; 1-indexed; watch overflow on INF.
77-
// usage: floyd g; g.init(n); g.add(u,v,w); g.run(); auto &d=g.d;
77+
// usage: floyd g; g.init(n); g.add_edge(u,v,w); g.run(); auto &d=g.d;
7878
struct floyd {
7979
static const ll INF = (1LL << 62);
8080
int n;
@@ -86,7 +86,7 @@ struct floyd {
8686
d.assign(n + 1, vector<ll>(n + 1, INF));
8787
for (int i = 1; i <= n; i++) d[i][i] = 0;
8888
}
89-
void add(int u, int v, ll w) { d[u][v] = min(d[u][v], w); }
89+
void add_edge(int u, int v, ll w) { d[u][v] = min(d[u][v], w); }
9090
void run() {
9191
// goal: relax all pairs via intermediate nodes.
9292
for (int k = 1; k <= n; k++) {

src/2-graph/sp_kth.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// what: enumerate k-th shortest walk from s to t with non-negative weights (Eppstein-style).
44
// time: O((n+m)log m + klog k); memory: O(n+m+heap)
55
// constraint: 1-indexed; w >= 0; n <= MAXN-1; recursion depth O(log m).
6-
// usage: kth_walk g; g.init(n); g.add(u,v,w); auto v=g.run(s,e,k);
6+
// usage: kth_walk g; g.init(n); g.add_edge(u,v,w); auto v=g.run(s,e,k);
77
struct kth_walk {
88
static const int MAXN = 303030;
99
static const ll INF = (ll)1e18;
@@ -42,7 +42,7 @@ struct kth_walk {
4242
for (int i = 1; i <= n; i++) g[i].clear(), rg[i].clear();
4343
hp.init();
4444
}
45-
void add(int u, int v, ll w) {
45+
void add_edge(int u, int v, ll w) {
4646
g[u].push_back({w, v});
4747
rg[v].push_back({w, u});
4848
}

src/3-tree/lca_sparse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// what: LCA via binary lifting for rooted tree.
44
// time: build O(n log n), query O(log n); memory: O(n log n)
55
// constraint: 1-indexed tree.
6-
// usage: lca_sparse l; l.init(n); l.add(u,v); l.build(1); int w=l.lca(u,v);
6+
// usage: lca_sparse l; l.init(n); l.add_edge(u,v); l.build(1); int w=l.lca(u,v);
77
struct lca_sparse {
88
int n, lg;
99
vector<vector<int>> adj, up;
@@ -17,7 +17,7 @@ struct lca_sparse {
1717
up.assign(lg, vector<int>(n + 1, 0));
1818
dep.assign(n + 1, 0);
1919
}
20-
void add(int u, int v) {
20+
void add_edge(int u, int v) {
2121
adj[u].push_back(v);
2222
adj[v].push_back(u);
2323
}

src/3-tree/tree_centroid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// what: centroid decomposition for tree, builds centroid parent/children for path queries.
44
// time: O(n log n); memory: O(n)
55
// constraint: 1-indexed tree.
6-
// usage: cen_decomp cd; cd.init(n); cd.add(u,v); cd.build(); int p=cd.par[v];
6+
// usage: cen_decomp cd; cd.init(n); cd.add_edge(u,v); cd.build(); int p=cd.par[v];
77
struct cen_decomp {
88
int n;
99
vector<vector<int>> adj, chd;
@@ -18,7 +18,7 @@ struct cen_decomp {
1818
siz.assign(n + 1, 0);
1919
used.assign(n + 1, 0);
2020
}
21-
void add(int u, int v) {
21+
void add_edge(int u, int v) {
2222
adj[u].push_back(v);
2323
adj[v].push_back(u);
2424
}

src/3-tree/tree_hld.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// what: heavy-light decomposition for path sum on tree (node values).
44
// time: build O(n), update/query O(log^2 n); memory: O(n)
55
// constraint: 1-indexed tree.
6-
// usage: hld_tree h; h.init(n); h.add(u,v); h.build(1); h.set(v,x); ll s=h.qry(u,v);
6+
// usage: hld_tree h; h.init(n); h.add_edge(u,v); h.build(1); h.set(v,x); ll s=h.query(u,v);
77
struct hld_tree {
88
seg_tree seg;
99

@@ -22,7 +22,7 @@ struct hld_tree {
2222
top.assign(n + 1, 0);
2323
in.assign(n + 1, 0);
2424
}
25-
void add(int u, int v) {
25+
void add_edge(int u, int v) {
2626
adj[u].push_back(v);
2727
adj[v].push_back(u);
2828
}
@@ -55,7 +55,7 @@ struct hld_tree {
5555
seg.build(a);
5656
}
5757
void set(int v, ll val) { seg.set(in[v], val); }
58-
ll qry(int a, int b) const {
58+
ll query(int a, int b) const {
5959
ll ret = 0;
6060
while (top[a] != top[b]) {
6161
if (dep[top[a]] < dep[top[b]]) swap(a, b);

src/3-tree/tree_vtree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// what: virtual tree builder for subset DP using LCA and dfs order.
44
// time: build O(n log n), make O(k log k); memory: O(n log n)
55
// constraint: 1-indexed tree.
6-
// usage: tree_comp tc; tc.init(n); tc.add(u,v); tc.build(root); auto nodes=tc.make(vs); // use tc.vt_adj
6+
// usage: tree_comp tc; tc.init(n); tc.add_edge(u,v); tc.build(root); auto nodes=tc.make(vs); // use tc.vt_adj
77
struct tree_comp {
88
int n, lg, tim;
99
vector<vector<int>> adj, up, vt_adj;
@@ -21,7 +21,7 @@ struct tree_comp {
2121
dep.assign(n + 1, 0);
2222
tim = 0;
2323
}
24-
void add(int u, int v) {
24+
void add_edge(int u, int v) {
2525
adj[u].push_back(v);
2626
adj[v].push_back(u);
2727
}

0 commit comments

Comments
 (0)