/* a generic DYNamic ARray implementation. */
-/* Copyright (c) 2004-2020. The SimGrid Team.
+/* Copyright (c) 2004-2021. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
static inline void* _xbt_dynar_elm(const_xbt_dynar_t dynar, unsigned long idx)
{
- char *const data = (char *) dynar->data;
+ auto* const data = static_cast<char*>(dynar->data);
const unsigned long elmsize = dynar->elmsize;
return data + idx * elmsize;
*/
unsigned long xbt_dynar_length(const_xbt_dynar_t dynar)
{
- return (dynar ? (unsigned long) dynar->used : (unsigned long) 0);
+ return (dynar ? dynar->used : 0UL);
}
/**@brief check if a dynar is empty
dynar->used--;
}
-/** @brief Returns the position of the element in the dynar (or -1 if not found)
- *
- * Beware that if your dynar contains pointed values (such as strings) instead of scalar, this function is probably not
- * what you want. Check the documentation of xbt_dynar_search() for more info.
- *
- * Note that usually, the dynar indices are unsigned integers. If you have more than 2 million elements in your dynar,
- * this very function will not work (but the other will).
- */
-signed int xbt_dynar_search_or_negative(const_xbt_dynar_t dynar, const void* elem)
-{
- unsigned long it;
-
- for (it = 0; it < dynar->used; it++)
- if (not memcmp(_xbt_dynar_elm(dynar, it), elem, dynar->elmsize)) {
- return it;
- }
-
- return -1;
-}
-
/** @brief Returns a boolean indicating whether the element is part of the dynar
*
* Beware that if your dynar contains pointed values (such as strings) instead of scalar, this function is probably not
- * what you want. Check the documentation of xbt_dynar_search() for more info.
+ * what you want.
*/
int xbt_dynar_member(const_xbt_dynar_t dynar, const void* elem)
{
- unsigned long it;
-
- for (it = 0; it < dynar->used; it++)
+ for (unsigned long it = 0; it < dynar->used; it++)
if (not memcmp(_xbt_dynar_elm(dynar, it), elem, dynar->elmsize)) {
return 1;
}
*/
void xbt_dynar_map(const_xbt_dynar_t dynar, void_f_pvoid_t op)
{
- char *const data = (char *) dynar->data;
+ auto* const data = static_cast<char*>(dynar->data);
const unsigned long elmsize = dynar->elmsize;
const unsigned long used = dynar->used;
- unsigned long i;
_sanity_check_dynar(dynar);
- for (i = 0; i < used; i++) {
- char* elm = (char*) data + i * elmsize;
+ for (unsigned long i = 0; i < used; i++) {
+ char* elm = data + i * elmsize;
op(elm);
}
}
-/** @brief Removes and free the entry pointed by the cursor
- *
- * This function can be used while traversing without problem.
- */
-void xbt_dynar_cursor_rm(xbt_dynar_t dynar, unsigned int* cursor)
-{
- xbt_dynar_remove_at(dynar, *cursor, nullptr);
- *cursor -= 1;
-}
-
/** @brief Sorts a dynar according to the function <tt>compar_fn</tt>
*
* This function simply apply the classical qsort(3) function to the data stored in the dynar.
*/
void* xbt_dynar_to_array(xbt_dynar_t dynar)
{
- void *res;
+ void* res;
xbt_dynar_shrink(dynar, 1);
memset(xbt_dynar_push_ptr(dynar), 0, dynar->elmsize);
res = dynar->data;