Mercurial > cgi-bin > hgwebdir.cgi > VMS > C_Libraries > ListOfArrays
changeset 1:fd441e4d0908
bugfix
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 19 Dec 2011 17:11:22 +0100 |
| parents | bc4b3434367f |
| children | ef1712d6d7d8 |
| files | ListOfArrays.c ListOfArrays.h |
| diffstat | 2 files changed, 23 insertions(+), 10 deletions(-) [+] |
line diff
1.1 --- a/ListOfArrays.c Mon Dec 19 13:25:30 2011 +0100 1.2 +++ b/ListOfArrays.c Mon Dec 19 17:11:22 2011 +0100 1.3 @@ -15,17 +15,19 @@ 1.4 1.5 void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr){ 1.6 ArrayFragment* current = list->first; 1.7 - while(current->next){ 1.8 - uintptr_t p; 1.9 - for(p = current->data; p < current->data + list->num_entries_per_fragment * list->entry_size; p += list->entry_size){ 1.10 - (*fnPtr)(p); 1.11 + int num_full_blocks = (list->next_free_index / list->num_entries_per_fragment); 1.12 + uintptr_t p; 1.13 + while(num_full_blocks > 0){ 1.14 + for(p = (uintptr_t)&(current->data); p < (uintptr_t) &(current->data) + list->num_entries_per_fragment * list->entry_size; p += list->entry_size){ 1.15 + (*fnPtr)((void*)p); 1.16 } 1.17 - current = current->next; 1.18 + current = (ArrayFragment*) current->next; 1.19 + num_full_blocks--; 1.20 } 1.21 //assert(current == list->last); 1.22 int offset_in_last = list->next_free_index % list->num_entries_per_fragment; 1.23 - uintptr_t p; 1.24 - for(p = current->data; p < current->data + offset_in_last * list->entry_size; p += list->entry_size){ 1.25 - (*fnPtr)(p); 1.26 + 1.27 + for(p = (uintptr_t)&(current->data); p < (uintptr_t)&(current->data) + offset_in_last * list->entry_size; p += list->entry_size){ 1.28 + (*fnPtr)((void*)p); 1.29 } 1.30 } 1.31 \ No newline at end of file
2.1 --- a/ListOfArrays.h Mon Dec 19 13:25:30 2011 +0100 2.2 +++ b/ListOfArrays.h Mon Dec 19 17:11:22 2011 +0100 2.3 @@ -8,8 +8,10 @@ 2.4 #ifndef LISTOFARRAYS_H 2.5 #define LISTOFARRAYS_H 2.6 2.7 +#include<stddef.h> 2.8 + 2.9 typedef struct { 2.10 - ArrayFragment* next; 2.11 + void* next; 2.12 void* data; 2.13 } ArrayFragment; 2.14 2.15 @@ -21,6 +23,8 @@ 2.16 int next_free_index; 2.17 } ListOfArrays; 2.18 2.19 +ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block); 2.20 + 2.21 #define addToListOfArrays(type,value,list) do { \ 2.22 int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ 2.23 if(offset_in_fragment == 0){ \ 2.24 @@ -34,11 +38,18 @@ 2.25 } \ 2.26 list->last = newBlock; \ 2.27 } \ 2.28 - (type*) typedFragment = (type*) list->last->data; \ 2.29 + type* typedFragment = (type*) &(list->last->data); \ 2.30 typedFragment[offset_in_fragment] = value; \ 2.31 + list->next_free_index++; \ 2.32 } while (0) 2.33 2.34 typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * 2.35 2.36 +void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr); 2.37 + 2.38 +#define getValuefromListOfArrays(type,index,list) 2.39 + 2.40 +#define setValueInListOfArrays(type,index,value,list) 2.41 + 2.42 #endif /* LISTOFARRAYS_H */ 2.43
