diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-12-01 20:39:20 -0800 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-12-01 20:39:20 -0800 |
commit | a569e3d3118c7a132ec554996f5fb03c71045e90 (patch) | |
tree | de5ae3371c2899f9b644714c96b1a9aae4a1058b /src | |
parent | 91e758a6eca4cc806e34a8be5d030138b7dae910 (diff) | |
download | modelthing-a569e3d3118c7a132ec554996f5fb03c71045e90.tar.gz modelthing-a569e3d3118c7a132ec554996f5fb03c71045e90.zip |
new intersect_strings helper
Diffstat (limited to 'src')
-rw-r--r-- | src/modelica_ast.rs | 16 |
1 files 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<String>, b: &Vec<String>) -> Vec<String> { +fn union_strings(a: &Vec<String>, b: &Vec<String>) -> Vec<String> { let mut u = a.clone(); for e in b { if !(u.contains(&e)) { @@ -114,6 +114,16 @@ fn union_vecs(a: &Vec<String>, b: &Vec<String>) -> Vec<String> { u } +fn intersect_strings(a: &Vec<String>, b: &Vec<String>) -> Vec<String> { + 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<String> { - union_vecs(&self.lhs.identifiers(), &self.rhs.identifiers()) + union_strings(&self.lhs.identifiers(), &self.rhs.identifiers()) } pub fn contains(&self, ident: &str) -> bool{ |