1
0
mirror of https://github.com/ellmau/adf-obdd.git synced 2025-12-19 09:29:36 +01:00

added ac to stmt relation

Signed-off-by: Stefan Ellmauthaler <stefan.ellmauthaler@tu-dresden.de>
This commit is contained in:
Stefan Ellmauthaler 2021-06-23 17:00:42 +02:00
parent 40ea81b417
commit 35918ce36e

View File

@ -1,6 +1,7 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
num::ParseFloatError, num::ParseFloatError,
ops::Deref,
str::{self, FromStr}, str::{self, FromStr},
}; };
@ -50,6 +51,25 @@ impl Adf {
} }
} }
pub fn init_statements(&mut self, stmts: Vec<&str>) -> usize {
for i in stmts.iter() {
self.add_statement(*i);
}
self.stmts.len()
}
pub fn add_ac(&mut self, statement: &str, ac: &str) {
if let Some(stmt) = self.dict.get(statement) {
let stm = *stmt;
let ac_nmbr = self.parseformula(ac);
self.set_ac(stm, ac_nmbr)
}
}
fn set_ac(&mut self, st: usize, ac: usize) {
self.stmts[st].ac = Some(ac);
}
fn parseformula(&mut self, ac: &str) -> usize { fn parseformula(&mut self, ac: &str) -> usize {
if let Some(split) = ac.find(',') { if let Some(split) = ac.find(',') {
let (l, r) = ac.split_at(split); let (l, r) = ac.split_at(split);
@ -138,4 +158,14 @@ mod test {
adf.parseformula("and(a,or(b,d))"); adf.parseformula("and(a,or(b,d))");
} }
#[test]
fn init_statements() {
let mut adf = Adf::new();
let stmts: Vec<&str> = vec!["a", "b", "c", "extra long text type statement"];
assert_eq!(adf.init_statements(stmts), 4);
assert_eq!(adf.stmts[3].label, "extra long text type statement");
}
} }