Changeset df3c6f02 in mainline for uspace/lib/c/include/adt/list.h


Ignore:
Timestamp:
2011-05-31T22:58:56Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d362410
Parents:
82582e4 (diff), 4ce90544 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/adt/list.h

    r82582e4 rdf3c6f02  
    4747 *
    4848 * @param name Name of the new statically allocated list.
    49  */
    50 #define LIST_INITIALIZE(name)  link_t name = { \
    51         .prev = &name, \
    52         .next = &name \
    53 }
     49 *
     50 */
     51#define LIST_INITIALIZE(name) \
     52        link_t name = { \
     53                .prev = &name, \
     54                .next = &name \
     55        }
     56
     57#define list_get_instance(link, type, member) \
     58        ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member))))
     59
     60#define list_foreach(list, iterator) \
     61        for (link_t *iterator = (list).next; \
     62            iterator != &(list); iterator = iterator->next)
    5463
    5564/** Initialize doubly-linked circular list link
     
    5867 *
    5968 * @param link Pointer to link_t structure to be initialized.
     69 *
    6070 */
    6171static inline void link_initialize(link_t *link)
     
    6979 * Initialize doubly-linked circular list.
    7080 *
    71  * @param head Pointer to link_t structure representing head of the list.
    72  */
    73 static inline void list_initialize(link_t *head)
    74 {
    75         head->prev = head;
    76         head->next = head;
     81 * @param list Pointer to link_t structure representing the list.
     82 *
     83 */
     84static inline void list_initialize(link_t *list)
     85{
     86        list->prev = list;
     87        list->next = list;
    7788}
    7889
     
    8293 *
    8394 * @param link Pointer to link_t structure to be added.
    84  * @param head Pointer to link_t structure representing head of the list.
    85  */
    86 static inline void list_prepend(link_t *link, link_t *head)
    87 {
    88         link->next = head->next;
    89         link->prev = head;
    90         head->next->prev = link;
    91         head->next = link;
     95 * @param list Pointer to link_t structure representing the list.
     96 *
     97 */
     98static inline void list_prepend(link_t *link, link_t *list)
     99{
     100        link->next = list->next;
     101        link->prev = list;
     102        list->next->prev = link;
     103        list->next = link;
    92104}
    93105
     
    97109 *
    98110 * @param link Pointer to link_t structure to be added.
    99  * @param head Pointer to link_t structure representing head of the list.
    100  */
    101 static inline void list_append(link_t *link, link_t *head)
    102 {
    103         link->prev = head->prev;
    104         link->next = head;
    105         head->prev->next = link;
    106         head->prev = link;
    107 }
    108 
    109 /** Insert item before another item in doubly-linked circular list. */
    110 static inline void list_insert_before(link_t *l, link_t *r)
    111 {
    112         list_append(l, r);
    113 }
    114 
    115 /** Insert item after another item in doubly-linked circular list. */
    116 static inline void list_insert_after(link_t *r, link_t *l)
    117 {
    118         list_prepend(l, r);
     111 * @param list Pointer to link_t structure representing the list.
     112 *
     113 */
     114static inline void list_append(link_t *link, link_t *list)
     115{
     116        link->prev = list->prev;
     117        link->next = list;
     118        list->prev->next = link;
     119        list->prev = link;
     120}
     121
     122/** Insert item before another item in doubly-linked circular list.
     123 *
     124 */
     125static inline void list_insert_before(link_t *link, link_t *list)
     126{
     127        list_append(link, list);
     128}
     129
     130/** Insert item after another item in doubly-linked circular list.
     131 *
     132 */
     133static inline void list_insert_after(link_t *link, link_t *list)
     134{
     135        list_prepend(list, link);
    119136}
    120137
     
    123140 * Remove item from doubly-linked circular list.
    124141 *
    125  * @param link Pointer to link_t structure to be removed from the list it is contained in.
     142 * @param link Pointer to link_t structure to be removed from the list
     143 *             it is contained in.
     144 *
    126145 */
    127146static inline void list_remove(link_t *link)
     
    136155 * Query emptiness of doubly-linked circular list.
    137156 *
    138  * @param head Pointer to link_t structure representing head of the list.
    139  */
    140 static inline int list_empty(link_t *head)
    141 {
    142         return ((head->next == head) ? 1 : 0);
    143 }
    144 
     157 * @param list Pointer to link_t structure representing the list.
     158 *
     159 */
     160static inline int list_empty(link_t *list)
     161{
     162        return (list->next == list);
     163}
     164
     165/** Get head item of a list.
     166 *
     167 * @param list Pointer to link_t structure representing the list.
     168 *
     169 * @return Head item of the list.
     170 * @return NULL if the list is empty.
     171 *
     172 */
     173static inline link_t *list_head(link_t *list)
     174{
     175        return ((list->next == list) ? NULL : list->next);
     176}
    145177
    146178/** Split or concatenate headless doubly-linked circular list
     
    151183 * concatenates splitted lists and splits concatenated lists.
    152184 *
    153  * @param part1 Pointer to link_t structure leading the first (half of the headless) list.
    154  * @param part2 Pointer to link_t structure leading the second (half of the headless) list.
     185 * @param part1 Pointer to link_t structure leading the first
     186 *              (half of the headless) list.
     187 * @param part2 Pointer to link_t structure leading the second
     188 *              (half of the headless) list.
     189 *
    155190 */
    156191static inline void headless_list_split_or_concat(link_t *part1, link_t *part2)
     
    165200}
    166201
    167 
    168202/** Split headless doubly-linked circular list
    169203 *
    170204 * Split headless doubly-linked circular list.
    171205 *
    172  * @param part1 Pointer to link_t structure leading the first half of the headless list.
    173  * @param part2 Pointer to link_t structure leading the second half of the headless list.
     206 * @param part1 Pointer to link_t structure leading
     207 *              the first half of the headless list.
     208 * @param part2 Pointer to link_t structure leading
     209 *              the second half of the headless list.
     210 *
    174211 */
    175212static inline void headless_list_split(link_t *part1, link_t *part2)
     
    182219 * Concatenate two headless doubly-linked circular lists.
    183220 *
    184  * @param part1 Pointer to link_t structure leading the first headless list.
    185  * @param part2 Pointer to link_t structure leading the second headless list.
     221 * @param part1 Pointer to link_t structure leading
     222 *              the first headless list.
     223 * @param part2 Pointer to link_t structure leading
     224 *              the second headless list.
     225 *
    186226 */
    187227static inline void headless_list_concat(link_t *part1, link_t *part2)
     
    190230}
    191231
    192 #define list_get_instance(link, type, member)  ((type *) (((void *)(link)) - ((void *) &(((type *) NULL)->member))))
    193 
    194 extern int list_member(const link_t *link, const link_t *head);
    195 extern void list_concat(link_t *head1, link_t *head2);
    196 extern unsigned int list_count(const link_t *link);
     232/** Get n-th item of a list.
     233 *
     234 * @param list Pointer to link_t structure representing the list.
     235 * @param n    Item number (indexed from zero).
     236 *
     237 * @return n-th item of the list.
     238 * @return NULL if no n-th item found.
     239 *
     240 */
     241static inline link_t *list_nth(link_t *list, unsigned int n)
     242{
     243        unsigned int cnt = 0;
     244       
     245        list_foreach(*list, link) {
     246                if (cnt == n)
     247                        return link;
     248               
     249                cnt++;
     250        }
     251       
     252        return NULL;
     253}
     254
     255extern int list_member(const link_t *, const link_t *);
     256extern void list_concat(link_t *, link_t *);
     257extern unsigned int list_count(const link_t *);
    197258
    198259#endif
Note: See TracChangeset for help on using the changeset viewer.