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>
impl<'a, C: GeoConfig<Diff>> GeoDiffMetric<'a, C>
Sourcepub fn new(filter: GeoDiffCount<'a, C>) -> Self
pub fn new(filter: GeoDiffCount<'a, C>) -> Self
Takes ownership of filter, caching its number of one-bits.
Sourcepub fn filter(&self) -> &GeoDiffCount<'a, C>
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>
impl<C: GeoConfig<Diff> + Default> MetricSpace for GeoDiffMetric<'_, C>
Source§fn size(&self) -> OnesMetric<C>
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>
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>
type Metric = OnesMetric<C>
Self::size and Self::symmetric_diff_size.