Main Page | Data Structures | File List | Globals | Related Pages

list.h

Go to the documentation of this file.
00001 
00012 #ifndef __KERN_LIST_H__
00013 #define __KERN_LIST_H__
00014 
00015 /* a list node */
00016 typedef struct ListNode
00017 {
00018     /* the next node in the list */
00019     struct ListNode * next;
00020     /* the previous node in the list */
00021     struct ListNode * previous;
00022 } ListNode;
00023 
00024 /* an abstract iterator for the list */
00025 typedef ListNode * ListIterator;
00026 
00027 /* a list structure which contains the sentinel node
00028  * the sentinel's next is the first item in the list
00029  * the sentinel's previous is the last item in the list
00030  * if no item are in the list the sentinel points to itself
00031  */
00032 typedef struct
00033 {   
00034    /* the sentinel node of the list */
00035     ListNode sentinel;
00036 } List;
00037 
00038 #define list_begin(list)        ((list) -> sentinel.next)
00039 #define list_end(list)          (& (list) -> sentinel)
00040 #define list_next(iterator)     ((iterator) -> next)
00041 #define list_previous(iterator) ((iterator) -> previous)
00042 
00043 #define list_front(list)        ((void *) list_begin (list))
00044 #define list_back(list)         ((void *) list_previous (list_end (list)))
00045 
00046 #define list_empty(list)        (list_begin (list) == list_end (list))
00047 
00048 #define list_insert_front(list,value)   (list_insert (list_begin (list), (value)))
00049 #define list_insert_back(list,value)    (list_insert (list_end (list), (value)))
00050 
00051 #define list_remove_front(list) (list_remove (list_begin (list)))
00052 #define list_remove_back(list)  (list_remove (list_previous (list_end (list))))
00053 
00054 #define LIST_ELEMENT(node,type,field) \
00055         ((type *) ((char *) (node) - (unsigned int) & ((type *) 0) -> field))
00056 
00065 extern void list_clear (List * list);
00075 extern ListIterator list_insert (ListIterator position, void *value);
00084 extern void * list_remove (ListIterator position);
00093 extern unsigned int list_size (List * list);
00094 
00095 #endif /* __KERN_LIST_H__ */
00096  

Generated on Fri Apr 9 21:59:16 2004 for 15-410 Project 3 by doxygen 1.3.2