Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > ListOfArrays
changeset 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 |
| files | ListOfArrays.c ListOfArrays.h |
| diffstat | 2 files changed, 48 insertions(+), 25 deletions(-) [+] |
line diff
1.1 --- a/ListOfArrays.c Mon Dec 19 17:11:22 2011 +0100 1.2 +++ b/ListOfArrays.c Tue Dec 20 18:52:57 2011 +0100 1.3 @@ -4,8 +4,9 @@ 1.4 1.5 ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block){ 1.6 ListOfArrays* newLoA = (ListOfArrays*) VMS__malloc(sizeof(ListOfArrays)); 1.7 - newLoA->first = NULL; 1.8 - newLoA->last = NULL; 1.9 + newLoA->dim1info = makePrivDynArrayOfSize(&(newLoA->dim1),8); 1.10 + 1.11 + 1.12 newLoA->entry_size = entry_size; 1.13 newLoA->num_entries_per_fragment = num_entries_per_block; 1.14 newLoA->next_free_index = 0; 1.15 @@ -14,20 +15,42 @@ 1.16 } 1.17 1.18 void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr){ 1.19 - ArrayFragment* current = list->first; 1.20 - int num_full_blocks = (list->next_free_index / list->num_entries_per_fragment); 1.21 + int n; 1.22 uintptr_t p; 1.23 - while(num_full_blocks > 0){ 1.24 - for(p = (uintptr_t)&(current->data); p < (uintptr_t) &(current->data) + list->num_entries_per_fragment * list->entry_size; p += list->entry_size){ 1.25 + for(n=0;n<list->dim1info->numInArray -1; n++){ 1.26 + for(p = (uintptr_t) (list->dim1)[n]; p < (uintptr_t) (list->dim1)[n] + list->num_entries_per_fragment * list->entry_size; p += list->entry_size){ 1.27 (*fnPtr)((void*)p); 1.28 } 1.29 - current = (ArrayFragment*) current->next; 1.30 - num_full_blocks--; 1.31 } 1.32 - //assert(current == list->last); 1.33 int offset_in_last = list->next_free_index % list->num_entries_per_fragment; 1.34 + n = list->dim1info->numInArray - 1; 1.35 + if (n >= 0){ 1.36 + for(p = (uintptr_t)(list->dim1)[n]; p < (uintptr_t)(list->dim1)[n] + offset_in_last * list->entry_size; p += list->entry_size){ 1.37 + (*fnPtr)((void*)p); 1.38 + } 1.39 + } 1.40 +} 1.41 1.42 - for(p = (uintptr_t)&(current->data); p < (uintptr_t)&(current->data) + offset_in_last * list->entry_size; p += list->entry_size){ 1.43 - (*fnPtr)((void*)p); 1.44 - } 1.45 -} 1.46 \ No newline at end of file 1.47 +/* 1.48 +void addToListOfArraysDependency(Dependency value, ListOfArrays* list){ 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 = VMS__malloc(list->entry_size * list->num_entries_per_fragment); 1.52 + addToDynArray(newBlock,list->dim1info); 1.53 + } 1.54 + Dependency* typedFragment = (Dependency*) ((list->dim1)[list->dim1info->numInArray -1]); 1.55 + typedFragment[offset_in_fragment] = value; 1.56 + list->next_free_index++; 1.57 +} 1.58 + 1.59 +void addToListOfArraysUnit(Unit value, ListOfArrays* list){ 1.60 + int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; 1.61 + if(offset_in_fragment == 0){ 1.62 + void* newBlock = VMS__malloc(list->entry_size * list->num_entries_per_fragment); 1.63 + addToDynArray(newBlock,list->dim1info); 1.64 + } 1.65 + Unit* typedFragment = (Unit*) ((list->dim1)[list->dim1info->numInArray -1]); 1.66 + typedFragment[offset_in_fragment] = value; 1.67 + list->next_free_index++; 1.68 +} 1.69 + */ 1.70 \ No newline at end of file
2.1 --- a/ListOfArrays.h Mon Dec 19 17:11:22 2011 +0100 2.2 +++ b/ListOfArrays.h Tue Dec 20 18:52:57 2011 +0100 2.3 @@ -9,6 +9,9 @@ 2.4 #define LISTOFARRAYS_H 2.5 2.6 #include<stddef.h> 2.7 +#include "../DynArray/DynArray.h" 2.8 +#include "../../dependency.h" 2.9 + 2.10 2.11 typedef struct { 2.12 void* next; 2.13 @@ -16,8 +19,9 @@ 2.14 } ArrayFragment; 2.15 2.16 typedef struct { 2.17 - ArrayFragment* first; 2.18 - ArrayFragment* last; 2.19 + void** dim1; 2.20 + PrivDynArrayInfo* dim1info; 2.21 + //ArrayFragment* last; 2.22 size_t entry_size; 2.23 int num_entries_per_fragment; 2.24 int next_free_index; 2.25 @@ -28,21 +32,17 @@ 2.26 #define addToListOfArrays(type,value,list) do { \ 2.27 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ 2.28 if(offset_in_fragment == 0){ \ 2.29 - ArrayFragment* newBlock = (ArrayFragment*) VMS__malloc(sizeof(ArrayFragment*) + list->entry_size * list->num_entries_per_fragment); \ 2.30 - newBlock->next == NULL; \ 2.31 - if(list->first == NULL) {\ 2.32 - list->first = newBlock; \ 2.33 - } \ 2.34 - if(list->last != NULL) { \ 2.35 - list->last->next = newBlock; \ 2.36 - } \ 2.37 - list->last = newBlock; \ 2.38 + void* newBlock = VMS__malloc(list->entry_size * list->num_entries_per_fragment); \ 2.39 + addToDynArray(newBlock,list->dim1info); \ 2.40 } \ 2.41 - type* typedFragment = (type*) &(list->last->data); \ 2.42 + type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \ 2.43 typedFragment[offset_in_fragment] = value; \ 2.44 list->next_free_index++; \ 2.45 } while (0) 2.46 2.47 +//void addToListOfArraysDependency(Dependency value, ListOfArrays* list); 2.48 +//void addToListOfArraysUnit(Unit value, ListOfArrays* list); 2.49 + 2.50 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * 2.51 2.52 void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr);
