~ireas/public-inbox

PATCH merge-rs Hashmap intersection strategy

Details
Message ID
<CDEB6929-06A7-495C-B131-3D2FEB0E1783@gmail.com>
DKIM signature
missing
Download raw message
Patch: +12 -0
diff --git a/src/lib.rs b/src/lib.rs
index ab9b4ab..9b9d565 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -298,4 +298,16 @@ 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),
                _ => {}
            }
        }
    }
}
Reply to thread Export thread (mbox)