/* $Id$ */
-/* dict - a generic dictionnary, 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. */
#include "dict_private.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict,xbt,
- "Dictionaries provide the same functionnalities than hash tables");
+ "Dictionaries provide the same functionalities than hash tables");
/*####[ Private prototypes ]#################################################*/
static xbt_mallocator_t dict_mallocator = NULL;
* \return pointer to the destination
* \see xbt_dict_new_ext(), xbt_dict_free()
*
- * Creates and initialize a new dictionnary 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;
/**
* \brief Destructor
- * \param dict the dictionnary to be freed
+ * \param dict the dictionary to be freed
*
* Frees a dictionary with all the data
*/
/* 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++;
}
* \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 dictionnary
+ * \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.
* \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 dictionnary
+ * \a key is removed from the dictionary
*
* set the \a data in the structure under the \a key, which is a
* null terminated string.
}
if (current == NULL)
- return NULL;
+ THROW2(not_found_error, 0, "key %.*s not found", key_len, key);
return current->content;
}
}
if (current == NULL)
- THROW2(not_found_error, 0, "key %.*s not found", key_len, key);
+ return NULL;
return current->content;
}
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 (debugging purpose)
*
* \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)
*
- * Ouputs the content of the structure. (for debuging purpose). \a ouput is a
+ * Outputs the content of the structure. (for debugging purpose). \a output is a
* function to output the data. If NULL, data won't be displayed.
*/
if (element) {
printf("[\n");
while (element != NULL) {
- printf(" %s -> ", element->key);
+ printf(" %s -> '", element->key);
if (output != NULL) {
(*output)(element->content);
}
- printf("\n");
+ printf("'\n");
element = element->next;
}
printf("]\n");
xbt_test_log2("Seen #%d: %s",++i,PRINTF_STR(key));
}
xbt_test_assert2(!data || !strcmp(key,data),
- "Key(%s) != value(%s). Abording",key,data);
+ "Key(%s) != value(%s). Aborting",key,data);
}
}
XBT_TEST_UNIT("basic",test_dict_basic,"Basic usage: change, retrieve, traverse"){
- xbt_test_add0("Traversal the null dictionnary");
+ xbt_test_add0("Traversal the null dictionary");
traverse(head);
- xbt_test_add0("Traversal and search the empty dictionnary");
+ xbt_test_add0("Traversal and search the empty dictionary");
head = xbt_dict_new();
traverse(head);
TRY {
}
xbt_dict_free(&head);
- xbt_test_add0("Traverse the full dictionnary");
+ xbt_test_add0("Traverse the full dictionary");
fill(&head);
count(head, 7);
search(head,"12a");
traverse(head);
- xbt_test_add0("Free the dictionnary (twice)");
+ xbt_test_add0("Free the dictionary (twice)");
xbt_dict_free(&head);
xbt_dict_free(&head);
xbt_dict_set(head,"12a",strdup("12a"),&free);
count(head, 7);
- xbt_test_add0("Traverse the resulting dictionnary");
+ xbt_test_add0("Traverse the resulting dictionary");
traverse(head);
/* RETRIEVE */
search(head,"1234");
search(head,"123457");
- xbt_test_add0("Traverse the resulting dictionnary");
+ xbt_test_add0("Traverse the resulting dictionary");
traverse(head);
/* xbt_dict_dump(head,(void (*)(void*))&printf); */
- xbt_test_add0("Free the dictionnary twice");
+ xbt_test_add0("Free the dictionary twice");
xbt_dict_free(&head);
xbt_dict_free(&head);
- xbt_test_add0("Traverse the resulting dictionnary");
+ xbt_test_add0("Traverse the resulting dictionary");
traverse(head);
}
xbt_dict_free(&head);
- xbt_test_add0("Remove each data manually (traversing the resulting dictionnary 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);
count(head, 0);
traverse(head);
- xbt_test_add0("Free the dictionnary twice");
+ xbt_test_add0("Free the dictionary twice");
xbt_dict_free(&head);
xbt_dict_free(&head);
}
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);