src/list.c

changeset 323
b8c49e7a1dba
parent 291
deb0035635eb
child 335
872ae61c8945
equal deleted inserted replaced
322:fd21d1840dff 323:b8c49e7a1dba
105 nl->prev = NULL; 105 nl->prev = NULL;
106 return nl; 106 return nl;
107 } 107 }
108 } 108 }
109 109
110 UcxList *ucx_list_append_once(UcxList *l, void *data,
111 cmp_func cmpfnc, void *cmpdata) {
112 return ucx_list_append_once_a(ucx_default_allocator(), l,
113 data, cmpfnc, cmpdata);
114 }
115
116 UcxList *ucx_list_append_once_a(UcxAllocator *alloc, UcxList *l, void *data,
117 cmp_func cmpfnc, void *cmpdata) {
118
119 UcxList *last = NULL;
120 {
121 UcxList *e = l;
122 while (e) {
123 if (cmpfnc(e->data, data, cmpdata) == 0) {
124 return l;
125 }
126 last = e;
127 e = e->next;
128 }
129 }
130
131 UcxList *nl = ucx_list_append_a(alloc, NULL, data);
132 if (!nl) {
133 return NULL;
134 }
135
136 if (last == NULL) {
137 return nl;
138 } else {
139 nl->prev = last;
140 last->next = nl;
141 return l;
142 }
143 }
144
145 UcxList *ucx_list_prepend_once(UcxList *l, void *data,
146 cmp_func cmpfnc, void *cmpdata) {
147 return ucx_list_prepend_once_a(ucx_default_allocator(), l,
148 data, cmpfnc, cmpdata);
149 }
150
151 UcxList *ucx_list_prepend_once_a(UcxAllocator *alloc, UcxList *l, void *data,
152 cmp_func cmpfnc, void *cmpdata) {
153
154 UcxList* first = ucx_list_first(l);
155 {
156 UcxList *e = first;
157 while (e) {
158 if (cmpfnc(e->data, data, cmpdata) == 0) {
159 return l;
160 }
161 e = e->next;
162 }
163 }
164
165 UcxList *nl = ucx_list_append_a(alloc, NULL, data);
166 if (!nl) {
167 return NULL;
168 }
169
170 if (first) {
171 nl->next = first;
172 first->prev = nl;
173 }
174
175 return nl;
176 }
177
178 UcxList *ucx_list_prepend(UcxList *l, void *data) { 110 UcxList *ucx_list_prepend(UcxList *l, void *data) {
179 return ucx_list_prepend_a(ucx_default_allocator(), l, data); 111 return ucx_list_prepend_a(ucx_default_allocator(), l, data);
180 } 112 }
181 113
182 UcxList *ucx_list_prepend_a(UcxAllocator *alloc, UcxList *l, void *data) { 114 UcxList *ucx_list_prepend_a(UcxAllocator *alloc, UcxList *l, void *data) {

mercurial