# HG changeset patch # User Me # Date 1283474918 25200 # Node ID ad8621ee5986bf662c1feed8e5c04e1f4d6e1d77 # Parent 2698781db8128058f86a5e4deb86d5d621d2d95f Chgd name to DynArray diff -r 2698781db812 -r ad8621ee5986 DynArray.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DynArray.c Thu Sep 02 17:48:38 2010 -0700 @@ -0,0 +1,69 @@ +/* + * Copyright 2010 OpenSourceCodeStewardshipFoundation + * + * Licensed under BSD + */ + + + +#include +#include + +#include "Vector.h" + + +/*make a struct with the sizes and a pointer to the + * array, but hide a reverse pointer at the front of the array that + * points back to the vector struct -- that way, can pass around the + * array when doing work on elements, but when need to increase size, + * get pointer to vector struct and use that, which will change the + * ptr to the array in the vector struc, and return the new pointer.. + * so from the point of changing size on, have the correct array ptr, + * and also all other places that initiate a sequence later will get + * the array ptr from the vector struct at the sequence start.. + */ +bool8 +addToVect( void *ptrToElem, Vector *vect ) + { int32 numPtrsInVect, sizeOfVect; + +/* + numPtrsInVect = *(vect -1); //num ptrs is "hidden" in front + sizeOfVect = *(vect -2); +*/ + numPtrsInVect = vect->numPtrsInArray; + sizeOfVect = vect->sizeOfArray; + + if( numPtrsInVect >= sizeOfVect ) return FALSE; + + vect->arrayOfPtrs[numPtrsInVect] = ptrToElem; + vect->numPtrsInArray++; + } + +void +increaseSizeOfVect( Vector *vect ) + { int32 oldSizeOfArray, newSizeOfArray, i; + void **newArray, **oldArray; + + oldSizeOfArray = vect->sizeOfArray; + newSizeOfArray = oldSizeOfArray * 2; + oldArray = vect->arrayOfPtrs; + newArray = malloc( (newSizeOfArray + 1) * sizeof(void *) ); + *newArray = vect; + newArray++; + for( i = 0; i < oldSizeOfArray; i++ ) + { + newArray[i] = oldArray[i]; + } + vect->arrayOfPtrs = newArray; + vect->sizeOfArray = newSizeOfArray; + + free( oldArray -1 ); + } + +/* +bool8 +forAllInVectDo( ptrToFnTakesVectElemAsVoid* ) + { + return success; + } +*/ diff -r 2698781db812 -r ad8621ee5986 DynArray.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DynArray.h Thu Sep 02 17:48:38 2010 -0700 @@ -0,0 +1,29 @@ +/* + * File: Vector.h + * Author: Me + * + * Created on May 14, 2010, 3:08 PM + */ + +#ifndef _VECTOR_H +#define _VECTOR_H + +#include "../VMS_primitive_data_types.h" + +//Doing one special cheat -- hiding a back-ptr in front of array +typedef struct + { + void **arrayOfPtrs; + int numPtrsInArray; + int sizeOfArray; + } +Vector; + +Vector *createVect ( int32 initialSizeOfArray ); +void increaseSizeOfVect( Vector *vect ); +bool8 addToVect ( void *ptrToAdd, Vector *vect ); +bool8 removeLastInVect ( Vector *vect ); + + +#endif /* _VECTOR_H */ + diff -r 2698781db812 -r ad8621ee5986 Vector.c --- a/Vector.c Wed Jul 28 13:14:00 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * Copyright 2010 OpenSourceCodeStewardshipFoundation - * - * Licensed under BSD - */ - - - -#include -#include - -#include "Vector.h" - - -/*make a struct with the sizes and a pointer to the - * array, but hide a reverse pointer at the front of the array that - * points back to the vector struct -- that way, can pass around the - * array when doing work on elements, but when need to increase size, - * get pointer to vector struct and use that, which will change the - * ptr to the array in the vector struc, and return the new pointer.. - * so from the point of changing size on, have the correct array ptr, - * and also all other places that initiate a sequence later will get - * the array ptr from the vector struct at the sequence start.. - */ -bool8 -addToVect( void *ptrToElem, Vector *vect ) - { int32 numPtrsInVect, sizeOfVect; - -/* - numPtrsInVect = *(vect -1); //num ptrs is "hidden" in front - sizeOfVect = *(vect -2); -*/ - numPtrsInVect = vect->numPtrsInArray; - sizeOfVect = vect->sizeOfArray; - - if( numPtrsInVect >= sizeOfVect ) return FALSE; - - vect->arrayOfPtrs[numPtrsInVect] = ptrToElem; - vect->numPtrsInArray++; - } - -void -increaseSizeOfVect( Vector *vect ) - { int32 oldSizeOfArray, newSizeOfArray, i; - void **newArray, **oldArray; - - oldSizeOfArray = vect->sizeOfArray; - newSizeOfArray = oldSizeOfArray * 2; - oldArray = vect->arrayOfPtrs; - newArray = malloc( (newSizeOfArray + 1) * sizeof(void *) ); - *newArray = vect; - newArray++; - for( i = 0; i < oldSizeOfArray; i++ ) - { - newArray[i] = oldArray[i]; - } - vect->arrayOfPtrs = newArray; - vect->sizeOfArray = newSizeOfArray; - - free( oldArray -1 ); - } - -/* -bool8 -forAllInVectDo( ptrToFnTakesVectElemAsVoid* ) - { - return success; - } -*/ diff -r 2698781db812 -r ad8621ee5986 Vector.h --- a/Vector.h Wed Jul 28 13:14:00 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * File: Vector.h - * Author: Me - * - * Created on May 14, 2010, 3:08 PM - */ - -#ifndef _VECTOR_H -#define _VECTOR_H - -#include "../VMS_primitive_data_types.h" - -//Doing one special cheat -- hiding a back-ptr in front of array -typedef struct - { - void **arrayOfPtrs; - int numPtrsInArray; - int sizeOfArray; - } -Vector; - -Vector *createVect ( int32 initialSizeOfArray ); -void increaseSizeOfVect( Vector *vect ); -bool8 addToVect ( void *ptrToAdd, Vector *vect ); -bool8 removeLastInVect ( Vector *vect ); - - -#endif /* _VECTOR_H */ -