Struct hyperloglog_rs::serde::HyperLogLogArray
source · #[repr(transparent)]pub struct HyperLogLogArray<const PRECISION: usize, const BITS: usize, const N: usize> { /* private fields */ }
Implementations§
source§impl<const PRECISION: usize, const BITS: usize, const N: usize> HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> HyperLogLogArray<PRECISION, BITS, N>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new HyperLogLogArray with the given precision and number of bits.
Example
#![feature(generic_const_exprs)]
use hyperloglog_rs::prelude::*;
let hll_array = HyperLogLogArray::<12, 6, 3>::new();
sourcepub fn estimated_difference_cardinality_vector(
&self,
other: &HyperLogLog<PRECISION, BITS>
) -> [f32; N]
pub fn estimated_difference_cardinality_vector( &self, other: &HyperLogLog<PRECISION, BITS> ) -> [f32; N]
sourcepub fn estimated_overlap_and_differences_cardinality_matrices(
&self,
other: &Self
) -> ([[f32; N]; N], [f32; N], [f32; N])
pub fn estimated_overlap_and_differences_cardinality_matrices( &self, other: &Self ) -> ([[f32; N]; N], [f32; N], [f32; N])
Returns the estimated overlap and difference cardinality matrices and vectors with the provided HyperLogLogArray.
Arguments
other
: The HyperLogLogArray to estimate the overlap and difference cardinality matrices and vectors with.
Returns
The estimated overlap and difference cardinality matrices and vectors with the provided HyperLogLogArray.
Trait Implementations§
source§impl<const PRECISION: usize, const BITS: usize, const N: usize> AsMut<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> AsMut<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
source§impl<const PRECISION: usize, const BITS: usize, const N: usize> AsRef<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> AsRef<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
source§impl<const PRECISION: usize, const BITS: usize, const N: usize> Clone for HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> Clone for HyperLogLogArray<PRECISION, BITS, N>
source§fn clone(&self) -> HyperLogLogArray<PRECISION, BITS, N>
fn clone(&self) -> HyperLogLogArray<PRECISION, BITS, N>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<const PRECISION: usize, const BITS: usize, const N: usize> Debug for HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> Debug for HyperLogLogArray<PRECISION, BITS, N>
source§impl<const PRECISION: usize, const BITS: usize, const N: usize> Default for HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> Default for HyperLogLogArray<PRECISION, BITS, N>
source§impl<'de, const PRECISION: usize, const BITS: usize, const N: usize> Deserialize<'de> for HyperLogLogArray<PRECISION, BITS, N>
impl<'de, const PRECISION: usize, const BITS: usize, const N: usize> Deserialize<'de> for HyperLogLogArray<PRECISION, BITS, N>
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserializes the HyperLogLog counter using the given deserializer.
This method is part of the Deserialize
trait implementation for the HyperLogLog struct,
allowing the counter to be deserialized from a format supported by the deserializer.
Arguments
deserializer
: The deserializer used to deserialize the HyperLogLog counter.
Returns
The deserialization result, indicating success or failure.
source§impl<const PRECISION: usize, const BITS: usize, const N: usize> Index<usize> for HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> Index<usize> for HyperLogLogArray<PRECISION, BITS, N>
source§fn index(&self, index: usize) -> &Self::Output
fn index(&self, index: usize) -> &Self::Output
Returns a reference to the HyperLogLog counter at the given index.
Arguments
index
: The index of the HyperLogLog counter to return.
Returns
A reference to the HyperLogLog counter at the given index.
Panics
Panics if the index is out of bounds.
Example
#![feature(generic_const_exprs)]
use hyperloglog_rs::prelude::*;
let mut hll_array = HyperLogLogArray::<12, 6, 4>::new();
hll_array[0].insert(&1);
hll_array[1].insert(&2);
hll_array[2].insert(&3);
assert!(hll_array[0].estimate_cardinality() > 0.9
&& hll_array[1].estimate_cardinality() < 1.1
);
assert!(hll_array[1].estimate_cardinality() > 0.9
&& hll_array[1].estimate_cardinality() < 1.1
);
assert!(hll_array[2].estimate_cardinality() > 0.9
&& hll_array[2].estimate_cardinality() < 1.1
);
assert!(hll_array[3].estimate_cardinality() > -0.1
&& hll_array[3].estimate_cardinality() < 0.1
);
§type Output = HyperLogLog<PRECISION, BITS>
type Output = HyperLogLog<PRECISION, BITS>
source§impl<const PRECISION: usize, const BITS: usize, const N: usize> IndexMut<usize> for HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> IndexMut<usize> for HyperLogLogArray<PRECISION, BITS, N>
source§fn index_mut(&mut self, index: usize) -> &mut Self::Output
fn index_mut(&mut self, index: usize) -> &mut Self::Output
Returns a mutable reference to the HyperLogLog counter at the given index.
Arguments
index
: The index of the HyperLogLog counter to return.
Returns
A mutable reference to the HyperLogLog counter at the given index.
Panics
Panics if the index is out of bounds.
Example
#![feature(generic_const_exprs)]
use hyperloglog_rs::prelude::*;
let mut hll_array = HyperLogLogArray::<12, 6, 4>::new();
hll_array[0].insert(&1);
hll_array[1].insert(&2);
hll_array[2].insert(&3);
assert!(hll_array[0].estimate_cardinality() > 0.9
&& hll_array[1].estimate_cardinality() < 1.1
);
assert!(hll_array[1].estimate_cardinality() > 0.9
&& hll_array[1].estimate_cardinality() < 1.1
);
assert!(hll_array[2].estimate_cardinality() > 0.9
&& hll_array[2].estimate_cardinality() < 1.1
);
assert!(hll_array[3].estimate_cardinality() > -0.1
&& hll_array[3].estimate_cardinality() < 0.1
);
source§impl<const PRECISION: usize, const BITS: usize, const N: usize> PartialEq<HyperLogLogArray<PRECISION, BITS, N>> for HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> PartialEq<HyperLogLogArray<PRECISION, BITS, N>> for HyperLogLogArray<PRECISION, BITS, N>
source§fn eq(&self, other: &HyperLogLogArray<PRECISION, BITS, N>) -> bool
fn eq(&self, other: &HyperLogLogArray<PRECISION, BITS, N>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<const PRECISION: usize, const BITS: usize, const N: usize> Serialize for HyperLogLogArray<PRECISION, BITS, N>
impl<const PRECISION: usize, const BITS: usize, const N: usize> Serialize for HyperLogLogArray<PRECISION, BITS, N>
source§fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
Serializes the HyperLogLog counter using the given serializer.
This method is part of the Serialize
trait implementation for the HyperLogLog struct,
allowing the counter to be serialized into a format supported by the serializer.
Arguments
serializer
: The serializer used to serialize the HyperLogLog counter.
Returns
The serialization result, indicating success or failure.
Example
In this example, we serialize an array of HyperLogLog counters into a JSON string. The resulting string is then deserialized back into an array of HyperLogLog counters.
Since we cannot implement these traits for array, we need to wrap the array in a struct,
which in this case is HyperLogLogArray
.
#![feature(generic_const_exprs)]
use serde::Serialize;
use serde_json::Serializer;
use hyperloglog_rs::prelude::*;
let mut hll_array = HyperLogLogArray::<12, 6, 3>::new();
hll_array[0].insert(&1);
hll_array[1].insert(&2);
hll_array[2].insert(&3);
let mut serializer = Serializer::new(Vec::new());
let result = hll_array.serialize(&mut serializer);
assert!(result.is_ok(), "Serialization failed, error: {:?}", result.err());
let hll_array_str = String::from_utf8(serializer.into_inner()).unwrap();
let hll_array_deserialized = serde_json::from_str(&hll_array_str);
assert!(hll_array_deserialized.is_ok(), "Deserialization failed, error: {:?}", hll_array_deserialized.err());
let hll_array_deserialized = hll_array_deserialized.unwrap();
assert_eq!(hll_array, hll_array_deserialized, "Deserialized array does not match original array");