From 749ea72cfe0d8e373c3af25654201b1366f6572b Mon Sep 17 00:00:00 2001 From: William Ball Date: Tue, 20 Jul 2021 10:59:28 -0400 Subject: [PATCH] new stopping condition --- .../circle_counting_new/src/lib.rs | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fractal_dimension/circle_counting_new/src/lib.rs b/fractal_dimension/circle_counting_new/src/lib.rs index d36b5db..802a7a2 100644 --- a/fractal_dimension/circle_counting_new/src/lib.rs +++ b/fractal_dimension/circle_counting_new/src/lib.rs @@ -13,12 +13,11 @@ pub fn fractal_dimension( orthogonal_generators: Vec>, ) -> Result { let mut totals = vec![root.len(); n]; - let mut current = vec![(root, std::usize::MAX, false)]; + let mut current = vec![(root, std::usize::MAX)]; let mut next = vec![]; let mut nodes: u64 = 1; let xs: Vec = (1..=n) - // .map(|x| (x as f64 * upper_bound / (n as f64))) .map(|x| (x as f64 * upper_bound / (2.0 * n as f64) + upper_bound / 2.0)) .collect(); @@ -26,7 +25,9 @@ pub fn fractal_dimension( loop { next.clear(); - for (tuple, previous_generator, bad) in ¤t { + for (tuple, previous_generator) in ¤t { + let mut add_children = false; + let mut children = vec![]; for (i, generator) in generators.iter().enumerate() { let mut skip = false; for orthogonal_pairs in &orthogonal_generators { @@ -63,16 +64,19 @@ pub fn fractal_dimension( } } if add { - next.push((new_tuple, i, false)); - nodes += 1; + add_children = true; + children.push((new_tuple, i)); } else { - if !bad { - next.push((new_tuple, i, true)); - nodes += 1; - } + children.push((new_tuple, i)); } } } + if add_children { + nodes += 1; + for child in children { + next.push(child); + } + } } std::mem::swap(&mut current, &mut next);