dag_walk: rename unreachable() to heads() to match name we use in index module

This commit is contained in:
Martin von Zweigbergk 2021-03-16 23:39:22 -07:00
parent 5aec8b9d77
commit 30cd94f842
2 changed files with 9 additions and 10 deletions

View file

@ -205,7 +205,7 @@ where
/// Find nodes in the start set that are not reachable from other nodes in the /// Find nodes in the start set that are not reachable from other nodes in the
/// start set. /// start set.
pub fn unreachable<T, ID, II, NI>( pub fn heads<T, ID, II, NI>(
start: II, start: II,
neighbors_fn: &impl Fn(&T) -> NI, neighbors_fn: &impl Fn(&T) -> NI,
id_fn: &impl Fn(&T) -> ID, id_fn: &impl Fn(&T) -> ID,
@ -300,7 +300,7 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn topo_order_reverse_linear() { fn test_topo_order_reverse_linear() {
// This graph: // This graph:
// o C // o C
// o B // o B
@ -322,7 +322,7 @@ mod tests {
} }
#[test] #[test]
fn topo_order_reverse_merge() { fn test_topo_order_reverse_merge() {
// This graph: // This graph:
// o F // o F
// |\ // |\
@ -352,7 +352,7 @@ mod tests {
} }
#[test] #[test]
fn topo_order_reverse_multiple_heads() { fn test_topo_order_reverse_multiple_heads() {
// This graph: // This graph:
// o F // o F
// |\ // |\
@ -384,7 +384,7 @@ mod tests {
} }
#[test] #[test]
fn closest_common_node_tricky() { fn test_closest_common_node_tricky() {
// Test this case where A is the shortest distance away, but we still want the // Test this case where A is the shortest distance away, but we still want the
// result to be B because A is an ancestor of B. In other words, we want // result to be B because A is an ancestor of B. In other words, we want
// to minimize the longest distance. // to minimize the longest distance.
@ -421,7 +421,7 @@ mod tests {
} }
#[test] #[test]
fn unreachable_mixed() { fn test_heads_mixed() {
// Test the uppercase letters are in the start set // Test the uppercase letters are in the start set
// //
// D F // D F
@ -442,7 +442,7 @@ mod tests {
}; };
let expected: HashSet<char> = vec!['D', 'F'].into_iter().collect(); let expected: HashSet<char> = vec!['D', 'F'].into_iter().collect();
let actual = unreachable( let actual = heads(
vec!['A', 'C', 'D', 'F'], vec!['A', 'C', 'D', 'F'],
&|node| neighbors[node].clone(), &|node| neighbors[node].clone(),
&|node| *node, &|node| *node,
@ -450,7 +450,7 @@ mod tests {
assert_eq!(actual, expected); assert_eq!(actual, expected);
// Check with a different order in the start set // Check with a different order in the start set
let actual = unreachable( let actual = heads(
vec!['F', 'D', 'C', 'A'], vec!['F', 'D', 'C', 'A'],
&|node| neighbors[node].clone(), &|node| neighbors[node].clone(),
&|node| *node, &|node| *node,

View file

@ -172,8 +172,7 @@ impl OpHeadsStore {
let neighbors_fn = |op: &Operation| op.parents(); let neighbors_fn = |op: &Operation| op.parents();
// Remove ancestors so we don't create merge operation with an operation and its // Remove ancestors so we don't create merge operation with an operation and its
// ancestor // ancestor
let op_heads = let op_heads = dag_walk::heads(op_heads, &neighbors_fn, &|op: &Operation| op.id().clone());
dag_walk::unreachable(op_heads, &neighbors_fn, &|op: &Operation| op.id().clone());
let op_head_ids_after: HashSet<_> = op_heads.iter().map(|op| op.id().clone()).collect(); let op_head_ids_after: HashSet<_> = op_heads.iter().map(|op| op.id().clone()).collect();
for removed_op_head in op_head_ids_before.difference(&op_head_ids_after) { for removed_op_head in op_head_ids_before.difference(&op_head_ids_after) {
self.remove_op_head(&removed_op_head); self.remove_op_head(&removed_op_head);