annotate prlistofarrays.h @ 18:db10d06ca4ad

adding netbeans project directories to repository
author Sean Halle <seanhalle@yahoo.com>
date Fri, 14 Feb 2014 07:48:08 -0800
parents
children
rev   line source
seanhalle@17 1 /*
seanhalle@17 2 * File: ListOfArrays.h
seanhalle@17 3 * Author: Nina Engelhardt
seanhalle@17 4 *
seanhalle@17 5 * Created on December 16, 2011, 2:06 PM
seanhalle@17 6 */
seanhalle@17 7
seanhalle@17 8 #ifndef _LISTOFARRAYS_H
seanhalle@17 9 #define _LISTOFARRAYS_H
seanhalle@17 10
seanhalle@17 11 #include<stddef.h>
seanhalle@17 12 #include <inttypes.h>
seanhalle@17 13
seanhalle@17 14 #include <PR__include/PR__primitive_data_types.h>
seanhalle@17 15 #include <PR__include/prdynarray.h>
seanhalle@17 16
seanhalle@17 17
seanhalle@17 18 typedef struct {
seanhalle@17 19 void* next;
seanhalle@17 20 void* data;
seanhalle@17 21 } ArrayFragment;
seanhalle@17 22
seanhalle@17 23 typedef struct {
seanhalle@17 24 void** dim1;
seanhalle@17 25 PrivDynArrayInfo* dim1info;
seanhalle@17 26 //ArrayFragment* last;
seanhalle@17 27 size_t entry_size;
seanhalle@17 28 int num_entries_per_fragment;
seanhalle@17 29 int next_free_index;
seanhalle@17 30 } ListOfArrays;
seanhalle@17 31
seanhalle@17 32 ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block);
seanhalle@17 33
seanhalle@17 34 #define addToListOfArrays(type,value,list) do { \
seanhalle@17 35 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \
seanhalle@17 36 if(offset_in_fragment == 0){ \
seanhalle@17 37 void* newBlock = PR__malloc(list->entry_size * list->num_entries_per_fragment); \
seanhalle@17 38 addToDynArray(newBlock,list->dim1info); \
seanhalle@17 39 } \
seanhalle@17 40 type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \
seanhalle@17 41 typedFragment[offset_in_fragment] = value; \
seanhalle@17 42 list->next_free_index++; \
seanhalle@17 43 } while (0)
seanhalle@17 44
seanhalle@17 45 #define addToListOfArrays_ext(type,value,list) do { \
seanhalle@17 46 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \
seanhalle@17 47 if(offset_in_fragment == 0){ \
seanhalle@17 48 void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); \
seanhalle@17 49 addToDynArray(newBlock,list->dim1info); \
seanhalle@17 50 } \
seanhalle@17 51 type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \
seanhalle@17 52 typedFragment[offset_in_fragment] = value; \
seanhalle@17 53 list->next_free_index++; \
seanhalle@17 54 } while (0)
seanhalle@17 55
seanhalle@17 56 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void *
seanhalle@17 57
seanhalle@17 58 void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr);
seanhalle@17 59
seanhalle@17 60 #define valueInListOfArrays(type,index,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment]
seanhalle@17 61
seanhalle@17 62 #define setValueInListOfArrays(type,index,value,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment] = value
seanhalle@17 63
seanhalle@17 64 void freeListOfArrays(ListOfArrays* list);
seanhalle@17 65
seanhalle@17 66 #endif /* LISTOFARRAYS_H */
seanhalle@17 67