pub trait Distance:
Send
+ Sync
+ Sized
+ Clone
+ Debug
+ 'static {
type Header: Pod + Zeroable + Debug;
type VectorCodec: UnalignedVectorCodec;
const DEFAULT_OVERSAMPLING: usize = 1usize;
Show 16 methods
// Required methods
fn name() -> &'static str;
fn new_header(vector: &UnalignedVector<Self::VectorCodec>) -> Self::Header;
fn built_distance(p: &Leaf<'_, Self>, q: &Leaf<'_, Self>) -> f32;
fn norm_no_header(v: &UnalignedVector<Self::VectorCodec>) -> f32;
fn init(node: &mut Leaf<'_, Self>);
fn create_split<'a, R: Rng>(
children: &'a ImmutableSubsetLeafs<'_, Self>,
rng: &mut R,
) -> Result<Cow<'a, UnalignedVector<Self::VectorCodec>>>;
fn margin_no_header(
p: &UnalignedVector<Self::VectorCodec>,
q: &UnalignedVector<Self::VectorCodec>,
) -> f32;
// Provided methods
fn non_built_distance(p: &Leaf<'_, Self>, q: &Leaf<'_, Self>) -> f32 { ... }
fn normalized_distance(d: f32, _dimensions: usize) -> f32 { ... }
fn pq_distance(distance: f32, margin: f32, side: Side) -> f32 { ... }
fn norm(leaf: &Leaf<'_, Self>) -> f32 { ... }
fn normalize(node: &mut Leaf<'_, Self>) { ... }
fn update_mean(
mean: &mut Leaf<'_, Self>,
new_node: &Leaf<'_, Self>,
norm: f32,
c: f32,
) { ... }
fn margin(p: &Leaf<'_, Self>, q: &Leaf<'_, Self>) -> f32 { ... }
fn side<R: Rng>(
normal_plane: &UnalignedVector<Self::VectorCodec>,
node: &Leaf<'_, Self>,
rng: &mut R,
) -> Side { ... }
fn preprocess(
_wtxn: &mut RwTxn<'_>,
_new_iter: impl for<'a> Fn(&'a mut RwTxn<'_>) -> Result<RwPrefix<'a, KeyCodec, NodeCodec<Self>>>,
) -> Result<()> { ... }
}Expand description
A trait used by arroy to compute the distances, compute the split planes, and normalize user vectors.
Provided Associated Constants§
const DEFAULT_OVERSAMPLING: usize = 1usize
Required Associated Types§
Required Methods§
fn name() -> &'static str
fn new_header(vector: &UnalignedVector<Self::VectorCodec>) -> Self::Header
Sourcefn built_distance(p: &Leaf<'_, Self>, q: &Leaf<'_, Self>) -> f32
fn built_distance(p: &Leaf<'_, Self>, q: &Leaf<'_, Self>) -> f32
Returns a non-normalized distance.
fn norm_no_header(v: &UnalignedVector<Self::VectorCodec>) -> f32
fn init(node: &mut Leaf<'_, Self>)
fn create_split<'a, R: Rng>( children: &'a ImmutableSubsetLeafs<'_, Self>, rng: &mut R, ) -> Result<Cow<'a, UnalignedVector<Self::VectorCodec>>>
fn margin_no_header( p: &UnalignedVector<Self::VectorCodec>, q: &UnalignedVector<Self::VectorCodec>, ) -> f32
Provided Methods§
fn non_built_distance(p: &Leaf<'_, Self>, q: &Leaf<'_, Self>) -> f32
Sourcefn normalized_distance(d: f32, _dimensions: usize) -> f32
fn normalized_distance(d: f32, _dimensions: usize) -> f32
Normalizes the distance returned by the distance method.
fn pq_distance(distance: f32, margin: f32, side: Side) -> f32
fn norm(leaf: &Leaf<'_, Self>) -> f32
fn normalize(node: &mut Leaf<'_, Self>)
fn update_mean( mean: &mut Leaf<'_, Self>, new_node: &Leaf<'_, Self>, norm: f32, c: f32, )
fn margin(p: &Leaf<'_, Self>, q: &Leaf<'_, Self>) -> f32
fn side<R: Rng>( normal_plane: &UnalignedVector<Self::VectorCodec>, node: &Leaf<'_, Self>, rng: &mut R, ) -> Side
fn preprocess( _wtxn: &mut RwTxn<'_>, _new_iter: impl for<'a> Fn(&'a mut RwTxn<'_>) -> Result<RwPrefix<'a, KeyCodec, NodeCodec<Self>>>, ) -> Result<()>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.