use serde::{Deserialize, Serialize}; use space::Metric; #[derive(Debug, Default, Clone, Copy, Serialize, Deserialize)] pub struct DotProduct; impl Metric> for DotProduct { type Unit = u32; // TODO explain me this function, I don't understand why f32.to_bits is ordered. // I tried to do this and it wasn't OK // // Following . fn distance(&self, a: &Vec, b: &Vec) -> Self::Unit { let dist: f32 = a.iter().zip(b).map(|(a, b)| a * b).sum(); let dist = 1.0 - dist; debug_assert!(!dist.is_nan()); dist.to_bits() } }