use super::summary::ImportedSite;
#[derive(Default)]
pub struct Sites {
list: Vec<ImportedSite>,
starts: Vec<u32>,
}
impl Sites {
pub(crate) fn intern(&mut self, start: u32, site: ImportedSite) -> usize {
let existing = self
.list
.iter()
.zip(&self.starts)
.position(|(known, at)| *at == start && *known == site);
existing.unwrap_or_else(|| {
self.list.push(site);
self.starts.push(start);
self.list.len() - 1
})
}
pub(crate) fn source_offset(&self, index: usize) -> Option<u32> {
self.starts.get(index).copied()
}
pub(crate) fn into_list(self) -> Vec<ImportedSite> {
self.list
}
}