use crate::distance::Distance;
use crate::hnsw::{Config, Hnsw, PruneStrategy};
#[derive(Clone, Debug, Default)]
pub struct Builder {
config: Config,
seed: Option<u64>,
}
impl Builder {
pub fn new() -> Self {
Self::default()
}
pub fn m(mut self, m: usize) -> Self {
self.config.m = m;
self
}
pub fn m0(mut self, m0: usize) -> Self {
self.config.m0 = Some(m0);
self
}
pub fn ef_construction(mut self, ef: usize) -> Self {
self.config.ef_construction = ef;
self
}
pub fn heuristic(mut self, yes: bool) -> Self {
self.config.use_heuristic = yes;
self
}
pub fn extend_candidates(mut self, yes: bool) -> Self {
self.config.extend_candidates = yes;
self
}
pub fn keep_pruned(mut self, yes: bool) -> Self {
self.config.keep_pruned = yes;
self
}
pub fn prune_strategy(mut self, strategy: PruneStrategy) -> Self {
self.config.prune_strategy = strategy;
self
}
pub fn capacity(mut self, n: usize) -> Self {
self.config.capacity = n;
self
}
pub fn seed(mut self, seed: u64) -> Self {
self.seed = Some(seed);
self
}
pub fn build<D: Distance>(self, metric: D) -> Hnsw<D> {
match self.seed {
Some(s) => Hnsw::new_with_seed(self.config, metric, s),
None => Hnsw::new(self.config, metric),
}
}
pub fn into_config(self) -> Config {
self.config
}
}