From f7e01a0da303e3842fb17d6d4483fb3984c07f95 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 17 Jul 2026 15:40:44 +0000 Subject: [PATCH] fmt: rustfmt arigraph/community.rs (unblocks main CI after #714) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #714 (feat(arigraph): community.rs, D-GR-3a) merged without `cargo fmt`, so `cargo fmt --manifest-path crates/lance-graph/Cargo.toml -- --check` fails on main and blocks CI on every subsequent PR. Pure formatting — zero semantic change (block-body vs single-line closures, struct-literal wrapping, test tuple wrapping). Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01Awg6TXocHcwTtc6eGsHcdD --- .../src/graph/arigraph/community.rs | 82 ++++++++++++++----- 1 file changed, 61 insertions(+), 21 deletions(-) diff --git a/crates/lance-graph/src/graph/arigraph/community.rs b/crates/lance-graph/src/graph/arigraph/community.rs index 527701b7..57afb278 100644 --- a/crates/lance-graph/src/graph/arigraph/community.rs +++ b/crates/lance-graph/src/graph/arigraph/community.rs @@ -75,7 +75,13 @@ impl Communities { self.entities .iter() .zip(self.labels.iter()) - .filter_map(|(e, &c)| if c == community { Some(e.as_str()) } else { None }) + .filter_map(|(e, &c)| { + if c == community { + Some(e.as_str()) + } else { + None + } + }) .collect() } } @@ -111,7 +117,13 @@ impl TripletGraph { s.dedup(); s.len() }; - Communities { entities, labels, levels, modularity: q, num_communities } + Communities { + entities, + labels, + levels, + modularity: q, + num_communities, + } } /// Dense entity index: a stable `Vec` (sorted for determinism) and @@ -119,19 +131,18 @@ impl TripletGraph { fn entity_index_dense(&self) -> (Vec, HashMap) { let mut names: Vec = self.entity_index.keys().cloned().collect(); names.sort_unstable(); - let index: HashMap = - names.iter().enumerate().map(|(i, e)| (e.clone(), i)).collect(); + let index: HashMap = names + .iter() + .enumerate() + .map(|(i, e)| (e.clone(), i)) + .collect(); (names, index) } /// Weighted undirected adjacency (both endpoints), weight = summed NARS /// confidence over the triplets joining two entities. Deleted triplets and /// self-loops are skipped. - fn build_adjacency( - &self, - index: &HashMap, - n: usize, - ) -> Vec> { + fn build_adjacency(&self, index: &HashMap, n: usize) -> Vec> { // Accumulate undirected weights in a per-node BTreeMap for determinism. let mut acc: Vec> = vec![BTreeMap::new(); n]; for t in &self.triplets { @@ -176,7 +187,12 @@ fn build(adj: Vec>, self_loop: Vec) -> WGraph { degree[u] = d + 2.0 * self_loop[u]; } let two_m: f64 = degree.iter().sum(); - WGraph { adj, self_loop, degree, two_m } + WGraph { + adj, + self_loop, + degree, + two_m, + } } /// First-appearance dense relabel — deterministic given node order. @@ -267,8 +283,10 @@ fn aggregate(g: &WGraph, label: &[usize]) -> WGraph { } } } - let adj: Vec> = - super_adj.into_iter().map(|m| m.into_iter().collect()).collect(); + let adj: Vec> = super_adj + .into_iter() + .map(|m| m.into_iter().collect()) + .collect(); build(adj, self_w) } @@ -298,10 +316,7 @@ fn modularity(g: &WGraph, label: &[usize]) -> f64 { /// Multi-level Louvain. Returns (hierarchy over ORIGINAL nodes, coarsest /// labels, `Q` of the coarsest partition on the original graph). -fn detect( - adj0: Vec>, - self0: Vec, -) -> (Vec>, Vec, f64) { +fn detect(adj0: Vec>, self0: Vec) -> (Vec>, Vec, f64) { let n0 = adj0.len(); let g0 = build(adj0.clone(), self0.clone()); let mut g = build(adj0, self0); @@ -345,8 +360,12 @@ mod tests { fn two_triangles_bridge_yields_two_communities() { // {a,b,c} triangle, {d,e,f} triangle, single a-d bridge. let g = tg(&[ - ("a", "b"), ("b", "c"), ("c", "a"), - ("d", "e"), ("e", "f"), ("f", "d"), + ("a", "b"), + ("b", "c"), + ("c", "a"), + ("d", "e"), + ("e", "f"), + ("f", "d"), ("a", "d"), ]); let c = g.communities(); @@ -360,13 +379,28 @@ mod tests { #[test] fn deterministic() { - let g = tg(&[("a", "b"), ("b", "c"), ("c", "a"), ("d", "e"), ("e", "f"), ("f", "d"), ("a", "d")]); + let g = tg(&[ + ("a", "b"), + ("b", "c"), + ("c", "a"), + ("d", "e"), + ("e", "f"), + ("f", "d"), + ("a", "d"), + ]); assert_eq!(g.communities().labels, g.communities().labels); } #[test] fn clique_is_one_community() { - let g = tg(&[("a", "b"), ("a", "c"), ("a", "d"), ("b", "c"), ("b", "d"), ("c", "d")]); + let g = tg(&[ + ("a", "b"), + ("a", "c"), + ("a", "d"), + ("b", "c"), + ("b", "d"), + ("c", "d"), + ]); assert_eq!(g.communities().num_communities, 1); } @@ -385,7 +419,13 @@ mod tests { Triplet::new("a", "b", "rel", 0), Triplet::new("b", "c", "rel", 1), Triplet::new("c", "a", "rel", 2), - Triplet::with_truth("c", "d", "rel", crate::graph::spo::truth::TruthValue::new(1.0, 0.05), 3), + Triplet::with_truth( + "c", + "d", + "rel", + crate::graph::spo::truth::TruthValue::new(1.0, 0.05), + 3, + ), ]; g.add_triplets(&ts); let c = g.communities();