Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define xbt_dict_new_homogeneous().
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Mon, 28 Nov 2011 13:39:44 +0000 (14:39 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 1 Dec 2011 10:32:49 +0000 (11:32 +0100)
ChangeLog
include/xbt/dict.h
src/xbt/dict.c

index 226f5c1..63e07ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,9 @@ SimGrid (3.7) NOT RELEASED; urgency=low
 
   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>
 
index cb5cde6..5c6f6df 100644 (file)
@@ -1,6 +1,6 @@
 /* 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
@@ -45,6 +45,7 @@ SG_BEGIN_DECL()
   /** \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);
 
index 2bbf177..dd1b010 100644 (file)
@@ -26,18 +26,38 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_dict, xbt,
  * \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;
 }