[PATCH merge-rs 1/1] feat(hashmap): Intersection
Export this patch
From: Gabouchet <gabriel.hamel.pro@gmail.com>
---
src/lib.rs | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/lib.rs b/src/lib.rs
index ab9b4ab..e289d84 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -298,4 +298,19 @@ pub mod hashmap {
}
}
}
+
+ /// Merge recursively elements if the key is present in `left` and `right`.
+ pub fn intersection<K: Eq + Hash, V: crate::Merge>(
+ left: &mut HashMap<K, V>,
+ right: HashMap<K, V>,
+ ) {
+ use std::collections::hash_map::Entry;
+
+ for (k, v) in right {
+ match left.entry(k) {
+ Entry::Occupied(mut existing) => existing.get_mut().merge(v),
+ _ => {}
+ }
+ }
+ }
}
--
2.34.5
merge-rs/patches: FAILED in 3m4s
[Hashmap feature proposal][0] from [~gabouchet][1]
[0]: https://lists.sr.ht/~ireas/public-inbox/patches/38541
[1]: mailto:gabriel.hamel.pro@gmail.com
✗ #930882 FAILED merge-rs/patches/archlinux-msrv.yml https://builds.sr.ht/~ireas/job/930882
✗ #930883 FAILED merge-rs/patches/archlinux.yml https://builds.sr.ht/~ireas/job/930883