pub fn insert(&mut self, key: Option<Key>, value: Value) -> Result<Addr, DictionaryErr> {
        // Remove first item with the same key
        let mut i = 0;

        match key {
            Some(ref key) => {
                while i < self.data.len() {
                    match &self.data[i].0 {
                        Some(stored_key) => {
                            if *stored_key == *key {
                                self.data.remove(i);
                                break;
                            }
                        }
                        None => {}
                    }

                    i += 1;
                }
            }
            None => {}
        }

        let addr = self.data.len();

        if addr == self.capacity {
            return Err(DictionaryErr::Overflow);
        }
        self.data.push((key, value));

        Ok(addr)
    }
/// Inserts a new value at the given key, overwriting any previous keys.
Inserts a new value at the given key, overwriting any previous keys.
Inserts a new value at the given key overwriting any previous keys .
pub fn insert(&mut self, key: Option<Key>, value: Value) -> Result<Addr, DictionaryErr> {
        // Remove first item with the same key
        let mut i = 0;
        match key {
            Some(ref key) => {
                while i < self.data.len() {
                    match &self.data[i].0 {
                        Some(stored_key) => {
                            if *stored_key == *key {
                                self.data.remove(i);
                                break;
                            }
                        }
                        None => {}
                    }
                    i += 1;
                }
            }
            None => {}
        }
        let addr = self.data.len();
        if addr == self.capacity {
            return Err(DictionaryErr::Overflow);
        }
        self.data.push((key, value));
        Ok(addr)
    }
pub fn insert ( & mut self , key : Option < Key > , value : Value ) -> Result < Addr , DictionaryErr > { // Remove first item with the same key let mut i = 0 ; match key { Some ( ref key ) => { while i < self . data . len ( ) { match & self . data [ i ] . 0 { Some ( stored_key ) => { if * stored_key == * key { self . data . remove ( i ) ; break ; } } None => { } } i += 1 ; } } None => { } } let addr = self . data . len ( ) ; if addr == self . capacity { return Err ( DictionaryErr :: Overflow ) ; } self . data . push ( ( key , value ) ) ; Ok ( addr ) }
Inserts a new value at the given key, overwriting any previous keys.
Inserts a new value at the given key overwriting any previous keys .
&mut self
key
Option<Key>
value
Value
&mut self
key
Option<Key>
value
Value