SimGrid  3.13
Versatile Simulation of Distributed Systems

Functions

void xbt_dynar_get_cpy (const xbt_dynar_t dynar, const unsigned long idx, void *const dst)
 Retrieve a copy of the Nth element of a dynar. More...
 
void xbt_dynar_set (xbt_dynar_t dynar, const int idx, const void *src)
 Set the Nth element of a dynar (expanded if needed). More...
 
void xbt_dynar_replace (xbt_dynar_t dynar, const unsigned long idx, const void *object)
 Set the Nth element of a dynar (expanded if needed). More...
 
void xbt_dynar_insert_at (xbt_dynar_t const dynar, const int idx, const void *src)
 Set the Nth dynar's element, expanding the dynar and sliding the previous values to the right. More...
 
void xbt_dynar_remove_at (xbt_dynar_t const dynar, const int idx, void *const dst)
 Remove the Nth dynar's element, sliding the previous values to the left. More...
 
void xbt_dynar_remove_n_at (xbt_dynar_t const dynar, const unsigned int n, const int idx)
 Remove a slice of the dynar, sliding the rest of the values to the left. More...
 
unsigned int xbt_dynar_search (xbt_dynar_t const dynar, void *elem)
 Returns the position of the element in the dynar. More...
 
signed int xbt_dynar_search_or_negative (xbt_dynar_t const dynar, void *const elem)
 Returns the position of the element in the dynar (or -1 if not found) More...
 
int xbt_dynar_member (xbt_dynar_t const dynar, void *elem)
 Returns a boolean indicating whether the element is part of the dynar. More...
 
void xbt_dynar_sort (xbt_dynar_t const dynar, int_f_cpvoid_cpvoid_t compar_fn)
 Sorts a dynar according to the function compar_fn More...
 
xbt_dynar_t xbt_dynar_sort_strings (xbt_dynar_t dynar)
 Sorts a dynar of strings (ie, char* data) More...
 
void xbt_dynar_three_way_partition (xbt_dynar_t const dynar, int_f_pvoid_t color)
 Sorts a dynar according to their color assuming elements can have only three colors. More...
 
int xbt_dynar_compare (xbt_dynar_t d1, xbt_dynar_t d2, int(*compar)(const void *, const void *))
 Compare two dynars. More...
 
voidxbt_dynar_to_array (xbt_dynar_t dynar)
 Transform a dynar into a NULL terminated array. More...
 

Detailed Description

Function Documentation

void xbt_dynar_get_cpy ( const xbt_dynar_t  dynar,
const unsigned long  idx,
void *const  dst 
)
inline

Retrieve a copy of the Nth element of a dynar.

Parameters
dynarinformation dealer
idxindex of the slot we want to retrieve
[out]dstwhere to put the result to.
void xbt_dynar_set ( xbt_dynar_t  dynar,
const int  idx,
const void *const  src 
)
inline

Set the Nth element of a dynar (expanded if needed).

Previous value at this position is NOT freed

Parameters
dynarinformation dealer
idxindex of the slot we want to modify
srcWhat will be feeded to the dynar

If you want to free the previous content, use xbt_dynar_replace().

void xbt_dynar_replace ( xbt_dynar_t  dynar,
const unsigned long  idx,
const void *const  object 
)

Set the Nth element of a dynar (expanded if needed).

Previous value is freed

Parameters
dynar
idx
objectSet the Nth element of a dynar, expanding the dynar if needed, AND DO free the previous value at this position. If you don't want to free the previous content, use xbt_dynar_set().
void xbt_dynar_insert_at ( xbt_dynar_t const  dynar,
const int  idx,
const void *const  src 
)
inline

Set the Nth dynar's element, expanding the dynar and sliding the previous values to the right.

Set the Nth element of a dynar, expanding the dynar if needed, and moving the previously existing value and all subsequent ones to one position right in the dynar.

void xbt_dynar_remove_at ( xbt_dynar_t const  dynar,
const int  idx,
void *const  object 
)

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_n_at ( xbt_dynar_t const  dynar,
const unsigned int  n,
const int  idx 
)

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.

unsigned int xbt_dynar_search ( xbt_dynar_t const  dynar,
void *const  elem 
)

Returns the position of the element in the dynar.

Beware that if your dynar contains pointed values (such as strings) instead of scalar, this function compares the pointer value, not what's pointed. The only solution to search for a pointed value is then to write the foreach loop yourself:

1 signed int position = -1;
2 xbt_dynar_foreach(dynar, iter, elem) {
3  if (!memcmp(elem, searched_element, sizeof(*elem))) {
4  position = iter;
5  break;
6  }
7 }

Raises not_found_error if not found. If you have less than 2 millions elements, you probably want to use xbt_dynar_search_or_negative() instead, so that you don't have to TRY/CATCH on element not found.

signed int xbt_dynar_search_or_negative ( xbt_dynar_t const  dynar,
void *const  elem 
)

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).

int xbt_dynar_member ( xbt_dynar_t const  dynar,
void *const  elem 
)

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.

void xbt_dynar_sort ( xbt_dynar_t  dynar,
int_f_cpvoid_cpvoid_t  compar_fn 
)
inline

Sorts a dynar according to the function compar_fn

Parameters
dynarthe dynar to sort
compar_fncomparison 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_dynar_t xbt_dynar_sort_strings ( xbt_dynar_t  dynar)

Sorts a dynar of strings (ie, char* data)

void xbt_dynar_three_way_partition ( xbt_dynar_t const  dynar,
int_f_pvoid_t  color 
)

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

Parameters
dynarthe dynar to sort
colorthe color function of type (int (compar_fn*) (void*) (void*)). The return value of color is assumed to be 0, 1, or 2.

At the end of the call, elements with color 0 are at the beginning of the dynar, elements with color 2 are at the end and elements with color 1 are in the middle.

Remark: if the elements stored in the dynar are structures, the color function has to retrieve the field to sort first.

int xbt_dynar_compare ( xbt_dynar_t  d1,
xbt_dynar_t  d2,
int(*)(const void *, const void *)  compar 
)

Compare two dynars.

Parameters
d1first dynar to compare
d2second dynar to compare
comparfunction to use to compare elements
Returns
0 if d1 and d2 are equal and 1 if not equal

d1 and d2 should be dynars of pointers. The compar function takes two elements and returns 0 when they are considered equal, and a value different of zero when they are considered different. Finally, d2 is destroyed afterwards.

void* xbt_dynar_to_array ( xbt_dynar_t  dynar)
inline

Transform a dynar into a NULL terminated array.

Parameters
dynarthe dynar to transform
Returns
pointer to the first element of the array

Note: The dynar won't be usable afterwards.