-/* $Id$ */
-
/* a generic DYNamic ARray implementation. */
-/* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
+/* Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
+ * All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
size_wanted = dynar->used + empty_slots_wanted;
if (size_wanted != dynar->size) {
dynar->size = size_wanted;
- dynar->data = xbt_realloc(dynar->data, sizeof(void *) * dynar->size);
+ dynar->data = xbt_realloc(dynar->data, dynar->elmsize * dynar->size);
}
_dynar_unlock(dynar);
}
return (dynar ? (unsigned long) dynar->used : (unsigned long) 0);
}
+/**@brief check if a dynar is empty
+ *
+ *\param dynar the dynat we want to check
+ */
+
+XBT_INLINE int xbt_dynar_is_empty(const xbt_dynar_t dynar)
+{
+ return (xbt_dynar_length(dynar) == 0);
+}
+
/** @brief Retrieve a copy of the Nth element of a dynar.
*
* \param dynar information dealer
*
* Raises not_found_error if not found.
*/
-int xbt_dynar_search(xbt_dynar_t const dynar, void *const elem)
+unsigned int xbt_dynar_search(xbt_dynar_t const dynar, void *const elem)
{
unsigned long it;
_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_cpvoid_cpvoid_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