mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-21 09:26:43 +00:00
fix(segment): place cancellation tests after items
This commit is contained in:
1 parent
5a86877b68
commit
830cb65d48
1 file changed
+36
-36
@@ -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<Self::Item> {
|
||||
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<Self::Item> {
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user