+/**
+ * \brief Change the hashtable size
+ * \param dict a dictionary
+ * \param hashsize the new hashtable size
+ *
+ * Change the hashtable size is a long operation, so it's better
+ * to use xbt_dict_new_ext or to call xbt_dict_hashsize_set when
+ * the dictionary is empty.
+ */
+void xbt_dict_hashsize_set(xbt_dict_t dict, int hashsize) {
+ xbt_dict_t new_dict = xbt_dict_new_ext(hashsize);
+ xbt_dictelm_t element, next;
+ int i;
+
+ for (i = 0; i < dict->table_size; i++) {
+ element = dict->table[i];
+ while (element != NULL) {
+ next = element->next; /* save the next because it will be lost */
+ xbt_dict_add_element(new_dict, element); /* no new xbt_dictelm_t is mallocated */
+ element = next;
+ }
+ }
+
+ xbt_free(dict->table);
+ dict->table = new_dict->table;
+ dict->table_size = hashsize;
+ xbt_free(new_dict);
+}
+
+/**
+ * Returns the hash code of a string.
+ */
+unsigned int xbt_dict_hash(const char *str) {
+ /* fast implementation of djb2 algorithm */
+ unsigned int hash = 5381;
+ int c;
+
+ while ((c = *str++)) {
+ hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
+ }
+
+ return hash;
+}
+