minhash_rs/
from_iter.rs

1use std::hash::Hash;
2
3use crate::prelude::{Maximal, Min, MinHash, Primitive, XorShift};
4
5impl<Word: Min + Clone + Eq + Maximal + XorShift, A: Hash, const PERMUTATATIONS: usize>
6    core::iter::FromIterator<A> for MinHash<Word, PERMUTATATIONS>
7where
8    u64: Primitive<Word>,
9{
10    #[inline(always)]
11    /// Creates a new MinHash and adds all elements from an iterator to it.
12    ///
13    /// # Examples
14    ///
15    /// ```
16    /// use minhash_rs::prelude::*;
17    ///
18    /// let data = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];
19    /// let minhash = MinHash::<u64, 128>::from_iter(data.clone());
20    ///
21    /// for item in data {
22    ///     assert!(minhash.may_contain_value_with_siphashes13(item));
23    /// }
24    ///
25    /// ```
26    fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self {
27        let mut hll = Self::new();
28        for item in iter {
29            hll.insert_with_siphashes13(item);
30        }
31        hll
32    }
33}