pub struct HyperLogLogArray<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> { /* private fields */ }
Implementations§
source§impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, 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
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.
Trait Implementations§
source§impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> AsMut<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> AsMut<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
source§impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> AsRef<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> AsRef<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
source§impl<PRECISION: Clone + Precision + WordType<BITS>, const BITS: usize, const N: usize> Clone for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Clone + Precision + WordType<BITS>, 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<PRECISION: Debug + Precision + WordType<BITS>, const BITS: usize, const N: usize> Debug for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Debug + Precision + WordType<BITS>, const BITS: usize, const N: usize> Debug for HyperLogLogArray<PRECISION, BITS, N>
source§impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> Default for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> Default for HyperLogLogArray<PRECISION, BITS, N>
source§impl<'de, PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> Deserialize<'de> for HyperLogLogArray<PRECISION, BITS, N>
impl<'de, PRECISION: Precision + WordType<BITS>, 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<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<&[&[H]]> for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<&[&[H]]> for HyperLogLogArray<PRECISION, 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<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<&[&[H]; N]> for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<&[&[H]; N]> for HyperLogLogArray<PRECISION, 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<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> From<&[HyperLogLog<PRECISION, BITS>]> for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> From<&[HyperLogLog<PRECISION, BITS>]> for HyperLogLogArray<PRECISION, BITS, N>
source§fn from(counters: &[HyperLogLog<PRECISION, BITS>]) -> Self
fn from(counters: &[HyperLogLog<PRECISION, 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<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<[&[H]; N]> for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize, H: Hash> From<[&[H]; N]> for HyperLogLogArray<PRECISION, 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<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> From<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> From<[HyperLogLog<PRECISION, BITS>; N]> for HyperLogLogArray<PRECISION, BITS, N>
source§fn from(counters: [HyperLogLog<PRECISION, BITS>; N]) -> Self
fn from(counters: [HyperLogLog<PRECISION, 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<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> Index<usize> for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, 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
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
);
§type Output = HyperLogLog<PRECISION, BITS>
type Output = HyperLogLog<PRECISION, BITS>
source§impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> IndexMut<usize> for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, 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
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<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> PartialEq for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> PartialEq for HyperLogLogArray<PRECISION, BITS, N>
source§impl<PRECISION: Precision + WordType<BITS>, const BITS: usize, const N: usize> Serialize for HyperLogLogArray<PRECISION, BITS, N>
impl<PRECISION: Precision + WordType<BITS>, 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
.
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");