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 * 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.
21 /** @defgroup XBT_fifo_cons Fifo constructor and destructor
27 /** \brief Bucket structure
29 typedef struct xbt_fifo_item *xbt_fifo_item_t;
31 /** \brief FIFO structure
33 typedef struct xbt_fifo *xbt_fifo_t;
35 xbt_fifo_t xbt_fifo_new(void);
36 void xbt_fifo_free(xbt_fifo_t);
39 /** @defgroup XBT_fifo_perl Fifo perl-like functions
44 xbt_fifo_item_t xbt_fifo_push(xbt_fifo_t, void *);
45 void *xbt_fifo_pop(xbt_fifo_t);
46 xbt_fifo_item_t xbt_fifo_unshift(xbt_fifo_t, void *);
47 void *xbt_fifo_shift(xbt_fifo_t);
48 int xbt_fifo_size(xbt_fifo_t);
49 int xbt_fifo_is_in(xbt_fifo_t, void *);
52 /** @defgroup XBT_fifo_direct Direct access to fifo elements
58 xbt_fifo_item_t xbt_fifo_new_item(void);
59 void xbt_fifo_set_item_content(xbt_fifo_item_t, void *);
60 void *xbt_fifo_get_item_content(xbt_fifo_item_t);
61 void xbt_fifo_free_item(xbt_fifo_item_t);
63 void xbt_fifo_push_item(xbt_fifo_t, xbt_fifo_item_t);
64 xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t);
65 void xbt_fifo_unshift_item(xbt_fifo_t, xbt_fifo_item_t);
66 xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t);
68 void xbt_fifo_remove(xbt_fifo_t, void *);
69 void xbt_fifo_remove_item(xbt_fifo_t, xbt_fifo_item_t);
71 xbt_fifo_item_t xbt_fifo_get_first_item(xbt_fifo_t l);
72 xbt_fifo_item_t xbt_fifo_get_next_item(xbt_fifo_item_t i);
73 xbt_fifo_item_t xbt_fifo_get_prev_item(xbt_fifo_item_t i);
76 * \brief List iterator
78 * \param f a list (#xbt_fifo_t)
79 * \param i a bucket (#xbt_fifo_item_t)
81 * \param n an object of type \a type.
84 * Iterates over the whole list.
86 #define xbt_fifo_foreach(f,i,n,type) \
87 for(i=xbt_fifo_get_first_item(f); \
88 ((i)?(n=(type)(xbt_fifo_get_item_content(i))):(NULL)); \
89 i=xbt_fifo_get_next_item(i))
93 /** @defgroup XBT_fifo_misc Misc fifo functions
98 void **xbt_fifo_to_array(xbt_fifo_t);
99 xbt_fifo_t xbt_fifo_copy(xbt_fifo_t);
102 /* Deprecated functions: don't use! */
103 xbt_fifo_item_t xbt_fifo_newitem(void);
104 void xbt_fifo_freeitem(xbt_fifo_item_t);
106 xbt_fifo_item_t xbt_fifo_getFirstItem(xbt_fifo_t l);
107 xbt_fifo_item_t xbt_fifo_getNextItem(xbt_fifo_item_t i);
108 xbt_fifo_item_t xbt_fifo_getPrevItem(xbt_fifo_item_t i);
114 #endif /* _XBT_FIFO_H */