src/config/config.cc
/*
 * Adds the given value to the configuration dictionary under the given key.
 * Copies of the given key and value are used in the dictionary.
 *
 * Assumes the given key and value are non-null and valid.
 */
Adds the given value to the configuration dictionary under the given key.
Copies of the given key and value are used in the dictionary.

Assumes the given key and value are non-null and valid.
Adds the given value to the configuration dictionary under the given key . Copies of the given key and value are used in the dictionary . Assumes the given key and value are non - null and valid .
void Config::Set(const char *key, const char *val) {
  size_t index = Hash(key);
  DictElem *elem = dict_[index];
  DictElem *last_elem = NULL;
  while (elem != NULL) {
    if (StrEq(elem->key, key)) {
      delete[] elem->val;
      elem->val = StrCpy(val);
      return;
    }
    last_elem = elem;
    elem = elem->next;
  }
  if (last_elem == NULL) {
    dict_[index] = new DictElem();
    elem = dict_[index];
  } else {
    last_elem->next = new DictElem();
    elem = last_elem->next;
  }
  elem->key = StrCpy(key);
  elem->val = StrCpy(val);
  return;
}
void Config :: Set ( const char * key , const char * val ) { size_t index = Hash ( key ) ; DictElem * elem = dict_ [ index ] ; DictElem * last_elem = NULL ; while ( elem != NULL ) { if ( StrEq ( elem -> key , key ) ) { delete [ ] elem -> val ; elem -> val = StrCpy ( val ) ; return ; } last_elem = elem ; elem = elem -> next ; } if ( last_elem == NULL ) { dict_ [ index ] = new DictElem ( ) ; elem = dict_ [ index ] ; } else { last_elem -> next = new DictElem ( ) ; elem = last_elem -> next ; } elem -> key = StrCpy ( key ) ; elem -> val = StrCpy ( val ) ; return ; }
Adds the given value to the configuration dictionary under the given key.
Adds the given value to the configuration dictionary under the given key .
// If the key is already in the configuration dictionary, the value // is updated. // If the key is not already in the dictionary, then a new element is // created for it and its value is set.