Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Various cleanups and some more debug
[simgrid.git] / src / xbt / dict.c
index af1977d..2ddab30 100644 (file)
@@ -78,12 +78,13 @@ void xbt_dict_free(xbt_dict_t *dict) {
   if (dict != NULL && *dict != NULL) {
     table_size = (*dict)->table_size;
     table = (*dict)->table;
-    for (i = 0; i < table_size; i++) {
+    for (i = 0; (*dict)->count && i < table_size; i++) {
       current = table[i];
       while (current != NULL) {
        previous = current;
        current = current->next;
        xbt_dictelm_free(previous);
+       (*dict)->count--;
       }
     }
     xbt_free(table);
@@ -92,6 +93,13 @@ void xbt_dict_free(xbt_dict_t *dict) {
   }
 }
 
+/**
+ * Returns the amount of elements in the dict
+ */
+unsigned int xbt_dict_size(xbt_dict_t dict) {   
+      return dict->count;
+}
+
 /**
  * Returns the hash code of a string.
  */
@@ -503,7 +511,7 @@ void xbt_dict_dump_sizes(xbt_dict_t dict) {
 
   int i;
   unsigned int count;
-  int size;
+  unsigned int size;
   xbt_dictelm_t element;
   xbt_dynar_t sizes = xbt_dynar_new(sizeof(int),NULL);
    
@@ -548,7 +556,7 @@ void xbt_dict_dump_sizes(xbt_dict_t dict) {
         continue;
        if (size==0)
         continue;
-       printf("%delm x %d cells; ",count,size);
+       printf("%delm x %u cells; ",count,size);
     }
   }
   printf("\n");