Skip to main content

GeoDiffMetric

Struct GeoDiffMetric 

Source
pub struct GeoDiffMetric<'a, C: GeoConfig<Diff>> { /* private fields */ }
Expand description

A GeoDiffCount paired with its cached one-bit count.

Taking ownership of a filter and caching its number of one-bits lets the exact bit-count (“ones”) distance to other filters be computed repeatedly - as needed for nearest-neighbor search - and, given a bound, abandoned early. The cached count (see Self::size) also yields an O(1) reverse-triangle lower bound on the distance. Once the nearest neighbor is found, Self::filter gives access to the underlying filter for a calibrated size estimate.

The one-bit distance is a noisy estimate of the true difference size, so this metric is best used with GeoDiffConfig10 or GeoDiffConfig13 (b >= 10). The coarser GeoDiffConfig7 can reorder candidates whose true distances are within roughly a factor of two of each other, returning an approximate rather than exact nearest neighbor; for an exact result, shortlist with this metric and re-rank the top candidates with Count::size_with_sketch.

Implementations§

Source§

impl<'a, C: GeoConfig<Diff>> GeoDiffMetric<'a, C>

Source

pub fn new(filter: GeoDiffCount<'a, C>) -> Self

Takes ownership of filter, caching its number of one-bits.

Source

pub fn filter(&self) -> &GeoDiffCount<'a, C>

The wrapped filter, e.g. to compute a calibrated size estimate once the nearest neighbor is known.

Trait Implementations§

Source§

impl<C: GeoConfig<Diff> + Default> MetricSpace for GeoDiffMetric<'_, C>

Source§

fn size(&self) -> OnesMetric<C>

The size of the wrapped filter, measured as its number of one-bits. The reverse-triangle lower bound on the distance between two filters is a.size().abs_diff(&b.size()).

Source§

fn symmetric_diff_size( &self, other: &Self, bound: OnesMetric<C>, ) -> OnesMetric<C>

The exact ones-distance (Hamming distance) to other, but abandoned as soon as at least bound differing bits have been counted, in which case Metric::infinite is returned. Otherwise (the distance is strictly below bound) the exact distance is returned. Pass Metric::infinite as the bound to always compute the exact distance.

A reverse-triangle rejection using the cached one-bit counts (|ones(a) - ones(b)| <= distance(a, b)) discards far candidates in O(1). Otherwise the dense lower bits shared by both filters are XOR-counted block by block directly, which is much faster than the general bit-chunk merge; only the sparse upper region (the boundary block and everything above it, where the most-significant positions live) falls back to the merge. Counting from least to most significant reaches bound early for far-apart filters, whose differing bits are concentrated in the dense lower region.

Source§

type Metric = OnesMetric<C>

The metric type produced by Self::size and Self::symmetric_diff_size.

Auto Trait Implementations§

§

impl<'a, C> Freeze for GeoDiffMetric<'a, C>
where C: Freeze, <C as GeoConfig<Diff>>::BucketType: Freeze,

§

impl<'a, C> RefUnwindSafe for GeoDiffMetric<'a, C>

§

impl<'a, C> Send for GeoDiffMetric<'a, C>
where C: Send,

§

impl<'a, C> Sync for GeoDiffMetric<'a, C>
where C: Sync,

§

impl<'a, C> Unpin for GeoDiffMetric<'a, C>
where C: Unpin, <C as GeoConfig<Diff>>::BucketType: Unpin,

§

impl<'a, C> UnsafeUnpin for GeoDiffMetric<'a, C>

§

impl<'a, C> UnwindSafe for GeoDiffMetric<'a, C>

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