Skip to content

Commit

Permalink
Reduce edge kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
QuarticCat committed Oct 7, 2022
1 parent 005a5a6 commit 10ce859
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/diff/dijkstra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ mod tests {
contiguous: false,
probably_punctuation: false,
},
ExitDelimiterBoth,
ExitDelimiter,
]
);
}
Expand Down Expand Up @@ -303,7 +303,7 @@ mod tests {
contiguous: false,
probably_punctuation: false
},
ExitDelimiterBoth,
ExitDelimiter,
]
);
}
Expand Down Expand Up @@ -353,8 +353,8 @@ mod tests {
UnchangedNode {
depth_difference: 0
},
ExitDelimiterRHS,
ExitDelimiterLHS,
ExitDelimiter,
ExitDelimiter,
],
);
}
Expand Down Expand Up @@ -434,7 +434,7 @@ mod tests {
contiguous: true,
probably_punctuation: false
},
ExitDelimiterLHS,
ExitDelimiter,
]
);
}
Expand Down Expand Up @@ -476,7 +476,7 @@ mod tests {
contiguous: true,
probably_punctuation: false
},
ExitDelimiterLHS,
ExitDelimiter,
NovelAtomLHS {
contiguous: true,
probably_punctuation: true
Expand Down
19 changes: 6 additions & 13 deletions src/diff/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,7 @@ pub enum Edge {
EnterNovelDelimiterRHS {
contiguous: bool,
},
ExitDelimiterLHS,
ExitDelimiterRHS,
ExitDelimiterBoth,
ExitDelimiter,
}

const NOT_CONTIGUOUS_PENALTY: u64 = 50;
Expand All @@ -329,12 +327,7 @@ impl Edge {
// delimiter possibility, so the cost doesn't matter. We
// choose a non-zero number as it's easier to reason
// about.
ExitDelimiterBoth => 1,
// Choose a higher value for exiting individually. This
// shouldn't matter since entering a novel delimiter is
// already more expensive than entering a matched
// delimiter, but be defensive.
ExitDelimiterLHS | ExitDelimiterRHS => 2,
ExitDelimiter => 1,

// Matching nodes is always best.
UnchangedNode { depth_difference } => min(40, u64::from(depth_difference) + 1),
Expand Down Expand Up @@ -454,7 +447,7 @@ pub fn get_neighbours<'syn, 'b>(

// Continue from sibling of parent.
add_neighbor(
ExitDelimiterBoth,
ExitDelimiter,
Vertex {
lhs_syntax: next_sibling(v.lhs_syntax.parent().unwrap()),
rhs_syntax: next_sibling(v.rhs_syntax.parent().unwrap()),
Expand All @@ -470,7 +463,7 @@ pub fn get_neighbours<'syn, 'b>(

// Continue from sibling of parent.
add_neighbor(
ExitDelimiterLHS,
ExitDelimiter,
Vertex {
lhs_syntax: next_sibling(v.lhs_syntax.parent().unwrap()),
rhs_syntax: v.rhs_syntax,
Expand All @@ -486,7 +479,7 @@ pub fn get_neighbours<'syn, 'b>(

// Continue from sibling of parent.
add_neighbor(
ExitDelimiterRHS,
ExitDelimiter,
Vertex {
lhs_syntax: v.lhs_syntax,
rhs_syntax: next_sibling(v.rhs_syntax.parent().unwrap()),
Expand Down Expand Up @@ -667,7 +660,7 @@ pub fn populate_change_map<'a, 'b>(

for (e, v) in route {
match e {
ExitDelimiterBoth | ExitDelimiterLHS | ExitDelimiterRHS => {
ExitDelimiter => {
// Nothing to do: we have already marked this node when we entered it.
}
UnchangedNode { .. } => {
Expand Down

0 comments on commit 10ce859

Please sign in to comment.