From 5086631c287a954bae9c2bb4a987cb7f1eda3e57 Mon Sep 17 00:00:00 2001 From: Franz Zotter Date: Tue, 21 Aug 2012 08:10:42 +0000 Subject: convex hull algorithm added svn path=/trunk/externals/iem/iemmatrix/; revision=16165 --- src/mtx_qhull/list.c | 294 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 294 insertions(+) create mode 100644 src/mtx_qhull/list.c (limited to 'src/mtx_qhull/list.c') diff --git a/src/mtx_qhull/list.c b/src/mtx_qhull/list.c new file mode 100644 index 0000000..07ce4f2 --- /dev/null +++ b/src/mtx_qhull/list.c @@ -0,0 +1,294 @@ + +// memory things: +list_t emptyList(void) { + list_t generated_list; + generated_list.length=0; + generated_list.entries=0; + return generated_list; +} + +list_t allocateList(const size_t length) { + list_t generated_list = emptyList(); + if (length>0) { + 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; +} + +void reallocateList(list_t *list, + const size_t length) { + entry_t *old_entries = list->entries; + if (length>0) { + if (list->length==0) + *list = allocateList(length); + else { + if (list->length != length) + list->entries = (entry_t*) realloc(list->entries,length*sizeof(entry_t)); + if (list->entries!=0) + list->length=length; + else + *list=emptyList(); + } + } + 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; + list->length=0; +} + +// programming interface: + +size_t getLength(const list_t list) { + return list.length; +} + +entry_t getEntry(const list_t list, const index_t index) { + if ((index>=0)&&(index=0)&&(index=start) { + length=(size_t) (stop-start+1); + incr=1; + } else { + length=(size_t) (start-stop+1); + incr=-1; + } + list_t l = allocateList(length); + if (l.entries!=0) + for (i=0,c=start; i0)&&(stop>0)&&(startstop) { + incr=-1; + new_list=allocateList(start-stop+1); + } else { + incr=1; + new_list=allocateList(start-stop+1); + } + for (j=start,i=0; i(size_t)i) { + setEntry(*list,i,entry); + } +} + +void removeEntryFromList(list_t *list, const index_t index) { + index_t i,j; + for (i=j=0; ilength; + 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)); + } +} + +void removeEntryListFromList(list_t *list, const list_t indices) { + index_t i,j; + for (i=j=0; i0) + for (i=0, j=getLength(*list)-1; ientries[j]!=list->entries[i]); + if (keep) { + list->entries[i++]=list->entries[j]; + k++; + } + } + reallocateList(list, k); +} + +list_t findValueListInList(const list_t value_list, + const list_t list) { + list_t l=emptyList(); + index_t i,j; + for (i=0; i0) + printf("%d",getEntry(list,0)); + for (i=1; i