//! //! Dissimilarities for vector-vector distance //! //! Representing distances as pairwise dissimilarities, so to build a //! graph of closest neighbours. This representation can be reused for //! different implementations (initially used in this library for FastPair). use std::cmp::{Eq, Ordering, PartialOrd}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use crate::math::num::RealNumber; /// /// The edge of the subgraph is defined by `PairwiseDistance`. /// The calling algorithm can store a list of distsances as /// a list of these structures. /// #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Debug, Clone, Copy)] pub struct PairwiseDistance { /// index of the vector in the original `Matrix` or list pub node: usize, /// index of the closest neighbor in the original `Matrix` or same list pub neighbour: Option, /// measure of distance, according to the algorithm distance function /// if the distance is None, the edge has value "infinite" or max distance /// each algorithm has to match pub distance: Option, } impl Eq for PairwiseDistance {} impl PartialEq for PairwiseDistance { fn eq(&self, other: &Self) -> bool { self.node == other.node && self.neighbour == other.neighbour && self.distance == other.distance } } impl PartialOrd for PairwiseDistance { fn partial_cmp(&self, other: &Self) -> Option { self.distance.partial_cmp(&other.distance) } }