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
, andset
.
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§
Sourcetype Estimator<'a>: EstimatorMut<Self>
where
Self: 'a
type Estimator<'a>: EstimatorMut<Self> where Self: 'a
The type of an estimator.
Required Methods§
Sourcefn add(&self, backend: &mut Self::Backend, element: impl Borrow<Self::Item>)
fn add(&self, backend: &mut Self::Backend, element: impl Borrow<Self::Item>)
Adds an element to an estimator with the given backend.
Sourcefn estimate(&self, backend: &Self::Backend) -> f64
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.
Sourcefn set(&self, dst: &mut Self::Backend, src: &Self::Backend)
fn set(&self, dst: &mut Self::Backend, src: &Self::Backend)
Sets the contents of dst
to the contents of src
.
Sourcefn new_estimator(&self) -> Self::Estimator<'_>
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.