mod clustered;
mod linear;
use distances::number::UInt;
use crate::Instance;
use super::CodecData;
pub enum Algorithm {
Linear,
Clustered,
}
impl Default for Algorithm {
fn default() -> Self {
Self::Clustered
}
}
impl Algorithm {
pub fn search<I, U, M>(&self, query: &I, radius: U, data: &CodecData<I, U, M>) -> Vec<(usize, U)>
where
I: Instance,
U: UInt,
M: Instance,
{
match self {
Self::Linear => linear::search(query, radius, data),
Self::Clustered => clustered::search(query, radius, data),
}
}
#[must_use]
pub const fn name(&self) -> &str {
match self {
Self::Linear => "Linear",
Self::Clustered => "Clustered",
}
}
pub fn from_name(s: &str) -> Result<Self, String> {
match s.to_lowercase().as_str() {
"linear" => Ok(Self::Linear),
"clustered" => Ok(Self::Clustered),
_ => Err(format!("Unknown algorithm: {s}")),
}
}
#[must_use]
pub fn variants() -> Box<[Self]> {
vec![Self::Clustered].into_boxed_slice()
}
#[must_use]
pub const fn baseline() -> Self {
Self::Linear
}
}