XBT:
* Mallocators: allow value NULL for the reset function.
+ * Dicts: new function xbt_dict_new_homogeneous(void(*)(void*)) to
+ create homogeneous dictionaries, where all the elements share the
+ same free function.
-- $date Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
/* xbt/dict.h -- api to a generic dictionary */
-/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2004-2011. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
/** \brief Dictionary data type (opaque structure) */
typedef struct s_xbt_dict *xbt_dict_t;
XBT_PUBLIC(xbt_dict_t) xbt_dict_new(void);
+XBT_PUBLIC(xbt_dict_t) xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn);
XBT_PUBLIC(void) xbt_dict_free(xbt_dict_t * dict);
XBT_PUBLIC(unsigned int) xbt_dict_size(xbt_dict_t dict);
* \see xbt_dict_free()
*
* Creates and initialize a new dictionary with a default hashtable size.
+ * The dictionary is heterogeneous: each element can have a different free
+ * function.
*/
xbt_dict_t xbt_dict_new(void)
+{
+ xbt_dict_t dict = xbt_dict_new_homogeneous(NULL);
+ dict->homogeneous = 0;
+
+ return dict;
+}
+
+/**
+ * \brief Constructor
+ * \param free_ctn function to call with (\a data as argument) when
+ * \a data is removed from the dictionary
+ * \return pointer to the destination
+ * \see xbt_dict_new(), xbt_dict_free()
+ *
+ * Creates and initialize a new dictionary with a default hashtable size.
+ * The dictionary is homogeneous: each element share the same free function.
+ */
+xbt_dict_t xbt_dict_new_homogeneous(void_f_pvoid_t free_ctn)
{
xbt_dict_t dict;
dict = xbt_new(s_xbt_dict_t, 1);
- dict->free_f = NULL;
+ dict->free_f = free_ctn;
dict->table_size = 127;
dict->table = xbt_new0(xbt_dictelm_t, dict->table_size + 1);
dict->count = 0;
dict->fill = 0;
- dict->homogeneous = 0;
+ dict->homogeneous = 1;
return dict;
}