unsigned int hash_code = xbt_str_hash_ext(key, key_len);
xbt_dictelm_t current, previous = NULL;
- xbt_assert(dict);
XBT_CDEBUG(xbt_dict,
"ADD %.*s hash = %u, size = %d, & = %u", key_len, key, hash_code,
*
* Search the given \a key. Throws not_found_error when not found.
*/
-XBT_INLINE void *xbt_dict_get_ext(xbt_dict_t dict, const char *key,
- int key_len)
+XBT_INLINE void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len)
{
-
-
unsigned int hash_code = xbt_str_hash_ext(key, key_len);
- xbt_dictelm_t current;
+ xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
- xbt_assert(dict);
-
- current = dict->table[hash_code & dict->table_size];
while (current != NULL &&
(hash_code != current->hash_code || key_len != current->key_len
|| memcmp(key, current->key, key_len))) {
return current->content;
}
-/**
- * \brief like xbt_dict_get_ext(), but returning NULL when not found
- */
-void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key,
- int key_len)
+/** @brief like xbt_dict_get_ext(), but returning NULL when not found */
+void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, int key_len)
{
-
unsigned int hash_code = xbt_str_hash_ext(key, key_len);
- xbt_dictelm_t current;
-
- xbt_assert(dict);
+ xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
- current = dict->table[hash_code & dict->table_size];
while (current != NULL &&
(hash_code != current->hash_code || key_len != current->key_len
|| memcmp(key, current->key, key_len))) {
*/
char *xbt_dict_get_key(xbt_dict_t dict, const void *data)
{
- int i;
- xbt_dictelm_t current;
-
-
- for (i = 0; i <= dict->table_size; i++) {
- current = dict->table[i];
+ for (int i = 0; i <= dict->table_size; i++) {
+ xbt_dictelm_t current = dict->table[i];
while (current != NULL) {
if (current->content == data)
return current->key;
return NULL;
}
-/**
- * @brief retrieve the key associated to that xbt_dictelm_t.
- *
- */
+/** @brief retrieve the key associated to that xbt_dictelm_t. */
char *xbt_dict_get_elm_key(xbt_dictelm_t elm)
{
return elm->key;
XBT_INLINE xbt_dictelm_t xbt_dict_get_elm_or_null(xbt_dict_t dict, const char *key)
{
unsigned int hash_code = xbt_str_hash(key);
- xbt_dictelm_t current;
-
- xbt_assert(dict);
+ xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
- current = dict->table[hash_code & dict->table_size];
while (current != NULL &&
(hash_code != current->hash_code || strcmp(key, current->key)))
current = current->next;
*
* Remove the entry associated with the given \a key (throws not_found)
*/
-XBT_INLINE void xbt_dict_remove_ext(xbt_dict_t dict, const char *key,
- int key_len)
+XBT_INLINE void xbt_dict_remove_ext(xbt_dict_t dict, const char *key, int key_len)
{
-
-
unsigned int hash_code = xbt_str_hash_ext(key, key_len);
- xbt_dictelm_t current, previous = NULL;
+ xbt_dictelm_t previous = NULL;
+ xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
- xbt_assert(dict);
-
- // fprintf(stderr,"RM %.*s hash = %d, size = %d, & = %d\n",key_len,key,hash_code, dict->table_size, hash_code & dict->table_size);
- current = dict->table[hash_code & dict->table_size];
while (current != NULL &&
(hash_code != current->hash_code || key_len != current->key_len
|| strncmp(key, current->key, key_len))) {
}
#endif
-/**
- * \brief Remove all data from the dict
- * \param dict the dict
- */
+/** @brief Remove all data from the dict */
void xbt_dict_reset(xbt_dict_t dict)
{
-
- int i;
- xbt_dictelm_t current, previous = NULL;
-
- xbt_assert(dict);
-
if (dict->count == 0)
return;
- for (i = 0; i <= dict->table_size; i++) {
- current = dict->table[i];
+ for (int i = 0; i <= dict->table_size; i++) {
+ xbt_dictelm_t previous = NULL;
+ xbt_dictelm_t current = dict->table[i];
while (current != NULL) {
previous = current;
current = current->next;
*/
XBT_INLINE int xbt_dict_length(xbt_dict_t dict)
{
- xbt_assert(dict);
-
return dict->count;
}
/** @brief shows some debugging info about the bucklet repartition */
void xbt_dict_dump_sizes(xbt_dict_t dict)
{
-
- int i;
unsigned int count;
unsigned int size;
- xbt_dictelm_t element;
+
+ printf("Dict %p: %d bucklets, %d used cells (of %d) ", dict, dict->count, dict->fill, dict->table_size);
+
+ if (!dict) {
+ printf("\n");
+ return;
+ }
xbt_dynar_t sizes = xbt_dynar_new(sizeof(int), NULL);
- printf("Dict %p: %d bucklets, %d used cells (of %d) ", dict, dict->count,
- dict->fill, dict->table_size);
- if (dict != NULL) {
- for (i = 0; i < dict->table_size; i++) {
- element = dict->table[i];
- size = 0;
- if (element) {
- while (element != NULL) {
- size++;
- element = element->next;
- }
- }
- if (xbt_dynar_length(sizes) <= size) {
- int prevsize = 1;
- xbt_dynar_set(sizes, size, &prevsize);
- } else {
- int prevsize;
- xbt_dynar_get_cpy(sizes, size, &prevsize);
- prevsize++;
- xbt_dynar_set(sizes, size, &prevsize);
+ for (int i = 0; i < dict->table_size; i++) {
+ xbt_dictelm_t element = dict->table[i];
+ size = 0;
+ if (element) {
+ while (element != NULL) {
+ size++;
+ element = element->next;
}
}
- if (!all_sizes)
- all_sizes = xbt_dynar_new(sizeof(int), NULL);
-
- xbt_dynar_foreach(sizes, count, size) {
- /* Copy values of this one into all_sizes */
- int prevcount;
- if (xbt_dynar_length(all_sizes) <= count) {
- prevcount = size;
- xbt_dynar_set(all_sizes, count, &prevcount);
- } else {
- xbt_dynar_get_cpy(all_sizes, count, &prevcount);
- prevcount += size;
- xbt_dynar_set(all_sizes, count, &prevcount);
- }
-
- /* Report current sizes */
- if (count == 0)
- continue;
- if (size == 0)
- continue;
- printf("%uelm x %u cells; ", count, size);
+ if (xbt_dynar_length(sizes) <= size) {
+ int prevsize = 1;
+ xbt_dynar_set(sizes, size, &prevsize);
+ } else {
+ int prevsize;
+ xbt_dynar_get_cpy(sizes, size, &prevsize);
+ prevsize++;
+ xbt_dynar_set(sizes, size, &prevsize);
+ }
+ }
+ if (!all_sizes)
+ all_sizes = xbt_dynar_new(sizeof(int), NULL);
+
+ xbt_dynar_foreach(sizes, count, size) {
+ /* Copy values of this one into all_sizes */
+ int prevcount;
+ if (xbt_dynar_length(all_sizes) <= count) {
+ prevcount = size;
+ xbt_dynar_set(all_sizes, count, &prevcount);
+ } else {
+ xbt_dynar_get_cpy(all_sizes, count, &prevcount);
+ prevcount += size;
+ xbt_dynar_set(all_sizes, count, &prevcount);
}
+
+ /* Report current sizes */
+ if (count == 0)
+ continue;
+ if (size == 0)
+ continue;
+ printf("%uelm x %u cells; ", count, size);
}
printf("\n");
xbt_dynar_free(&sizes);
{
xbt_replay_reader_t res = xbt_new0(s_xbt_replay_reader_t,1);
res->fp = fopen(filename, "r");
- if (res->fp == NULL)
- xbt_die("Cannot open %s: %s", filename, strerror(errno));
+ xbt_assert(res->fp != NULL, "Cannot open %s: %s", filename, strerror(errno));
res->filename = xbt_strdup(filename);
return res;
}
-const char *xbt_replay_reader_position(xbt_replay_reader_t reader)
-{
- free(reader->position);
- reader->position = bprintf("%s:%d",reader->filename,reader->linenum);
- return reader->position;
-}
-
const char **xbt_replay_reader_get(xbt_replay_reader_t reader)
{
ssize_t read;
xbt_free(lowername);
}
-/** \ingroup XBT_replay
- * \brief Unregisters a function, which handled a kind of action
- *
- * \param action_name the reference name of the action.
- */
-void xbt_replay_action_unregister(const char *action_name)
-{
- char* lowername = str_tolower (action_name);
- xbt_dict_remove(xbt_action_funs, lowername);
- xbt_free(lowername);
-}
-
/** @brief Initializes the replay mechanism, and returns true if (and only if) it was necessary
*
* It returns false if it was already done by another process.
}
CATCH(e) {
free(evt);
- xbt_die("Replay error :\n %s"
- , e.msg);
+ xbt_die("Replay error :\n %s", e.msg);
}
for (i=0;evt[i]!= NULL;i++)
free(evt[i]);
}
CATCH(e) {
free(evt);
- xbt_die("Replay error on line %d of file %s :\n %s"
- , reader->linenum,reader->filename, e.msg);
+ xbt_die("Replay error on line %d of file %s :\n %s" , reader->linenum,reader->filename, e.msg);
}
} else {
- XBT_WARN("%s: Ignore trace element not for me",
- xbt_replay_reader_position(reader));
+ XBT_WARN("%s:%d: Ignore trace element not for me", reader->filename, reader->linenum);
}
free(evt);
}