Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > ListOfArrays
comparison ListOfArrays.h @ 2:ef1712d6d7d8
change internal structure from list to dynarray
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 20 Dec 2011 18:52:57 +0100 |
| parents | fd441e4d0908 |
| children | 9c577efe70cd |
comparison
equal
deleted
inserted
replaced
| 1:d6ab726ceb8a | 2:1cca35d9beb6 |
|---|---|
| 7 | 7 |
| 8 #ifndef LISTOFARRAYS_H | 8 #ifndef LISTOFARRAYS_H |
| 9 #define LISTOFARRAYS_H | 9 #define LISTOFARRAYS_H |
| 10 | 10 |
| 11 #include<stddef.h> | 11 #include<stddef.h> |
| 12 #include "../DynArray/DynArray.h" | |
| 13 #include "../../dependency.h" | |
| 14 | |
| 12 | 15 |
| 13 typedef struct { | 16 typedef struct { |
| 14 void* next; | 17 void* next; |
| 15 void* data; | 18 void* data; |
| 16 } ArrayFragment; | 19 } ArrayFragment; |
| 17 | 20 |
| 18 typedef struct { | 21 typedef struct { |
| 19 ArrayFragment* first; | 22 void** dim1; |
| 20 ArrayFragment* last; | 23 PrivDynArrayInfo* dim1info; |
| 24 //ArrayFragment* last; | |
| 21 size_t entry_size; | 25 size_t entry_size; |
| 22 int num_entries_per_fragment; | 26 int num_entries_per_fragment; |
| 23 int next_free_index; | 27 int next_free_index; |
| 24 } ListOfArrays; | 28 } ListOfArrays; |
| 25 | 29 |
| 26 ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block); | 30 ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block); |
| 27 | 31 |
| 28 #define addToListOfArrays(type,value,list) do { \ | 32 #define addToListOfArrays(type,value,list) do { \ |
| 29 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ | 33 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ |
| 30 if(offset_in_fragment == 0){ \ | 34 if(offset_in_fragment == 0){ \ |
| 31 ArrayFragment* newBlock = (ArrayFragment*) VMS__malloc(sizeof(ArrayFragment*) + list->entry_size * list->num_entries_per_fragment); \ | 35 void* newBlock = VMS__malloc(list->entry_size * list->num_entries_per_fragment); \ |
| 32 newBlock->next == NULL; \ | 36 addToDynArray(newBlock,list->dim1info); \ |
| 33 if(list->first == NULL) {\ | |
| 34 list->first = newBlock; \ | |
| 35 } \ | |
| 36 if(list->last != NULL) { \ | |
| 37 list->last->next = newBlock; \ | |
| 38 } \ | |
| 39 list->last = newBlock; \ | |
| 40 } \ | 37 } \ |
| 41 type* typedFragment = (type*) &(list->last->data); \ | 38 type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \ |
| 42 typedFragment[offset_in_fragment] = value; \ | 39 typedFragment[offset_in_fragment] = value; \ |
| 43 list->next_free_index++; \ | 40 list->next_free_index++; \ |
| 44 } while (0) | 41 } while (0) |
| 42 | |
| 43 //void addToListOfArraysDependency(Dependency value, ListOfArrays* list); | |
| 44 //void addToListOfArraysUnit(Unit value, ListOfArrays* list); | |
| 45 | 45 |
| 46 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * | 46 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * |
| 47 | 47 |
| 48 void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr); | 48 void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr); |
| 49 | 49 |
