Beispiel #1
0
/**
 * \brief like xbt_dict_get_elm(), but returning NULL when not found
 */
XBT_INLINE xbt_dictelm_t xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key)
{
    unsigned int hash_code = xbt_str_hash(key);
    xbt_dictelm_t current;

    xbt_assert(dict);

    current = dict->table[hash_code & dict->table_size];
    while (current != NULL &&
            (hash_code != current->hash_code || strcmp(key, current->key)))
        current = current->next;
    return current;
}
Beispiel #2
0
/**
 * \brief Retrieve data from the dict (null-terminated key)
 *
 * \param dict the dealer of data
 * \param key the key to find data
 * \return the data that we are looking for
 *
 * Search the given \a key. Throws not_found_error when not found.
 * Check xbt_dict_get_or_null() for a version returning NULL without exception when
 * not found.
 */
XBT_INLINE void *xbt_dict_get(xbt_dict_t dict, const char *key)
{

  unsigned int hash_code = xbt_str_hash(key);
  xbt_dictelm_t current;

  xbt_assert(dict);

  current = dict->table[hash_code & dict->table_size];
  while (current != NULL
         && (hash_code != current->hash_code || strcmp(key, current->key)))
    current = current->next;

  if (current == NULL)
    THROWF(not_found_error, 0, "key %s not found", key);

  return current->content;
}