changeset 2:ad8621ee5986

Chgd name to DynArray
author Me
date Thu, 02 Sep 2010 17:48:38 -0700
parents 2698781db812
children
files DynArray.c DynArray.h Vector.c Vector.h
diffstat 4 files changed, 98 insertions(+), 98 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/DynArray.c	Thu Sep 02 17:48:38 2010 -0700
     1.3 @@ -0,0 +1,69 @@
     1.4 +/*
     1.5 + * Copyright 2010  OpenSourceCodeStewardshipFoundation
     1.6 + *
     1.7 + * Licensed under BSD
     1.8 + */
     1.9 +
    1.10 +
    1.11 +
    1.12 +#include <stdio.h>
    1.13 +#include <malloc.h>
    1.14 +
    1.15 +#include "Vector.h"
    1.16 +
    1.17 +
    1.18 +/*make a struct with the sizes and a pointer to the
    1.19 + * array, but hide a reverse pointer at the front of the array that
    1.20 + * points back to the vector struct -- that way, can pass around the
    1.21 + * array when doing work on elements, but when need to increase size,
    1.22 + * get pointer to vector struct and use that, which will change the
    1.23 + * ptr to the array in the vector struc, and return the new pointer..
    1.24 + * so from the point of changing size on, have the correct array ptr,
    1.25 + * and also all other places that initiate a sequence later will get
    1.26 + * the array ptr from the vector struct at the sequence start..
    1.27 + */
    1.28 +bool8
    1.29 +addToVect( void *ptrToElem, Vector *vect )
    1.30 + { int32 numPtrsInVect, sizeOfVect;
    1.31 +
    1.32 +/*
    1.33 +   numPtrsInVect = *(vect -1);  //num ptrs is "hidden" in front
    1.34 +   sizeOfVect    = *(vect -2);
    1.35 +*/
    1.36 +   numPtrsInVect = vect->numPtrsInArray;
    1.37 +   sizeOfVect    = vect->sizeOfArray;
    1.38 +
    1.39 +   if( numPtrsInVect >= sizeOfVect ) return FALSE;
    1.40 +
    1.41 +   vect->arrayOfPtrs[numPtrsInVect] = ptrToElem;
    1.42 +   vect->numPtrsInArray++;
    1.43 + }
    1.44 +
    1.45 +void
    1.46 +increaseSizeOfVect( Vector *vect )
    1.47 + { int32 oldSizeOfArray, newSizeOfArray, i;
    1.48 +   void **newArray, **oldArray;
    1.49 + 
    1.50 +   oldSizeOfArray   = vect->sizeOfArray;
    1.51 +   newSizeOfArray   = oldSizeOfArray * 2;
    1.52 +   oldArray      = vect->arrayOfPtrs;
    1.53 +   newArray      = malloc( (newSizeOfArray + 1) * sizeof(void *) );
    1.54 +   *newArray     = vect;
    1.55 +   newArray++;
    1.56 +   for( i = 0; i < oldSizeOfArray; i++ )
    1.57 +    {
    1.58 +      newArray[i] = oldArray[i];
    1.59 +    }
    1.60 +   vect->arrayOfPtrs = newArray;
    1.61 +   vect->sizeOfArray = newSizeOfArray;
    1.62 +
    1.63 +   free( oldArray -1 );
    1.64 + }
    1.65 +
    1.66 +/*
    1.67 +bool8
    1.68 +forAllInVectDo( ptrToFnTakesVectElemAsVoid* )
    1.69 + {
    1.70 +   return success; 
    1.71 + }
    1.72 +*/
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/DynArray.h	Thu Sep 02 17:48:38 2010 -0700
     2.3 @@ -0,0 +1,29 @@
     2.4 +/* 
     2.5 + * File:   Vector.h
     2.6 + * Author: Me
     2.7 + *
     2.8 + * Created on May 14, 2010, 3:08 PM
     2.9 + */
    2.10 +
    2.11 +#ifndef _VECTOR_H
    2.12 +#define	_VECTOR_H
    2.13 +
    2.14 +#include "../VMS_primitive_data_types.h"
    2.15 +
    2.16 +//Doing one special cheat -- hiding a back-ptr in front of array
    2.17 +typedef struct
    2.18 + {
    2.19 +   void  **arrayOfPtrs;
    2.20 +   int     numPtrsInArray;
    2.21 +   int     sizeOfArray;
    2.22 + }
    2.23 +Vector;
    2.24 +
    2.25 +Vector *createVect        ( int32 initialSizeOfArray );
    2.26 +void    increaseSizeOfVect( Vector *vect );
    2.27 +bool8   addToVect         ( void *ptrToAdd, Vector *vect );
    2.28 +bool8   removeLastInVect  ( Vector *vect );
    2.29 +
    2.30 +
    2.31 +#endif	/* _VECTOR_H */
    2.32 +
     3.1 --- a/Vector.c	Wed Jul 28 13:14:00 2010 -0700
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,69 +0,0 @@
     3.4 -/*
     3.5 - * Copyright 2010  OpenSourceCodeStewardshipFoundation
     3.6 - *
     3.7 - * Licensed under BSD
     3.8 - */
     3.9 -
    3.10 -
    3.11 -
    3.12 -#include <stdio.h>
    3.13 -#include <malloc.h>
    3.14 -
    3.15 -#include "Vector.h"
    3.16 -
    3.17 -
    3.18 -/*make a struct with the sizes and a pointer to the
    3.19 - * array, but hide a reverse pointer at the front of the array that
    3.20 - * points back to the vector struct -- that way, can pass around the
    3.21 - * array when doing work on elements, but when need to increase size,
    3.22 - * get pointer to vector struct and use that, which will change the
    3.23 - * ptr to the array in the vector struc, and return the new pointer..
    3.24 - * so from the point of changing size on, have the correct array ptr,
    3.25 - * and also all other places that initiate a sequence later will get
    3.26 - * the array ptr from the vector struct at the sequence start..
    3.27 - */
    3.28 -bool8
    3.29 -addToVect( void *ptrToElem, Vector *vect )
    3.30 - { int32 numPtrsInVect, sizeOfVect;
    3.31 -
    3.32 -/*
    3.33 -   numPtrsInVect = *(vect -1);  //num ptrs is "hidden" in front
    3.34 -   sizeOfVect    = *(vect -2);
    3.35 -*/
    3.36 -   numPtrsInVect = vect->numPtrsInArray;
    3.37 -   sizeOfVect    = vect->sizeOfArray;
    3.38 -
    3.39 -   if( numPtrsInVect >= sizeOfVect ) return FALSE;
    3.40 -
    3.41 -   vect->arrayOfPtrs[numPtrsInVect] = ptrToElem;
    3.42 -   vect->numPtrsInArray++;
    3.43 - }
    3.44 -
    3.45 -void
    3.46 -increaseSizeOfVect( Vector *vect )
    3.47 - { int32 oldSizeOfArray, newSizeOfArray, i;
    3.48 -   void **newArray, **oldArray;
    3.49 - 
    3.50 -   oldSizeOfArray   = vect->sizeOfArray;
    3.51 -   newSizeOfArray   = oldSizeOfArray * 2;
    3.52 -   oldArray      = vect->arrayOfPtrs;
    3.53 -   newArray      = malloc( (newSizeOfArray + 1) * sizeof(void *) );
    3.54 -   *newArray     = vect;
    3.55 -   newArray++;
    3.56 -   for( i = 0; i < oldSizeOfArray; i++ )
    3.57 -    {
    3.58 -      newArray[i] = oldArray[i];
    3.59 -    }
    3.60 -   vect->arrayOfPtrs = newArray;
    3.61 -   vect->sizeOfArray = newSizeOfArray;
    3.62 -
    3.63 -   free( oldArray -1 );
    3.64 - }
    3.65 -
    3.66 -/*
    3.67 -bool8
    3.68 -forAllInVectDo( ptrToFnTakesVectElemAsVoid* )
    3.69 - {
    3.70 -   return success; 
    3.71 - }
    3.72 -*/
     4.1 --- a/Vector.h	Wed Jul 28 13:14:00 2010 -0700
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,29 +0,0 @@
     4.4 -/* 
     4.5 - * File:   Vector.h
     4.6 - * Author: Me
     4.7 - *
     4.8 - * Created on May 14, 2010, 3:08 PM
     4.9 - */
    4.10 -
    4.11 -#ifndef _VECTOR_H
    4.12 -#define	_VECTOR_H
    4.13 -
    4.14 -#include "../VMS_primitive_data_types.h"
    4.15 -
    4.16 -//Doing one special cheat -- hiding a back-ptr in front of array
    4.17 -typedef struct
    4.18 - {
    4.19 -   void  **arrayOfPtrs;
    4.20 -   int     numPtrsInArray;
    4.21 -   int     sizeOfArray;
    4.22 - }
    4.23 -Vector;
    4.24 -
    4.25 -Vector *createVect        ( int32 initialSizeOfArray );
    4.26 -void    increaseSizeOfVect( Vector *vect );
    4.27 -bool8   addToVect         ( void *ptrToAdd, Vector *vect );
    4.28 -bool8   removeLastInVect  ( Vector *vect );
    4.29 -
    4.30 -
    4.31 -#endif	/* _VECTOR_H */
    4.32 -