1 /* |
1 /* |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * |
3 * |
4 * Copyright 2015 Olaf Wintermann. All rights reserved. |
4 * Copyright 2016 Olaf Wintermann. All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: |
7 * modification, are permitted provided that the following conditions are met: |
8 * |
8 * |
9 * 1. Redistributions of source code must retain the above copyright |
9 * 1. Redistributions of source code must retain the above copyright |
74 e = e->next; |
74 e = e->next; |
75 alfree(alloc, f); |
75 alfree(alloc, f); |
76 } |
76 } |
77 } |
77 } |
78 |
78 |
|
79 void ucx_list_free_content(UcxList* list, ucx_destructor destr) { |
|
80 while (list != NULL) { |
|
81 destr(list->data); |
|
82 list = list->next; |
|
83 } |
|
84 } |
|
85 |
79 UcxList *ucx_list_append(UcxList *l, void *data) { |
86 UcxList *ucx_list_append(UcxList *l, void *data) { |
80 return ucx_list_append_a(ucx_default_allocator(), l, data); |
87 return ucx_list_append_a(ucx_default_allocator(), l, data); |
81 } |
88 } |
82 |
89 |
83 UcxList *ucx_list_append_a(UcxAllocator *alloc, UcxList *l, void *data) { |
90 UcxList *ucx_list_append_a(UcxAllocator *alloc, UcxList *l, void *data) { |
97 nl->prev = NULL; |
104 nl->prev = NULL; |
98 return nl; |
105 return nl; |
99 } |
106 } |
100 } |
107 } |
101 |
108 |
|
109 UcxList *ucx_list_append_once(UcxList *l, void *data, |
|
110 cmp_func cmpfnc, void *cmpdata) { |
|
111 return ucx_list_append_once_a(ucx_default_allocator(), l, |
|
112 data, cmpfnc, cmpdata); |
|
113 } |
|
114 |
|
115 UcxList *ucx_list_append_once_a(UcxAllocator *alloc, UcxList *l, void *data, |
|
116 cmp_func cmpfnc, void *cmpdata) { |
|
117 |
|
118 UcxList *last = NULL; |
|
119 { |
|
120 UcxList *e = l; |
|
121 while (e) { |
|
122 if (cmpfnc(e->data, data, cmpdata) == 0) { |
|
123 return l; |
|
124 } |
|
125 last = e; |
|
126 e = e->next; |
|
127 } |
|
128 } |
|
129 |
|
130 UcxList *nl = ucx_list_append_a(alloc, NULL, data); |
|
131 if (!nl) { |
|
132 return NULL; |
|
133 } |
|
134 |
|
135 if (last == NULL) { |
|
136 return nl; |
|
137 } else { |
|
138 nl->prev = last; |
|
139 last->next = nl; |
|
140 return l; |
|
141 } |
|
142 } |
|
143 |
102 UcxList *ucx_list_prepend(UcxList *l, void *data) { |
144 UcxList *ucx_list_prepend(UcxList *l, void *data) { |
103 return ucx_list_prepend_a(ucx_default_allocator(), l, data); |
145 return ucx_list_prepend_a(ucx_default_allocator(), l, data); |
104 } |
146 } |
105 |
147 |
106 UcxList *ucx_list_prepend_a(UcxAllocator *alloc, UcxList *l, void *data) { |
148 UcxList *ucx_list_prepend_a(UcxAllocator *alloc, UcxList *l, void *data) { |