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

fixed all clippy warnings

Signed-off-by: Stefan Ellmauthaler <stefan.ellmauthaler@tu-dresden.de>
This commit is contained in:
Stefan Ellmauthaler 2021-06-30 10:42:20 +02:00
parent ee1e1bd1bf
commit bce8b87341
3 changed files with 22 additions and 16 deletions

View File

@ -15,7 +15,7 @@ impl Statement {
pub fn new(label: &str, var: usize) -> Self {
Statement {
label: String::from_str(label).unwrap(),
var: var,
var,
ac: None,
}
}
@ -32,6 +32,12 @@ pub struct Adf {
dict: HashMap<String, usize>, // label to pos in vec
}
impl Default for Adf{
fn default() -> Self {
Adf::new()
}
}
impl Adf {
pub fn new() -> Self {
Adf {
@ -48,7 +54,7 @@ impl Adf {
//self.stmts
// .push(Statement::new(statement, pos.clone()));
self.stmts
.push(Statement::new(statement, self.bdd.variable(pos).clone()));
.push(Statement::new(statement, self.bdd.variable(pos)));
self.dict.insert(self.stmts[pos].label.to_string(), pos);
}
}
@ -111,7 +117,6 @@ impl Adf {
}
}
if !change {break;}
println!("bla");
}
interpretation
}
@ -184,13 +189,13 @@ impl Adf {
}
}
pub fn findpairs<'a>(formula: &'a str) -> (&'a str,&'a str){
pub fn findpairs(formula: &str) -> (&str,&str){
let lpos = Adf::findterm(formula).unwrap();
let rpos = Adf::findterm(&formula[lpos+1..]).unwrap() + lpos;
(&formula[..lpos],&formula[lpos+1..rpos+1])
}
pub fn findterm_str<'a> (formula: &'a str) -> &'a str{
pub fn findterm_str(formula: &str) -> &str{
&formula[..Adf::findterm(formula).unwrap()]
}

View File

@ -18,24 +18,24 @@ fn main() {
let mut ac: Vec<(String,String)> = Vec::new();
let path = Path::new(args[1].as_str());
if let Ok(lines) = read_lines(path){
for resline in lines {
if let Ok(line) = resline {
for line in lines.flatten() {
//if let Ok(line) = resline {
//let slice = line.as_str();
if line.starts_with("s("){
// let slice = line.as_str();
// statements.push(Adf::findterm_str(&slice[2..]).clone());
statements.push(String::from(Adf::findterm_str(&line[2..]).replace(" ", "")));
statements.push(Adf::findterm_str(line.strip_prefix("s(").unwrap()).replace(" ", ""));
}
else if line.starts_with("ac("){
let (s,c) = Adf::findpairs(&line[3..]);
ac.push((String::from(s.replace(" ","")),String::from(c.replace(" ", ""))));
let (s,c) = Adf::findpairs(line.strip_prefix("ac(").unwrap());
ac.push((s.replace(" ",""),c.replace(" ", "")));
}
}
//}
}
}
println!("parsed {} statements", statements.len());
if statements.len() > 0 && ac.len() > 0 {
if !statements.is_empty() && !ac.is_empty() {
let mut my_adf = Adf::new();
my_adf.init_statements(statements.iter().map(AsRef::as_ref).collect());
for (s,c) in ac {

View File

@ -54,9 +54,9 @@ impl Bdd {
lo
} else {
let node = BddNode {
var: var,
lo: lo,
hi: hi,
var,
lo,
hi,
};
match self.hash.get(&node) {
Some(n) => *n,
@ -65,7 +65,7 @@ impl Bdd {
if newid == usize::MAX {
panic!("Maximal amount of elements in node-table reached!")
}
self.nodes.push(node.clone());
self.nodes.push(node);
self.hash.insert(node, newid);
newid
}
@ -87,6 +87,7 @@ impl Bdd {
pub fn restrict(&mut self, subtree: Term, var: usize, val: bool) -> Term {
let treenode = self.nodes[subtree];
#[allow(clippy::clippy::collapsible_else_if)] // Better readabilty of the if/then/else structure of the algorithm
if treenode.var > var || treenode.var == usize::MAX {
subtree
} else if treenode.var < var {