#![allow(dead_code)]
#[cfg(feature = "std")]
use crate::raw::build::BuilderNode;
use crate::raw::CompiledAddr;
#[cfg(feature = "std")]
use std::collections::hash_map::{Entry, HashMap};
#[derive(Debug)]
#[cfg(feature = "std")]
pub struct Registry {
table: HashMap<BuilderNode, RegistryCell>,
}
#[derive(Debug)]
pub enum RegistryEntry<'a> {
Found(CompiledAddr),
NotFound(&'a mut RegistryCell),
Rejected,
}
#[derive(Clone, Copy, Debug)]
pub struct RegistryCell(CompiledAddr);
#[cfg(feature = "std")]
impl Registry {
pub fn new(table_size: usize, _lru_size: usize) -> Registry {
Registry { table: HashMap::with_capacity(table_size) }
}
pub fn entry<'a>(&'a mut self, bnode: &BuilderNode) -> RegistryEntry<'a> {
match self.table.entry(bnode.clone()) {
Entry::Occupied(v) => RegistryEntry::Found(v.get().0),
Entry::Vacant(v) => {
RegistryEntry::NotFound(v.insert(RegistryCell(0)))
}
}
}
}
impl RegistryCell {
pub fn insert(&mut self, addr: CompiledAddr) {
self.0 = addr;
}
}