Rev 55 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
55 | pj | 1 | /* $Id: simple_list.h,v 1.1 2003-02-28 11:42:04 pj Exp $ */ |
2 | |||
3 | /* |
||
4 | * Mesa 3-D graphics library |
||
5 | * Version: 3.5 |
||
6 | * |
||
7 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
||
8 | * |
||
9 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
10 | * copy of this software and associated documentation files (the "Software"), |
||
11 | * to deal in the Software without restriction, including without limitation |
||
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
13 | * and/or sell copies of the Software, and to permit persons to whom the |
||
14 | * Software is furnished to do so, subject to the following conditions: |
||
15 | * |
||
16 | * The above copyright notice and this permission notice shall be included |
||
17 | * in all copies or substantial portions of the Software. |
||
18 | * |
||
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||
23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||
24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | */ |
||
26 | |||
27 | /* Simple macros for typesafe, intrusive lists. |
||
28 | * (C) 1997, Keith Whitwell |
||
29 | * |
||
30 | * Intended to work with a list sentinal which is created as an empty |
||
31 | * list. Insert & delete are O(1). |
||
32 | */ |
||
33 | |||
34 | |||
35 | #ifndef _SIMPLE_LIST_H |
||
36 | #define _SIMPLE_LIST_H |
||
37 | |||
38 | #define remove_from_list(elem) \ |
||
39 | do { \ |
||
40 | (elem)->next->prev = (elem)->prev; \ |
||
41 | (elem)->prev->next = (elem)->next; \ |
||
42 | } while (0) |
||
43 | |||
44 | #define insert_at_head(list, elem) \ |
||
45 | do { \ |
||
46 | (elem)->prev = list; \ |
||
47 | (elem)->next = (list)->next; \ |
||
48 | (list)->next->prev = elem; \ |
||
49 | (list)->next = elem; \ |
||
50 | } while(0) |
||
51 | |||
52 | #define insert_at_tail(list, elem) \ |
||
53 | do { \ |
||
54 | (elem)->next = list; \ |
||
55 | (elem)->prev = (list)->prev; \ |
||
56 | (list)->prev->next = elem; \ |
||
57 | (list)->prev = elem; \ |
||
58 | } while(0) |
||
59 | |||
60 | #define move_to_head(list, elem) \ |
||
61 | do { \ |
||
62 | remove_from_list(elem); \ |
||
63 | insert_at_head(list, elem); \ |
||
64 | } while (0) |
||
65 | |||
66 | #define move_to_tail(list, elem) \ |
||
67 | do { \ |
||
68 | remove_from_list(elem); \ |
||
69 | insert_at_tail(list, elem); \ |
||
70 | } while (0) |
||
71 | |||
72 | |||
73 | #define make_empty_list(sentinal) \ |
||
74 | do { \ |
||
75 | (sentinal)->next = sentinal; \ |
||
76 | (sentinal)->prev = sentinal; \ |
||
77 | } while (0) |
||
78 | |||
79 | |||
80 | #define first_elem(list) ((list)->next) |
||
81 | #define last_elem(list) ((list)->prev) |
||
82 | #define next_elem(elem) ((elem)->next) |
||
83 | #define prev_elem(elem) ((elem)->prev) |
||
84 | #define at_end(list, elem) ((elem) == (list)) |
||
85 | #define is_empty_list(list) ((list)->next == (list)) |
||
86 | |||
87 | #define foreach(ptr, list) \ |
||
88 | for( ptr=(list)->next ; ptr!=list ; ptr=(ptr)->next ) |
||
89 | |||
90 | /* Kludgey - Lets you unlink the current value during a list |
||
91 | * traversal. Useful for free()-ing a list, element |
||
92 | * by element. |
||
93 | */ |
||
94 | #define foreach_s(ptr, t, list) \ |
||
95 | for(ptr=(list)->next,t=(ptr)->next; list != ptr; ptr=t, t=(t)->next) |
||
96 | |||
97 | |||
98 | #endif |