Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
plug memleak, fix uninitialized values, export functions
[simgrid.git] / include / xbt / fifo.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
4
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. */
7
8 #ifndef _XBT_FIFO_H
9 #define _XBT_FIFO_H
10 #include "xbt/misc.h" /* SG_BEGIN_DECL */
11
12 SG_BEGIN_DECL()
13
14 /** @addtogroup XBT_fifo
15  *  @brief This section describes the API to generic workqueue.
16  *
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>
21  *
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.            
24  */
25
26 /** @defgroup XBT_fifo_cons Fifo constructor and destructor
27  *  @ingroup XBT_fifo
28  *
29  * <center><table><tr><td><b>Top</b>    <td> [\ref index]::[\ref XBT_API]::[\ref XBT_fifo]
30  *                <tr><td>   Prev       <td> 
31  *                <tr><td><b>Next</b>   <td> [\ref XBT_fifo_perl]        </table></center>
32  *  @{
33  */
34
35 /** \brief  Bucket structure 
36 */
37 typedef struct xbt_fifo_item *xbt_fifo_item_t;
38
39 /** \brief  FIFO structure
40 */
41 typedef struct xbt_fifo *xbt_fifo_t;
42
43 xbt_fifo_t xbt_fifo_new(void);
44 void xbt_fifo_free(xbt_fifo_t);
45 /** @} */
46
47 /** @defgroup XBT_fifo_perl Fifo perl-like functions
48  *  @ingroup XBT_fifo
49  *
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>
53  *  @{
54  */
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 *);
61 /** @} */
62
63 /** @defgroup XBT_fifo_direct Direct access to fifo elements
64  *  @ingroup XBT_fifo
65  *
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>
69  *
70  *  @{
71  */
72
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);
77
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);
82
83 void xbt_fifo_remove(xbt_fifo_t, void *);
84 void xbt_fifo_remove_item(xbt_fifo_t, xbt_fifo_item_t);
85
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);
89
90 /** 
91  * \brief List iterator
92  * asserts and stuff
93  * \param f a list (#xbt_fifo_t)
94  * \param i a bucket (#xbt_fifo_item_t)
95  * \param type a type
96  * \param n an object of type \a type.
97  * @hideinitializer
98  *
99  * Iterates over the whole list. 
100  */
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))
105
106 /** @} */
107
108 /** @defgroup XBT_fifo_misc Misc fifo functions
109  *  @ingroup XBT_fifo
110  *
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>
114  *
115  *  @{
116  */
117 void **xbt_fifo_to_array(xbt_fifo_t);
118 xbt_fifo_t xbt_fifo_copy(xbt_fifo_t);
119 /** @} */
120
121 /* Deprecated functions: don't use! */
122 xbt_fifo_item_t xbt_fifo_newitem(void);
123 void xbt_fifo_freeitem(xbt_fifo_item_t);
124
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);
128
129
130 SG_END_DECL()
131
132
133 #endif                          /* _XBT_FIFO_H */