Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

bsd-list.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1991, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. All advertising materials mentioning features or use of this software
00014  *    must display the following acknowledgement:
00015  *      This product includes software developed by the University of
00016  *      California, Berkeley and its contributors.
00017  * 4. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  *      @(#)queue.h     8.5 (Berkeley) 8/20/94
00034  * $Id: bsd-list.h,v 1.1 2000/08/17 00:04:21 haoboy Exp $
00035  */
00036 
00037 #ifndef _NS_BSD_LIST_H_
00038 #define _NS_BSD_LIST_H_
00039 
00040 // Copied from sys/queue.h in FreeBSD
00041 
00042 /*
00043  * This file defines five types of data structures: singly-linked lists,
00044  * slingly-linked tail queues, lists, tail queues, and circular queues.
00045  *
00046  * A singly-linked list is headed by a single forward pointer. The elements
00047  * are singly linked for minimum space and pointer manipulation overhead at
00048  * the expense of O(n) removal for arbitrary elements. New elements can be
00049  * added to the list after an existing element or at the head of the list.
00050  * Elements being removed from the head of the list should use the explicit
00051  * macro for this purpose for optimum efficiency. A singly-linked list may
00052  * only be traversed in the forward direction.  Singly-linked lists are ideal
00053  * for applications with large datasets and few or no removals or for
00054  * implementing a LIFO queue.
00055  *
00056  * A singly-linked tail queue is headed by a pair of pointers, one to the
00057  * head of the list and the other to the tail of the list. The elements are
00058  * singly linked for minimum space and pointer manipulation overhead at the
00059  * expense of O(n) removal for arbitrary elements. New elements can be added
00060  * to the list after an existing element, at the head of the list, or at the
00061  * end of the list. Elements being removed from the head of the tail queue
00062  * should use the explicit macro for this purpose for optimum efficiency.
00063  * A singly-linked tail queue may only be traversed in the forward direction.
00064  * Singly-linked tail queues are ideal for applications with large datasets
00065  * and few or no removals or for implementing a FIFO queue.
00066  *
00067  * A list is headed by a single forward pointer (or an array of forward
00068  * pointers for a hash table header). The elements are doubly linked
00069  * so that an arbitrary element can be removed without a need to
00070  * traverse the list. New elements can be added to the list before
00071  * or after an existing element or at the head of the list. A list
00072  * may only be traversed in the forward direction.
00073  *
00074  * A tail queue is headed by a pair of pointers, one to the head of the
00075  * list and the other to the tail of the list. The elements are doubly
00076  * linked so that an arbitrary element can be removed without a need to
00077  * traverse the list. New elements can be added to the list before or
00078  * after an existing element, at the head of the list, or at the end of
00079  * the list. A tail queue may only be traversed in the forward direction.
00080  *
00081  * A circle queue is headed by a pair of pointers, one to the head of the
00082  * list and the other to the tail of the list. The elements are doubly
00083  * linked so that an arbitrary element can be removed without a need to
00084  * traverse the list. New elements can be added to the list before or after
00085  * an existing element, at the head of the list, or at the end of the list.
00086  * A circle queue may be traversed in either direction, but has a more
00087  * complex end of list detection.
00088  *
00089  * For details on the use of these macros, see the queue(3) manual page.
00090  */
00091 
00092 /*
00093  * List definitions.
00094  */
00095 #define LIST_HEAD(name, type)                                           \
00096 struct name {                                                           \
00097         type *lh_first; /* first element */                     \
00098 }
00099 
00100 #define LIST_ENTRY(type)                                                \
00101 struct {                                                                \
00102         type *le_next;  /* next element */                      \
00103         type **le_prev; /* address of previous next element */  \
00104 }
00105 
00106 /*
00107  * List functions.
00108  */
00109 #define LIST_INIT(head) {                                               \
00110         (head)->lh_first = NULL;                                        \
00111 }
00112 
00113 #define LIST_INSERT_AFTER(listelm, elm, field) {                        \
00114         if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)  \
00115                 (listelm)->field.le_next->field.le_prev =               \
00116                     &(elm)->field.le_next;                              \
00117         (listelm)->field.le_next = (elm);                               \
00118         (elm)->field.le_prev = &(listelm)->field.le_next;               \
00119 }
00120 
00121 #define LIST_INSERT_BEFORE(listelm, elm, field) {                       \
00122         (elm)->field.le_prev = (listelm)->field.le_prev;                \
00123         (elm)->field.le_next = (listelm);                               \
00124         *(listelm)->field.le_prev = (elm);                              \
00125         (listelm)->field.le_prev = &(elm)->field.le_next;               \
00126 }
00127 
00128 #define LIST_INSERT_HEAD(head, elm, field) {                            \
00129         if (((elm)->field.le_next = (head)->lh_first) != NULL)          \
00130                 (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
00131         (head)->lh_first = (elm);                                       \
00132         (elm)->field.le_prev = &(head)->lh_first;                       \
00133 }
00134 
00135 #define LIST_REMOVE(elm, field) {                                       \
00136         if ((elm)->field.le_next != NULL)                               \
00137                 (elm)->field.le_next->field.le_prev =                   \
00138                     (elm)->field.le_prev;                               \
00139         *(elm)->field.le_prev = (elm)->field.le_next;                   \
00140 }
00141 
00142 #endif /* !_NS_BSD_LIST_H_ */

Generated on Tue Apr 20 12:14:11 2004 for NS2.26SourcesOriginal by doxygen 1.3.3