Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bugfix: I inverted the semantic of xbt_dict_get_or_null_ext and xbt_dict_get_ext...
[simgrid.git] / src / xbt / dict.c
index 0e02729..f116e5a 100644 (file)
@@ -324,6 +324,27 @@ void *xbt_dict_get_ext(xbt_dict_t dict,
 
   return current->content;
 }
+/**
+ * \brief like xbt_dict_get_ext(), but returning NULL when not found
+ */
+void *xbt_dict_get_or_null_ext(xbt_dict_t dict,
+                               const char *key, int key_len) {
+  unsigned int hash_code = xbt_dict_hash_ext(key,key_len);
+  xbt_dictelm_t current;
+
+  xbt_assert(dict);
+
+  current = dict->table[hash_code & dict->table_size];
+  while (current != NULL &&
+      (hash_code != current->hash_code || key_len != current->key_len || memcmp(key, current->key, key_len))) {
+    current = current->next;
+  }
+
+  if (current == NULL)
+    return NULL;
+
+  return current->content;
+}
 
 /**
  * \brief Retrieve data from the dict (null-terminated key)