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