SimGrid  3.11
Versatile Simulation of Distributed Systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Fifo perl-like functions

Functions

xbt_fifo_item_t xbt_fifo_push (xbt_fifo_t, void *)
 
void * xbt_fifo_pop (xbt_fifo_t)
 
xbt_fifo_item_t xbt_fifo_unshift (xbt_fifo_t, void *)
 
void * xbt_fifo_shift (xbt_fifo_t)
 
int xbt_fifo_size (xbt_fifo_t)
 
int xbt_fifo_is_in (xbt_fifo_t, void *)
 
xbt_fifo_item_t xbt_fifo_search_item (xbt_fifo_t f, int_f_pvoid_pvoid_t cmp_fun, void *closure)
 Search the given element in the fifo using a comparison function. More...
 

Detailed Description

Function Documentation

xbt_fifo_item_t xbt_fifo_push ( xbt_fifo_t  l,
void *  t 
)

Push

Parameters
llist
telement
Returns
the bucket that was just added

Add an object at the tail of the list

void* xbt_fifo_pop ( xbt_fifo_t  l)

Pop

Parameters
llist
Returns
the object stored at the tail of the list.

Removes and returns the object stored at the tail of the list. Returns NULL if the list is empty.

xbt_fifo_item_t xbt_fifo_unshift ( xbt_fifo_t  l,
void *  t 
)
Parameters
llist
telement
Returns
the bucket that was just added

Add an object at the head of the list

void* xbt_fifo_shift ( xbt_fifo_t  l)

Shift

Parameters
llist
Returns
the object stored at the head of the list.

Removes and returns the object stored at the head of the list. Returns NULL if the list is empty.

int xbt_fifo_size ( xbt_fifo_t  f)
Parameters
fa list
Returns
the number of buckets in f.
int xbt_fifo_is_in ( xbt_fifo_t  f,
void *  content 
)
Parameters
fa list
contentan object
Returns
1 if content is in f.
xbt_fifo_item_t xbt_fifo_search_item ( xbt_fifo_t  f,
int_f_pvoid_pvoid_t  cmp_fun,
void *  closure 
)

Search the given element in the fifo using a comparison function.

This function allows to search an item with a user provided function instead of the pointer comparison used elsewhere in this module. Assume for example that you have a fifo of strings. You cannot use xbt_fifo_remove() to remove, say, "TOTO" from it because internally, xbt_fifo_remove() will do something like "if (item->content == "toto"), then remove it". And the pointer to the item content and the pointer to "toto" will never match. As a solution, the current function provides a way to search elements that are semanticaly equivalent instead of only syntaxically. So, removing "Toto" from a fifo can be achieved this way:

int my_comparison_function(void *searched, void *seen) {
  return !strcmp(searched, seen);
}

  xbt_fifo_remove_item(fifo,
                       xbt_fifo_search_item(fifo, my_comparison_function, "Toto"));
Parameters
fa fifo list
cmp_funthe comparison function. Prototype: void *a,void *b -> int. Semantic: returns true iff a=b
closurethe element to search. It will be provided as first argument to each call of cmp_fun
Returns
the first item matching the comparison function, or NULL if no such item exists