Logo AND Algorithmique Numérique Distribuée

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