A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add the possibility to remove an item in the middle of the list.
[simgrid.git]
/
src
/
xbt
/
dict.c
diff --git
a/src/xbt/dict.c
b/src/xbt/dict.c
index
1e8ccdb
..
96a2d5e
100644
(file)
--- a/
src/xbt/dict.c
+++ b/
src/xbt/dict.c
@@
-8,8
+8,6
@@
/* This program is free software; you can redistribute it and/or modify it
under the terms of the license (GNU LGPL) which comes with this package. */
/* This program is free software; you can redistribute it and/or modify it
under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "gras_private.h"
#include "dict_private.h"
#include <stdlib.h> /* malloc() */
#include "dict_private.h"
#include <stdlib.h> /* malloc() */
@@
-17,7
+15,8
@@
#include <stdio.h>
#include <stdio.h>
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dict,GRAS);
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(dict,xbt,
+ "Dictionaries provide the same functionnalities than hash tables");
/*####[ Private prototypes ]#################################################*/
/*####[ Private prototypes ]#################################################*/
@@
-25,183
+24,174
@@
GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(dict,GRAS);
/*####[ Code ]###############################################################*/
/**
/*####[ Code ]###############################################################*/
/**
- *
gras
_dict_new:
+ *
xbt
_dict_new:
*
* @whereto: pointer to the destination
*
* Creates and initialize a new dictionnary
*/
*
* @whereto: pointer to the destination
*
* Creates and initialize a new dictionnary
*/
-gras_error_t
-gras_dict_new(gras_dict_t **whereto) {
- gras_dict_t *dict;
-
- if (!(dict = calloc(1, sizeof(gras_dict_t))))
- RAISE_MALLOC;
-
- dict->head=NULL;
-
- *whereto = dict;
-
- return no_error;
+xbt_dict_t
+xbt_dict_new(void) {
+ xbt_dict_t res= xbt_new(s_xbt_dict_t,1);
+ res->head=NULL;
+ return res;
}
/**
}
/**
- *
gras
_dict_free:
+ *
xbt
_dict_free:
* @dict: the dictionnary to be freed
*
* Frees a cache structure with all its childs.
*/
void
* @dict: the dictionnary to be freed
*
* Frees a cache structure with all its childs.
*/
void
-
gras_dict_free(gras_dict_t *
*dict) {
+
xbt_dict_free(xbt_dict_t
*dict) {
if (dict && *dict) {
if ((*dict)->head) {
if (dict && *dict) {
if ((*dict)->head) {
-
gras
_dictelm_free( &( (*dict)->head ) );
+
xbt
_dictelm_free( &( (*dict)->head ) );
(*dict)->head = NULL;
}
(*dict)->head = NULL;
}
- free(*dict);
+
xbt_
free(*dict);
*dict=NULL;
}
}
/**
*dict=NULL;
}
}
/**
- *
gras
_dict_set_ext:
+ *
xbt
_dict_set_ext:
*
*
- * @
p_
dict: the container
+ * @dict: the container
* @key: the key to set the new data
* @data: the data to add in the dict
* @key: the key to set the new data
* @data: the data to add in the dict
- * @Returns: a gras_error
*
* set the @data in the structure under the @key, which can be any kind
* of data, as long as its length is provided in @key_len.
*/
*
* set the @data in the structure under the @key, which can be any kind
* of data, as long as its length is provided in @key_len.
*/
-gras_error_t
-
gras_dict_set_ext(gras_dict_t *p_
dict,
-
const char *key,
-
int key_len,
-
void *data,
-
void_f_pvoid_t *free_ctn) {
+void
+
xbt_dict_set_ext(xbt_dict_t
dict,
+ const char *key,
+ int key_len,
+ void *data,
+ void_f_pvoid_t *free_ctn) {
-
gras_assert(p_
dict);
+
xbt_assert(
dict);
-
return gras_dictelm_set_ext(&(p_
dict->head),
-
key, key_len, data, free_ctn);
+
xbt_dictelm_set_ext(&(
dict->head),
+ key, key_len, data, free_ctn);
}
/**
}
/**
- *
gras
_dict_set:
+ *
xbt
_dict_set:
*
* @head: the head of the dict
* @key: the key to set the new data
* @data: the data to add in the dict
*
* @head: the head of the dict
* @key: the key to set the new data
* @data: the data to add in the dict
- * @Returns: a gras_error
*
* set the @data in the structure under the @key, which is a
* null terminated string.
*/
*
* set the @data in the structure under the @key, which is a
* null terminated string.
*/
-gras_error_t
-
gras_dict_set(gras_dict_t *p_
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,
+ void_f_pvoid_t *free_ctn) {
-
gras_assert(p_
dict);
+
xbt_assert(
dict);
-
return gras_dictelm_set(&(p_
dict->head), key, data, free_ctn);
+
xbt_dictelm_set(&(
dict->head), key, data, free_ctn);
}
/**
}
/**
- *
gras
_dict_get_ext:
+ *
xbt
_dict_get_ext:
*
* @dict: the dealer of data
* @key: the key to find data
* @data: the data that we are looking for
*
* @dict: the dealer of data
* @key: the key to find data
* @data: the data that we are looking for
- * @Returns:
gras
_error
+ * @Returns:
xbt
_error
*
* Search the given @key. mismatch_error when not found.
*/
*
* Search the given @key. mismatch_error when not found.
*/
-
gras
_error_t
-
gras_dict_get_ext(gras_dict_t *
dict,
-
const char *key,
-
int key_len,
-
/* OUT */void **data) {
+
xbt
_error_t
+
xbt_dict_get_ext(xbt_dict_t
dict,
+ const char *key,
+ int key_len,
+ /* OUT */void **data) {
-
gras
_assert(dict);
+
xbt
_assert(dict);
- return
gras
_dictelm_get_ext(dict->head, key, key_len, data);
+ return
xbt
_dictelm_get_ext(dict->head, key, key_len, data);
}
/**
}
/**
- *
gras
_dict_get:
+ *
xbt
_dict_get:
*
* @dict: the dealer of data
* @key: the key to find data
* @data: the data that we are looking for
*
* @dict: the dealer of data
* @key: the key to find data
* @data: the data that we are looking for
- * @Returns:
gras
_error
+ * @Returns:
xbt
_error
*
* Search the given @key. mismatch_error when not found.
*/
*
* Search the given @key. mismatch_error when not found.
*/
-
gras
_error_t
-
gras_dict_get(gras_dict_t *
dict,
-
const char *key,
-
/* OUT */void **data) {
-
gras
_assert(dict);
+
xbt
_error_t
+
xbt_dict_get(xbt_dict_t
dict,
+ const char *key,
+ /* OUT */void **data) {
+
xbt
_assert(dict);
- return
gras
_dictelm_get(dict->head, key, data);
+ return
xbt
_dictelm_get(dict->head, key, data);
}
/**
}
/**
- *
gras
_dict_remove_ext:
+ *
xbt
_dict_remove_ext:
*
* @dict: the trash can
* @key: the key of the data to be removed
*
* @dict: the trash can
* @key: the key of the data to be removed
- * @Returns:
gras
_error_t
+ * @Returns:
xbt
_error_t
*
* Remove the entry associated with the given @key
*/
*
* Remove the entry associated with the given @key
*/
-
gras
_error_t
-
gras_dict_remove_ext(gras_dict_t *
dict,
+
xbt
_error_t
+
xbt_dict_remove_ext(xbt_dict_t
dict,
const char *key,
int key_len) {
const char *key,
int key_len) {
-
gras
_assert(dict);
+
xbt
_assert(dict);
- return
gras
_dictelm_remove_ext(dict->head, key, key_len);
+ return
xbt
_dictelm_remove_ext(dict->head, key, key_len);
}
/**
}
/**
- *
gras
_dict_remove:
+ *
xbt
_dict_remove:
*
* @head: the head of the dict
* @key: the key of the data to be removed
*
* @head: the head of the dict
* @key: the key of the data to be removed
- * @Returns:
gras
_error_t
+ * @Returns:
xbt
_error_t
*
* Remove the entry associated with the given @key
*/
*
* Remove the entry associated with the given @key
*/
-
gras
_error_t
-
gras_dict_remove(gras_dict_t *
dict,
+
xbt
_error_t
+
xbt_dict_remove(xbt_dict_t
dict,
const char *key) {
if (!dict)
RAISE1(mismatch_error,"Asked to remove key %s from NULL dict",key);
const char *key) {
if (!dict)
RAISE1(mismatch_error,"Asked to remove key %s from NULL dict",key);
- return
gras
_dictelm_remove(dict->head, key);
+ return
xbt
_dictelm_remove(dict->head, key);
}
/**
}
/**
- *
gras
_dict_dump:
+ *
xbt
_dict_dump:
*
* @dict: the exibitionist
* @output: a function to dump each data in the tree
*
* @dict: the exibitionist
* @output: a function to dump each data in the tree
- * @Returns:
gras
_error_t
+ * @Returns:
xbt
_error_t
*
* Ouputs the content of the structure. (for debuging purpose). @ouput is a
* function to output the data. If NULL, data won't be displayed.
*/
*
* Ouputs the content of the structure. (for debuging purpose). @ouput is a
* function to output the data. If NULL, data won't be displayed.
*/
-gras_error_t
-
gras_dict_dump(gras_dict_t *
dict,
+void
+
xbt_dict_dump(xbt_dict_t
dict,
void_f_pvoid_t *output) {
void_f_pvoid_t *output) {
- printf("Dict %p:\n", dict);
-
return gras
_dictelm_dump(dict ? dict->head: NULL, output);
+ printf("Dict %p:\n",
(void*)
dict);
+
xbt
_dictelm_dump(dict ? dict->head: NULL, output);
}
}