1.1 --- a/ucx/dlist.c Thu Oct 11 08:42:56 2012 +0200 1.2 +++ b/ucx/dlist.c Thu Oct 11 11:42:31 2012 +0200 1.3 @@ -1,6 +1,7 @@ 1.4 #include "dlist.h" 1.5 1.6 -UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) { 1.7 +UcxDlist *restrict ucx_dlist_clone(UcxDlist *restrict l, 1.8 + copy_func fnc, void *data) { 1.9 UcxDlist *ret = NULL; 1.10 while (l != NULL) { 1.11 if (fnc != NULL) { 1.12 @@ -13,7 +14,8 @@ 1.13 return ret; 1.14 } 1.15 1.16 -int ucx_dlist_equals(UcxDlist *l1, UcxDlist *l2, cmp_func fnc, void* data) { 1.17 +int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2, 1.18 + cmp_func fnc, void* data) { 1.19 if (l1 == l2) return 1; 1.20 1.21 while (l1 != NULL && l2 != NULL) { 1.22 @@ -66,7 +68,7 @@ 1.23 return nl; 1.24 } 1.25 1.26 -UcxDlist *ucx_dlist_concat(UcxDlist *l1, UcxDlist *l2) { 1.27 +UcxDlist *ucx_dlist_concat(UcxDlist *restrict l1, UcxDlist *restrict l2) { 1.28 if (l1 == NULL) { 1.29 return l2; 1.30 } else { 1.31 @@ -77,32 +79,32 @@ 1.32 } 1.33 } 1.34 1.35 -UcxDlist *ucx_dlist_last(UcxDlist *l) { 1.36 +UcxDlist *ucx_dlist_last(const UcxDlist *l) { 1.37 if (l == NULL) return NULL; 1.38 1.39 - UcxDlist *e = l; 1.40 + const UcxDlist *e = l; 1.41 while (e->next != NULL) { 1.42 e = e->next; 1.43 } 1.44 - return e; 1.45 + return (UcxDlist*)e; 1.46 } 1.47 1.48 -UcxDlist *ucx_dlist_get(UcxDlist *l, int index) { 1.49 +UcxDlist *ucx_dlist_get(const UcxDlist *l, int index) { 1.50 if (l == NULL) return NULL; 1.51 1.52 - UcxDlist *e = l; 1.53 + const UcxDlist *e = l; 1.54 while (e->next != NULL && index > 0) { 1.55 e = e->next; 1.56 index--; 1.57 } 1.58 1.59 - return index == 0 ? e : NULL; 1.60 + return (UcxDlist*)(index == 0 ? e : NULL); 1.61 } 1.62 1.63 -size_t ucx_dlist_size(UcxDlist *l) { 1.64 +size_t ucx_dlist_size(const UcxDlist *l) { 1.65 if (l == NULL) return 0; 1.66 1.67 - UcxDlist *e = l; 1.68 + const UcxDlist *e = l; 1.69 size_t s = 1; 1.70 while (e->next != NULL) { 1.71 e = e->next; 1.72 @@ -113,14 +115,14 @@ 1.73 } 1.74 1.75 UcxDlist *ucx_dlist_sort_merge(int length, 1.76 - UcxDlist* ls, UcxDlist* rs, UcxDlist* le, UcxDlist* re, 1.77 + UcxDlist* restrict ls, UcxDlist* restrict le, UcxDlist* restrict re, 1.78 cmp_func fnc, void* data) { 1.79 UcxDlist *sorted[length]; 1.80 UcxDlist *rc, *lc; 1.81 1.82 - lc = ls; rc = rs; 1.83 + lc = ls; rc = le; 1.84 int n = 0; 1.85 - while (lc != le && rc != re) { 1.86 + while (lc && lc != le && rc != re) { 1.87 if (fnc(lc->data, rc->data, data) <= 0) { 1.88 sorted[n] = lc; 1.89 lc = lc->next; 1.90 @@ -130,12 +132,12 @@ 1.91 } 1.92 n++; 1.93 } 1.94 - while (lc != le) { 1.95 + while (lc && lc != le) { 1.96 sorted[n] = lc; 1.97 lc = lc->next; 1.98 n++; 1.99 } 1.100 - while (rc != re) { 1.101 + while (rc && rc != re) { 1.102 sorted[n] = rc; 1.103 rc = rc->next; 1.104 n++; 1.105 @@ -160,7 +162,7 @@ 1.106 UcxDlist *lc; 1.107 int ln = 1; 1.108 1.109 - UcxDlist *ls = l, *le; 1.110 + UcxDlist *restrict ls = l, *restrict le, *restrict re; 1.111 lc = ls; 1.112 while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) { 1.113 lc = lc->next; 1.114 @@ -168,13 +170,12 @@ 1.115 } 1.116 le = lc->next; 1.117 1.118 - UcxDlist *rs = le, *re; 1.119 - if (rs == NULL) { 1.120 + if (le == NULL) { 1.121 return l; // this list is already sorted :) 1.122 } else { 1.123 UcxDlist *rc; 1.124 int rn = 1; 1.125 - rc = rs; 1.126 + rc = le; 1.127 while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) { 1.128 rc = rc->next; 1.129 rn++; 1.130 @@ -190,27 +191,26 @@ 1.131 1.132 // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them 1.133 UcxDlist *sorted = ucx_dlist_sort_merge(ln+rn, 1.134 - ls, rs, le, re, 1.135 + ls, le, re, 1.136 fnc, data); 1.137 1.138 // merge sorted list with (also sorted) remainder 1.139 l = ucx_dlist_sort_merge(ln+rn+remainder_length, 1.140 - sorted, remainder, NULL, NULL, 1.141 - fnc, data); 1.142 + sorted, remainder, NULL, fnc, data); 1.143 1.144 return l; 1.145 } 1.146 } 1.147 1.148 /* dlist specific functions */ 1.149 -UcxDlist *ucx_dlist_first(UcxDlist *l) { 1.150 +UcxDlist *ucx_dlist_first(const UcxDlist *l) { 1.151 if (l == NULL) return NULL; 1.152 1.153 - UcxDlist *e = l; 1.154 + const UcxDlist *e = l; 1.155 while (e->prev != NULL) { 1.156 e = e->prev; 1.157 } 1.158 - return e; 1.159 + return (UcxDlist *)e; 1.160 } 1.161 1.162 UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) {