From 3ab6148c0b7b61804f8f6f700a82601e5b018c47 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 27 Jul 2023 19:41:12 +0200 Subject: [PATCH 1/2] Do not use `bool::then()` in `filter_map()` The succession `.filter().map()` does the right thing in this case and is easier to read. --- src/directed/topological_sort.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/directed/topological_sort.rs b/src/directed/topological_sort.rs index 91aad61c..50ee9876 100644 --- a/src/directed/topological_sort.rs +++ b/src/directed/topological_sort.rs @@ -179,7 +179,8 @@ where let mut groups = Vec::>::new(); let mut prev_group: Vec = preds_map .iter() - .filter_map(|(node, &num_preds)| (num_preds == 0).then(|| node.clone())) + .filter(|(_, &num_preds)| num_preds == 0) + .map(|(node, _)| node.clone()) .collect(); if prev_group.is_empty() { let remaining: Vec = preds_map.into_keys().collect(); From 07d50d87571b4662c047bb4b401396600e45f874 Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Thu, 27 Jul 2023 19:43:28 +0200 Subject: [PATCH 2/2] Use `or_default()` rather than `or_insert_with()` with default value --- src/directed/edmonds_karp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/directed/edmonds_karp.rs b/src/directed/edmonds_karp.rs index 714abefe..407574fc 100644 --- a/src/directed/edmonds_karp.rs +++ b/src/directed/edmonds_karp.rs @@ -354,7 +354,7 @@ unsafe impl Send for SparseCapacity {} impl SparseCapacity { fn set_value(data: &mut BTreeMap>, from: usize, to: usize, value: C) { let to_remove = { - let sub = data.entry(from).or_insert_with(BTreeMap::new); + let sub = data.entry(from).or_default(); if value == Zero::zero() { sub.remove(&to); } else {