Skip to content

Commit

Permalink
refactor: Use node id and simplify continue
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Mar 12, 2024
1 parent 0a7a119 commit 0ba89fe
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions merge/src/unordered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub fn unordered_merge<'a>(
}

let mut result_children = vec![];
let mut processed_nodes: HashSet<&CSTNode> = HashSet::new();
let mut processed_nodes: HashSet<uuid::Uuid> = HashSet::new();

for left_child in left.children.iter() {
if let CSTNode::Terminal(Terminal {
Expand All @@ -44,7 +44,7 @@ pub fn unordered_merge<'a>(
// Added only by left
(None, None) => {
result_children.push(left_child.to_owned().into());
processed_nodes.insert(left_child);
processed_nodes.insert(left_child.id());
}
(None, Some(right_matching)) => {
result_children.push(merge(
Expand All @@ -55,8 +55,8 @@ pub fn unordered_merge<'a>(
base_right_matchings,
left_right_matchings,
)?);
processed_nodes.insert(left_child);
processed_nodes.insert(right_matching.matching_node);
processed_nodes.insert(left_child.id());
processed_nodes.insert(right_matching.matching_node.id());
}
// Removed in right
(Some(matching_base_left), None) => {
Expand All @@ -67,7 +67,7 @@ pub fn unordered_merge<'a>(
right: None,
})
}
processed_nodes.insert(left_child);
processed_nodes.insert(left_child.id());
}
(Some(_), Some(right_matching)) => {
result_children.push(merge(
Expand All @@ -78,20 +78,17 @@ pub fn unordered_merge<'a>(
base_right_matchings,
left_right_matchings,
)?);
processed_nodes.insert(left_child);
processed_nodes.insert(right_matching.matching_node);
processed_nodes.insert(left_child.id());
processed_nodes.insert(right_matching.matching_node.id());
}
}
}

for right_child in right.children.iter() {
if processed_nodes
.iter()
.any(|node| node.id() == right_child.id())
{
continue;
}

for right_child in right
.children
.iter()
.filter(|node| !processed_nodes.contains(&node.id()))
{
let matching_base_right = base_right_matchings.find_matching_for(right_child);
let matching_left_right = left_right_matchings.find_matching_for(right_child);

Expand Down

0 comments on commit 0ba89fe

Please sign in to comment.