Skip to content

Commit

Permalink
refactor: use unreachable for unreachable case
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed May 1, 2024
1 parent 1de8663 commit de42f36
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
29 changes: 4 additions & 25 deletions matching/src/assignment_problem/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use std::cmp::max;

use matching_handlers::MatchingHandlers;
use model::{
cst_node::{NonTerminal, Terminal},
CSTNode,
};
use model::{cst_node::NonTerminal, CSTNode};
use pathfinding::{kuhn_munkres::Weights, matrix};
use unordered_pair::UnorderedPair;

Expand All @@ -16,24 +13,6 @@ pub fn unordered_tree_matching<'a>(
matching_handlers: &'a MatchingHandlers<'a>,
) -> crate::Matchings<'a> {
match (left, right) {
(
CSTNode::Terminal(Terminal {
kind: kind_left,
value: value_left,
..
}),
CSTNode::Terminal(Terminal {
kind: kind_right,
value: value_right,
..
}),
) => {
let is_perfetch_match = kind_left == kind_right && value_left == value_right;
Matchings::from_single(
UnorderedPair(left, right),
MatchingEntry::new(is_perfetch_match.into(), is_perfetch_match),
)
}
(
CSTNode::NonTerminal(NonTerminal {
kind: kind_left,
Expand Down Expand Up @@ -66,7 +45,7 @@ pub fn unordered_tree_matching<'a>(

return solve_assignment_problem(left, right, matchings, root_matching);
}
(_, _) => unreachable!("Invalid configuration reached"),
(_, _) => unreachable!("Unordered matching must never be called if the nodes are not NonTerminals."),
}
}

Expand All @@ -90,9 +69,9 @@ fn solve_assignment_problem<'a>(
let weights_matrix = matrix::Matrix::from_rows(matrix)
.expect("Could not build weights matrix for assignment problem.");
let (max_matching, best_matches) = pathfinding::kuhn_munkres::kuhn_munkres(&weights_matrix);

let mut result = Matchings::empty();

for i in 0..best_matches.len() {
let j = best_matches[i];
let cur_matching = weights_matrix.at(i, j);
Expand Down
6 changes: 1 addition & 5 deletions matching/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ pub fn calculate_matchings<'a>(
) => {
if non_terminal_left.are_children_unordered && non_terminal_right.are_children_unordered
{
assignment_problem::unordered_tree_matching(
left,
right,
matching_handlers,
)
assignment_problem::unordered_tree_matching(left, right, matching_handlers)
} else {
ordered_tree_matching::ordered_tree_matching(left, right, matching_handlers)
}
Expand Down

0 comments on commit de42f36

Please sign in to comment.