INNER CODE UNIT · Rust

get_or_insert_with

xoriors/rencfs · src/arc_hashmap.rs:68

    pub fn get_or_insert_with<F>(&self, key: K, f: F) -> Holder<'_, K, V>
    where
        F: FnOnce() -> V,
    {
        let mut map = self.map.write().expect("cannot obtain lock");
        self.get_internal(Some(
            map.entry(key)
                .or_insert_with(|| (Arc::new(f()), Arc::new(AtomicUsize::new(0)))),
        ))
        .unwrap()
    }

    fn purge(&self) {
        let mut map = self.map.write().unwrap();
        map.retain(|_, v| v.1.load(Ordering::SeqCst) > 0);
    }

    pub fn is_empty(&self) -> bool {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…