diff DynArray.h @ 4:f35e64d7a42b

Working version used for probes in Master Env
author Me
date Sat, 30 Oct 2010 22:12:32 -0700
parents 8473c52c6f0e
children f4b108f21041 f9776626259b
line diff
     1.1 --- a/DynArray.h	Sun Sep 12 12:10:25 2010 -0700
     1.2 +++ b/DynArray.h	Sat Oct 30 22:12:32 2010 -0700
     1.3 @@ -5,23 +5,53 @@
     1.4   * Created on May 14, 2010, 3:08 PM
     1.5   */
     1.6  
     1.7 -#ifndef _VECTOR_H
     1.8 -#define	_VECTOR_H
     1.9 +#ifndef _DYNARRAY_H
    1.10 +#define	_DYNARRAY_H
    1.11  
    1.12 -//Doing one special cheat -- hiding a back-ptr in front of array
    1.13 +#include "../VMS_primitive_data_types.h"
    1.14 +
    1.15 +
    1.16 +   //A dynamic array is same as any other array, but add a DynArrayInfo next
    1.17 +   // to it.  Accesses and updates of array indexes are done normally, it's
    1.18 +   // only when add a new element into array that use the extra info.
    1.19 +   // An add can cause the pointer to the normal array to change..  so must
    1.20 +   // be protected to single VP at a time.
    1.21  typedef struct
    1.22   {
    1.23 -   void  **arrayOfPtrs;
    1.24 -   int     numPtrsInArray;
    1.25 -   int     sizeOfArray;
    1.26 +   void ***addrOfPtrToArray; //addr of array of ptrs == triple *
    1.27 +   int32   numInArray;
    1.28 +   int32   sizeOfArray;
    1.29   }
    1.30 -Vector;
    1.31 +DynArrayInfo;
    1.32  
    1.33 -Vector *createVect        ( int32 initialSizeOfArray );
    1.34 -Vector *increaseSizeOfVect( Vector *vect );
    1.35 -bool8   addToVect         ( void *ptrToAdd, Vector *vect );
    1.36 -bool8   removeLastInVect  ( Vector *vect );
    1.37 +DynArrayInfo *
    1.38 +makeDynArrayInfoFrom( void ***addrOfPtrToArray, int32 sizeOfArray );
    1.39  
    1.40 +DynArrayInfo *
    1.41 +makeDynArrayOfSize( void ***addrOfPtrToArray, int32 sizeOfArray );
    1.42  
    1.43 -#endif	/* _VECTOR_H */
    1.44 +int32
    1.45 +addToDynArray( void *value, DynArrayInfo *info );
    1.46  
    1.47 +void
    1.48 +makeHighestDynArrayIndexBe( DynArrayInfo *info, int32 highestIndex );
    1.49 +
    1.50 +void
    1.51 +increaseSizeOfDynArrayTo( DynArrayInfo *info, int32 newSize );
    1.52 +
    1.53 +typedef void  (*FreeFnPtr)  ( void * ); //fn has to cast void * to whatever
    1.54 +
    1.55 +void
    1.56 +freeDynArrayDeep( DynArrayInfo *info, FreeFnPtr freeFnPtr );
    1.57 +
    1.58 +void
    1.59 +freeDynArrayFlat( DynArrayInfo *info );
    1.60 +
    1.61 +
    1.62 +typedef void  (*DynArrayFnPtr)  ( void * );  //fn has to cast void *
    1.63 +
    1.64 +void
    1.65 +forAllInDynArrayDo( DynArrayInfo *info, DynArrayFnPtr fnPtr );
    1.66 +
    1.67 +#endif	/* _DYNARRAY_H */
    1.68 +