From 291c783983b64f4b0ae4f6f67a016233193efa8c Mon Sep 17 00:00:00 2001 From: Franz Zotter Date: Wed, 29 Aug 2012 06:58:22 +0000 Subject: cleaned up code for mtx_qhull svn path=/trunk/externals/iem/iemmatrix/; revision=16183 --- src/mtx_qhull/list.c | 54 +++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'src/mtx_qhull/list.c') diff --git a/src/mtx_qhull/list.c b/src/mtx_qhull/list.c index 6f3b416..cf2b797 100644 --- a/src/mtx_qhull/list.c +++ b/src/mtx_qhull/list.c @@ -2,6 +2,20 @@ #include #include +/* + * list operations for zhull + * + * Copyright (c) 2012, Franz Zotter, + * with friendly help from + * IOhannes zmoelnig + * for variable entry types + * in entry.h + * IEM, Graz, Austria + * + * + */ + + // memory things: list_t emptyList(void) { list_t generated_list; @@ -16,7 +30,6 @@ list_t allocateList(const size_t length) { generated_list.entries= (entry_t*) malloc(length*sizeof(entry_t)); if (generated_list.entries!=0) { generated_list.length=length; - // printf("got list %li\n",generated_list.entries); } } return generated_list; @@ -26,7 +39,7 @@ void reallocateList(list_t *list, const size_t length) { entry_t *old_entries = list->entries; if (length>0) { - if (list->length==0) + if (getLength(*list)==0) *list = allocateList(length); else { if (list->length != length) @@ -39,18 +52,11 @@ void reallocateList(list_t *list, } else freeList(list); - /* if ((list->entries!=old_entries)&&(old_entries!=0)) { - if (list->entries!=0) - printf("moved %li by realloc to %li\n",old_entries,list->entries); - else - printf("freed %li by realloc\n", old_entries); - }*/ } void freeList(list_t *list) { if (list->entries!=0) { - // printf("deleting list %li\n",list->entries); free(list->entries); } list->entries=0; @@ -72,24 +78,27 @@ entry_t getEntry(const list_t list, const index_t index) { } } -void setEntry(const list_t list, const index_t index, const entry_t entry) { +void setEntry(const list_t list, const index_t index, + const entry_t entry) { if ((index>=0)&&(index=getLength(list1)) { for (i=0; i(size_t)i) { + if (getLength(*list)>i) { setEntry(*list,i,entry); } } @@ -213,13 +222,10 @@ void removeValueFromList(list_t *list, const entry_t entry) { void appendListToList(list_t *list1, const list_t list2) { index_t i,j; - size_t siz_old = getLength(*list1); - siz_old=list1->length; + const size_t siz_old = getLength(*list1); reallocateList(list1, getLength(*list1) + getLength(list2)); - if (getLength(*list1)>siz_old) { - for (i=siz_old, j=0; ilength; i++, j++) - setEntry(*list1,i,getEntry(list2,j)); - } + for (i=siz_old, j=0; i