#[derive(Debug, Clone, Default)]
pub struct GraphReuseCounter {
reuse_count: u64,
hot_threshold: u64,
cache_enabled: bool,
}
impl GraphReuseCounter {
pub fn new(hot_threshold: u64) -> Self {
Self { reuse_count: 0, hot_threshold, cache_enabled: false }
}
pub fn record_use(&mut self) {
self.reuse_count += 1;
if self.reuse_count >= self.hot_threshold {
self.cache_enabled = true;
}
}
#[must_use]
pub fn is_hot(&self) -> bool {
self.reuse_count >= self.hot_threshold
}
#[must_use]
pub fn should_cache(&self) -> bool {
self.cache_enabled
}
#[must_use]
pub fn count(&self) -> u64 {
self.reuse_count
}
pub fn reset(&mut self) {
self.reuse_count = 0;
self.cache_enabled = false;
}
}