X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/fa222c38f9b796be07ab4351ffc810a61a8fd705..2c8c164d58104acb6256b6d8efd476a6a2165b8a:/src/xbt/dynar.c diff --git a/src/xbt/dynar.c b/src/xbt/dynar.c index 25de69ff1b..5885ce21af 100644 --- a/src/xbt/dynar.c +++ b/src/xbt/dynar.c @@ -27,7 +27,7 @@ static XBT_INLINE void _sanity_check_idx(int idx) static XBT_INLINE void _check_inbound_idx(xbt_dynar_t dynar, int idx) { - if (idx < 0 || idx >= dynar->used) { + if (idx < 0 || idx >= (int)dynar->used) { THROWF(bound_error, idx, "dynar is not that long. You asked %d, but it's only %lu long", (int) (idx), (unsigned long) dynar->used); @@ -471,8 +471,8 @@ unsigned int xbt_dynar_search(xbt_dynar_t const dynar, void *const elem) return it; } - THROWF(not_found_error, 0, "Element %p not part of dynar %p", elem, - dynar); + THROWF(not_found_error, 0, "Element %p not part of dynar %p", elem, dynar); + return -1; // Won't happen, just to please eclipse } /** @brief Returns the position of the element in the dynar (or -1 if not found) @@ -630,6 +630,16 @@ XBT_INLINE void xbt_dynar_sort(xbt_dynar_t dynar, qsort(dynar->data, dynar->used, dynar->elmsize, compar_fn); } +static int strcmp_voidp(const void *pa, const void *pb) { + return strcmp(*(const char **)pa, *(const char **)pb); +} +/** @brief Sorts a dynar of strings (ie, char* data) */ +xbt_dynar_t xbt_dynar_sort_strings(xbt_dynar_t dynar) +{ + xbt_dynar_sort(dynar, strcmp_voidp); + return dynar; // to enable functional uses +} + /** @brief Sorts a dynar according to their color assuming elements can have only three colors. * Since there are only three colors, it is linear and much faster than a classical sort. * See for example http://en.wikipedia.org/wiki/Dutch_national_flag_problem