Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added support for sampling up to a given number of iterations or until a threshold...
[simgrid.git] / include / xbt / fifo.h
1 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. 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_FIFO_H
8 #define _XBT_FIFO_H
9 #include "xbt/misc.h"           /* SG_BEGIN_DECL */
10
11 SG_BEGIN_DECL()
12
13 /** @addtogroup XBT_fifo
14  *  @brief This section describes the API to generic workqueue.
15  *
16  * These functions provide the same kind of functionnality as dynamic arrays but in time O(1).
17  * However these functions use malloc/free way too much often.            
18  */
19 /** @defgroup XBT_fifo_cons Fifo constructor and destructor
20  *  @ingroup XBT_fifo
21  *
22  *  @{
23  */
24 /** \brief  Bucket structure 
25 */
26 typedef struct xbt_fifo_item *xbt_fifo_item_t;
27
28 /** \brief  FIFO structure
29 */
30 typedef struct xbt_fifo *xbt_fifo_t;
31
32 XBT_PUBLIC(xbt_fifo_t) xbt_fifo_new(void);
33 XBT_PUBLIC(void) xbt_fifo_free(xbt_fifo_t);
34 /** @} */
35
36 /** @defgroup XBT_fifo_perl Fifo perl-like functions
37  *  @ingroup XBT_fifo
38  *
39  *  @{
40  */
41 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_push(xbt_fifo_t, void *);
42 XBT_PUBLIC(void *) xbt_fifo_pop(xbt_fifo_t);
43 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_unshift(xbt_fifo_t, void *);
44 XBT_PUBLIC(void *) xbt_fifo_shift(xbt_fifo_t);
45 XBT_PUBLIC(int) xbt_fifo_size(xbt_fifo_t);
46 XBT_PUBLIC(int) xbt_fifo_is_in(xbt_fifo_t, void *);
47 /** @} */
48
49 /** @defgroup XBT_fifo_direct Direct access to fifo elements
50  *  @ingroup XBT_fifo
51  *
52  *  @{
53  */
54
55 XBT_INLINE XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_new_item(void);
56 XBT_PUBLIC(void) xbt_fifo_set_item_content(xbt_fifo_item_t, void *);
57 XBT_PUBLIC(void *) xbt_fifo_get_item_content(xbt_fifo_item_t);
58 XBT_INLINE XBT_PUBLIC(void) xbt_fifo_free_item(xbt_fifo_item_t);
59
60 XBT_PUBLIC(void) xbt_fifo_push_item(xbt_fifo_t, xbt_fifo_item_t);
61 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_pop_item(xbt_fifo_t);
62 XBT_PUBLIC(void) xbt_fifo_unshift_item(xbt_fifo_t, xbt_fifo_item_t);
63 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_shift_item(xbt_fifo_t);
64
65 XBT_PUBLIC(int) xbt_fifo_remove(xbt_fifo_t, void *);
66 XBT_PUBLIC(int) xbt_fifo_remove_all(xbt_fifo_t, void *);
67 XBT_PUBLIC(void) xbt_fifo_remove_item(xbt_fifo_t, xbt_fifo_item_t);
68
69 XBT_INLINE XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_first_item(xbt_fifo_t
70                                                                l);
71 XBT_INLINE XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_last_item(xbt_fifo_t
72                                                               l);
73 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_next_item(xbt_fifo_item_t i);
74 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_get_prev_item(xbt_fifo_item_t i);
75
76 /** 
77  * \brief List iterator
78  * asserts and stuff
79  * \param f a list (#xbt_fifo_t)
80  * \param i a bucket (#xbt_fifo_item_t)
81  * \param type a type
82  * \param n an object of type \a type.
83  * @hideinitializer
84  *
85  * Iterates over the whole list. 
86  */
87 #define xbt_fifo_foreach(f,i,n,type)                  \
88    for(i=xbt_fifo_get_first_item(f);                    \
89      ((i)?(n=(type)(xbt_fifo_get_item_content(i))):(NULL));             \
90        i=xbt_fifo_get_next_item(i))
91
92 /** @} */
93
94 /** @defgroup XBT_fifo_misc Misc fifo functions
95  *  @ingroup XBT_fifo
96  *
97  *  @{
98  */
99 XBT_PUBLIC(void **) xbt_fifo_to_array(xbt_fifo_t);
100 XBT_PUBLIC(xbt_fifo_t) xbt_fifo_copy(xbt_fifo_t);
101 /** @} */
102
103 /* Deprecated functions: don't use! */
104 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_newitem(void);
105 XBT_PUBLIC(void) xbt_fifo_freeitem(xbt_fifo_item_t);
106
107 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_getFirstItem(xbt_fifo_t l);
108 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_getNextItem(xbt_fifo_item_t i);
109 XBT_PUBLIC(xbt_fifo_item_t) xbt_fifo_getPrevItem(xbt_fifo_item_t i);
110
111
112 SG_END_DECL()
113 #endif                          /* _XBT_FIFO_H */