From a569e3d3118c7a132ec554996f5fb03c71045e90 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 1 Dec 2016 20:39:20 -0800 Subject: new intersect_strings helper --- src/modelica_ast.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/modelica_ast.rs b/src/modelica_ast.rs index 33af4ac..6903900 100644 --- a/src/modelica_ast.rs +++ b/src/modelica_ast.rs @@ -104,7 +104,7 @@ impl ModelicaModel { vars.map(|c| c.name.clone()).collect() } -fn union_vecs(a: &Vec, b: &Vec) -> Vec { +fn union_strings(a: &Vec, b: &Vec) -> Vec { let mut u = a.clone(); for e in b { if !(u.contains(&e)) { @@ -114,6 +114,16 @@ fn union_vecs(a: &Vec, b: &Vec) -> Vec { u } +fn intersect_strings(a: &Vec, b: &Vec) -> Vec { + let mut both = vec![]; + for e in a { + if b.contains(&e) { + both.push(e.clone()); + } + } + both +} + impl Expr { // Order is undefined @@ -124,7 +134,7 @@ impl Expr { Ident(ref s) => vec![s.clone()], Der(ref e) | Abs(ref e) => e.identifiers(), BinExpr(_, ref e1, ref e2) => { - union_vecs(&e1.identifiers(), &e2.identifiers()) + union_strings(&e1.identifiers(), &e2.identifiers()) }, } } @@ -138,7 +148,7 @@ impl SimpleEquation { // Order is undefined pub fn identifiers(&self) -> Vec { - union_vecs(&self.lhs.identifiers(), &self.rhs.identifiers()) + union_strings(&self.lhs.identifiers(), &self.rhs.identifiers()) } pub fn contains(&self, ident: &str) -> bool{ -- cgit v1.2.3