Me@0: /* Me@0: * Copyright 2010 OpenSourceCodeStewardshipFoundation Me@0: * Me@0: * Licensed under BSD Me@0: */ Me@0: Me@0: Me@0: Me@0: #include Me@0: #include Me@0: Me@1: #include "Vector.h" Me@0: Me@0: Me@0: /*make a struct with the sizes and a pointer to the Me@0: * array, but hide a reverse pointer at the front of the array that Me@0: * points back to the vector struct -- that way, can pass around the Me@0: * array when doing work on elements, but when need to increase size, Me@0: * get pointer to vector struct and use that, which will change the Me@0: * ptr to the array in the vector struc, and return the new pointer.. Me@0: * so from the point of changing size on, have the correct array ptr, Me@0: * and also all other places that initiate a sequence later will get Me@0: * the array ptr from the vector struct at the sequence start.. Me@0: */ Me@0: bool8 Me@1: addToVect( void *ptrToElem, Vector *vect ) Me@0: { int32 numPtrsInVect, sizeOfVect; Me@0: Me@0: /* Me@0: numPtrsInVect = *(vect -1); //num ptrs is "hidden" in front Me@0: sizeOfVect = *(vect -2); Me@0: */ Me@0: numPtrsInVect = vect->numPtrsInArray; Me@0: sizeOfVect = vect->sizeOfArray; Me@0: Me@0: if( numPtrsInVect >= sizeOfVect ) return FALSE; Me@0: Me@0: vect->arrayOfPtrs[numPtrsInVect] = ptrToElem; Me@0: vect->numPtrsInArray++; Me@0: } Me@0: Me@1: void Me@0: increaseSizeOfVect( Vector *vect ) Me@0: { int32 oldSizeOfArray, newSizeOfArray, i; Me@0: void **newArray, **oldArray; Me@0: Me@0: oldSizeOfArray = vect->sizeOfArray; Me@0: newSizeOfArray = oldSizeOfArray * 2; Me@0: oldArray = vect->arrayOfPtrs; Me@0: newArray = malloc( (newSizeOfArray + 1) * sizeof(void *) ); Me@0: *newArray = vect; Me@0: newArray++; Me@0: for( i = 0; i < oldSizeOfArray; i++ ) Me@0: { Me@0: newArray[i] = oldArray[i]; Me@0: } Me@0: vect->arrayOfPtrs = newArray; Me@0: vect->sizeOfArray = newSizeOfArray; Me@0: Me@0: free( oldArray -1 ); Me@0: } Me@0: Me@0: /* Me@0: bool8 Me@0: forAllInVectDo( ptrToFnTakesVectElemAsVoid* ) Me@0: { Me@0: return success; Me@0: } Me@0: */