Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a new function xbt_dynar_sort() which is a wrapper on qsort.
authorsuter <suter@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 14 Jun 2010 08:43:15 +0000 (08:43 +0000)
committersuter <suter@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 14 Jun 2010 08:43:15 +0000 (08:43 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7843 48e7efb5-ca39-0410-a469-dd3cf9ba447f

ChangeLog
include/xbt/dynar.h
src/xbt/dynar.c

index 7c7cd98..f44f226 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,7 @@ SimGrid (3.5) unstable; urgency=low
  * New data container: setset (set of sets of elements)
  * New module: mmalloc (mapped malloc)
  * New function: xbt_dict_cursor_set_data()
+ * New function: xbt_dynar_sort()
  * New function: xbt_fifo_get_last_item()
  * Bug fix in xbt_dynar_shrink(): use the right element size
  * Use library init/fini functions for our initialization.
index a045e10..6fb99a8 100644 (file)
@@ -97,6 +97,8 @@ XBT_PUBLIC(void) xbt_dynar_remove_at(xbt_dynar_t const dynar, const int idx,
 
 XBT_PUBLIC(int) xbt_dynar_search(xbt_dynar_t const dynar, void *elem);
 XBT_PUBLIC(int) xbt_dynar_member(xbt_dynar_t const dynar, void *elem);
+XBT_PUBLIC(void) xbt_dynar_sort(xbt_dynar_t const dynar, int_f_pvoid_pvoid_t compar_fn);
+
 /** @} */
 /** @defgroup XBT_dynar_perl Perl-like use of dynars
  *  @ingroup XBT_dynar
index 1937efb..5498ba1 100644 (file)
@@ -685,6 +685,22 @@ XBT_INLINE void xbt_dynar_cursor_unlock(xbt_dynar_t dynar)
   _dynar_unlock(dynar);
 }
 
+/** @brief Sorts a dynar according to the function <tt>compar_fn</tt>
+ *
+ * \param compar_fn comparison function of type (int (compar_fn*) (void*) (void*)).
+ *
+ * Remark: if the elements stored in the dynar are structures, the compar_fn
+ * function has to retrieve the field to sort first.
+ */
+XBT_INLINE void xbt_dynar_sort(xbt_dynar_t dynar, int_f_pvoid_pvoid_t compar_fn){
+
+       _dynar_lock(dynar);
+
+       qsort(dynar->data, dynar->used, dynar->elmsize, compar_fn);
+
+       _dynar_unlock(dynar);
+}
+
 #ifdef SIMGRID_TEST
 
 #define NB_ELEM 5000