Skip to content

Commit

Permalink
refactor: Use unordered pair implementation from crates.io (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh authored Dec 5, 2023
1 parent 493f85d commit b2c5e0e
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 105 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ members = [
"matching",
"merge",
"parsing",
"model",
"utils"
"model"
]
1 change: 0 additions & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ merge = { path = "../merge" }
model = { path = "../model" }
parsing = { path = "../parsing" }
matching = { path = "../matching" }
utils = { path = "../utils" }
assert_cmd = "2.0.12"
clap = { version = "4.4.8", features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion matching/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"

[dependencies]
model = { path = "../model" }
utils = { path = "../utils" }
unordered-pair = "0.2.4"
4 changes: 2 additions & 2 deletions matching/src/matchings.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use model::CSTNode;
use utils::unordered_pair::UnorderedPair;
use unordered_pair::UnorderedPair;

use crate::matching::Matching;
use crate::matching_entry::MatchingEntry;
Expand Down Expand Up @@ -47,7 +47,7 @@ impl<'a> Matchings<'a> {
left: &'a CSTNode<'a>,
right: &'a CSTNode<'a>,
) -> Option<&MatchingEntry> {
self.matching_entries.get(&UnorderedPair::new(left, right))
self.matching_entries.get(&UnorderedPair(left, right))
}

pub fn has_bidirectional_matching(
Expand Down
11 changes: 4 additions & 7 deletions matching/src/ordered_tree_matching.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{calculate_matchings, matching_entry::MatchingEntry, Matchings};
use model::CSTNode;
use utils::unordered_pair::UnorderedPair;
use unordered_pair::UnorderedPair;

#[derive(PartialEq, Eq, Debug, Clone)]
enum Direction {
Expand Down Expand Up @@ -72,7 +72,7 @@ pub fn ordered_tree_matching<'a>(left: &'a CSTNode, right: &'a CSTNode) -> Match
let mut j = n;

let mut matchings = Matchings::from_single(
UnorderedPair::new(left, right),
UnorderedPair(left, right),
MatchingEntry::new(matrix_m[m][n] + root_matching, left == right),
);

Expand Down Expand Up @@ -106,14 +106,11 @@ pub fn ordered_tree_matching<'a>(left: &'a CSTNode, right: &'a CSTNode) -> Match
) => {
let is_perfetch_match = kind_left == kind_right && value_left == value_right;
Matchings::from_single(
UnorderedPair::new(left, right),
UnorderedPair(left, right),
MatchingEntry::new(is_perfetch_match.into(), is_perfetch_match),
)
}
(_, _) => Matchings::from_single(
UnorderedPair::new(left, right),
MatchingEntry::new(0, false),
),
(_, _) => Matchings::from_single(UnorderedPair(left, right), MatchingEntry::new(0, false)),
}
}

Expand Down
4 changes: 2 additions & 2 deletions matching/src/unordered_tree_matching.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use model::CSTNode;
use utils::unordered_pair::UnorderedPair;
use unordered_pair::UnorderedPair;

use crate::{calculate_matchings, MatchingEntry, Matchings};

Expand All @@ -19,7 +19,7 @@ pub fn unordered_tree_matching<'a>(left: &'a CSTNode, right: &'a CSTNode) -> cra
) => {
let is_perfetch_match = kind_left == kind_right && value_left == value_right;
Matchings::from_single(
UnorderedPair::new(left, right),
UnorderedPair(left, right),
MatchingEntry::new(is_perfetch_match.into(), is_perfetch_match),
)
}
Expand Down
1 change: 0 additions & 1 deletion merge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ edition = "2021"
[dependencies]
model = { path = "../model" }
matching = { path = "../matching" }
utils = { path = "../utils" }
diffy = "0.3.0"
8 changes: 0 additions & 8 deletions utils/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion utils/src/lib.rs

This file was deleted.

73 changes: 0 additions & 73 deletions utils/src/unordered_pair.rs

This file was deleted.

0 comments on commit b2c5e0e

Please sign in to comment.