Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove unused parameter 'free_ctn' for xbt_dict_set() and xbt_dict_set_ext().
[simgrid.git] / src / xbt / dict.cpp
index 178b151..44361dc 100644 (file)
 #include "xbt/log.h"
 #include "xbt/mallocator.h"
 #include "xbt/str.h"
+#include "xbt/string.hpp"
 
 #include <cstdio>
 #include <cstring>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict, xbt, "Dictionaries provide the same functionalities as hash tables");
 
+constexpr int MAX_FILL_PERCENT = 80;
+
 /**
  * @brief Constructor
  * @param free_ctn function to call with (@a data as argument) when @a data is removed from the dictionary
@@ -127,13 +130,11 @@ static void xbt_dict_rehash(xbt_dict_t dict)
  * @param key the key to set the new data
  * @param key_len the size of the @a key
  * @param data the data to add in the dict
- * @param free_ctn unused parameter (kept for compatibility)
  *
  * Set the @a data in the structure under the @a key, which can be any kind of data, as long as its length is provided
  * in @a key_len.
  */
-void xbt_dict_set_ext(xbt_dict_t dict, const char* key, int key_len, void* data,
-                      XBT_ATTRIB_UNUSED void_f_pvoid_t free_ctn)
+void xbt_dict_set_ext(xbt_dict_t dict, const char* key, int key_len, void* data)
 {
   unsigned int hash_code = xbt_str_hash_ext(key, key_len);
 
@@ -175,13 +176,12 @@ void xbt_dict_set_ext(xbt_dict_t dict, const char* key, int key_len, void* data,
  * @param dict the dict
  * @param key the key to set the new data
  * @param data the data to add in the dict
- * @param free_ctn unused parameter (kept for compatibility)
  *
- * set the @a data in the structure under the @a key, which is anull terminated string.
+ * set the @a data in the structure under the @a key, which is a null terminated string.
  */
-void xbt_dict_set(xbt_dict_t dict, const char *key, void *data, void_f_pvoid_t free_ctn)
+void xbt_dict_set(xbt_dict_t dict, const char* key, void* data)
 {
-  xbt_dict_set_ext(dict, key, strlen(key), data, free_ctn);
+  xbt_dict_set_ext(dict, key, strlen(key), data);
 }
 
 /**
@@ -192,7 +192,7 @@ void xbt_dict_set(xbt_dict_t dict, const char *key, void *data, void_f_pvoid_t f
  * @param key_len the size of the @a key
  * @return the data that we are looking for
  *
- * Search the given @a key. Throws not_found_error when not found.
+ * Search the given @a key. Throws std::out_of_range when not found.
  */
 void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len)
 {
@@ -205,7 +205,7 @@ void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len)
   }
 
   if (current == nullptr)
-    THROWF(not_found_error, 0, "key %.*s not found", key_len, key);
+    throw std::out_of_range(simgrid::xbt::string_printf("key %.*s not found", key_len, key));
 
   return current->content;
 }
@@ -252,7 +252,7 @@ char *xbt_dict_get_key(xbt_dict_t dict, const void *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.
+ * Search the given @a key. Throws std::out_of_range when not found.
  * Check xbt_dict_get_or_null() for a version returning nullptr without exception when not found.
  */
 void *xbt_dict_get(xbt_dict_t dict, const char *key)
@@ -267,7 +267,7 @@ void *xbt_dict_get(xbt_dict_t dict, const char *key)
  * @param key the key to find data
  * @return the s_xbt_dictelm_t that we are looking for
  *
- * Search the given @a key. Throws not_found_error when not found.
+ * Search the given @a key. Throws std::out_of_range when not found.
  * Check xbt_dict_get_or_null() for a version returning nullptr without exception when not found.
  */
 xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key)
@@ -275,7 +275,7 @@ xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key)
   xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key);
 
   if (current == nullptr)
-    THROWF(not_found_error, 0, "key %s not found", key);
+    throw std::out_of_range(simgrid::xbt::string_printf("key %s not found", key));
 
   return current;
 }
@@ -313,7 +313,7 @@ xbt_dictelm_t xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key)
  * @param key the key of the data to be removed
  * @param key_len the size of the @a key
  *
- * Remove the entry associated with the given @a key (throws not_found)
+ * Remove the entry associated with the given @a key (throws std::out_of_range)
  */
 void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len)
 {
@@ -328,7 +328,7 @@ void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len)
   }
 
   if (current == nullptr)
-    THROWF(not_found_error, 0, "key %.*s not found", key_len, key);
+    throw std::out_of_range(simgrid::xbt::string_printf("key %.*s not found", key_len, key));
   else {
     if (previous != nullptr) {
       previous->next = current->next;
@@ -395,40 +395,6 @@ int xbt_dict_is_empty(xbt_dict_t dict)
   return not dict || (xbt_dict_length(dict) == 0);
 }
 
-/**
- * @brief Outputs the content of the structure (debugging purpose)
- *
- * @param dict the exibitionist
- * @param output a function to dump each data in the tree
- *
- * Outputs the content of the structure. (for debugging purpose).
- * @a output is a function to output the data. If nullptr, data won't be displayed.
- */
-void xbt_dict_dump(xbt_dict_t dict, void_f_pvoid_t output)
-{
-  xbt_dictelm_t element;
-  printf("Dict %p:\n", dict);
-  if (dict != nullptr) {
-    for (int i = 0; i < dict->table_size; i++) {
-      element = dict->table[i];
-      if (element) {
-        printf("[\n");
-        while (element != nullptr) {
-          printf(" %s -> '", element->key);
-          if (output != nullptr) {
-            output(element->content);
-          }
-          printf("'\n");
-          element = element->next;
-        }
-        printf("]\n");
-      } else {
-        printf("[]\n");
-      }
-    }
-  }
-}
-
 /**
  * Create the dict mallocators.
  * This is an internal XBT function called during the lib initialization.