fst/raw/
registry_minimal.rs1#![allow(dead_code)]
13
14use std::collections::hash_map::{Entry, HashMap};
15
16use crate::raw::build::BuilderNode;
17use crate::raw::CompiledAddr;
18
19#[derive(Debug)]
20pub struct Registry {
21 table: HashMap<BuilderNode, RegistryCell>,
22}
23
24#[derive(Debug)]
25pub enum RegistryEntry<'a> {
26 Found(CompiledAddr),
27 NotFound(&'a mut RegistryCell),
28 Rejected,
29}
30
31#[derive(Clone, Copy, Debug)]
32pub struct RegistryCell(CompiledAddr);
33
34impl Registry {
35 pub fn new(table_size: usize, _lru_size: usize) -> Registry {
36 Registry { table: HashMap::with_capacity(table_size) }
37 }
38
39 pub fn entry<'a>(&'a mut self, bnode: &BuilderNode) -> RegistryEntry<'a> {
40 match self.table.entry(bnode.clone()) {
41 Entry::Occupied(v) => RegistryEntry::Found(v.get().0),
42 Entry::Vacant(v) => {
43 RegistryEntry::NotFound(v.insert(RegistryCell(0)))
44 }
45 }
46 }
47}
48
49impl RegistryCell {
50 pub fn insert(&mut self, addr: CompiledAddr) {
51 self.0 = addr;
52 }
53}