This page is part of an archival collection and is no longer actively maintained.

It may contain outdated information and may not meet current or future WCAG accessibility standards. We provide this content, its subpages, and associated links for historical reference only. If you need assistance, please contact support@cs.washington.edu

VFML: lists.h Source File
Main Page | Modules | Data Structures | File List | Globals | Related Pages

lists.h

Go to the documentation of this file.
00001 #ifndef LISTSH
00002 #define LISTSH
00003 
00004 
00058 /* Generic list code.  VoidList is for when you want a list of pointers to
00059    things and IntList is for when you just want to store a bunch of integers
00060     in a list.
00061 
00062     IntList is so you don't always have to create a bunch of pointers to ints
00063     to store them.
00064 
00065    By Geoff Hulten
00066    Revised 2/5/98
00067 */
00068 
00069 /* HERE add some asserts to this code */
00070 
00071 //#define LINKEDLISTS
00072 
00073 #ifdef LINKEDLISTS
00074    #define VoidList     VoidLList
00075    #define VoidListPtr  VoidLListPtr
00076    #define VoidListHandle       VoidLListHandle
00077 
00078    #define VLNew                VLLNew
00079    #define VLAppend             VLLAppend
00080    #define VLPush               VLLPush
00081    #define VLLength             VLLLength
00082    #define VLIndex              VLLIndex
00083    #define VLSort               VLLSort
00084    #define VLRemove             VLLRemove
00085    #define VLInsert             VLLInsert
00086    #define VLSet                VLLSet
00087    #define VLFree               VLLFree
00088 
00089 #else /* ARRAYLISTS */
00090    #define VoidList     VoidAList
00091    #define VoidListPtr  VoidAListPtr
00092    #define VoidListHandle       VoidAListHandle
00093 
00094    #define VLNew                VALNew
00095    #define VLAppend             VALAppend
00096    #define VLPush               VALPush
00097    #define VLLength             VALLength
00098    #define VLIndex              VALIndex
00099    #define VLSort               VALSort
00100    #define VLRemove             VALRemove
00101    #define VLInsert             VALInsert
00102    #define VLSet                VALSet
00103    #define VLFree               VALFree
00104 #endif
00105 
00106 typedef struct _VoidLList_ {
00107    void *element;
00108    struct _VoidLList_ *next;
00109 } VoidLList, *VoidLListPtr, **VoidLListHandle;
00110 
00111 VoidLListPtr VLLNew(void);
00112 /* append the element to the end of the list */
00113 void VLLAppend(VoidLListPtr list, void *element);
00114 /* push element on the head of the list */
00115 void VLLPush(VoidLListPtr list, void *element);
00116 int VLLLength(VoidLListPtr list);
00117 
00118 void *VLLIndex(VoidLListPtr list, long index);
00119 void VLLSort(VoidLListPtr list, int (*cmp)(const void *, const void *));
00120 void *VLLRemove(VoidLListPtr list, long index);
00121 void VLLInsert(VoidLListPtr list, void *element, long index);
00122 void VLLSet(VoidLListPtr list, long index, void *newVal);
00123 void VLLFree(VoidLListPtr list);
00124 
00132 typedef struct _VoidAList_ {
00133    int size;
00134    int allocatedSize;
00135    void **array;
00136 } VoidAList, *VoidAListPtr, **VoidAListHandle;
00137 
00139 VoidAListPtr VALNew(void);
00141 void VALAppend(VoidAListPtr list, void *element);
00143 void VALPush(VoidAListPtr list, void *element);
00144 
00146 //int VALLength(VoidAListPtr list);
00147 #define VALLength(list) \
00148    (((VoidAListPtr)(list))->size)
00149 
00154 //void *VALIndex(VoidAListPtr list, long index);
00155 #define VALIndex(list, index) \
00156     ( (index < ((VoidAListPtr)list)->size) ? (((VoidAListPtr)list)->array[index]) : (0) )
00157 
00163 void VALSort(VoidAListPtr list, int (*cmp)(const void *, const void *));
00164 
00169 void *VALRemove(VoidAListPtr list, long index);
00170 
00177 void VALInsert(VoidAListPtr list, void *element, long index);
00178 
00184 void VALSet(VoidAListPtr list, long index, void *newVal);
00185 
00190 void VALFree(VoidAListPtr list);
00191 
00198 typedef VoidAList    IntList;
00199 typedef VoidAListPtr IntListPtr;
00200 
00201 #define ILNew()             VLNew()
00202 #define ILClone(l)          VLClone(l)
00203 #define ILAppend(l, e)      VLAppend(l, (void *)e)
00204 #define ILPush(l, e)        VLPush(l, (void *) e)
00205 #define ILInsert(l, e, i)   VLInsert(l, (void *) e, i)
00206 #define ILLength(l)         VLLength(l)
00207 #define ILIndex(l, i)       (void *)VLIndex(l, i)
00208 #define ILRemove(l, i)      (void *)VLRemove(l, i)
00209 #define ILSet(l, i, e)      VLSet(l, i, (void *)e)
00210 #define ILFree(l)           VLFree(l)
00211 #define ILFind(l, e)        VLFind(l, (void *)e)
00212 
00213 //typedef struct _IntList_ {
00214 //   int theInt;
00215 //   struct _IntList_ *next;
00216 //} IntList, *IntListPtr, **IntListHandle;
00217 
00218 //IntListPtr ILNew(void);
00219 //IntListPtr ILClone(IntListPtr orig);
00220 /* append the element to the end of the list */
00221 //void ILAppend(IntListPtr list, int element);
00222 /* push element on the head of the list */
00223 //void ILPush(IntListPtr list, int element);
00224 //void ILInsert(IntListPtr list, int element, long index);
00225 //int ILLength(IntListPtr list);
00226 //int ILIndex(IntListPtr list, long index);
00227 //int ILRemove(IntListPtr list, long index);
00228 //void ILSet(IntListPtr list, long index, int newVal);
00229 //void ILFree(IntListPtr list);
00230 //int ILFind(IntListPtr list, int element);
00231 
00232 
00239 typedef struct _FloatList_ {
00240    int size;
00241    int allocatedSize;
00242    float *array;
00243 } FloatList, *FloatListPtr, **FloatListHandle;
00244 
00245 FloatListPtr FLNew(void);
00246 FloatListPtr FLClone(FloatListPtr orig);
00247 /* append the element to the end of the list */
00248 void FLAppend(FloatListPtr list, float element);
00249 /* push element on the head of the list */
00250 void FLPush(FloatListPtr list, float element);
00251 void FLInsert(FloatListPtr list, float element, long index);
00252 int FLLength(FloatListPtr list);
00253 
00254 float FLIndex(FloatListPtr list, long index);
00255 float FLRemove(FloatListPtr list, long index);
00256 void FLSet(FloatListPtr list, long index, float newVal);
00257 void FLFree(FloatListPtr list);
00258 int FLFind(FloatListPtr list, float element);
00259 
00260 #endif

Generated for VFML by doxygen hosted by SourceForge.net Logo