Main Page | Data Structures | File List | Data Fields | Globals

llist.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1999-2003 Andrew Moenk and Alex Scott
00003  *
00004  * This library is free software; you can redistribute it and/or modify it
00005  * under the terms of the GNU Library General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or (at
00007  * your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; if not, write to the Free Software Foundation,
00016  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00023 #include "cuf-global.h"
00024 
00025 #ifndef _LLIST_H_
00026 #define _LLIST_H_
00027 
00032 #define DEFAULT_PIVOT_THRESHOLD         20
00033 
00037 typedef struct _Llist Llist;
00038 
00043 typedef struct _LlistExtras {
00044         Llist *first;
00045         Llist *last;
00046         int done;
00047         int pivot_threshold;
00048         unsigned long length;
00049         int autorewind;
00050 } LlistExtras;
00051 
00058 struct _Llist {
00059         Llist *prev, *next;             
00060         LlistExtras *ext;               
00061         void *data;                     
00062 };
00063 
00064 typedef Comparison (*CompareFunc) (void *, void *);
00065 typedef void (*OperationFunc) (void *);
00066 
00067 
00068 /* Attempt at backwards compatable functions */
00069 
00070 void *llist_node_data_next (Llist **inlist);
00071 void *llist_node_data_prev (Llist **inlist);
00072 void *llist_node_data_seek_cfunc (Llist **inlist, void *data,
00073                                   CompareFunc cfunc);
00074 void *llist_node_data_seek_position (Llist **inlist, unsigned long pos);
00075 
00076 
00077 /*** Add/Remove data from a list ***/
00078 
00079 Llist *llist_append (Llist *list, void *data);
00080 Llist *llist_prepend (Llist *list, void *data);
00081 Llist *llist_remove (Llist *list, void *data);
00082 Llist *llist_remove_cfunc (Llist *list, void *data, CompareFunc cfunc);
00083 Llist *llist_remove_opfunc (Llist *list, void *data, OperationFunc opfunc);
00084 Llist *llist_remove_cfunc_opfunc (Llist *list, void *data, CompareFunc cfunc,
00085                                   OperationFunc opfunc);
00086 
00087 
00088 /*** Dupicate/Deallocation of a list ***/
00089 
00090 Llist *llist_duplicate (Llist *orglist);
00091 void llist_free (Llist *list);
00092 void llist_free_opfunc (Llist *list, OperationFunc opfunc);
00093 
00094 
00095 /*** Data Retrieval/List Traversing ***/
00096 
00097 Llist *llist_seek (Llist *list, void *data);
00098 Llist *llist_seek_cfunc (Llist *list, void *data, CompareFunc cfunc);
00099 Llist *llist_seek_position (Llist *list, unsigned long pos);
00100 Llist *llist_rewind (Llist *list);
00101 Llist *llist_fastforward (Llist *list);
00102 
00103 
00104 /*** Sorting/Data Position Manipulation ***/
00105 
00106 Llist *llist_reverse (Llist *list);
00107 Llist *llist_bubblesort (Llist *list, CompareFunc cfunc);
00108 Llist *llist_quicksort (Llist *list, CompareFunc cfunc);
00109 Llist *llist_data_rise (Llist *list, void *data);
00110 Llist *llist_data_fall (Llist *list, void *data);
00111 
00112 
00113 /*** List Option Manipulation ***/
00114 
00115 void llist_autorewind_set (Llist *list, int autorewind);
00116 void llist_default_autorewind_set (int autorewind);
00117 void llist_pivot_threshold_set (Llist *list, int pivot_threshold);
00118 
00119 /*** Miscellaneous ***/
00120 
00121 unsigned long llist_length (Llist *list);
00122 unsigned long llist_length_recalculate (Llist *list);
00123 void llist_extras_print (Llist *list);
00124 
00125 
00126 /***-- Macros To Lessen The Function Names --***/
00127 
00136 #define lla(l, d)               l=llist_append (l, d)
00137 
00145 #define llp(l, d)               l=llist_prepend (l, d)
00146 
00153 #define llrm(l, d)              l=llist_remove (l, d)
00154 
00162 #define llrmcf(l, d, cf)                l=llist_remove_cfunc (l, d, (CompareFunc)cf)
00163 
00171 #define llrmop(l, d, op)                l=llist_remove_opfunc (l, d, (OperationFunc)op)
00172 
00182 #define llrmcfop(l, d, cf, op)  l=llist_remove_cfunc_opfunc (l, d, (CompareFunc)cf, (OperationFunc)op)
00183 
00189 #define llfree(l)               llist_free (l)
00190 
00197 #define llfreeop(l, op)         llist_free_opfunc (l, (OperationFunc)op)
00198 
00207 #define llnext(l)               llist_node_data_next (&l)
00208 
00216 #define llprev(l)               llist_node_data_prev (&l)
00217 
00228 #define llseekcf(l, d, cf)      llist_node_data_seek_cfunc (&l, d, (CompareFunc)cf)
00229 
00237 #define llseekp(l, pos) llist_node_data_seek_position (&l, pos)
00238 
00245 #define llrise(l)               l=llist_data_rise (l, l->data)
00246 
00252 #define llfall(l)               l=llist_data_fall (l, l->data)
00253 
00259 #define llrew(l)                l=llist_rewind (l)
00260 
00265 #define llff(l)                 l=llist_fastforward (l)
00266 
00271 #define llrev(l)                l=llist_reverse (l)
00272 
00280 #define lllen(l)                llist_length (l)
00281 
00296 #define llforeach(l, v)         for (v=llnext (l); v; v=llnext (l))
00297 
00314 #define llforeachb(l, v, b)     for (v=llnext (l); v && b; v=llnext (l))
00315 
00316 #endif /* _LLIST_H_ */

Generated on Fri Jun 4 18:35:18 2004 for cuf by doxygen 1.3.6