Skip to content

Commit

Permalink
refactor: Address cargo clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Nov 9, 2023
1 parent a358d10 commit ef5e48b
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 173 deletions.
4 changes: 2 additions & 2 deletions matching/src/matching_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub struct MatchingEntry {

impl MatchingEntry {
pub fn new(score: usize, is_perfect_match: bool) -> Self {
return MatchingEntry {
MatchingEntry {
score,
is_perfect_match,
};
}
}
}

Expand Down
40 changes: 19 additions & 21 deletions matching/src/ordered_tree_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use utils::unordered_pair::UnorderedPair;

#[derive(PartialEq, Eq, Debug, Clone)]
enum Direction {
TOP,
LEFT,
DIAG,
Top,
Left,
Diag,
}

#[derive(Clone)]
struct Entry<'a>(pub Direction, pub Matchings<'a>);

impl<'a> Default for Entry<'a> {
fn default() -> Self {
Self(Direction::TOP, Default::default())
Self(Direction::Top, Default::default())
}
}

Expand Down Expand Up @@ -53,19 +53,17 @@ pub fn ordered_tree_matching<'a>(left: &'a CSTNode, right: &'a CSTNode) -> Match
if matrix_m[i][j - 1] > matrix_m[i - 1][j] {
if matrix_m[i][j - 1] > matrix_m[i - 1][j - 1] + matching.score {
matrix_m[i][j] = matrix_m[i][j - 1];
matrix_t[i][j] = Entry(Direction::LEFT, w);
matrix_t[i][j] = Entry(Direction::Left, w);
} else {
matrix_m[i][j] = matrix_m[i - 1][j - 1] + matching.score;
matrix_t[i][j] = Entry(Direction::DIAG, w);
matrix_t[i][j] = Entry(Direction::Diag, w);
}
} else if matrix_m[i - 1][j] > matrix_m[i - 1][j - 1] + matching.score {
matrix_m[i][j] = matrix_m[i - 1][j];
matrix_t[i][j] = Entry(Direction::Top, w);
} else {
if matrix_m[i - 1][j] > matrix_m[i - 1][j - 1] + matching.score {
matrix_m[i][j] = matrix_m[i - 1][j];
matrix_t[i][j] = Entry(Direction::TOP, w);
} else {
matrix_m[i][j] = matrix_m[i - 1][j - 1] + matching.score;
matrix_t[i][j] = Entry(Direction::DIAG, w);
}
matrix_m[i][j] = matrix_m[i - 1][j - 1] + matching.score;
matrix_t[i][j] = Entry(Direction::Diag, w);
}
}
}
Expand All @@ -80,14 +78,14 @@ pub fn ordered_tree_matching<'a>(left: &'a CSTNode, right: &'a CSTNode) -> Match

while i >= 1 && j >= 1 {
match matrix_t.get(i).unwrap().get(j).unwrap().0 {
Direction::TOP => i = i - 1,
Direction::LEFT => j = j - 1,
Direction::DIAG => {
Direction::Top => i -= 1,
Direction::Left => j -= 1,
Direction::Diag => {
if matrix_m[i][j] > matrix_m[i - 1][j - 1] {
matchings.extend(matrix_t[i][j].1.clone());
}
i = i - 1;
j = j - 1;
i -= 1;
j -= 1;
}
}
}
Expand Down Expand Up @@ -254,7 +252,7 @@ mod tests {
end_position: Point { row: 0, column: 7 },
};
let right_child = CSTNode::Terminal {
kind: "kind_c".into(),
kind: "kind_c",
value: "value_c".into(),
start_position: Point { row: 1, column: 0 },
end_position: Point { row: 1, column: 7 },
Expand Down Expand Up @@ -290,7 +288,7 @@ mod tests {
end_position: Point { row: 0, column: 7 },
};
let unique_right_child = CSTNode::Terminal {
kind: "kind_c".into(),
kind: "kind_c",
value: "value_c".into(),
start_position: Point { row: 0, column: 0 },
end_position: Point { row: 0, column: 7 },
Expand Down Expand Up @@ -357,7 +355,7 @@ mod tests {
};

let intermediate = CSTNode::NonTerminal {
kind: "intermediate".into(),
kind: "intermediate",
start_position: Point { row: 0, column: 0 },
end_position: Point { row: 0, column: 7 },
children: vec![leaf],
Expand Down
2 changes: 1 addition & 1 deletion matching/src/unordered_tree_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn unordered_tree_matching<'a>(left: &'a CSTNode, right: &'a CSTNode) -> cra

for child_left in children_left {
for child_right in children_right {
let matching_score = compute_matching_score(&child_left, &child_right);
let matching_score = compute_matching_score(child_left, child_right);

if matching_score == 1 {
let child_matching = calculate_matchings(child_left, child_right);
Expand Down
8 changes: 4 additions & 4 deletions merge/src/merged_cst_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub enum MergedCSTNode<'a> {
},
}

impl<'a> Into<MergedCSTNode<'a>> for CSTNode<'a> {
fn into(self) -> MergedCSTNode<'a> {
match self {
impl<'a> From<CSTNode<'a>> for MergedCSTNode<'a> {
fn from(val: CSTNode<'a>) -> Self {
match val {
CSTNode::Terminal { kind, value, .. } => MergedCSTNode::Terminal { kind, value },
CSTNode::NonTerminal { kind, children, .. } => MergedCSTNode::NonTerminal {
kind,
Expand All @@ -35,7 +35,7 @@ impl ToString for MergedCSTNode<'_> {
MergedCSTNode::NonTerminal { children, .. } => {
children.iter().fold(String::new(), |acc, current| {
let mut result = acc.to_owned();
result.push_str(" ");
result.push(' ');
result.push_str(&current.clone().to_string());
result
})
Expand Down
Loading

0 comments on commit ef5e48b

Please sign in to comment.