Fixing Freq, now main functions

This commit is contained in:
elvis
2025-07-02 07:30:05 +02:00
parent eba5d1266d
commit 2e16e2b002
6 changed files with 23 additions and 14 deletions

View File

@ -15,11 +15,11 @@ fn main() -> std::io::Result<()> {
examples::freq()?;
// examples::hoop()?;
examples::hoop()?;
// examples::target()?;
examples::target()?;
// examples::run()?;
examples::run()?;
Ok(())
}

View File

@ -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
}

View File

@ -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,
<identifier: Literal> =>
RSprocess::RecursiveIdentifier{
identifier: translator.encode(identifier)

View File

@ -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(&current)? {
current = next;
res.push(label.get_context());

View File

@ -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<String> {
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()