use std::collections::HashMap;
use crate::{MatchTable, Matcher, ProcessType, SimpleMatcher};
#[derive(Default)]
pub struct SimpleMatcherBuilder<'a> {
word_map: HashMap<ProcessType, HashMap<u32, &'a str>>,
}
impl<'a> SimpleMatcherBuilder<'a> {
pub fn new() -> Self {
Self {
word_map: HashMap::new(),
}
}
pub fn add_word(mut self, process_type: ProcessType, word_id: u32, word: &'a str) -> Self {
self.word_map
.entry(process_type)
.or_default()
.insert(word_id, word);
self
}
pub fn build(self) -> SimpleMatcher {
SimpleMatcher::new(&self.word_map)
}
}
#[derive(Default)]
pub struct MatcherBuilder<'a> {
table_map: HashMap<u32, Vec<MatchTable<'a>>>,
}
impl<'a> MatcherBuilder<'a> {
pub fn new() -> Self {
Self {
table_map: HashMap::new(), }
}
pub fn add_table(mut self, match_id: u32, table: MatchTable<'a>) -> Self {
self.table_map.entry(match_id).or_default().push(table);
self
}
pub fn build(self) -> Matcher {
Matcher::new(&self.table_map)
}
}