use crate::node::PlaceholderKind;
use std::collections::HashMap;
pub struct NormalizationContext {
mappings: HashMap<(String, PlaceholderKind), usize>,
counters: HashMap<PlaceholderKind, usize>,
}
impl NormalizationContext {
#[must_use]
pub fn new() -> Self {
Self {
mappings: HashMap::new(),
counters: HashMap::new(),
}
}
pub fn placeholder(&mut self, name: &str, kind: PlaceholderKind) -> usize {
let key = (name.to_string(), kind);
if let Some(&idx) = self.mappings.get(&key) {
return idx;
}
let counter = self.counters.entry(kind).or_insert(0);
let idx = *counter;
*counter += 1;
self.mappings.insert(key, idx);
idx
}
}
impl Default for NormalizationContext {
fn default() -> Self {
Self::new()
}
}