XBT_PUBLIC xbt_dict_t xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn);
XBT_PUBLIC void xbt_dict_free(xbt_dict_t* dict);
-XBT_PUBLIC unsigned int xbt_dict_size(xbt_dict_t dict);
+XBT_PUBLIC unsigned int xbt_dict_size(const_xbt_dict_t dict);
/** @} */
/** @defgroup XBT_dict_basic Dictionaries basic usage
*/
XBT_PUBLIC void xbt_dict_set(xbt_dict_t dict, const char* key, void* data);
-XBT_PUBLIC void* xbt_dict_get(xbt_dict_t dict, const char* key);
-XBT_PUBLIC void* xbt_dict_get_or_null(xbt_dict_t dict, const char* key);
-XBT_PUBLIC char* xbt_dict_get_key(xbt_dict_t dict, const void* data);
-XBT_PUBLIC xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char* key);
-XBT_PUBLIC xbt_dictelm_t xbt_dict_get_elm_or_null(xbt_dict_t dict, const char* key);
+XBT_PUBLIC void* xbt_dict_get(const_xbt_dict_t dict, const char* key);
+XBT_PUBLIC void* xbt_dict_get_or_null(const_xbt_dict_t dict, const char* key);
+XBT_PUBLIC char* xbt_dict_get_key(const_xbt_dict_t dict, const void* data);
+XBT_PUBLIC xbt_dictelm_t xbt_dict_get_elm(const_xbt_dict_t dict, const char* key);
+XBT_PUBLIC xbt_dictelm_t xbt_dict_get_elm_or_null(const_xbt_dict_t dict, const char* key);
XBT_PUBLIC void xbt_dict_remove(xbt_dict_t dict, const char* key);
XBT_PUBLIC void xbt_dict_reset(xbt_dict_t dict);
-XBT_PUBLIC int xbt_dict_length(xbt_dict_t dict);
-XBT_PUBLIC int xbt_dict_is_empty(xbt_dict_t dict);
+XBT_PUBLIC int xbt_dict_length(const_xbt_dict_t dict);
+XBT_PUBLIC int xbt_dict_is_empty(const_xbt_dict_t dict);
/** @} */
/** @defgroup XBT_dict_nnul Dictionaries with non-nul terminated keys
* @{
*/
XBT_PUBLIC void xbt_dict_set_ext(xbt_dict_t dict, const char* key, int key_len, void* data);
-XBT_PUBLIC void* xbt_dict_get_ext(xbt_dict_t dict, const char* key, int key_len);
-XBT_PUBLIC void* xbt_dict_get_or_null_ext(xbt_dict_t dict, const char* key, int key_len);
+XBT_PUBLIC void* xbt_dict_get_ext(const_xbt_dict_t dict, const char* key, int key_len);
+XBT_PUBLIC void* xbt_dict_get_or_null_ext(const_xbt_dict_t dict, const char* key, int key_len);
XBT_PUBLIC void xbt_dict_remove_ext(xbt_dict_t dict, const char* key, int key_len);
struct s_xbt_dict_cursor {
xbt_dictelm_t current;
int line;
- xbt_dict_t dict;
+ const_xbt_dict_t dict;
};
/** @} */
return cursor->current;
}
-XBT_PUBLIC xbt_dict_cursor_t xbt_dict_cursor_new(const xbt_dict_t dict);
+XBT_PUBLIC xbt_dict_cursor_t xbt_dict_cursor_new(const_xbt_dict_t dict);
XBT_PUBLIC void xbt_dict_cursor_free(xbt_dict_cursor_t* cursor);
XBT_PUBLIC void xbt_dict_cursor_rewind(xbt_dict_cursor_t cursor);
-XBT_PUBLIC char* xbt_dict_cursor_get_key(xbt_dict_cursor_t cursor);
-XBT_PUBLIC void* xbt_dict_cursor_get_data(xbt_dict_cursor_t cursor);
+XBT_PUBLIC char* xbt_dict_cursor_get_key(const_xbt_dict_cursor_t cursor);
+XBT_PUBLIC void* xbt_dict_cursor_get_data(const_xbt_dict_cursor_t cursor);
-XBT_PUBLIC void xbt_dict_cursor_first(const xbt_dict_t dict, xbt_dict_cursor_t* cursor);
+XBT_PUBLIC void xbt_dict_cursor_first(const_xbt_dict_t dict, xbt_dict_cursor_t* cursor);
XBT_PUBLIC void xbt_dict_cursor_step(xbt_dict_cursor_t cursor);
XBT_PUBLIC int xbt_dict_cursor_get_or_free(xbt_dict_cursor_t* cursor, char** key, void** data);
/** @def xbt_dict_foreach
}
/** Returns the amount of elements in the dict */
-unsigned int xbt_dict_size(xbt_dict_t dict)
+unsigned int xbt_dict_size(const_xbt_dict_t dict)
{
return (dict != nullptr ? static_cast<unsigned int>(dict->count) : static_cast<unsigned int>(0));
}
*
* 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)
+void* xbt_dict_get_ext(const_xbt_dict_t dict, const char* key, int key_len)
{
unsigned int hash_code = xbt_str_hash_ext(key, key_len);
const s_xbt_dictelm* current = dict->table[hash_code & dict->table_size];
}
/** @brief like xbt_dict_get_ext(), but returning nullptr when not found */
-void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, int key_len)
+void* xbt_dict_get_or_null_ext(const_xbt_dict_t dict, const char* key, int key_len)
{
unsigned int hash_code = xbt_str_hash_ext(key, key_len);
const s_xbt_dictelm* current = dict->table[hash_code & dict->table_size];
*
* Returns nullptr if the object cannot be found
*/
-char *xbt_dict_get_key(xbt_dict_t dict, const void *data)
+char* xbt_dict_get_key(const_xbt_dict_t dict, const void* data)
{
for (int i = 0; i <= dict->table_size; i++) {
const s_xbt_dictelm* current = dict->table[i];
* 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)
+void* xbt_dict_get(const_xbt_dict_t dict, const char* key)
{
return xbt_dict_get_elm(dict, key)->content;
}
* 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)
+xbt_dictelm_t xbt_dict_get_elm(const_xbt_dict_t dict, const char* key)
{
xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key);
/**
* @brief like xbt_dict_get(), but returning nullptr when not found
*/
-void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key)
+void* xbt_dict_get_or_null(const_xbt_dict_t dict, const char* key)
{
const s_xbt_dictelm* current = xbt_dict_get_elm_or_null(dict, key);
/**
* @brief like xbt_dict_get_elm(), but returning nullptr when not found
*/
-xbt_dictelm_t xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key)
+xbt_dictelm_t xbt_dict_get_elm_or_null(const_xbt_dict_t dict, const char* key)
{
unsigned int hash_code = xbt_str_hash(key);
xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
* @brief Return the number of elements in the dict.
* @param dict a dictionary
*/
-int xbt_dict_length(xbt_dict_t dict)
+int xbt_dict_length(const_xbt_dict_t dict)
{
return dict->count;
}
/**
* @brief test if the dict is empty or not
*/
-int xbt_dict_is_empty(xbt_dict_t dict)
+int xbt_dict_is_empty(const_xbt_dict_t dict)
{
return not dict || (xbt_dict_length(dict) == 0);
}
/** @brief Creator
* @param dict the dict
*/
-inline xbt_dict_cursor_t xbt_dict_cursor_new(const xbt_dict_t dict)
+inline xbt_dict_cursor_t xbt_dict_cursor_new(const_xbt_dict_t dict)
{
xbt_dict_cursor_t res = xbt_new(struct s_xbt_dict_cursor, 1);
res->dict = dict;
* @param dict on what to let the cursor iterate
* @param[out] cursor dest address
*/
-inline void xbt_dict_cursor_first(const xbt_dict_t dict, xbt_dict_cursor_t * cursor)
+inline void xbt_dict_cursor_first(const_xbt_dict_t dict, xbt_dict_cursor_t* cursor)
{
XBT_CDEBUG(xbt_dict_cursor, "xbt_dict_cursor_first");
if (!*cursor) {
* @param cursor: the cursor
* @returns the current key
*/
-inline char *xbt_dict_cursor_get_key(xbt_dict_cursor_t cursor)
+inline char* xbt_dict_cursor_get_key(const_xbt_dict_cursor_t cursor)
{
__cursor_not_null(cursor);
* @param cursor the cursor
* @returns the current data
*/
-inline void *xbt_dict_cursor_get_data(xbt_dict_cursor_t cursor)
+inline void* xbt_dict_cursor_get_data(const_xbt_dict_cursor_t cursor)
{
__cursor_not_null(cursor);
return head;
}
-static void search_ext(xbt_dict_t head, const char* key, const char* data)
+static void search_ext(const_xbt_dict_t head, const char* key, const char* data)
{
INFO("Search " << STR(key));
char* found = (char*)xbt_dict_get(head, key);
}
}
-static void search(xbt_dict_t head, const char* key)
+static void search(const_xbt_dict_t head, const char* key)
{
search_ext(head, key, key);
}
xbt_dict_remove(head, key);
}
-static void traverse(xbt_dict_t head)
+static void traverse(const_xbt_dict_t head)
{
xbt_dict_cursor_t cursor = nullptr;
char* key;
}
}
-static void search_not_found(xbt_dict_t head, const char* data)
+static void search_not_found(const_xbt_dict_t head, const char* data)
{
INFO("Search " << STR(data) << " (expected not to be found)");
REQUIRE_THROWS_AS(xbt_dict_get(head, data), std::out_of_range);
}
-static void count(xbt_dict_t dict, int length)
+static void count(const_xbt_dict_t dict, int length)
{
INFO("Count elements (expecting " << length << ")");
REQUIRE(xbt_dict_length(dict) == length); // Announced length differs
REQUIRE(effective == length); // Effective length differs
}
-static void count_check_get_key(xbt_dict_t dict, int length)
+static void count_check_get_key(const_xbt_dict_t dict, int length)
{
xbt_dict_cursor_t cursor;
char* key;
REQUIRE(effective == length); // Effective length differs
}
-static int countelems(xbt_dict_t head)
+static int countelems(const_xbt_dict_t head)
{
xbt_dict_cursor_t cursor;
char* key;