Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add/update copyright notices.
[simgrid.git] / include / xbt / setset.h
1 /* Copyright (c) 2010, 2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef _XBT_SETSET_H
8 #define _XBT_SETSET_H
9 #include "xbt/misc.h"
10
11 typedef struct s_xbt_setset *xbt_setset_t;
12
13 typedef struct s_xbt_setset_set *xbt_setset_set_t;
14
15 typedef struct s_xbt_setset_cursor *xbt_setset_cursor_t;
16
17 #define XBT_SETSET_HEADERS \
18   unsigned long ID
19
20 /* Constructor */
21 xbt_setset_t xbt_setset_new(unsigned int size);
22
23 /* Destructor */
24 void xbt_setset_destroy(xbt_setset_t setset);
25
26 /* Add an object to the setset, this will calculate its ID */
27 void xbt_setset_elm_add(xbt_setset_t setset, void *obj);
28
29 /* Remove an object from the setset */
30 void xbt_setset_elm_remove(xbt_setset_t setset, void *obj);
31
32 /* Create a new set in the setset */
33 xbt_setset_set_t xbt_setset_new_set(xbt_setset_t setset);
34
35 /* Destroy a set in the setset */
36 void xbt_setset_destroy_set(xbt_setset_set_t);
37
38 /* Insert an element into a set */
39 void xbt_setset_set_insert(xbt_setset_set_t set, void *obj);
40
41 /* Remove an element from a set */
42 void xbt_setset_set_remove(xbt_setset_set_t set, void *obj);
43
44 /* Remove all the elements of a set */
45 void xbt_setset_set_reset(xbt_setset_set_t set);
46
47 /* Select one element of a set */
48 void *xbt_setset_set_choose(xbt_setset_set_t set);
49
50 /* Extract one element of a set */
51 void *xbt_setset_set_extract(xbt_setset_set_t set);
52
53 /* Test if an element belongs to a set */
54 int xbt_setset_set_belongs(xbt_setset_set_t set, void *obj);
55
56 /* Get the number of elements in a set */
57 int xbt_setset_set_size(xbt_setset_set_t set);
58
59 /* Add all elements of set2 to set1 */
60 void xbt_setset_add(xbt_setset_set_t set1, xbt_setset_set_t set2);
61
62 /* Substract all elements of set2 from set1 */
63 void xbt_setset_substract(xbt_setset_set_t set1, xbt_setset_set_t set2);
64
65 /* Intersect set1 and set2 storing the result in set1 */
66 void xbt_setset_intersect(xbt_setset_set_t set1, xbt_setset_set_t set2);
67
68 /* Get the cursor to point to the first element of a set */
69 void xbt_setset_cursor_first(xbt_setset_set_t set,
70                              xbt_setset_cursor_t * cursor);
71
72 /* Get the data pointed by a cursor */
73 int xbt_setset_cursor_get_data(xbt_setset_cursor_t cursor, void **data);
74
75 /* Advance a cursor to the next element */
76 void xbt_setset_cursor_next(xbt_setset_cursor_t cursor);
77
78
79 #define xbt_setset_foreach(set, cursor, data) \
80           for(xbt_setset_cursor_first(set, &cursor);  \
81               xbt_setset_cursor_get_data(cursor, (void **)&data); \
82               xbt_setset_cursor_next(cursor))
83
84 #endif