Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > ListOfArrays
comparison ListOfArrays.h @ 1:fd441e4d0908
bugfix
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 19 Dec 2011 17:11:22 +0100 |
| parents | bc4b3434367f |
| children | ef1712d6d7d8 |
comparison
equal
deleted
inserted
replaced
| 0:5a2d77f93c8e | 1:d6ab726ceb8a |
|---|---|
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef LISTOFARRAYS_H | 8 #ifndef LISTOFARRAYS_H |
| 9 #define LISTOFARRAYS_H | 9 #define LISTOFARRAYS_H |
| 10 | 10 |
| 11 #include<stddef.h> | |
| 12 | |
| 11 typedef struct { | 13 typedef struct { |
| 12 ArrayFragment* next; | 14 void* next; |
| 13 void* data; | 15 void* data; |
| 14 } ArrayFragment; | 16 } ArrayFragment; |
| 15 | 17 |
| 16 typedef struct { | 18 typedef struct { |
| 17 ArrayFragment* first; | 19 ArrayFragment* first; |
| 18 ArrayFragment* last; | 20 ArrayFragment* last; |
| 19 size_t entry_size; | 21 size_t entry_size; |
| 20 int num_entries_per_fragment; | 22 int num_entries_per_fragment; |
| 21 int next_free_index; | 23 int next_free_index; |
| 22 } ListOfArrays; | 24 } ListOfArrays; |
| 25 | |
| 26 ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block); | |
| 23 | 27 |
| 24 #define addToListOfArrays(type,value,list) do { \ | 28 #define addToListOfArrays(type,value,list) do { \ |
| 25 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ | 29 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ |
| 26 if(offset_in_fragment == 0){ \ | 30 if(offset_in_fragment == 0){ \ |
| 27 ArrayFragment* newBlock = (ArrayFragment*) VMS__malloc(sizeof(ArrayFragment*) + list->entry_size * list->num_entries_per_fragment); \ | 31 ArrayFragment* newBlock = (ArrayFragment*) VMS__malloc(sizeof(ArrayFragment*) + list->entry_size * list->num_entries_per_fragment); \ |
| 32 if(list->last != NULL) { \ | 36 if(list->last != NULL) { \ |
| 33 list->last->next = newBlock; \ | 37 list->last->next = newBlock; \ |
| 34 } \ | 38 } \ |
| 35 list->last = newBlock; \ | 39 list->last = newBlock; \ |
| 36 } \ | 40 } \ |
| 37 (type*) typedFragment = (type*) list->last->data; \ | 41 type* typedFragment = (type*) &(list->last->data); \ |
| 38 typedFragment[offset_in_fragment] = value; \ | 42 typedFragment[offset_in_fragment] = value; \ |
| 43 list->next_free_index++; \ | |
| 39 } while (0) | 44 } while (0) |
| 40 | 45 |
| 41 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * | 46 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * |
| 42 | 47 |
| 48 void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr); | |
| 49 | |
| 50 #define getValuefromListOfArrays(type,index,list) | |
| 51 | |
| 52 #define setValueInListOfArrays(type,index,value,list) | |
| 53 | |
| 43 #endif /* LISTOFARRAYS_H */ | 54 #endif /* LISTOFARRAYS_H */ |
| 44 | 55 |
