use std::collections::HashMap;
use std::sync::Arc;
use super::zobrist::Zobrist;
#[derive(Clone, Debug)]
pub struct RepetitionCounts {
counts: Arc<HashMap<Zobrist, u8>>,
}
impl Default for RepetitionCounts {
fn default() -> Self {
Self::new()
}
}
impl RepetitionCounts {
pub fn new() -> Self {
Self { counts: Arc::new(HashMap::new()) }
}
pub fn append(&self, hash: Zobrist) -> Self {
let mut counts = (*self.counts).clone();
*counts.entry(hash).or_insert(0) += 1;
Self { counts: Arc::new(counts) }
}
pub fn num_repetitions(&self, hash: Zobrist) -> u8 {
self.counts.get(&hash).copied().unwrap_or(0)
}
}