From e4f56a32d01350b09212172a509d34d9411a0d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Mon, 27 Aug 2012 15:04:59 +0000 Subject: read list 'entry' type svn path=/trunk/externals/iem/iemmatrix/; revision=16177 --- src/mtx_qhull/entry.h | 89 +++++++++++++++++++++++++++++++ src/mtx_qhull/list.c | 136 +++++++++++++++++++++++++++++++----------------- src/mtx_qhull/list.h | 13 ++--- src/mtx_qhull/vectors.c | 22 +++++--- 4 files changed, 198 insertions(+), 62 deletions(-) create mode 100644 src/mtx_qhull/entry.h (limited to 'src/mtx_qhull') diff --git a/src/mtx_qhull/entry.h b/src/mtx_qhull/entry.h new file mode 100644 index 0000000..bc22f35 --- /dev/null +++ b/src/mtx_qhull/entry.h @@ -0,0 +1,89 @@ +#ifndef QHULL_ENTRY_H +#define QHULL_ENTRY_H + +#include +#include + +typedef size_t index_t; + +typedef union { + index_t i; + void*p; +} entryvalu_t; + +typedef enum { + INDEX, + POINTER, + INVALID +} entrytype_t; + +typedef struct entry_ { + entrytype_t typ; + entryvalu_t val; +} entry_t; + +static +void entry_setIndex(entry_t*e, index_t i) { + e->typ=INDEX; + e->val.i=i; +} +static +void entry_setPointer(entry_t*e, void*p) { + e->typ=POINTER; + e->val.p=p; +} +static +entry_t entry_makeIndex(index_t i) { + entry_t result; + entry_setIndex(&result, i); + return result; +} +static +entry_t entry_makePointer(void*p) { + entry_t result; + entry_setPointer(&result, p); + return result; +} + +static +index_t entry_getIndex(const entry_t*e) { + return (INDEX==e->typ)?e->val.i:0; +} +static +void*entry_getPointer(const entry_t*e) { + return (POINTER==e->typ)?e->val.p:0; +} +static +int entry_equals(const entry_t*e1, const entry_t*e2) { + if(e1->typ!=e2->typ)return 0; + switch(e1->typ) { + case INDEX: + return (e1->val.i == e2->val.i); + case POINTER: + return (e1->val.p == e2->val.p); + default: + return 0; + } + return 0; +} + +static +void print_entry(const entry_t e) { + switch(e.typ) { + case INDEX: + printf("%d", e.val.i); + return; + case POINTER: + printf("0x%p", e.val.p); + return; + default: + printf(""); + return; + } +} + + + + + +#endif diff --git a/src/mtx_qhull/list.c b/src/mtx_qhull/list.c index 1f8f58b..6f3b416 100644 --- a/src/mtx_qhull/list.c +++ b/src/mtx_qhull/list.c @@ -66,8 +66,10 @@ size_t getLength(const list_t list) { entry_t getEntry(const list_t list, const index_t index) { if ((index>=0)&&(index=start) { - length=(size_t) (stop-start+1); + length=(size_t) (stop-start+1); incr=1; } else { - length=(size_t) (start-stop+1); - incr=-1; + length=(size_t) (start-stop+1); + incr=-1; } list_t l = allocateList(length); - if (l.entries!=0) - for (i=0,c=start; ientries[j]!=list->entries[i]); - if (keep) { + for (i=0; ientries[j]; + entry_t e2=list->entries[i]; + if(entry_equals(&e1, &e2)) + break; + } + if (i==k) { list->entries[i++]=list->entries[j]; k++; } @@ -271,27 +302,36 @@ 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; i0) { + print_entry(getEntry(list,0)); + } + for (i=1; i -typedef long int entry_t; -typedef long int index_t; +#include "entry.h" + typedef struct list_ { entry_t *entries; size_t length; @@ -21,8 +21,9 @@ void freeList(list_t *list); size_t getLength(const list_t list); 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); -list_t initList(entry_t *entries, const size_t length); -list_t initListFromTo(const entry_t start, const entry_t stop); +list_t initList(const entry_t *entries, const size_t length); +list_t initListIndex(const index_t *entries, const size_t length); +list_t initListFromTo(const index_t start, const index_t stop); list_t initConstantList(const entry_t c, const size_t length); list_t duplicateList(const list_t list_in); list_t mergeLists(const list_t list1, const list_t list2); @@ -31,7 +32,7 @@ list_t getSubListFromTo(const list_t list, const index_t start, const index_t stop); void appendToList(list_t *list, const entry_t entry); void removeValueFromList(list_t *list, const entry_t entry); -void removeEntryFromList(list_t *list, const index_t index); +void removeIndexFromList(list_t *list, const index_t index); void appendListToList(list_t *list1, const list_t list2); void removeValueListFromList(list_t *list, const list_t excl_list); void removeEntryListFromList(list_t *list, const list_t indices); @@ -39,7 +40,7 @@ void reverseList(list_t * const list); int inList(const entry_t entry, const list_t list); int notInList(const entry_t entry, const list_t list); list_t findValueListInList(const list_t value_list, const list_t list); -entry_t findValueInList(const entry_t entry, const list_t list); +index_t findValueInList(const entry_t entry, const list_t list); void uniquefyListEntries(list_t *list); void printList(const list_t list); diff --git a/src/mtx_qhull/vectors.c b/src/mtx_qhull/vectors.c index d9d3bd0..655ed94 100644 --- a/src/mtx_qhull/vectors.c +++ b/src/mtx_qhull/vectors.c @@ -172,7 +172,8 @@ vector_t averageListedPoints(const points_t points, const list_t list) { index_t i; vector_t m = initVector(0.0f, 0.0f, 0.0f); for (i=0; i