Ejemplo n.º 1
0
Archivo: dynar.c Proyecto: R7R8/simgrid
/** @brief Remove a slice of the dynar, sliding the rest of the values to the left
 *
 * This function removes an n-sized slice that starts at element idx. It is equivalent to xbt_dynar_remove_at with a
 * NULL object argument if n equals to 1.
 *
 * Each of the removed elements is freed using the free_f function passed at dynar creation.
 */
void xbt_dynar_remove_n_at(xbt_dynar_t const dynar, const unsigned int n, const int idx)
{
  unsigned long nb_shift;
  unsigned long offset;
  unsigned long cur;

  if (!n) return;

  _sanity_check_dynar(dynar);
  _check_inbound_idx(dynar, idx);
  _check_inbound_idx(dynar, idx + n - 1);

  if (dynar->free_f) {
    for (cur = idx; cur < idx + n; cur++) {
      dynar->free_f(_xbt_dynar_elm(dynar, cur));
    }
  }

  nb_shift = dynar->used - n - idx;

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

  dynar->used -= n;
}
Ejemplo n.º 2
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.º 3
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--;
}
Ejemplo n.º 4
0
Archivo: dynar.c Proyecto: R7R8/simgrid
/** @brief Retrieve a pointer to the Nth element of a dynar.
 *
 * \param dynar information dealer
 * \param idx index of the slot we want to retrieve
 * \return the \a idx-th element of \a dynar.
 *
 * \warning The returned value is the actual content of the dynar.
 * Make a copy before fooling with it.
 */
inline void *xbt_dynar_get_ptr(const xbt_dynar_t dynar, const unsigned long idx)
{
  void *res;
  _sanity_check_dynar(dynar);
  _check_inbound_idx(dynar, idx);

  res = _xbt_dynar_elm(dynar, idx);
  return res;
}