pub fn insert(&mut self, item: KeyValue) {
        let KeyValue { key, value } = item;
        let mut already_exists = false;
        // Check for existing item
        match self.map.entry(key.clone()) {
            Entry::Occupied(mut occupied) => {
                occupied.insert(value);
                already_exists = true;
            }
            Entry::Vacant(entry) => {
                entry.insert(value);
            }
        }

        if already_exists {
            self.move_key_to_front(key);
        } else {
            // Add new item
            self.evict_list.push_front(key);
        }

        // Verify size not exceeded
        if self.evict_list.len() as u32 > self.max_len {
            self.remove_oldest();
            self.dropped_count += 1;
        }
    }
/// Inserts a key-value pair into the map.
Inserts a key-value pair into the map.
Inserts a key - value pair into the map .
pub fn insert(&mut self, item: KeyValue) {
        let KeyValue { key, value } = item;
        let mut already_exists = false;
        // Check for existing item
        match self.map.entry(key.clone()) {
            Entry::Occupied(mut occupied) => {
                occupied.insert(value);
                already_exists = true;
            }
            Entry::Vacant(entry) => {
                entry.insert(value);
            }
        }
        if already_exists {
            self.move_key_to_front(key);
        } else {
            // Add new item
            self.evict_list.push_front(key);
        }
        // Verify size not exceeded
        if self.evict_list.len() as u32 > self.max_len {
            self.remove_oldest();
            self.dropped_count += 1;
        }
    }
pub fn insert ( & mut self , item : KeyValue ) { let KeyValue { key , value } = item ; let mut already_exists = false ; // Check for existing item match self . map . entry ( key . clone ( ) ) { Entry :: Occupied ( mut occupied ) => { occupied . insert ( value ) ; already_exists = true ; } Entry :: Vacant ( entry ) => { entry . insert ( value ) ; } } if already_exists { self . move_key_to_front ( key ) ; } else { // Add new item self . evict_list . push_front ( key ) ; } // Verify size not exceeded if self . evict_list . len ( ) as u32 > self . max_len { self . remove_oldest ( ) ; self . dropped_count += 1 ; } }
Inserts a key-value pair into the map.
Inserts a key - value pair into the map .
&mut self
item
KeyValue
&mut self
item
KeyValue