SimGrid: SWAG functions

SimGrid 3.10 Versatile Simulation of Distributed Systems

- Home page
- Online documentation
- Dev's Corner

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Macros | Functions
SWAG functions
Swag: O(1) set datatype

## Macros
#define | xbt_swag_reset(swag)
| Makes a swag empty.
#define | xbt_swag_insert(obj, swag)
#define | xbt_swag_offset(var, field)
| Offset computation.

## Functions
xbt_swag_t | xbt_swag_new (size_t offset)
void | xbt_swag_free (xbt_swag_t swag)
void | xbt_swag_init (xbt_swag_t swag, size_t offset)
void | xbt_swag_insert_at_head (void *obj, xbt_swag_t swag)
void | xbt_swag_insert_at_tail (void *obj, xbt_swag_t swag)
void * | xbt_swag_remove (void *obj, xbt_swag_t swag)
void * | xbt_swag_extract (xbt_swag_t swag)
int | xbt_swag_size (xbt_swag_t swag)

## Detailed Description

## Macro Definition Documentation

#define xbt_swag_reset | ( |  | swag | ) |

Makes a swag empty.

Parameters

  swag | a swag

#define xbt_swag_insert | ( |  | obj,
|  |  | swag
| ) |  |

Parameters

  obj | the objet to insert in the swag
  swag | a swag

insert obj in swag

#define xbt_swag_offset | ( |  | var,
|  |  | field
| ) |  |

Offset computation.

- var a variable of type `struct` something
- field a field of `struct` something
  Returns
    the offset of field in `struct` something.
  It is very similar to offsetof except that is done at runtime and that you have to declare a variable. Why defining such a macro then ? Because it is portable...

## Function Documentation

xbt_swag_t xbt_swag_new | ( | size_t | offset | ) |

Creates a new swag.

Parameters

  offset | where the hookup is located in the structure

See Also
  xbt_swag_offset

Usage : xbt_swag_new(&obj.setA-&obj);

void xbt_swag_free | ( | xbt_swag_t | swag | ) |

Parameters

  swag | poor victim

kilkil a swag but not it's content. If you do not understand why xbt_swag_free should not free its content, don't use swags.

void xbt_swag_init | ( | xbt_swag_t | swag,
|  | size_t | offset
| ) |  |

Creates a new swag.

Parameters

  swag | the swag to initialize
  offset | where the hookup is located in the structure

See Also
  xbt_swag_offset

Usage : xbt_swag_init(swag,&obj.setA-&obj);

void xbt_swag_insert_at_head | ( | void * | obj,
|  | xbt_swag_t | swag
| ) |  |

Parameters

  obj | the objet to insert in the swag
  swag | a swag

insert (at the head... you probably had a very good reason to do that, I hope you know what you're doing) obj in swag

void xbt_swag_insert_at_tail | ( | void * | obj,
|  | xbt_swag_t | swag
| ) |  |

Parameters

  obj | the objet to insert in the swag
  swag | a swag

insert (at the tail... you probably had a very good reason to do that, I hope you know what you're doing) obj in swag

void* xbt_swag_remove | ( | void * | obj,
|  | xbt_swag_t | swag
| ) |  |

Parameters

  obj | the objet to remove from the swag
  swag | a swag

Returns
  obj if it was in the swag and NULL otherwise

removes obj from swag

void* xbt_swag_extract | ( | xbt_swag_t | swag | ) |

Parameters

  swag | a swag

Returns
  an object from the swag

int xbt_swag_size | ( | xbt_swag_t | swag | ) |

Parameters

  swag | a swag

Returns
  the number of objects in swag