3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/misc.h" /* SG_BEGIN_DECL */
14 /** @addtogroup XBT_fifo
15 * @brief This section describes the API to generic workqueue.
17 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref XBT_API]
18 * <tr><td><b>Prev</b> <td> [\ref XBT_set]
19 * <tr><td><b>Next</b> <td> [\ref XBT_swag]
20 * <tr><td><b>Down</b> <td> [\ref XBT_fifo_cons] </table></center>
22 * These functions provide the same kind of functionnality as dynamic arrays but in time O(1).
23 * However these functions use malloc/free way too much often.
26 /** @defgroup XBT_fifo_cons Fifo constructor and destructor
29 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref XBT_API]::[\ref XBT_fifo]
31 * <tr><td><b>Next</b> <td> [\ref XBT_fifo_perl] </table></center>
35 /** \brief Bucket structure
37 typedef struct xbt_fifo_item *xbt_fifo_item_t;
39 /** \brief FIFO structure
41 typedef struct xbt_fifo *xbt_fifo_t;
43 xbt_fifo_t xbt_fifo_new(void);
44 void xbt_fifo_free(xbt_fifo_t);
47 /** @defgroup XBT_fifo_perl Fifo perl-like functions
50 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref XBT_API]::[\ref XBT_fifo]
51 * <tr><td><b>Prev</b> <td> [\ref XBT_fifo_cons]
52 * <tr><td><b>Next</b> <td> [\ref XBT_fifo_direct] </table></center>
55 xbt_fifo_item_t xbt_fifo_push(xbt_fifo_t, void *);
56 void *xbt_fifo_pop(xbt_fifo_t);
57 xbt_fifo_item_t xbt_fifo_unshift(xbt_fifo_t, void *);
58 void *xbt_fifo_shift(xbt_fifo_t);
59 int xbt_fifo_size(xbt_fifo_t);
60 int xbt_fifo_is_in(xbt_fifo_t, void *);
63 /** @defgroup XBT_fifo_direct Direct access to fifo elements
66 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref XBT_API]::[\ref XBT_fifo]
67 * <tr><td><b>Prev</b> <td> [\ref XBT_fifo_perl]
68 * <tr><td><b>Next</b> <td> [\ref XBT_fifo_misc] </table></center>
73 xbt_fifo_item_t xbt_fifo_new_item(void);
74 void xbt_fifo_set_item_content(xbt_fifo_item_t, void *);
75 void *xbt_fifo_get_item_content(xbt_fifo_item_t);
76 void xbt_fifo_free_item(xbt_fifo_item_t);
78 void xbt_fifo_push_item(xbt_fifo_t, xbt_fifo_item_t);
79 xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t);
80 void xbt_fifo_unshift_item(xbt_fifo_t, xbt_fifo_item_t);
81 xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t);
83 void xbt_fifo_remove(xbt_fifo_t, void *);
84 void xbt_fifo_remove_item(xbt_fifo_t, xbt_fifo_item_t);
86 xbt_fifo_item_t xbt_fifo_get_first_item(xbt_fifo_t l);
87 xbt_fifo_item_t xbt_fifo_get_next_item(xbt_fifo_item_t i);
88 xbt_fifo_item_t xbt_fifo_get_prev_item(xbt_fifo_item_t i);
91 * \brief List iterator
93 * \param f a list (#xbt_fifo_t)
94 * \param i a bucket (#xbt_fifo_item_t)
96 * \param n an object of type \a type.
99 * Iterates over the whole list.
101 #define xbt_fifo_foreach(f,i,n,type) \
102 for(i=xbt_fifo_get_first_item(f); \
103 ((i)?(n=(type)(xbt_fifo_get_item_content(i))):(NULL)); \
104 i=xbt_fifo_get_next_item(i))
108 /** @defgroup XBT_fifo_misc Misc fifo functions
111 * <center><table><tr><td><b>Top</b> <td> [\ref index]::[\ref XBT_API]::[\ref XBT_fifo]
112 * <tr><td><b>Prev</b> <td> [\ref XBT_fifo_direct]
113 * <tr><td> Next <td> </table></center>
117 void **xbt_fifo_to_array(xbt_fifo_t);
118 xbt_fifo_t xbt_fifo_copy(xbt_fifo_t);
121 /* Deprecated functions: don't use! */
122 xbt_fifo_item_t xbt_fifo_newitem(void);
123 void xbt_fifo_freeitem(xbt_fifo_item_t);
125 xbt_fifo_item_t xbt_fifo_getFirstItem(xbt_fifo_t l);
126 xbt_fifo_item_t xbt_fifo_getNextItem(xbt_fifo_item_t i);
127 xbt_fifo_item_t xbt_fifo_getPrevItem(xbt_fifo_item_t i);
133 #endif /* _XBT_FIFO_H */