Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > DynArray
comparison Vector.c @ 1:2698781db812
Not sure changes -- not being used in VMSHW_matrix_mult
| author | Me |
|---|---|
| date | Wed, 28 Jul 2010 13:14:00 -0700 |
| parents | b1f178ed41a3 |
| children |
comparison
equal
deleted
inserted
replaced
| 0:9040f3edda48 | 1:fe718783932f |
|---|---|
| 7 | 7 |
| 8 | 8 |
| 9 #include <stdio.h> | 9 #include <stdio.h> |
| 10 #include <malloc.h> | 10 #include <malloc.h> |
| 11 | 11 |
| 12 #include "Vector.h" | |
| 12 | 13 |
| 13 | 14 |
| 14 /*make a struct with the sizes and a pointer to the | 15 /*make a struct with the sizes and a pointer to the |
| 15 * array, but hide a reverse pointer at the front of the array that | 16 * array, but hide a reverse pointer at the front of the array that |
| 16 * points back to the vector struct -- that way, can pass around the | 17 * points back to the vector struct -- that way, can pass around the |
| 20 * so from the point of changing size on, have the correct array ptr, | 21 * so from the point of changing size on, have the correct array ptr, |
| 21 * and also all other places that initiate a sequence later will get | 22 * and also all other places that initiate a sequence later will get |
| 22 * the array ptr from the vector struct at the sequence start.. | 23 * the array ptr from the vector struct at the sequence start.. |
| 23 */ | 24 */ |
| 24 bool8 | 25 bool8 |
| 25 addToVect( Vector *vect, void *ptrToElem ) | 26 addToVect( void *ptrToElem, Vector *vect ) |
| 26 { int32 numPtrsInVect, sizeOfVect; | 27 { int32 numPtrsInVect, sizeOfVect; |
| 27 | 28 |
| 28 /* | 29 /* |
| 29 numPtrsInVect = *(vect -1); //num ptrs is "hidden" in front | 30 numPtrsInVect = *(vect -1); //num ptrs is "hidden" in front |
| 30 sizeOfVect = *(vect -2); | 31 sizeOfVect = *(vect -2); |
| 36 | 37 |
| 37 vect->arrayOfPtrs[numPtrsInVect] = ptrToElem; | 38 vect->arrayOfPtrs[numPtrsInVect] = ptrToElem; |
| 38 vect->numPtrsInArray++; | 39 vect->numPtrsInArray++; |
| 39 } | 40 } |
| 40 | 41 |
| 41 void ** | 42 void |
| 42 increaseSizeOfVect( Vector *vect ) | 43 increaseSizeOfVect( Vector *vect ) |
| 43 { int32 oldSizeOfArray, newSizeOfArray, i; | 44 { int32 oldSizeOfArray, newSizeOfArray, i; |
| 44 void **newArray, **oldArray; | 45 void **newArray, **oldArray; |
| 45 | 46 |
| 46 oldSizeOfArray = vect->sizeOfArray; | 47 oldSizeOfArray = vect->sizeOfArray; |
| 55 } | 56 } |
| 56 vect->arrayOfPtrs = newArray; | 57 vect->arrayOfPtrs = newArray; |
| 57 vect->sizeOfArray = newSizeOfArray; | 58 vect->sizeOfArray = newSizeOfArray; |
| 58 | 59 |
| 59 free( oldArray -1 ); | 60 free( oldArray -1 ); |
| 60 return newArray; | |
| 61 } | 61 } |
| 62 | 62 |
| 63 /* | 63 /* |
| 64 bool8 | 64 bool8 |
| 65 forAllInVectDo( ptrToFnTakesVectElemAsVoid* ) | 65 forAllInVectDo( ptrToFnTakesVectElemAsVoid* ) |
