use std::collections::HashSet;
use purrdf_hash::fixed::FixedState;
use crate::cost::{hash_entry, shared_text};
use crate::item::SharedStr;
pub(crate) const INTERN_ENTRY_BYTES: usize = hash_entry::<SharedStr>() + shared_text(0);
#[derive(Debug, Default)]
pub(crate) struct Interner {
strings: HashSet<SharedStr, FixedState>,
}
impl Interner {
pub(crate) fn intern(&mut self, text: &str) -> (SharedStr, usize) {
if let Some(known) = self.strings.get(text) {
return (known.clone(), 0);
}
let shared = SharedStr::from(text);
self.strings.insert(shared.clone());
(shared, text.len() + INTERN_ENTRY_BYTES)
}
}