pub struct HyperLogLogArray<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> { /* private fields */ }
Implementations§
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> HyperLogLogArray<P, BITS, N>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new HyperLogLogArray with the given precision and number of bits.
§Example
use hyperloglog_rs::prelude::*;
let hll_array = HyperLogLogArray::<Precision12, 6, 3>::new();
Sourcepub fn overlap_and_differences_cardinality_matrices<F: Primitive<f32>>(
&self,
other: &Self,
) -> ([[F; N]; N], [F; N], [F; N])
pub fn overlap_and_differences_cardinality_matrices<F: Primitive<f32>>( &self, other: &Self, ) -> ([[F; N]; N], [F; N], [F; 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.
Sourcepub fn normalized_overlap_and_differences_cardinality_matrices<F: Primitive<f32>>(
&self,
other: &Self,
) -> ([[F; N]; N], [F; N], [F; N])
pub fn normalized_overlap_and_differences_cardinality_matrices<F: Primitive<f32>>( &self, other: &Self, ) -> ([[F; N]; N], [F; N], [F; N])
Returns the estimated normalized overlap and difference cardinality matrices and vectors with the provided HyperLogLogArray.
§Arguments
other
: The HyperLogLogArray to estimate the normalized overlap and difference cardinality matrices and vectors with.
§Returns
The estimated normalized overlap and difference cardinality matrices and vectors with the provided HyperLogLogArray.
Trait Implementations§
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> AsMut<[HyperLogLog<P, BITS>; N]> for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> AsMut<[HyperLogLog<P, BITS>; N]> for HyperLogLogArray<P, BITS, N>
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> AsRef<[HyperLogLog<P, BITS>; N]> for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> AsRef<[HyperLogLog<P, BITS>; N]> for HyperLogLogArray<P, BITS, N>
Source§impl<P: Clone + Precision + WordType<BITS>, const BITS: usize, const N: usize> Clone for HyperLogLogArray<P, BITS, N>
impl<P: Clone + Precision + WordType<BITS>, const BITS: usize, const N: usize> Clone for HyperLogLogArray<P, BITS, N>
Source§fn clone(&self) -> HyperLogLogArray<P, BITS, N>
fn clone(&self) -> HyperLogLogArray<P, BITS, N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<P: Debug + Precision + WordType<BITS>, const BITS: usize, const N: usize> Debug for HyperLogLogArray<P, BITS, N>
impl<P: Debug + Precision + WordType<BITS>, const BITS: usize, const N: usize> Debug for HyperLogLogArray<P, BITS, N>
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> Default for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> Default for HyperLogLogArray<P, BITS, N>
Source§impl<'de, P: Precision + WordType<BITS>, const BITS: usize, const N: usize> Deserialize<'de> for HyperLogLogArray<P, BITS, N>
impl<'de, P: Precision + WordType<BITS>, const BITS: usize, const N: usize> Deserialize<'de> for HyperLogLogArray<P, 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<P: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<&[&[H]]> for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<&[&[H]]> for HyperLogLogArray<P, BITS, N>
Source§fn from(items: &[&[H]]) -> Self
fn from(items: &[&[H]]) -> Self
Creates a new HyperLogLogArray from the given vector of vectors of hashable items.
§Arguments
items
: The vector of vectors of hashable items to create the HyperLogLogArray from.
§Returns
A new HyperLogLogArray from the given vector of vectors of hashable items.
§Example
use core::hash::Hash;
use hyperloglog_rs::prelude::*;
let hll_array = HyperLogLogArray::<Precision12, 6, 3>::from(&[
[1, 2, 3].as_slice(),
[4, 5, 6].as_slice(),
[7, 8, 9].as_slice(),
]);
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<&[&[H]; N]> for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<&[&[H]; N]> for HyperLogLogArray<P, BITS, N>
Source§fn from(items: &[&[H]; N]) -> Self
fn from(items: &[&[H]; N]) -> Self
Creates a new HyperLogLogArray from the given array of vectors of hashable items.
§Arguments
items
: The array of vectors of hashable items to create the HyperLogLogArray from.
§Returns
A new HyperLogLogArray from the given array of vectors of hashable items.
§Example
use core::hash::Hash;
use hyperloglog_rs::prelude::*;
let hll_array = HyperLogLogArray::<Precision12, 6, 3>::from(&[
[1, 2, 3].as_slice(),
[4, 5, 6].as_slice(),
[7, 8, 9].as_slice(),
]);
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> From<&[HyperLogLog<P, BITS>]> for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> From<&[HyperLogLog<P, BITS>]> for HyperLogLogArray<P, BITS, N>
Source§fn from(counters: &[HyperLogLog<P, BITS>]) -> Self
fn from(counters: &[HyperLogLog<P, BITS>]) -> Self
Creates a new HyperLogLogArray from the given vector of HyperLogLog counters.
§Arguments
counters
: The vector of HyperLogLog counters to create the HyperLogLogArray from.
§Returns
A new HyperLogLogArray from the given vector of HyperLogLog counters.
§Example
use hyperloglog_rs::prelude::*;
let hll_array = HyperLogLogArray::<Precision12, 6, 3>::from(vec![
HyperLogLog::default(),
HyperLogLog::default(),
HyperLogLog::default(),
].as_slice());
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<[&[H]; N]> for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<[&[H]; N]> for HyperLogLogArray<P, BITS, N>
Source§fn from(items: [&[H]; N]) -> Self
fn from(items: [&[H]; N]) -> Self
Creates a new HyperLogLogArray from the given array of vectors of hashable items.
§Arguments
items
: The array of vectors of hashable items to create the HyperLogLogArray from.
§Returns
A new HyperLogLogArray from the given array of vectors of hashable items.
§Example
use core::hash::Hash;
use hyperloglog_rs::prelude::*;
let hll_array = HyperLogLogArray::<Precision12, 6, 3>::from([
vec![1_usize, 2, 3].as_slice(),
vec![4, 5, 6].as_slice(),
vec![7, 8, 9].as_slice(),
]);
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> From<[HyperLogLog<P, BITS>; N]> for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> From<[HyperLogLog<P, BITS>; N]> for HyperLogLogArray<P, BITS, N>
Source§fn from(counters: [HyperLogLog<P, BITS>; N]) -> Self
fn from(counters: [HyperLogLog<P, BITS>; N]) -> Self
Creates a new HyperLogLogArray from the given array of HyperLogLog counters.
§Arguments
counters
: The array of HyperLogLog counters to create the HyperLogLogArray from.
§Returns
A new HyperLogLogArray from the given array of HyperLogLog counters.
§Example
use hyperloglog_rs::prelude::*;
let hll_array = HyperLogLogArray::<Precision12, 6, 3>::from([
HyperLogLog::default(),
HyperLogLog::default(),
HyperLogLog::default(),
]);
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> Index<usize> for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> Index<usize> for HyperLogLogArray<P, 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
use hyperloglog_rs::prelude::*;
let mut hll_array = HyperLogLogArray::<Precision12, 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§type Output = HyperLogLog<P, BITS>
type Output = HyperLogLog<P, BITS>
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> IndexMut<usize> for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> IndexMut<usize> for HyperLogLogArray<P, 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
use hyperloglog_rs::prelude::*;
let mut hll_array = HyperLogLogArray::<Precision12, 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<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> PartialEq for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> PartialEq for HyperLogLogArray<P, BITS, N>
Source§impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> Serialize for HyperLogLogArray<P, BITS, N>
impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> Serialize for HyperLogLogArray<P, 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
.
use serde::Serialize;
use serde_json::Serializer;
use hyperloglog_rs::prelude::*;
let mut hll_array = HyperLogLogArray::<Precision12, 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");