Ejemplo n.º 1
0
Archivo: dynar.c Proyecto: R7R8/simgrid
/** @brief Retrieve a copy of the Nth element of a dynar.
 *
 * \param dynar information dealer
 * \param idx index of the slot we want to retrieve
 * \param[out] dst where to put the result to.
 */
inline void xbt_dynar_get_cpy(const xbt_dynar_t dynar, const unsigned long idx, void *const dst)
{
  _sanity_check_dynar(dynar);
  _check_inbound_idx(dynar, idx);

  _xbt_dynar_get_elm(dst, dynar, idx);
}
Ejemplo n.º 2
0
/** @brief Remove the Nth dynar's element, sliding the previous values to the left
 *
 * Get the Nth element of a dynar, removing it from the dynar and moving
 * all subsequent values to one position left in the dynar.
 *
 * If the object argument of this function is a non-null pointer, the removed
 * element is copied to this address. If not, the element is freed using the
 * free_f function passed at dynar creation.
 */
void
xbt_dynar_remove_at(xbt_dynar_t const dynar,
                    const int idx, void *const object)
{
  unsigned long nb_shift;
  unsigned long offset;

  _sanity_check_dynar(dynar);
  _check_inbound_idx(dynar, idx);

  if (object) {
    _xbt_dynar_get_elm(object, dynar, idx);
  } else if (dynar->free_f) {
    dynar->free_f(_xbt_dynar_elm(dynar, idx));
  }

  nb_shift = dynar->used - 1 - idx;

  if (nb_shift) {
    offset = nb_shift * dynar->elmsize;
    memmove(_xbt_dynar_elm(dynar, idx), _xbt_dynar_elm(dynar, idx + 1),
            offset);
  }

  dynar->used--;
}