# HG changeset patch # User Nina Engelhardt # Date 1331229926 -3600 # Node ID 79982974d355e490dcaad9ee7a26a11f046697c5 # Parent 53df05eb8d43f4ba154bbeae241495847d7e23b3 fix bug when last fragment exactly full diff -r 53df05eb8d43 -r 79982974d355 ListOfArrays.c --- a/ListOfArrays.c Wed Dec 21 16:55:02 2011 +0100 +++ b/ListOfArrays.c Thu Mar 08 19:05:26 2012 +0100 @@ -1,6 +1,6 @@ #include "ListOfArrays.h" -#include "../vmalloc.h" +#include "../../VMS_Implementations/VMS_impl/vmalloc.h" ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block){ ListOfArrays* newLoA = (ListOfArrays*) VMS__malloc(sizeof(ListOfArrays)); @@ -16,7 +16,8 @@ void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr){ int n; uintptr_t p; - for(n=0;ndim1info->numInArray -1; n++){ + int num_full = list->next_free_index / list->num_entries_per_fragment; //list->dim1info->numInArray -1 + for(n=0;ndim1)[n]; p < (uintptr_t) (list->dim1)[n] + list->num_entries_per_fragment * list->entry_size; p += list->entry_size){ (*fnPtr)((void*)p); } diff -r 53df05eb8d43 -r 79982974d355 ListOfArrays.h --- a/ListOfArrays.h Wed Dec 21 16:55:02 2011 +0100 +++ b/ListOfArrays.h Thu Mar 08 19:05:26 2012 +0100 @@ -39,6 +39,17 @@ list->next_free_index++; \ } while (0) +#define addToListOfArrays_ext(type,value,list) do { \ + int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \ + if(offset_in_fragment == 0){ \ + void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); \ + addToDynArray(newBlock,list->dim1info); \ + } \ + type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \ + typedFragment[offset_in_fragment] = value; \ + list->next_free_index++; \ +} while (0) + typedef void (*ListOfArraysFnPtr) ( void * ); //fn has to cast void * void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr);