diff --git a/src/main.rs b/src/main.rs index 24e6373..7afc2e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,11 +15,11 @@ fn main() -> std::io::Result<()> { examples::freq()?; - // examples::hoop()?; + examples::hoop()?; - // examples::target()?; + examples::target()?; - // examples::run()?; + examples::run()?; Ok(()) } diff --git a/src/rsprocess/frequency.rs b/src/rsprocess/frequency.rs index 8d4f98a..17aa617 100644 --- a/src/rsprocess/frequency.rs +++ b/src/rsprocess/frequency.rs @@ -28,6 +28,10 @@ impl Frequency { for &el in e.iter() { self.frequency_map.entry(el).or_insert(vec![0; run + 1])[run] += 1 } + // TODO resize clones all prev values, replace with in place method + if self.totals.len() < run + 1 { + self.totals.resize(run + 1, 0); + } self.totals[run] += 1 } diff --git a/src/rsprocess/grammar.lalrpop b/src/rsprocess/grammar.lalrpop index 2901a1c..2967963 100644 --- a/src/rsprocess/grammar.lalrpop +++ b/src/rsprocess/grammar.lalrpop @@ -95,7 +95,7 @@ CTX_process: RSprocess = { RSprocess::WaitEntity{ repeat: n, repeated_process: Rc::new(k1), next_process: Rc::new(k) }, - "nil" => RSprocess::Nill, + "nill" => RSprocess::Nill, => RSprocess::RecursiveIdentifier{ identifier: translator.encode(identifier) diff --git a/src/rsprocess/structure.rs b/src/rsprocess/structure.rs index 3f1b69c..f041812 100644 --- a/src/rsprocess/structure.rs +++ b/src/rsprocess/structure.rs @@ -186,7 +186,7 @@ impl Default for RSreaction { pub enum RSprocess { Nill, RecursiveIdentifier { - identifier: IdType, + identifier: IdType, }, EntitySet { entities: RSset, diff --git a/src/rsprocess/transitions.rs b/src/rsprocess/transitions.rs index 6bc7378..93fc192 100644 --- a/src/rsprocess/transitions.rs +++ b/src/rsprocess/transitions.rs @@ -147,6 +147,7 @@ pub fn run_separated( let current = current.unwrap(); res.push(current.0.get_context()); let mut current = current.1; + while let Some((label, next)) = one_transition(¤t)? { current = next; res.push(label.get_context()); diff --git a/src/rsprocess/translator.rs b/src/rsprocess/translator.rs index 82520b6..5b0f82f 100644 --- a/src/rsprocess/translator.rs +++ b/src/rsprocess/translator.rs @@ -37,12 +37,10 @@ impl Translator { id } - pub fn decode(&self, el: IdType) -> String { - // TODO maybe find more efficient method?? + pub fn decode(&self, el: IdType) -> Option { self.reverse .get(&el) .map(|x| x.to_string()) - .unwrap_or(String::from("Not Found")) } } @@ -161,9 +159,13 @@ fn print_set( let mut it = set.iter().peekable(); while let Some(el) = it.next() { if it.peek().is_none() { - write!(f, "{}", translator.decode(*el))?; + write!(f, + "{}", + translator.decode(*el).unwrap_or("Missing".into()))?; } else { - write!(f, "{}, ", translator.decode(*el))?; + write!(f, + "{}, ", + translator.decode(*el).unwrap_or("Missing".into()))?; } } write!(f, "}}") @@ -194,7 +196,9 @@ fn print_process( write!(f, "[Nill]") } RecursiveIdentifier { identifier } => { - write!(f, "[{}]", translator.decode(*identifier)) + write!(f, + "[{}]", + translator.decode(*identifier).unwrap_or("Missing".into())) } EntitySet { entities, @@ -301,14 +305,14 @@ fn print_environment( write!( f, "({} -> {})", - translator.decode(*el.0), + translator.decode(*el.0).unwrap_or("Missing".into()), WithTranslator::from_RSprocess(translator, el.1) )?; } else { write!( f, "({} -> {}), ", - translator.decode(*el.0), + translator.decode(*el.0).unwrap_or("Missing".into()), WithTranslator::from_RSprocess(translator, el.1) )?; } @@ -407,7 +411,7 @@ fn print_frequency( let mut freq_it = frequency.frequency_map.iter().peekable(); while let Some((e, freq)) = freq_it.next() { - write!(f, "{} -> ", translator.decode(*e))?; + write!(f, "{} -> ", translator.decode(*e).unwrap_or("Missing".into()))?; let mut iter = freq .iter()