use crate::token::Token;
use std::collections::HashMap;
/// Stores the number of token occourances in a document.
#[derive(Debug, Clone)]
pub struct TokenStatistics {
pub token_occurances: HashMap<Token, usize>,
}
impl TokenStatistics {
pub fn new() -> Self {
Self {
token_occurances: HashMap::new(),
}
}
pub fn count_token(&mut self, token: Token) {
self.token_occurances
.entry(token)
.and_modify(|n| *n += 1)
.or_insert(1);
}
}
impl Default for TokenStatistics {
fn default() -> Self {
Self::new()
}
}