Fixing Freq, now main functions
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -186,7 +186,7 @@ impl Default for RSreaction {
|
||||
pub enum RSprocess {
|
||||
Nill,
|
||||
RecursiveIdentifier {
|
||||
identifier: IdType,
|
||||
identifier: IdType,
|
||||
},
|
||||
EntitySet {
|
||||
entities: RSset,
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user