changeset 12:abf2117d7535 MC_shared

make lists clearable
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Fri, 31 Aug 2012 18:27:26 +0200
parents 5df9392eca1a
children 7128ffdcc797
files ListOfArrays.c ListOfArrays.h
diffstat 2 files changed, 10 insertions(+), 10 deletions(-) [+]
line diff
     1.1 --- a/ListOfArrays.c	Tue Mar 13 18:31:06 2012 -0700
     1.2 +++ b/ListOfArrays.c	Fri Aug 31 18:27:26 2012 +0200
     1.3 @@ -16,21 +16,24 @@
     1.4  void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr){
     1.5      int n;
     1.6      uintptr_t p;
     1.7 -    int num_full = list->next_free_index / list->num_entries_per_fragment; //list->dim1info->numInArray -1
     1.8 +    int num_full = list->next_free_index / list->num_entries_per_fragment; //!\\ != list->dim1info->numInArray-1
     1.9      for(n=0;n<num_full; n++){
    1.10          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.11              (*fnPtr)((void*)p);
    1.12          }
    1.13      }
    1.14      int offset_in_last = list->next_free_index % list->num_entries_per_fragment;
    1.15 -    n = list->dim1info->numInArray - 1;
    1.16 -    if (n >= 0){
    1.17 +    if (n < list->dim1info->numInArray){
    1.18          for(p = (uintptr_t)(list->dim1)[n]; p < (uintptr_t)(list->dim1)[n] + offset_in_last * list->entry_size; p += list->entry_size){
    1.19              (*fnPtr)((void*)p);
    1.20          }
    1.21      }
    1.22  }
    1.23  
    1.24 +void clearListOfArrays(ListOfArrays* list){
    1.25 +    list->next_free_index = 0;
    1.26 +}
    1.27 +
    1.28  void freeListOfArrays(ListOfArrays* list){
    1.29      freeDynArrayDeep(list->dim1info,&VMS_int__free);
    1.30      VMS_int__free((void*)list);
     2.1 --- a/ListOfArrays.h	Tue Mar 13 18:31:06 2012 -0700
     2.2 +++ b/ListOfArrays.h	Fri Aug 31 18:27:26 2012 +0200
     2.3 @@ -12,15 +12,10 @@
     2.4  #include "DynArray/DynArray.h"
     2.5  
     2.6  
     2.7 -typedef struct {
     2.8 -    void* next;
     2.9 -    void* data;
    2.10 -} ArrayFragment;
    2.11  
    2.12  typedef struct {
    2.13      void** dim1;
    2.14      PrivDynArrayInfo* dim1info;
    2.15 -    //ArrayFragment* last;
    2.16      size_t entry_size;
    2.17      int num_entries_per_fragment;
    2.18      int next_free_index;
    2.19 @@ -30,7 +25,7 @@
    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 +    if(offset_in_fragment == 0 && (list->next_free_index / list->num_entries_per_fragment) >= list->dim1info->numInArray){ \
    2.25          void* newBlock = VMS_int__malloc(list->entry_size * list->num_entries_per_fragment); \
    2.26          addToDynArray(newBlock,list->dim1info); \
    2.27      } \
    2.28 @@ -41,7 +36,7 @@
    2.29  
    2.30  #define addToListOfArrays_ext(type,value,list) do { \
    2.31      int offset_in_fragment = list->next_free_index % list->num_entries_per_fragment; \
    2.32 -    if(offset_in_fragment == 0){ \
    2.33 +    if(offset_in_fragment == 0 && (list->next_free_index / list->num_entries_per_fragment) >= list->dim1info->numInArray){ \
    2.34          void* newBlock = malloc(list->entry_size * list->num_entries_per_fragment); \
    2.35          addToDynArray(newBlock,list->dim1info); \
    2.36      } \
    2.37 @@ -54,6 +49,8 @@
    2.38  
    2.39  void forAllInListOfArraysDo(ListOfArrays* list, ListOfArraysFnPtr fnPtr);
    2.40  
    2.41 +void clearListOfArrays(ListOfArrays* list);
    2.42 +
    2.43  #define valueInListOfArrays(type,index,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment]
    2.44  
    2.45  #define setValueInListOfArrays(type,index,value,list) ((type*)((list->dim1)[index / list->num_entries_per_fragment]))[index % list->num_entries_per_fragment] = value