Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > ListOfArrays
comparison 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 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4238ad135c71 |
|---|---|
| 1 /* | |
| 2 * File: ListOfArrays.h | |
| 3 * Author: Nina Engelhardt | |
| 4 * | |
| 5 * Created on December 16, 2011, 2:06 PM | |
| 6 */ | |
| 7 | |
| 8 #ifndef _LISTOFARRAYS_H | |
| 9 #define _LISTOFARRAYS_H | |
| 10 | |
| 11 #include<stddef.h> | |
| 12 #include <inttypes.h> | |
| 13 | |
| 14 #include <PR__include/PR__primitive_data_types.h> | |
| 15 #include <PR__include/prdynarray.h> | |
| 16 | |
| 17 | |
| 18 typedef struct { | |
| 19 void* next; | |
| 20 void* data; | |
| 21 } ArrayFragment; | |
| 22 | |
| 23 typedef struct { | |
| 24 void** dim1; | |
| 25 PrivDynArrayInfo* dim1info; | |
| 26 //ArrayFragment* last; | |
| 27 size_t entry_size; | |
| 28 int num_entries_per_fragment; | |
| 29 int next_free_index; | |
| 30 } ListOfArrays; | |
| 31 | |
| 32 ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block); | |
| 33 | |
| 34 #define addToListOfArrays(type,value,list) do { \ | |
| 35 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ | |
| 36 if(offset_in_fragment == 0){ \ | |
| 37 void* newBlock = PR__malloc(list->entry_size * list->num_entries_per_fragment); \ | |
| 38 addToDynArray(newBlock,list->dim1info); \ | |
| 39 } \ | |
| 40 type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \ | |
| 41 typedFragment[offset_in_fragment] = value; \ | |
| 42 list->next_free_index++; \ | |
| 43 } while (0) | |
| 44 | |
| 45 #define addToListOfArrays_ext(type,value,list) do { \ | |
| 46 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ | |
| 47 if(offset_in_fragment == 0){ \ | |
| 48 void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); \ | |
| 49 addToDynArray(newBlock,list->dim1info); \ | |
| 50 } \ | |
| 51 type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \ | |
| 52 typedFragment[offset_in_fragment] = value; \ | |
| 53 list->next_free_index++; \ | |
| 54 } while (0) | |
| 55 | |
| 56 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * | |
| 57 | |
| 58 void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr); | |
| 59 | |
| 60 #define valueInListOfArrays(type,index,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment] | |
| 61 | |
| 62 #define setValueInListOfArrays(type,index,value,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment] = value | |
| 63 | |
| 64 void freeListOfArrays(ListOfArrays* list); | |
| 65 | |
| 66 #endif /* LISTOFARRAYS_H */ | |
| 67 |
