[][src]Trait space::MetricPoint

pub trait MetricPoint {
    fn distance(&self, rhs: &Self) -> u32;
}

This trait is implemented by points inside of a metric space.

It is important that all points that implement this trait satisfy the triangle inequality. This requirement basically means that the sum of distances that start at a point A and end at a point B can never be less than the distance from A to B directly. All implementors must also take care to avoid negative numbers, as valid distances are only positive numbers.

In practice, the u32 distance returned by this trait should only be used to compare distances between points in a metric space. If the distances are added, one would need to take care of overflow. Regardless of the underlying representation (float or integer), one can map the metric distance into the set of 32-bit integers. This may cause some loss of precision, but the choice to use 32 bits of precision is one that is done with practicality in mind. Specifically, there may be cases where only a few bits of precision are needed (hamming distance), but there may also be cases where a 32-bit floating point number may be different by only one bit of precision. It is trivial to map a 32-bit float to the unsigned integers for comparison, as IEEE 754 is designed such that a direct bit-to-bit translation of a 32-bit float to a 32-bit signed integer will compare as intended using a standard signed integer comparation operation. 64-bit floating point numbers must be truncated to their upper 32-bits and loose some precision. This loss is acceptable in most scenarios. 32-bit integers are widely supported on embedded and desktop processors as native registers.

If you have a floating distance, use f32_metric or f64_metric. Keep in mind that f64_metric will cause precision loss of 32 bits.

Required methods

fn distance(&self, rhs: &Self) -> u32

Loading content...

Implementors

impl MetricPoint for Hamming<u8>[src]

impl MetricPoint for Hamming<u16>[src]

impl MetricPoint for Hamming<u32>[src]

impl MetricPoint for Hamming<u64>[src]

impl MetricPoint for Hamming<u128>[src]

Loading content...