Struct HyperLogLogArray

Source
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>

Source

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();
Source

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.

Source

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>

Source§

fn as_mut(&mut self) -> &mut [HyperLogLog<P, BITS>; N]

Returns a mutable reference to the underlying array of HyperLogLog counters.

§Returns

A mutable reference to the underlying array of HyperLogLog counters.

Source§

impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> AsRef<[HyperLogLog<P, BITS>; N]> for HyperLogLogArray<P, BITS, N>

Source§

fn as_ref(&self) -> &[HyperLogLog<P, BITS>; N]

Returns a reference to the underlying array of HyperLogLog counters.

§Returns

A reference to the underlying array of HyperLogLog counters.

Source§

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>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Debug + Precision + WordType<BITS>, const BITS: usize, const N: usize> Debug for HyperLogLogArray<P, BITS, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: Precision + WordType<BITS>, const BITS: usize, const N: usize> Default for HyperLogLogArray<P, BITS, N>

Source§

fn default() -> Self

Creates a new HyperLogLogArray with the given precision and number of bits.

§Returns

A new HyperLogLogArray with the given precision and number of bits.

§Example
use hyperloglog_rs::prelude::*;

let hll_array = HyperLogLogArray::<Precision12, 6, 3>::default();
Source§

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>

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>

Source§

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>

Source§

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>

Source§

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>

Source§

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>

Source§

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>

Source§

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>

The returned type after indexing.
Source§

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

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>

Source§

fn eq(&self, other: &Self) -> bool

Returns true if the HyperLogLogArray is equal to the other HyperLogLogArray.

§Arguments
  • other: The other HyperLogLogArray to compare to.
§Returns

True if the HyperLogLogArray is equal to the other HyperLogLogArray.

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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>

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");
Source§

impl<P: Copy + Precision + WordType<BITS>, const BITS: usize, const N: usize> Copy for HyperLogLogArray<P, BITS, N>

Source§

impl<P: Eq + Precision + WordType<BITS>, const BITS: usize, const N: usize> Eq for HyperLogLogArray<P, BITS, N>

Auto Trait Implementations§

§

impl<P, const BITS: usize, const N: usize> Freeze for HyperLogLogArray<P, BITS, N>
where <P as WordType<BITS>>::Words: Freeze, <P as Precision>::NumberOfZeros: Freeze,

§

impl<P, const BITS: usize, const N: usize> RefUnwindSafe for HyperLogLogArray<P, BITS, N>

§

impl<P, const BITS: usize, const N: usize> Send for HyperLogLogArray<P, BITS, N>

§

impl<P, const BITS: usize, const N: usize> Sync for HyperLogLogArray<P, BITS, N>

§

impl<P, const BITS: usize, const N: usize> Unpin for HyperLogLogArray<P, BITS, N>
where <P as WordType<BITS>>::Words: Unpin, <P as Precision>::NumberOfZeros: Unpin,

§

impl<P, const BITS: usize, const N: usize> UnwindSafe for HyperLogLogArray<P, BITS, N>
where <P as WordType<BITS>>::Words: UnwindSafe, <P as Precision>::NumberOfZeros: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,