diff --git a/src/rsprocess/confluence.rs b/src/rsprocess/confluence.rs index 2c3b4c6..cd70278 100644 --- a/src/rsprocess/confluence.rs +++ b/src/rsprocess/confluence.rs @@ -11,6 +11,7 @@ use super::perpetual::{ use super::structure::{RSenvironment, RSreaction, RSset}; use super::translator::IdType; use std::cmp; +use std::collections::HashSet; // see confluent, confluents @@ -101,5 +102,46 @@ pub fn invariant_named( } invariant.append(&mut new_prefix.clone()); } + // remove duplicates, maybe better with sorting? + invariant = + invariant + .iter() + .cloned() + .collect::>() + .iter() + .cloned() + .collect::>(); Some((invariant, hoop)) } + +// ----------------------------------------------------------------------------- + +pub fn loop_confluent_named( + deltas: &[RSenvironment], + reaction_rules: &[RSreaction], + entities: &[RSset], + symb: IdType +) -> Option)>> { + deltas.iter() + .map(|q| confluent_named(q, reaction_rules, entities, symb)) + .collect::>>() +} + +#[allow(clippy::type_complexity)] +pub fn strong_confluent_named( + deltas: &[RSenvironment], + reaction_rules: &[RSreaction], + entities: &[RSset], + symb: IdType +) -> Option, usize, Vec)>> { + deltas.iter() + .map(|q| { + let (invariant, hoop) = invariant_named(q, + reaction_rules, + entities, + symb)?; + let length = invariant.len(); + Some((invariant, length, hoop)) } + ) + .collect::>>() +} diff --git a/src/rsprocess/structure.rs b/src/rsprocess/structure.rs index 018ef79..d5ceb2e 100644 --- a/src/rsprocess/structure.rs +++ b/src/rsprocess/structure.rs @@ -1,6 +1,7 @@ #![allow(dead_code)] use std::collections::{HashMap, HashSet}; +use std::hash::{Hash, Hasher}; use std::rc::Rc; use super::translator::{IdType}; @@ -79,6 +80,16 @@ impl RSset { } } +impl Hash for RSset { + fn hash(&self, state: &mut H) { + let mut a: Vec<&_> = self.identifiers.iter().collect(); + a.sort(); + for s in a.iter() { + s.hash(state); + } + } + +} // ----------------------------------------------------------------------------- // RSreaction