use std::time::{Duration, Instant};
#[derive(Clone, Copy, Debug)]
pub struct TrieStats {
duration: Duration,
branches_added: u64,
leaves_added: u64,
}
impl TrieStats {
pub const fn duration(&self) -> Duration {
self.duration
}
pub const fn leaves_added(&self) -> u64 {
self.leaves_added
}
pub const fn branches_added(&self) -> u64 {
self.branches_added
}
}
#[derive(Debug)]
pub struct TrieTracker {
started_at: Instant,
branches_added: u64,
leaves_added: u64,
}
impl Default for TrieTracker {
fn default() -> Self {
Self { started_at: Instant::now(), branches_added: 0, leaves_added: 0 }
}
}
impl TrieTracker {
pub fn inc_branch(&mut self) {
self.branches_added += 1;
}
pub fn inc_leaf(&mut self) {
self.leaves_added += 1;
}
pub fn finish(self) -> TrieStats {
TrieStats {
duration: self.started_at.elapsed(),
branches_added: self.branches_added,
leaves_added: self.leaves_added,
}
}
}