pub fn insert(&mut self, k: K, v: V) -> Option<Arc<V>> {
        use std::collections::hash_map::Entry;
        let k = Rc::new(k);
        let v = Arc::new(v);

        // need to update the entry
        if let Entry::Occupied(mut entry) = self.map.entry(k.clone()) {
            return Some(entry.insert(v));
        }

        // If the capacity is exceeded, remove old entry from the cache
        while self.fifo.len() > self.size - 1 {
            let entry = self
                .fifo
                .pop_front()
                .expect("failed to pop_front from FifoCache");
            self.map
                .remove(&entry)
                .expect("failed to remove from FifoCache");
        }

        // need to insert the entry
        let k1 = k.clone();
        self.fifo.push_back(k1);
        self.map.insert(k, v)
    }
/// insert a KV pair into the FifoCache
/// If the FifoCache did not have this key present, None is returned.
/// If the FifoCache did have this key present, the value is updated, and the old
/// value is returned. The key is not updated, though; this matters for
/// types that can be `==` without being identical.
/// If the size of FifoCache is larger than the maxed size, the oldest entries
/// would be removed.
insert a KV pair into the FifoCache
If the FifoCache did not have this key present, None is returned.
If the FifoCache did have this key present, the value is updated, and the old
value is returned. The key is not updated, though; this matters for
types that can be `==` without being identical.
If the size of FifoCache is larger than the maxed size, the oldest entries
would be removed.
insert a KV pair into the FifoCache If the FifoCache did not have this key present None is returned . If the FifoCache did have this key present the value is updated and the old value is returned . The key is not updated though ; this matters for types that can be ` == ` without being identical . If the size of FifoCache is larger than the maxed size the oldest entries would be removed .
pub fn insert(&mut self, k: K, v: V) -> Option<Arc<V>> {
        use std::collections::hash_map::Entry;
        let k = Rc::new(k);
        let v = Arc::new(v);
        // need to update the entry
        if let Entry::Occupied(mut entry) = self.map.entry(k.clone()) {
            return Some(entry.insert(v));
        }
        // If the capacity is exceeded, remove old entry from the cache
        while self.fifo.len() > self.size - 1 {
            let entry = self
                .fifo
                .pop_front()
                .expect("failed to pop_front from FifoCache");
            self.map
                .remove(&entry)
                .expect("failed to remove from FifoCache");
        }
        // need to insert the entry
        let k1 = k.clone();
        self.fifo.push_back(k1);
        self.map.insert(k, v)
    }
pub fn insert ( & mut self , k : K , v : V ) -> Option < Arc < V > > { use std :: collections :: hash_map :: Entry ; let k = Rc :: new ( k ) ; let v = Arc :: new ( v ) ; // need to update the entry if let Entry :: Occupied ( mut entry ) = self . map . entry ( k . clone ( ) ) { return Some ( entry . insert ( v ) ) ; } // If the capacity is exceeded, remove old entry from the cache while self . fifo . len ( ) > self . size - 1 { let entry = self . fifo . pop_front ( ) . expect ( " " ) ; self . map . remove ( & entry ) . expect ( " " ) ; } // need to insert the entry let k1 = k . clone ( ) ; self . fifo . push_back ( k1 ) ; self . map . insert ( k , v ) }
insert a KV pair into the FifoCache
If the FifoCache did not have this key present, None is returned.
insert a KV pair into the FifoCache If the FifoCache did not have this key present None is returned .
&mut self
k
K
v
V