Skip to content

Commit

Permalink
feat: early return and tweak test scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed May 1, 2024
1 parent 9505799 commit 082b46e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
1 change: 0 additions & 1 deletion bin/tests/scenarios/unordered_non_labelled/merge.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ public class Main {
static {
System.out.println("I'm a static block");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ public class Main {
static {
System.out.println("I'm a static block");
}
}

public Main() {
System.out.println("I'm a constructor");
}
}
1 change: 1 addition & 0 deletions bin/tests/scenarios/unordered_with_non_labelled/merge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public class Main { static { int <<<<<<<<< x ========= y >>>>>>>>> = <<<<<<<<< 0 ========= 2 >>>>>>>>> ; } static { System . out . println ( "I'm a static block" ) ; } public Main ( ) { System . out . println ( "I'm a constructor" ) ; int y = 3 ; } static { System . out . println ( "I don't know what's going on" ) ; } }
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ public class Main {
static {
System.out.println("I don't know what's going on");
}
}

public Main() {
System.out.println("I'm a constructor");
int y = 3;
}
}
11 changes: 6 additions & 5 deletions matching/src/assignment_problem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ pub fn unordered_tree_matching<'a>(
..
}),
) => {
let root_matching: usize = (kind_left == kind_right).into();
if kind_left != kind_right {
return Matchings::empty();
}

let children_matchings = children_left
.iter()
Expand All @@ -43,7 +45,7 @@ pub fn unordered_tree_matching<'a>(
})
.collect();

return solve_assignment_problem(left, right, children_matchings, root_matching);
solve_assignment_problem(left, right, children_matchings)
}
(_, _) => unreachable!(
"Unordered matching must never be called if the nodes are not NonTerminals."
Expand All @@ -54,8 +56,7 @@ pub fn unordered_tree_matching<'a>(
fn solve_assignment_problem<'a>(
left: &'a CSTNode,
right: &'a CSTNode,
children_matchings: Vec<Vec<(usize, Matchings<'a>)>>,
root_matching: usize,
children_matchings: Vec<Vec<(usize, Matchings<'a>)>>
) -> Matchings<'a> {
let m = children_matchings.len();
let n = children_matchings[0].len();
Expand Down Expand Up @@ -85,7 +86,7 @@ fn solve_assignment_problem<'a>(
result.extend(Matchings::from_single(
UnorderedPair(left, right),
MatchingEntry {
score: max_matching as usize + root_matching,
score: max_matching as usize + 1,
is_perfect_match: left.contents() == right.contents(),
},
));
Expand Down

0 comments on commit 082b46e

Please sign in to comment.