use distances::Number;
use crate::{Cluster, Dataset, PartitionCriteria};
#[derive(Debug)]
pub struct Tree<T: Send + Sync + Copy, U: Number, D: Dataset<T, U>> {
data: D,
root: Cluster<T, U>,
depth: usize,
center: 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 {
let root = Cluster::new_root(&data, data.indices(), seed);
let depth = root.max_leaf_depth();
let center = root.center;
Self {
data,
root,
depth,
center,
}
}
#[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(crate) const fn root(&self) -> &Cluster<T, U> {
&self.root
}
pub(crate) const fn depth(&self) -> usize {
self.depth
}
pub(crate) const fn center(&self) -> T {
self.center
}
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()
}
}