ucx/list.c

changeset 505
481802342fdf
parent 335
c1bc13faadaa
child 747
efbd59642577
equal deleted inserted replaced
504:bf3695fee719 505:481802342fdf
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) { 79 void ucx_list_free_content(UcxList* list, ucx_destructor destr) {
80 if (!destr) destr = free;
80 while (list != NULL) { 81 while (list != NULL) {
81 destr(list->data); 82 destr(list->data);
82 list = list->next; 83 list = list->next;
83 } 84 }
84 } 85 }
104 nl->prev = NULL; 105 nl->prev = NULL;
105 return nl; 106 return nl;
106 } 107 }
107 } 108 }
108 109
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
144 UcxList *ucx_list_prepend(UcxList *l, void *data) { 110 UcxList *ucx_list_prepend(UcxList *l, void *data) {
145 return ucx_list_prepend_a(ucx_default_allocator(), l, data); 111 return ucx_list_prepend_a(ucx_default_allocator(), l, data);
146 } 112 }
147 113
148 UcxList *ucx_list_prepend_a(UcxAllocator *alloc, UcxList *l, void *data) { 114 UcxList *ucx_list_prepend_a(UcxAllocator *alloc, UcxList *l, void *data) {

mercurial