changeset 5:79982974d355

fix bug when last fragment exactly full
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Thu, 08 Mar 2012 19:05:26 +0100
parents 53df05eb8d43
children 2b29a1b832fd 33dd14a7f49d
files ListOfArrays.c ListOfArrays.h
diffstat 2 files changed, 14 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/ListOfArrays.c	Wed Dec 21 16:55:02 2011 +0100
     1.2 +++ b/ListOfArrays.c	Thu Mar 08 19:05:26 2012 +0100
     1.3 @@ -1,6 +1,6 @@
     1.4  
     1.5  #include "ListOfArrays.h"
     1.6 -#include "../vmalloc.h"
     1.7 +#include "../../VMS_Implementations/VMS_impl/vmalloc.h"
     1.8  
     1.9  ListOfArrays* makeListOfArrays(size_t entry_size, int num_entries_per_block){
    1.10      ListOfArrays* newLoA = (ListOfArrays*) VMS__malloc(sizeof(ListOfArrays));
    1.11 @@ -16,7 +16,8 @@
    1.12  void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr){
    1.13      int n;
    1.14      uintptr_t p;
    1.15 -    for(n=0;n<list->dim1info->numInArray -1; n++){
    1.16 +    int num_full = list->next_free_index / list->num_entries_per_fragment; //list->dim1info->numInArray -1
    1.17 +    for(n=0;n<num_full; n++){
    1.18          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.19              (*fnPtr)((void*)p);
    1.20          }
     2.1 --- a/ListOfArrays.h	Wed Dec 21 16:55:02 2011 +0100
     2.2 +++ b/ListOfArrays.h	Thu Mar 08 19:05:26 2012 +0100
     2.3 @@ -39,6 +39,17 @@
     2.4      list->next_free_index++; \
     2.5  } while (0)
     2.6  
     2.7 +#define addToListOfArrays_ext(type,value,list) do { \
     2.8 +    int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \
     2.9 +    if(offset_in_fragment == 0){ \
    2.10 +        void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); \
    2.11 +        addToDynArray(newBlock,list->dim1info); \
    2.12 +    } \
    2.13 +    type* typedFragment = (type*) ((list->dim1)[list->dim1info->numInArray -1]); \
    2.14 +    typedFragment[offset_in_fragment] = value; \
    2.15 +    list->next_free_index++; \
    2.16 +} while (0)
    2.17 +
    2.18  typedef void  (*ListOfArraysFnPtr)  ( void * );  //fn has to cast void *
    2.19  
    2.20  void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr);