1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::precisions::{Precision, WordType};
use crate::HyperLogLog;
use core::hash::Hash;
use core::ops::{BitOr, BitOrAssign};
impl<
Item: Hash,
I: IntoIterator<Item = Item>,
P: Precision + WordType<BITS>,
const BITS: usize,
> BitOrAssign<I> for HyperLogLog<P, BITS>
{
#[inline(always)]
/// Computes inplace union between an HLL counter and an iterator.
///
/// ```rust
/// # use hyperloglog_rs::prelude::*;
/// # use core::ops::BitOrAssign;
///
/// let mut hll = HyperLogLog::<Precision8, 6>::default();
///
/// hll |= [1u8, 2u8];
///
/// assert!(hll.estimate_cardinality() > 2.0 - 0.1, "The cardinality is {}, we were expecting 2.", hll.estimate_cardinality());
/// assert!(hll.estimate_cardinality() < 2.0 + 0.1, "The cardinality is {}, we were expecting 2.", hll.estimate_cardinality());
///
/// hll |= [2u8, 3u8];
///
/// assert!(hll.estimate_cardinality() > 3.0 - 0.1, "Expected a value equal to around 3, got {}", hll.estimate_cardinality());
/// assert!(hll.estimate_cardinality() < 3.0 + 0.1, "Expected a value equal to around 3, got {}", hll.estimate_cardinality());
/// ```
fn bitor_assign(&mut self, rhs: I) {
rhs.into_iter().for_each(|item| {
self.insert(item);
});
}
}
impl<
Item: Hash,
I: IntoIterator<Item = Item>,
P: Precision + WordType<BITS>,
const BITS: usize,
> BitOrAssign<I> for &mut HyperLogLog<P, BITS>
{
#[inline(always)]
fn bitor_assign(&mut self, rhs: I) {
rhs.into_iter().for_each(|item| {
self.insert(item);
});
}
}
impl<Item: Hash, I: Iterator<Item = Item>, P: Precision + WordType<BITS>, const BITS: usize>
BitOr<I> for HyperLogLog<P, BITS>
{
type Output = Self;
#[inline(always)]
/// Computes the union between an HLL counter and an iterator.
///
fn bitor(mut self, rhs: I) -> Self {
self.bitor_assign(rhs);
self
}
}