Function stringmetrics::jaccard_set
source · pub fn jaccard_set<T, S: BuildHasher>(
a: &HashSet<T, S>,
b: &HashSet<T, S>
) -> f32where
T: Eq + Hash,
Expand description
Calculate the Jaccard index on two HashSet
s.
Returns the mathematical Jaccard index, i.e. |A ∩ B| / |A ∪ B|
Usually this is interfaced via jaccard
; that is recommended unless your
data is already in a HashSet
.
Example
use std::collections::HashSet;
use stringmetrics::jaccard_set;
let crew1 = HashSet::from(["Einar", "Olaf", "Harald"]);
let crew2 = HashSet::from(["Olaf", "Harald", "Birger"]);
assert_eq!(jaccard_set(&crew1, &crew2), 0.5);