Skip to content

Commit

Permalink
feat: get number of collisions from soup
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentElement committed Sep 26, 2024
1 parent ca3f38e commit 2608cd0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/soup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rand_chacha::ChaCha8Rng;
#[derive(Debug, Clone)]
pub struct Soup {
expressions: Vec<Term>,
n_collisions: usize,
reaction_rules: Vec<Term>,
reduction_limit: usize,
size_limit: usize,
Expand Down Expand Up @@ -106,6 +107,7 @@ impl Soup {
discard_identity: cfg.discard_identity,
discard_free_variable_expressions: cfg.discard_free_variable_expressions,
rng,
n_collisions: 0,
}
}

Expand Down Expand Up @@ -146,6 +148,7 @@ impl Soup {
return Err(ReactionError::HasFreeVariables);
}


Ok((expr, n))
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -353,6 +357,10 @@ impl Soup {
pub fn len(&self) -> usize {
self.expressions.len()
}

pub fn collisions(&self) -> usize {
self.n_collisions
}
}

impl Tape {
Expand Down

0 comments on commit 2608cd0

Please sign in to comment.