pub fn insert(&mut self, key: Arc<K>, value: V, cost: u64) -> Option<Arc<V>> {
        let ret = self.remove(&key);
        let ind = self.find_empty();
        let old_head = self.entries_head;

        self.entries[ind] = CacheEntry::Occupied(OccupiedEntry {
            key: key.clone(),
            item: Arc::new(value),
            prev: None,
            next: self.entries_head,
            cost,
        });
        self.entries_head = Some(ind);
        self.index.insert(key, ind);
        self.current_cost += cost;

        // Link up the prev of the old head.
        if let Some(h) = old_head {
            self.entries[h].as_occupied_mut().prev = self.entries_head;
        }

        // If there's no tail this was the first insert and we need one.
        if self.entries_tail.is_none() {
            self.entries_tail = Some(ind);
        }

        self.maybe_evict();
        ret
    }
/// Add an entry to the cache.  Return the old entry if this key was already present.
Add an entry to the cache.  Return the old entry if this key was already present.
Add an entry to the cache . Return the old entry if this key was already present .
pub fn insert(&mut self, key: Arc<K>, value: V, cost: u64) -> Option<Arc<V>> {
        let ret = self.remove(&key);
        let ind = self.find_empty();
        let old_head = self.entries_head;
        self.entries[ind] = CacheEntry::Occupied(OccupiedEntry {
            key: key.clone(),
            item: Arc::new(value),
            prev: None,
            next: self.entries_head,
            cost,
        });
        self.entries_head = Some(ind);
        self.index.insert(key, ind);
        self.current_cost += cost;
        // Link up the prev of the old head.
        if let Some(h) = old_head {
            self.entries[h].as_occupied_mut().prev = self.entries_head;
        }
        // If there's no tail this was the first insert and we need one.
        if self.entries_tail.is_none() {
            self.entries_tail = Some(ind);
        }
        self.maybe_evict();
        ret
    }
pub fn insert ( & mut self , key : Arc < K > , value : V , cost : u64 ) -> Option < Arc < V > > { let ret = self . remove ( & key ) ; let ind = self . find_empty ( ) ; let old_head = self . entries_head ; self . entries [ ind ] = CacheEntry :: Occupied ( OccupiedEntry { key : key . clone ( ) , item : Arc :: new ( value ) , prev : None , next : self . entries_head , cost , } ) ; self . entries_head = Some ( ind ) ; self . index . insert ( key , ind ) ; self . current_cost += cost ; // Link up the prev of the old head. if let Some ( h ) = old_head { self . entries [ h ] . as_occupied_mut ( ) . prev = self . entries_head ; } // If there's no tail this was the first insert and we need one. if self . entries_tail . is_none ( ) { self . entries_tail = Some ( ind ) ; } self . maybe_evict ( ) ; ret }
Add an entry to the cache.
Add an entry to the cache .
&mut self
key
Arc<K>
value
V
cost
u64
&mut self
key
Arc<K>
value
V
cost
u64