//! Compile cache (L1): hash -> Arc<ClosureNode>.

use std::sync::Arc;
use std::collections::HashMap;
use pfcl_types::Hash;
use crate::closure_node::ClosureNode;

pub struct CompileCache {
    entries: HashMap<Hash, Arc<ClosureNode>>,
}

impl CompileCache {
    pub fn new() -> Self { Self { entries: HashMap::new() } }
    pub fn get(&self, hash: &Hash) -> Option<Arc<ClosureNode>> { self.entries.get(hash).cloned() }
    pub fn insert(&mut self, hash: Hash, node: Arc<ClosureNode>) { self.entries.insert(hash, node); }
    pub fn len(&self) -> usize { self.entries.len() }
    pub fn is_empty(&self) -> bool { self.entries.is_empty() }
}

impl Default for CompileCache {
    fn default() -> Self { Self::new() }
}
