Logo AND Algorithmique Numérique Distribuée

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