vector.h

Go to the documentation of this file.
00001 
00033 #ifndef _vector_h_
00034 #define _vector_h_
00035 
00036 #include "bool.h"
00037 
00045 typedef Bool (*LessThanOp)(void *item1, void *item2);
00046 
00053 typedef void (*DestructorOp)(void *item);
00054 
00061 void GenericPointerFree(void *item);
00062 
00071 #define HEAP_PARENT_INDEX(i)  (((i) - 1) >> 1)
00072 
00081 #define HEAP_CHILD_INDEX(i)   (((i) << 1) + 1)
00082 
00089 struct Vector_t {
00094     LessThanOp lessOp;
00099     DestructorOp destructOp;
00105     void  *array;
00111     unsigned int itemSize;
00116     unsigned int items;
00122     unsigned int size;
00127     unsigned int minSize;
00128 };
00129 
00130 typedef struct Vector_t Vector;
00131 
00158 Bool VectorInit(Vector *vec, unsigned int initSize);
00159 
00172 void VectorDestroy(Vector *vec);
00173 
00184 Bool VectorCopy(Vector *target, Vector *source);
00185 
00195 void VectorClear(Vector *vec);
00196 
00207 void *VectorAdd(Vector *vec);
00208 
00220 void *VectorPush(Vector *vec, void *item);
00221 
00238 void *VectorHeapPush(Vector *vec, void *item);
00239 
00248 void VectorPop(Vector *vec);
00249 
00264 void VectorHeapPop(Vector *vec);
00265 
00277 void VectorHeapSort(Vector *vec);
00278 
00294 #define VectorInsert(vec, index)  VectorInsertMany(vec, index, 1)
00295 
00312 void *VectorInsertMany(Vector *vec, unsigned int index, unsigned int count);
00313 
00323 #define VectorRemove(vec, index)  VectorRemoveMany(vec, index, 1)
00324 
00336 void VectorRemoveMany(Vector *vec, unsigned int index, unsigned int count);
00337 
00350 void VectorMakeHeap(Vector *vec);
00351 
00363 Bool VectorReserve(Vector *vec, unsigned int size);
00364 
00373 #define VectorFirst(vec)  (((vec)->items) ? (vec)->array : NULL)
00374 
00383 #define VectorLast(vec)   (((vec)->items) ? \
00384              &(((char*)(vec)->array)[((vec)->items - 1) * (vec)->itemSize]) : \
00385              NULL)
00386 
00398 #define VectorItem(vec, index)  (((unsigned)(index) < (vec)->items) ? \
00399                    &(((char*)(vec)->array)[index * (vec)->itemSize]) : NULL)
00400 
00401 #endif
00402 

Generated on Mon May 28 04:41:39 2007 for Retro Tank Super Attack by  doxygen 1.5.2