Skip to main content

oxilean_std/hashset/
oxihashset_len_group.rs

1//! # OxiHashSet - len_group Methods
2//!
3//! This module contains method implementations for `OxiHashSet`.
4//!
5//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
6
7use super::oxihashset_type::OxiHashSet;
8use std::hash::Hash;
9
10impl<T: Eq + Hash + Clone> OxiHashSet<T> {
11    /// Return the number of elements.
12    pub fn len(&self) -> usize {
13        self.inner.len()
14    }
15    /// Number of elements not shared with `other`.
16    pub fn exclusive_count(&self, other: &Self) -> usize {
17        self.difference(other).len()
18    }
19    /// Total elements in union minus shared elements (Jaccard denominator).
20    pub fn union_size(&self, other: &Self) -> usize {
21        self.union(other).len()
22    }
23    /// Jaccard similarity coefficient (0.0–1.0).
24    pub fn jaccard(&self, other: &Self) -> f64 {
25        let u = self.union_size(other);
26        if u == 0 {
27            1.0
28        } else {
29            self.intersection(other).len() as f64 / u as f64
30        }
31    }
32}