3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 /* Simple macros for typesafe, intrusive lists.
27 * (C) 1997, Keith Whitwell
29 * Intended to work with a list sentinal which is created as an empty
30 * list. Insert & delete are O(1).
34 #ifndef _SIMPLE_LIST_H
35 #define _SIMPLE_LIST_H
37 #define remove_from_list(elem) \
39 (elem)->next->prev = (elem)->prev; \
40 (elem)->prev->next = (elem)->next; \
43 #define insert_at_head(list, elem) \
45 (elem)->prev = list; \
46 (elem)->next = (list)->next; \
47 (list)->next->prev = elem; \
48 (list)->next = elem; \
51 #define insert_at_tail(list, elem) \
53 (elem)->next = list; \
54 (elem)->prev = (list)->prev; \
55 (list)->prev->next = elem; \
56 (list)->prev = elem; \
59 #define move_to_head(list, elem) \
61 remove_from_list(elem); \
62 insert_at_head(list, elem); \
65 #define move_to_tail(list, elem) \
67 remove_from_list(elem); \
68 insert_at_tail(list, elem); \
72 #define make_empty_list(sentinal) \
74 (sentinal)->next = sentinal; \
75 (sentinal)->prev = sentinal; \
79 #define first_elem(list) ((list)->next)
80 #define last_elem(list) ((list)->prev)
81 #define next_elem(elem) ((elem)->next)
82 #define prev_elem(elem) ((elem)->prev)
83 #define at_end(list, elem) ((elem) == (list))
84 #define is_empty_list(list) ((list)->next == (list))
86 #define foreach(ptr, list) \
87 for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next )
89 /* Kludgey - Lets you unlink the current value during a list
90 * traversal. Useful for free()-ing a list, element
93 #define foreach_s(ptr, t, list) \
94 for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next)