SimGrid: Dictionaries basic usage

SimGrid 3.10 Versatile Simulation of Distributed Systems

- Home page
- Online documentation
- Dev's Corner

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Functions
Dictionaries basic usage
Dict: generic dictionnary

## Functions
void | xbt_dict_set (xbt_dict_t dict, const char *key, void *data, void_f_pvoid_t free_ctn)
| Add data to the dict (null-terminated key)
void * | xbt_dict_get (xbt_dict_t dict, const char *key)
| Retrieve data from the dict (null-terminated key)
void * | xbt_dict_get_or_null (xbt_dict_t dict, const char *key)
| like xbt_dict_get(), but returning NULL when not found
char * | xbt_dict_get_key (xbt_dict_t dict, const void *data)
| retrieve the key associated to that object. Warning, that's a linear search
xbt_dictelm_t | xbt_dict_get_elm (xbt_dict_t dict, const char *key)
| Retrieve element from the dict (null-terminated key)
xbt_dictelm_t | xbt_dict_get_elm_or_null (xbt_dict_t dict, const char *key)
| like xbt_dict_get_elm(), but returning NULL when not found
void | xbt_dict_remove (xbt_dict_t dict, const char *key)
| Remove data from the dict (null-terminated key)
void | xbt_dict_reset (xbt_dict_t dict)
| Remove all data from the dict.
int | xbt_dict_length (xbt_dict_t dict)
| Return the number of elements in the dict.
void | xbt_dict_dump_output_string (void *s)
| function to be used in xbt_dict_dump as long as the stored values are strings
void | xbt_dict_dump (xbt_dict_t dict, void(*output)(void *))
| Outputs the content of the structure (debugging purpose)
void | xbt_dict_dump_sizes (xbt_dict_t dict)
| shows some debugging info about the bucklet repartition
int | xbt_dict_is_empty (xbt_dict_t dict)
| test if the dict is empty or not

## Detailed Description

Careful, those functions assume that the key is null-terminated.

## Function Documentation

void xbt_dict_set | ( | xbt_dict_t | dict,
|  | const char * | key,
|  | void * | data,
|  | void_f_pvoid_t | free_ctn
| ) |  |

Add data to the dict (null-terminated key)

Parameters

  dict | the dict
  key | the key to set the new data
  data | the data to add in the dict
  free_ctn | function to call with (data as argument) when data is removed from the dictionary

set the data in the structure under the key, which is a null terminated string.

void* xbt_dict_get | ( | xbt_dict_t | dict,
|  | const char * | key
| ) |  |

Retrieve data from the dict (null-terminated key)

Parameters

  dict | the dealer of data
  key | the key to find data

Returns
  the data that we are looking for

Search the given key. Throws not_found_error when not found. Check xbt_dict_get_or_null() for a version returning NULL without exception when not found.

char* xbt_dict_get_key | ( | xbt_dict_t | dict,
|  | const void * | data
| ) |  |

retrieve the key associated to that object. Warning, that's a linear search

Returns NULL if the object cannot be found

xbt_dictelm_t xbt_dict_get_elm | ( | xbt_dict_t | dict,
|  | const char * | key
| ) |  |

Retrieve element from the dict (null-terminated key)

Parameters

  dict | the dealer of data
  key | the key to find data

Returns
  the s_xbt_dictelm_t that we are looking for

Search the given key. Throws not_found_error when not found. Check xbt_dict_get_or_null() for a version returning NULL without exception when not found.

void xbt_dict_remove | ( | xbt_dict_t | dict,
|  | const char * | key
| ) |  |

Remove data from the dict (null-terminated key)

Parameters

  dict | the dict
  key | the key of the data to be removed

Remove the entry associated with the given key

void xbt_dict_reset | ( | xbt_dict_t | dict | ) |

Remove all data from the dict.

Parameters

  dict | the dict

int xbt_dict_length | ( | xbt_dict_t | dict | ) |

Return the number of elements in the dict.

Parameters

  dict | a dictionary

void xbt_dict_dump | ( | xbt_dict_t | dict,
|  | void_f_pvoid_t | output
| ) |  |

Outputs the content of the structure (debugging purpose)

Parameters

  dict | the exibitionist
  output | a function to dump each data in the tree (check xbt_dict_dump_output_string)

Outputs the content of the structure. (for debugging purpose). output is a function to output the data. If NULL, data won't be displayed.