Trait EstimationLogic

Source
pub trait EstimationLogic {
    type Item;
    type Backend: ?Sized;
    type Estimator<'a>: EstimatorMut<Self>
       where Self: 'a;

    // Required methods
    fn add(&self, backend: &mut Self::Backend, element: impl Borrow<Self::Item>);
    fn estimate(&self, backend: &Self::Backend) -> f64;
    fn clear(&self, backend: &mut Self::Backend);
    fn set(&self, dst: &mut Self::Backend, src: &Self::Backend);
    fn new_estimator(&self) -> Self::Estimator<'_>;
}
Expand description

A kind of cardinality estimator.

Implementations of this trait describe the behavior of a kind of cardinality estimator. Instances contains usually parameters that further refine the behavior and the precision of the estimator.

The trait contain the following items:

  • Three associated types:
    • Item: the type of items the estimator accepts.
    • Backend: the type of the estimator backend, that is, the raw, concrete representation of the estimator state.
    • estimator<'a>: the type of a estimator of this kind.
  • A method to create a new estimator: new_estimator.
  • A method to add elements to an estimator, given its backend: add.
  • Methods to manipulate backends: estimate, clear, and set.

By providing methods based on backends, an EstimationLogic can be used to manipulate families of estimators with the same backend and the same configuration (i.e., precision) in a controlled way, and saving space by sharing common parameters. This is particularly useful to build arrays of cardinality estimators, which are array of estimators sharing the same logic.

If you plan to use a small number of non-related estimators, we suggest you create them and use their methods. More complex applications, coordinating large numbers of estimators, will find backed-based methods useful.

Required Associated Types§

Source

type Item

The type of items.

Source

type Backend: ?Sized

The type of the backend.

Source

type Estimator<'a>: EstimatorMut<Self> where Self: 'a

The type of an estimator.

Required Methods§

Source

fn add(&self, backend: &mut Self::Backend, element: impl Borrow<Self::Item>)

Adds an element to an estimator with the given backend.

Source

fn estimate(&self, backend: &Self::Backend) -> f64

Returns an estimation of the number of distinct elements that have been added to an estimator with the given backend so far.

Source

fn clear(&self, backend: &mut Self::Backend)

Clears a backend, making it empty.

Source

fn set(&self, dst: &mut Self::Backend, src: &Self::Backend)

Sets the contents of dst to the contents of src.

Source

fn new_estimator(&self) -> Self::Estimator<'_>

Creates a new empty estimator using this logic.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Hash, H: BuildHasher + Clone, W: Word + UpcastableInto<u64> + CastableFrom<u64>> EstimationLogic for HyperLogLog<T, H, W>

Source§

type Item = T

Source§

type Backend = [W]

Source§

type Estimator<'a> = DefaultEstimator<HyperLogLog<T, H, W>, &'a HyperLogLog<T, H, W>, Box<[W]>> where T: 'a, W: 'a, H: 'a