annotate 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
rev   line source
Me@0 1 /*
Me@0 2 * Copyright 2010 OpenSourceCodeStewardshipFoundation
Me@0 3 *
Me@0 4 * Licensed under BSD
Me@0 5 */
Me@0 6
Me@0 7
Me@0 8
Me@0 9 #include <stdio.h>
Me@0 10 #include <malloc.h>
Me@0 11
Me@1 12 #include "Vector.h"
Me@0 13
Me@0 14
Me@0 15 /*make a struct with the sizes and a pointer to the
Me@0 16 * array, but hide a reverse pointer at the front of the array that
Me@0 17 * points back to the vector struct -- that way, can pass around the
Me@0 18 * array when doing work on elements, but when need to increase size,
Me@0 19 * get pointer to vector struct and use that, which will change the
Me@0 20 * ptr to the array in the vector struc, and return the new pointer..
Me@0 21 * so from the point of changing size on, have the correct array ptr,
Me@0 22 * and also all other places that initiate a sequence later will get
Me@0 23 * the array ptr from the vector struct at the sequence start..
Me@0 24 */
Me@0 25 bool8
Me@1 26 addToVect( void *ptrToElem, Vector *vect )
Me@0 27 { int32 numPtrsInVect, sizeOfVect;
Me@0 28
Me@0 29 /*
Me@0 30 numPtrsInVect = *(vect -1); //num ptrs is "hidden" in front
Me@0 31 sizeOfVect = *(vect -2);
Me@0 32 */
Me@0 33 numPtrsInVect = vect->numPtrsInArray;
Me@0 34 sizeOfVect = vect->sizeOfArray;
Me@0 35
Me@0 36 if( numPtrsInVect >= sizeOfVect ) return FALSE;
Me@0 37
Me@0 38 vect->arrayOfPtrs[numPtrsInVect] = ptrToElem;
Me@0 39 vect->numPtrsInArray++;
Me@0 40 }
Me@0 41
Me@1 42 void
Me@0 43 increaseSizeOfVect( Vector *vect )
Me@0 44 { int32 oldSizeOfArray, newSizeOfArray, i;
Me@0 45 void **newArray, **oldArray;
Me@0 46
Me@0 47 oldSizeOfArray = vect->sizeOfArray;
Me@0 48 newSizeOfArray = oldSizeOfArray * 2;
Me@0 49 oldArray = vect->arrayOfPtrs;
Me@0 50 newArray = malloc( (newSizeOfArray + 1) * sizeof(void *) );
Me@0 51 *newArray = vect;
Me@0 52 newArray++;
Me@0 53 for( i = 0; i < oldSizeOfArray; i++ )
Me@0 54 {
Me@0 55 newArray[i] = oldArray[i];
Me@0 56 }
Me@0 57 vect->arrayOfPtrs = newArray;
Me@0 58 vect->sizeOfArray = newSizeOfArray;
Me@0 59
Me@0 60 free( oldArray -1 );
Me@0 61 }
Me@0 62
Me@0 63 /*
Me@0 64 bool8
Me@0 65 forAllInVectDo( ptrToFnTakesVectElemAsVoid* )
Me@0 66 {
Me@0 67 return success;
Me@0 68 }
Me@0 69 */