use crate::patterns::Pattern;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DictionaryEntry {
pub pattern: Pattern,
pub local_frequency: u64,
pub network_frequency: u64,
}
pub struct PatternDictionary {
entries: Vec<DictionaryEntry>,
}
impl PatternDictionary {
pub fn new() -> Self {
Self { entries: Vec::new() }
}
pub fn add(&mut self, entry: DictionaryEntry) {
self.entries.push(entry);
}
pub fn get(&self, id: &[u8; 32]) -> Option<&DictionaryEntry> {
self.entries.iter().find(|e| e.pattern.id == *id)
}
}
impl Default for PatternDictionary {
fn default() -> Self {
Self::new()
}
}
lazy_static::lazy_static! {
pub static ref GLOBAL_PATTERN_DICT: std::sync::RwLock<PatternDictionary> =
std::sync::RwLock::new(PatternDictionary::new());
}