// use std::borrow::Borrow; use std::collections::HashMap; use std::hash::Hash; use std::sync::Arc; use parking_lot::Mutex; pub struct InsertOnlyCHashMap { base: Mutex>>, } impl InsertOnlyCHashMap { #[inline] pub fn new() -> Self { Self { base: Mutex::new(HashMap::new()), } } // #[inline] // pub fn get(&self, key: &Q) -> Option> // where // K: Borrow, // Q: Hash + Eq, // { // self.base.lock().get(key).map(|v| Arc::clone(v)) // } #[inline] pub fn get_or_insert_with V>(&self, key: K, default: F) -> Arc { Arc::clone( self.base .lock() .entry(key) .or_insert_with(|| Arc::new(default())), ) } }