use distances::Number;
use crate::dataset::Dataset;
use super::{Cluster, PartitionCriteria};
#[derive(Debug)]
pub struct Tree<T: Send + Sync + Copy, U: Number, D: Dataset<T, U>> {
data: D,
root: Cluster<T, U>,
_t: std::marker::PhantomData<T>,
}
impl<T: Send + Sync + Copy, U: Number, D: Dataset<T, U>> Tree<T, U, D> {
pub fn new(data: D, seed: Option<u64>) -> Self {
Tree {
root: Cluster::new_root(&data, data.indices(), seed),
data,
_t: Default::default(),
}
}
pub(crate) fn root(&self) -> &Cluster<T, U> {
&self.root
}
pub fn data(&self) -> &D {
&self.data
}
pub fn cardinality(&self) -> usize {
self.root.cardinality
}
pub fn radius(&self) -> U {
self.root.radius
}
pub fn partition(mut self, criteria: &PartitionCriteria<T, U>) -> Self {
self.root = self.root.partition(&mut self.data, criteria);
self
}
pub fn indices(&self) -> &[usize] {
self.data.indices()
}
}