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:
parent
ee1e1bd1bf
commit
bce8b87341
15
src/adf.rs
15
src/adf.rs
@ -15,7 +15,7 @@ impl Statement {
|
|||||||
pub fn new(label: &str, var: usize) -> Self {
|
pub fn new(label: &str, var: usize) -> Self {
|
||||||
Statement {
|
Statement {
|
||||||
label: String::from_str(label).unwrap(),
|
label: String::from_str(label).unwrap(),
|
||||||
var: var,
|
var,
|
||||||
ac: None,
|
ac: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,6 +32,12 @@ pub struct Adf {
|
|||||||
dict: HashMap<String, usize>, // label to pos in vec
|
dict: HashMap<String, usize>, // label to pos in vec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Adf{
|
||||||
|
fn default() -> Self {
|
||||||
|
Adf::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Adf {
|
impl Adf {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Adf {
|
Adf {
|
||||||
@ -48,7 +54,7 @@ impl Adf {
|
|||||||
//self.stmts
|
//self.stmts
|
||||||
// .push(Statement::new(statement, pos.clone()));
|
// .push(Statement::new(statement, pos.clone()));
|
||||||
self.stmts
|
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);
|
self.dict.insert(self.stmts[pos].label.to_string(), pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +117,6 @@ impl Adf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !change {break;}
|
if !change {break;}
|
||||||
println!("bla");
|
|
||||||
}
|
}
|
||||||
interpretation
|
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 lpos = Adf::findterm(formula).unwrap();
|
||||||
let rpos = Adf::findterm(&formula[lpos+1..]).unwrap() + lpos;
|
let rpos = Adf::findterm(&formula[lpos+1..]).unwrap() + lpos;
|
||||||
(&formula[..lpos],&formula[lpos+1..rpos+1])
|
(&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()]
|
&formula[..Adf::findterm(formula).unwrap()]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
src/main.rs
14
src/main.rs
@ -18,24 +18,24 @@ fn main() {
|
|||||||
let mut ac: Vec<(String,String)> = Vec::new();
|
let mut ac: Vec<(String,String)> = Vec::new();
|
||||||
let path = Path::new(args[1].as_str());
|
let path = Path::new(args[1].as_str());
|
||||||
if let Ok(lines) = read_lines(path){
|
if let Ok(lines) = read_lines(path){
|
||||||
for resline in lines {
|
for line in lines.flatten() {
|
||||||
if let Ok(line) = resline {
|
//if let Ok(line) = resline {
|
||||||
//let slice = line.as_str();
|
//let slice = line.as_str();
|
||||||
if line.starts_with("s("){
|
if line.starts_with("s("){
|
||||||
// let slice = line.as_str();
|
// let slice = line.as_str();
|
||||||
// statements.push(Adf::findterm_str(&slice[2..]).clone());
|
// 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("){
|
else if line.starts_with("ac("){
|
||||||
let (s,c) = Adf::findpairs(&line[3..]);
|
let (s,c) = Adf::findpairs(line.strip_prefix("ac(").unwrap());
|
||||||
ac.push((String::from(s.replace(" ","")),String::from(c.replace(" ", ""))));
|
ac.push((s.replace(" ",""),c.replace(" ", "")));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("parsed {} statements", statements.len());
|
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();
|
let mut my_adf = Adf::new();
|
||||||
my_adf.init_statements(statements.iter().map(AsRef::as_ref).collect());
|
my_adf.init_statements(statements.iter().map(AsRef::as_ref).collect());
|
||||||
for (s,c) in ac {
|
for (s,c) in ac {
|
||||||
|
|||||||
@ -54,9 +54,9 @@ impl Bdd {
|
|||||||
lo
|
lo
|
||||||
} else {
|
} else {
|
||||||
let node = BddNode {
|
let node = BddNode {
|
||||||
var: var,
|
var,
|
||||||
lo: lo,
|
lo,
|
||||||
hi: hi,
|
hi,
|
||||||
};
|
};
|
||||||
match self.hash.get(&node) {
|
match self.hash.get(&node) {
|
||||||
Some(n) => *n,
|
Some(n) => *n,
|
||||||
@ -65,7 +65,7 @@ impl Bdd {
|
|||||||
if newid == usize::MAX {
|
if newid == usize::MAX {
|
||||||
panic!("Maximal amount of elements in node-table reached!")
|
panic!("Maximal amount of elements in node-table reached!")
|
||||||
}
|
}
|
||||||
self.nodes.push(node.clone());
|
self.nodes.push(node);
|
||||||
self.hash.insert(node, newid);
|
self.hash.insert(node, newid);
|
||||||
newid
|
newid
|
||||||
}
|
}
|
||||||
@ -87,6 +87,7 @@ impl Bdd {
|
|||||||
|
|
||||||
pub fn restrict(&mut self, subtree: Term, var: usize, val: bool) -> Term {
|
pub fn restrict(&mut self, subtree: Term, var: usize, val: bool) -> Term {
|
||||||
let treenode = self.nodes[subtree];
|
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 {
|
if treenode.var > var || treenode.var == usize::MAX {
|
||||||
subtree
|
subtree
|
||||||
} else if treenode.var < var {
|
} else if treenode.var < var {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user