use crate::dataset::Dataset;
use crate::number::Number;
use super::{Cluster, PartitionCriteria};
#[derive(Debug)]
pub struct Tree<T: Number, U: Number, D: Dataset<T, U>> {
data: D,
root: Cluster<T, U, D>,
_t: std::marker::PhantomData<T>,
}
impl<T: Number, 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, D> {
&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 par_partition(mut self, criteria: &PartitionCriteria<T, U, D>, recursive: bool) -> Self {
self.root = self.root.par_partition(&self.data, criteria, recursive);
self
}
pub fn partition(mut self, criteria: &PartitionCriteria<T, U, D>, recursive: bool) -> Self {
self.root = self.root.partition(&self.data, criteria, recursive);
self
}
pub fn indices(&self) -> &[usize] {
self.root.indices(&self.data)
}
pub fn depth_first_reorder(mut self) -> Self {
let leaf_indices = self.root.leaf_indices();
self.data.reorder(&leaf_indices);
self.root.dfr(&self.data, 0);
self
}
}