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
Hey, gcc, calm down with your stupid useless warnings
[simgrid.git]
/
src
/
xbt
/
dict.c
diff --git
a/src/xbt/dict.c
b/src/xbt/dict.c
index 4bd519ba40f0f9612d836160d01478d0e7b93273..649091bb688e5321c6617fcb9f6dd5a4d707e34e 100644
(file)
--- a/
src/xbt/dict.c
+++ b/
src/xbt/dict.c
@@
-1,6
+1,6
@@
/* $Id$ */
/* $Id$ */
-/* dict - a generic diction
n
ary, variation over the B-tree concept */
+/* dict - a generic dictionary, variation over the B-tree concept */
/* Copyright (c) 2003,2004 Martin Quinson. All rights reserved. */
/* Copyright (c) 2003,2004 Martin Quinson. All rights reserved. */
@@
-19,7
+19,7
@@
#include "dict_private.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict,xbt,
#include "dict_private.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict,xbt,
- "Dictionaries provide the same function
n
alities than hash tables");
+ "Dictionaries provide the same functionalities than hash tables");
/*####[ Private prototypes ]#################################################*/
static xbt_mallocator_t dict_mallocator = NULL;
/*####[ Private prototypes ]#################################################*/
static xbt_mallocator_t dict_mallocator = NULL;
@@
-35,7
+35,7
@@
static void dict_mallocator_reset_f(void* dict);
* \return pointer to the destination
* \see xbt_dict_new_ext(), xbt_dict_free()
*
* \return pointer to the destination
* \see xbt_dict_new_ext(), xbt_dict_free()
*
- * Creates and initialize a new diction
n
ary with a default hashtable size.
+ * Creates and initialize a new dictionary with a default hashtable size.
*/
xbt_dict_t xbt_dict_new(void) {
xbt_dict_t dict;
*/
xbt_dict_t xbt_dict_new(void) {
xbt_dict_t dict;
@@
-63,7
+63,7
@@
xbt_dict_t xbt_dict_new(void) {
/**
* \brief Destructor
/**
* \brief Destructor
- * \param dict the diction
n
ary to be freed
+ * \param dict the dictionary to be freed
*
* Frees a dictionary with all the data
*/
*
* Frees a dictionary with all the data
*/
@@
-157,7
+157,7
@@
static XBT_INLINE unsigned int xbt_dict_hash(const char *str) {
/* multiply by the 32 bit FNV magic prime mod 2^32 */
hash += (hash<<1) + (hash<<4) + (hash<<7) + (hash<<8) + (hash<<24);
/* multiply by the 32 bit FNV magic prime mod 2^32 */
hash += (hash<<1) + (hash<<4) + (hash<<7) + (hash<<8) + (hash<<24);
- /* xor the bottom with the current
octet
*/
+ /* xor the bottom with the current
byte
*/
hash ^= (unsigned int)*str++;
}
hash ^= (unsigned int)*str++;
}
@@
-224,7
+224,7
@@
static void xbt_dict_rehash(xbt_dict_t dict) {
* \param key_len the size of the \a key
* \param data the data to add in the dict
* \param free_ctn function to call with (\a key as argument) when
* \param key_len the size of the \a key
* \param data the data to add in the dict
* \param free_ctn function to call with (\a key as argument) when
- * \a key is removed from the diction
n
ary
+ * \a key is removed from the dictionary
*
* 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.
*
* 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.
@@
-281,7
+281,7
@@
XBT_INLINE void xbt_dict_set_ext(xbt_dict_t dict,
* \param key the key to set the new data
* \param data the data to add in the dict
* \param free_ctn function to call with (\a key as argument) when
* \param key the key to set the new data
* \param data the data to add in the dict
* \param free_ctn function to call with (\a key as argument) when
- * \a key is removed from the diction
n
ary
+ * \a key is removed from the dictionary
*
* set the \a data in the structure under the \a key, which is a
* null terminated string.
*
* set the \a data in the structure under the \a key, which is a
* null terminated string.
@@
-320,7
+320,7
@@
void *xbt_dict_get_ext(xbt_dict_t dict,
}
if (current == NULL)
}
if (current == NULL)
-
return NULL
;
+
THROW2(not_found_error, 0, "key %.*s not found", key_len, key)
;
return current->content;
}
return current->content;
}
@@
-341,7
+341,7
@@
void *xbt_dict_get_or_null_ext(xbt_dict_t dict,
}
if (current == NULL)
}
if (current == NULL)
-
THROW2(not_found_error, 0, "key %.*s not found", key_len, key)
;
+
return NULL
;
return current->content;
}
return current->content;
}
@@
-490,13
+490,19
@@
int xbt_dict_length(xbt_dict_t dict) {
return dict->count;
}
return dict->count;
}
+/** @brief function to be used in xbt_dict_dump as long as the stored values are strings */
+void xbt_dict_dump_output_string(void *s) {
+ fputs(s,stdout);
+}
+
+
/**
/**
- * \brief Outputs the content of the structure (debuging purpose)
+ * \brief Outputs the content of the structure (debug
g
ing purpose)
*
* \param dict the exibitionist
*
* \param dict the exibitionist
- * \param output a function to dump each data in the tree
+ * \param output a function to dump each data in the tree
(check @ref xbt_dict_dump_output_string)
*
*
- * Ou
puts the content of the structure. (for debuging purpose). \a ou
put is a
+ * Ou
tputs the content of the structure. (for debugging purpose). \a out
put is a
* function to output the data. If NULL, data won't be displayed.
*/
* function to output the data. If NULL, data won't be displayed.
*/
@@
-511,11
+517,11
@@
void xbt_dict_dump(xbt_dict_t dict,
if (element) {
printf("[\n");
while (element != NULL) {
if (element) {
printf("[\n");
while (element != NULL) {
- printf(" %s -> ", element->key);
+ printf(" %s ->
'
", element->key);
if (output != NULL) {
(*output)(element->content);
}
if (output != NULL) {
(*output)(element->content);
}
- printf("\n");
+ printf("
'
\n");
element = element->next;
}
printf("]\n");
element = element->next;
}
printf("]\n");
@@
-710,7
+716,7
@@
static void traverse(xbt_dict_t head) {
xbt_test_log2("Seen #%d: %s",++i,PRINTF_STR(key));
}
xbt_test_assert2(!data || !strcmp(key,data),
xbt_test_log2("Seen #%d: %s",++i,PRINTF_STR(key));
}
xbt_test_assert2(!data || !strcmp(key,data),
- "Key(%s) != value(%s). Abor
d
ing",key,data);
+ "Key(%s) != value(%s). Abor
t
ing",key,data);
}
}
}
}
@@
-754,10
+760,10
@@
char *data;
XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse"){
XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse"){
- xbt_test_add0("Traversal the null diction
n
ary");
+ xbt_test_add0("Traversal the null dictionary");
traverse(head);
traverse(head);
- xbt_test_add0("Traversal and search the empty diction
n
ary");
+ xbt_test_add0("Traversal and search the empty dictionary");
head = xbt_dict_new();
traverse(head);
TRY {
head = xbt_dict_new();
traverse(head);
TRY {
@@
-769,7
+775,7
@@
XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse")
}
xbt_dict_free(&head);
}
xbt_dict_free(&head);
- xbt_test_add0("Traverse the full diction
n
ary");
+ xbt_test_add0("Traverse the full dictionary");
fill(&head);
count(head, 7);
fill(&head);
count(head, 7);
@@
-780,7
+786,7
@@
XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse")
search(head,"12a");
traverse(head);
search(head,"12a");
traverse(head);
- xbt_test_add0("Free the diction
n
ary (twice)");
+ xbt_test_add0("Free the dictionary (twice)");
xbt_dict_free(&head);
xbt_dict_free(&head);
xbt_dict_free(&head);
xbt_dict_free(&head);
@@
-803,7
+809,7
@@
XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse")
xbt_dict_set(head,"12a",strdup("12a"),&free);
count(head, 7);
xbt_dict_set(head,"12a",strdup("12a"),&free);
count(head, 7);
- xbt_test_add0("Traverse the resulting diction
n
ary");
+ xbt_test_add0("Traverse the resulting dictionary");
traverse(head);
/* RETRIEVE */
traverse(head);
/* RETRIEVE */
@@
-823,16
+829,16
@@
XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse")
search(head,"1234");
search(head,"123457");
search(head,"1234");
search(head,"123457");
- xbt_test_add0("Traverse the resulting diction
n
ary");
+ xbt_test_add0("Traverse the resulting dictionary");
traverse(head);
/* xbt_dict_dump(head,(void (*)(void*))&printf); */
traverse(head);
/* xbt_dict_dump(head,(void (*)(void*))&printf); */
- xbt_test_add0("Free the diction
n
ary twice");
+ xbt_test_add0("Free the dictionary twice");
xbt_dict_free(&head);
xbt_dict_free(&head);
xbt_dict_free(&head);
xbt_dict_free(&head);
- xbt_test_add0("Traverse the resulting diction
n
ary");
+ xbt_test_add0("Traverse the resulting dictionary");
traverse(head);
}
traverse(head);
}
@@
-851,7
+857,7
@@
XBT_TEST_UNIT("remove",test_dict_remove,"Removing some values"){
xbt_dict_free(&head);
xbt_dict_free(&head);
- xbt_test_add0("Remove each data manually (traversing the resulting diction
n
ary each time)");
+ xbt_test_add0("Remove each data manually (traversing the resulting dictionary each time)");
fill(&head);
debuged_remove(head,"12a"); traverse(head);
count(head, 6);
fill(&head);
debuged_remove(head,"12a"); traverse(head);
count(head, 6);
@@
-887,7
+893,7
@@
XBT_TEST_UNIT("remove",test_dict_remove,"Removing some values"){
count(head, 0);
traverse(head);
count(head, 0);
traverse(head);
- xbt_test_add0("Free the diction
n
ary twice");
+ xbt_test_add0("Free the dictionary twice");
xbt_dict_free(&head);
xbt_dict_free(&head);
}
xbt_dict_free(&head);
xbt_dict_free(&head);
}
@@
-1081,7
+1087,7
@@
XBT_TEST_UNIT("multicrash",test_dict_multicrash,"Multi-dict crash test"){
data = xbt_multidict_get(mdict,keys);
xbt_test_assert2(data && !strcmp((char*)data,key),
data = xbt_multidict_get(mdict,keys);
xbt_test_assert2(data && !strcmp((char*)data,key),
- "Retrieved value (%s) does not match the
entrered
one (%s)\n",
+ "Retrieved value (%s) does not match the
given
one (%s)\n",
(char*)data,key);
}
xbt_dict_free(&mdict);
(char*)data,key);
}
xbt_dict_free(&mdict);