dag_walk: simply pass callback function by value

This commit is contained in:
Yuya Nishihara 2023-05-20 16:27:23 +09:00
parent 864c17b8c4
commit 522308bb9c
4 changed files with 17 additions and 17 deletions

View file

@ -110,8 +110,8 @@ where
pub fn leaves<T, ID, II, NI>(
start: II,
neighbors_fn: &mut impl FnMut(&T) -> NI,
id_fn: &impl Fn(&T) -> ID,
mut neighbors_fn: impl FnMut(&T) -> NI,
id_fn: impl Fn(&T) -> ID,
) -> HashSet<T>
where
T: Hash + Eq + Clone,
@ -147,8 +147,8 @@ where
/// start set.
pub fn heads<T, ID, II, NI>(
start: II,
neighbors_fn: &impl Fn(&T) -> NI,
id_fn: &impl Fn(&T) -> ID,
neighbors_fn: impl Fn(&T) -> NI,
id_fn: impl Fn(&T) -> ID,
) -> HashSet<T>
where
T: Hash + Eq + Clone,
@ -175,8 +175,8 @@ where
pub fn closest_common_node<T, ID, II1, II2, NI>(
set1: II1,
set2: II2,
neighbors_fn: &impl Fn(&T) -> NI,
id_fn: &impl Fn(&T) -> ID,
neighbors_fn: impl Fn(&T) -> NI,
id_fn: impl Fn(&T) -> ID,
) -> Option<T>
where
T: Hash + Eq + Clone,
@ -341,8 +341,8 @@ mod tests {
let common = closest_common_node(
vec!['E'],
vec!['H'],
&|node| neighbors[node].clone(),
&|node| *node,
|node| neighbors[node].clone(),
|node| *node,
);
// TODO: fix the implementation to return B
@ -372,16 +372,16 @@ mod tests {
let actual = heads(
vec!['A', 'C', 'D', 'F'],
&|node| neighbors[node].clone(),
&|node| *node,
|node| neighbors[node].clone(),
|node| *node,
);
assert_eq!(actual, hashset!['D', 'F']);
// Check with a different order in the start set
let actual = heads(
vec!['F', 'D', 'C', 'A'],
&|node| neighbors[node].clone(),
&|node| *node,
|node| neighbors[node].clone(),
|node| *node,
);
assert_eq!(actual, hashset!['D', 'F']);
}

View file

@ -55,7 +55,7 @@ pub trait OpHeadsStore: Send + Sync + Debug {
let neighbors_fn = |op: &Operation| op.parents();
// Remove ancestors so we don't create merge operation with an operation and its
// ancestor
let op_heads = dag_walk::heads(op_heads, &neighbors_fn, &|op: &Operation| op.id().clone());
let op_heads = dag_walk::heads(op_heads, neighbors_fn, |op: &Operation| op.id().clone());
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) {
self.remove_op_head(removed_op_head);

View file

@ -68,8 +68,8 @@ impl Transaction {
let ancestor_op = closest_common_node(
self.parent_ops.clone(),
vec![other_op.clone()],
&|op: &Operation| op.parents(),
&|op: &Operation| op.id().clone(),
|op: &Operation| op.parents(),
|op: &Operation| op.id().clone(),
)
.unwrap();
let repo_loader = self.base_repo().loader();

View file

@ -1457,8 +1457,8 @@ pub fn check_stale_working_copy(
let maybe_ancestor_op = dag_walk::closest_common_node(
[wc_operation.clone()],
[repo_operation.clone()],
&|op: &Operation| op.parents(),
&|op: &Operation| op.id().clone(),
|op: &Operation| op.parents(),
|op: &Operation| op.id().clone(),
);
if let Some(ancestor_op) = maybe_ancestor_op {
if ancestor_op.id() == repo_operation.id() {