use distances::Number;
use crate::{Dataset, Instance, Tree};
pub(crate) mod clustered;
pub(crate) mod linear;
#[derive(Clone, Copy, Debug)]
pub enum Algorithm {
Linear,
Clustered,
}
impl Default for Algorithm {
fn default() -> Self {
Self::Clustered
}
}
impl Algorithm {
pub fn search<I, U, D>(self, query: &I, radius: U, tree: &Tree<I, U, D>) -> Vec<(usize, U)>
where
I: Instance,
U: Number,
D: Dataset<I, U>,
{
match self {
Self::Linear => {
let indices = (0..tree.cardinality()).collect::<Vec<_>>();
linear::search(tree.data(), query, radius, &indices)
}
Self::Clustered => clustered::search(tree, query, radius),
}
}
#[must_use]
pub const fn name(&self) -> &str {
match self {
Self::Linear => "Linear",
Self::Clustered => "Clustered",
}
}
#[must_use]
pub const fn variants<'a>() -> &'a [Self] {
&[Self::Clustered]
}
}