src/ucx/list.c

changeset 645
0c85c4cd0dd8
parent 621
956c03c25edd
equal deleted inserted replaced
644:e96e92e3508f 645:0c85c4cd0dd8
183 const struct cx_iterator_s *iter = it; 183 const struct cx_iterator_s *iter = it;
184 void **ptr = iter->base.current_impl(it); 184 void **ptr = iter->base.current_impl(it);
185 return ptr == NULL ? NULL : *ptr; 185 return ptr == NULL ? NULL : *ptr;
186 } 186 }
187 187
188 static int cx_pl_change_capacity(struct cx_list_s *list, size_t cap) {
189 if (list->climpl->change_capacity == NULL) {
190 return 0;
191 } else {
192 return list->climpl->change_capacity(list, cap);
193 }
194 }
195
188 static struct cx_iterator_s cx_pl_iterator( 196 static struct cx_iterator_s cx_pl_iterator(
189 const struct cx_list_s *list, 197 const struct cx_list_s *list,
190 size_t index, 198 size_t index,
191 bool backwards 199 bool backwards
192 ) { 200 ) {
209 cx_pl_at, 217 cx_pl_at,
210 cx_pl_find_remove, 218 cx_pl_find_remove,
211 cx_pl_sort, 219 cx_pl_sort,
212 cx_pl_compare, 220 cx_pl_compare,
213 cx_pl_reverse, 221 cx_pl_reverse,
222 cx_pl_change_capacity,
214 cx_pl_iterator, 223 cx_pl_iterator,
215 }; 224 };
216 // </editor-fold> 225 // </editor-fold>
217 226
218 // <editor-fold desc="empty list implementation"> 227 // <editor-fold desc="empty list implementation">
265 cx_emptyl_at, 274 cx_emptyl_at,
266 cx_emptyl_find_remove, 275 cx_emptyl_find_remove,
267 cx_emptyl_noop, 276 cx_emptyl_noop,
268 NULL, 277 NULL,
269 cx_emptyl_noop, 278 cx_emptyl_noop,
279 NULL,
270 cx_emptyl_iterator, 280 cx_emptyl_iterator,
271 }; 281 };
272 282
273 CxList cx_empty_list = { 283 CxList cx_empty_list = {
274 { 284 {
1018 bool dst_was_empty = cxCollectionSize(dst) == 0; 1028 bool dst_was_empty = cxCollectionSize(dst) == 0;
1019 1029
1020 CxIterator src_iter = cxListIterator(src); 1030 CxIterator src_iter = cxListIterator(src);
1021 CxIterator other_iter = cxListIterator(other); 1031 CxIterator other_iter = cxListIterator(other);
1022 while (cxIteratorValid(src_iter) || cxIteratorValid(other_iter)) { 1032 while (cxIteratorValid(src_iter) || cxIteratorValid(other_iter)) {
1023 void *src_elem, *other_elem; 1033 void *src_elem = NULL, *other_elem = NULL;
1024 int d; 1034 int d;
1025 if (!cxIteratorValid(src_iter)) { 1035 if (!cxIteratorValid(src_iter)) {
1026 other_elem = cxIteratorCurrent(other_iter); 1036 other_elem = cxIteratorCurrent(other_iter);
1027 d = 1; 1037 d = 1;
1028 } else if (!cxIteratorValid(other_iter)) { 1038 } else if (!cxIteratorValid(other_iter)) {
1100 } 1110 }
1101 1111
1102 int cxListUnionSimple(CxList *dst, const CxList *src, const CxList *other) { 1112 int cxListUnionSimple(CxList *dst, const CxList *src, const CxList *other) {
1103 return cxListUnion(dst, src, other, use_simple_clone_func(src)); 1113 return cxListUnion(dst, src, other, use_simple_clone_func(src));
1104 } 1114 }
1115
1116 int cxListReserve(CxList *list, size_t capacity) {
1117 if (list->cl->change_capacity == NULL) {
1118 return 0;
1119 }
1120 if (capacity <= cxCollectionSize(list)) {
1121 return 0;
1122 }
1123 return list->cl->change_capacity(list, capacity);
1124 }
1125
1126 int cxListShrink(CxList *list) {
1127 if (list->cl->change_capacity == NULL) {
1128 return 0;
1129 }
1130 return list->cl->change_capacity(list, cxCollectionSize(list));
1131 }

mercurial