From 2608cd059666cbc3a720bdb9680fbfda71dd2fe7 Mon Sep 17 00:00:00 2001 From: agentelement Date: Thu, 26 Sep 2024 13:37:36 -0700 Subject: [PATCH] feat: get number of collisions from soup --- src/soup.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/soup.rs b/src/soup.rs index 3ef7102..020517a 100644 --- a/src/soup.rs +++ b/src/soup.rs @@ -11,6 +11,7 @@ use rand_chacha::ChaCha8Rng; #[derive(Debug, Clone)] pub struct Soup { expressions: Vec, + n_collisions: usize, reaction_rules: Vec, reduction_limit: usize, size_limit: usize, @@ -106,6 +107,7 @@ impl Soup { discard_identity: cfg.discard_identity, discard_free_variable_expressions: cfg.discard_free_variable_expressions, rng, + n_collisions: 0, } } @@ -146,6 +148,7 @@ impl Soup { return Err(ReactionError::HasFreeVariables); } + Ok((expr, n)) } @@ -175,6 +178,7 @@ impl Soup { let mut n_successful_reactions = 0; for rule in &self.reaction_rules { let result = self.collide(rule.clone(), left.clone(), right.clone()); + self.n_collisions += 1; match result { Ok((value, n)) => { let datum = CollisionResult { @@ -353,6 +357,10 @@ impl Soup { pub fn len(&self) -> usize { self.expressions.len() } + + pub fn collisions(&self) -> usize { + self.n_collisions + } } impl Tape {