diff prlistofarrays.h @ 17:6386ae5cc770

Updated include paths
author Sean Halle <seanhalle@yahoo.com>
date Fri, 20 Sep 2013 00:02:12 -0700
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/prlistofarrays.h	Fri Sep 20 00:02:12 2013 -0700
     1.3 @@ -0,0 +1,67 @@
     1.4 +/* 
     1.5 + * File:   ListOfArrays.h
     1.6 + * Author: Nina Engelhardt
     1.7 + *
     1.8 + * Created on December 16, 2011, 2:06 PM
     1.9 + */
    1.10 +
    1.11 +#ifndef  _LISTOFARRAYS_H
    1.12 +#define	_LISTOFARRAYS_H
    1.13 +
    1.14 +#include<stddef.h>
    1.15 +#include <inttypes.h>
    1.16 +
    1.17 +#include <PR__include/PR__primitive_data_types.h>
    1.18 +#include <PR__include/prdynarray.h>
    1.19 +
    1.20 +
    1.21 +typedef struct {
    1.22 +    void* next;
    1.23 +    void* data;
    1.24 +} ArrayFragment;
    1.25 +
    1.26 +typedef struct {
    1.27 +    void** dim1;
    1.28 +    PrivDynArrayInfo* dim1info;
    1.29 +    //ArrayFragment* last;
    1.30 +    size_t entry_size;
    1.31 +    int num_entries_per_fragment;
    1.32 +    int next_free_index;
    1.33 +} ListOfArrays;
    1.34 +
    1.35 +ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block);
    1.36 +
    1.37 +#define addToListOfArrays(type,value,list) do { \
    1.38 +    int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \
    1.39 +    if(offset_in_fragment == 0){ \
    1.40 +        void* newBlock = PR__malloc(list->entry_size * list->num_entries_per_fragment); \
    1.41 +        addToDynArray(newBlock,list->dim1info); \
    1.42 +    } \
    1.43 +    type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \
    1.44 +    typedFragment[offset_in_fragment] = value; \
    1.45 +    list->next_free_index++; \
    1.46 +} while (0)
    1.47 +
    1.48 +#define addToListOfArrays_ext(type,value,list) do { \
    1.49 +    int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \
    1.50 +    if(offset_in_fragment == 0){ \
    1.51 +        void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); \
    1.52 +        addToDynArray(newBlock,list->dim1info); \
    1.53 +    } \
    1.54 +    type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \
    1.55 +    typedFragment[offset_in_fragment] = value; \
    1.56 +    list->next_free_index++; \
    1.57 +} while (0)
    1.58 +
    1.59 +typedef void  (*ListOfArraysFnPtr)  ( void * );  //fn has to cast void *
    1.60 +
    1.61 +void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr);
    1.62 +
    1.63 +#define valueInListOfArrays(type,index,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment]
    1.64 +
    1.65 +#define setValueInListOfArrays(type,index,value,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment] = value
    1.66 +
    1.67 +void freeListOfArrays(ListOfArrays* list);
    1.68 +
    1.69 +#endif	/* LISTOFARRAYS_H */
    1.70 +