From 830cb65d480e9f00a67d8f01eeca90a189d09660 Mon Sep 17 00:00:00 2001 From: Khawar Zamman Wani Date: Wed, 28 Oct 2026 19:53:59 +0530 Subject: [PATCH] fix(segment): place cancellation tests after items --- crates/algo/src/segment/maxflow.rs | 72 +++++++++++++++--------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/crates/algo/src/segment/maxflow.rs b/crates/algo/src/segment/maxflow.rs index 004559497d..d2041bd924 100644 --- a/crates/algo/src/segment/maxflow.rs +++ b/crates/algo/src/segment/maxflow.rs @@ -384,6 +384,42 @@ impl Graph { } } +struct ArcIter<'a> { + g: &'a Graph, + a: u32, +} + +impl Iterator for ArcIter<'_> { + /// `(neighbour, residual capacity out, residual capacity in)`. + type Item = (usize, f32, f32); + fn next(&mut self) -> Option { + if self.a == NONE { + return None; + } + let a = self.a as usize; + self.a = self.g.next[a]; + Some((self.g.head[a] as usize, self.g.r_cap[a], self.g.r_cap[a ^ 1])) + } +} + +impl Graph { + /// Sum of residual capacities on arcs leaving the source side of the cut (zero after + /// [`Graph::maxflow`]: no augmenting path remains). + pub fn residual_out_of_source_side(&self) -> f32 { + let mut s = 0.0; + for i in 0..self.node_count() { + if self.in_source(i) { + for (j, out, _) in self.arcs(i) { + if !self.in_source(j) { + s += out; + } + } + } + } + s + } +} + #[cfg(test)] mod cancellation_tests { use super::{CANCEL_EVERY, Graph}; @@ -428,39 +464,3 @@ mod cancellation_tests { assert_eq!(calls.get(), 2); } } - -struct ArcIter<'a> { - g: &'a Graph, - a: u32, -} - -impl Iterator for ArcIter<'_> { - /// `(neighbour, residual capacity out, residual capacity in)`. - type Item = (usize, f32, f32); - fn next(&mut self) -> Option { - if self.a == NONE { - return None; - } - let a = self.a as usize; - self.a = self.g.next[a]; - Some((self.g.head[a] as usize, self.g.r_cap[a], self.g.r_cap[a ^ 1])) - } -} - -impl Graph { - /// Sum of residual capacities on arcs leaving the source side of the cut (zero after - /// [`Graph::maxflow`]: no augmenting path remains). - pub fn residual_out_of_source_side(&self) -> f32 { - let mut s = 0.0; - for i in 0..self.node_count() { - if self.in_source(i) { - for (j, out, _) in self.arcs(i) { - if !self.in_source(j) { - s += out; - } - } - } - } - s - } -}