src/linked_list.c

changeset 1532
313fd460d264
parent 1504
467a77a85f43
child 1533
6d65b1e97136
equal deleted inserted replaced
1531:3ee5a5c7823a 1532:313fd460d264
690 return cx_linked_list_at(list->begin, 0, list->loc_next, index); 690 return cx_linked_list_at(list->begin, 0, list->loc_next, index);
691 } 691 }
692 } 692 }
693 693
694 static void *cx_ll_malloc_node(const cx_linked_list *list) { 694 static void *cx_ll_malloc_node(const cx_linked_list *list) {
695 return cxZalloc(list->base.collection.allocator, 695 size_t n;
696 list->loc_data + list->base.collection.elem_size + list->extra_data_len); 696 if (list->extra_data_len == 0) {
697 n = list->loc_data + list->base.collection.elem_size;
698 } else {
699 n = list->loc_extra + list->extra_data_len;
700 }
701 return cxZalloc(list->base.collection.allocator, n);
697 } 702 }
698 703
699 static int cx_ll_insert_at( 704 static int cx_ll_insert_at(
700 struct cx_list_s *list, 705 struct cx_list_s *list,
701 void *node, 706 void *node,
1265 allocator = cxDefaultAllocator; 1270 allocator = cxDefaultAllocator;
1266 } 1271 }
1267 1272
1268 cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list)); 1273 cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list));
1269 if (list == NULL) return NULL; 1274 if (list == NULL) return NULL;
1270 list->extra_data_len = 0;
1271 list->loc_prev = 0; 1275 list->loc_prev = 0;
1272 list->loc_next = sizeof(void*); 1276 list->loc_next = sizeof(void*);
1273 list->loc_data = sizeof(void*)*2; 1277 list->loc_data = sizeof(void*)*2;
1278 list->loc_extra = -1;
1279 list->extra_data_len = 0;
1274 cx_list_init((CxList*)list, &cx_linked_list_class, 1280 cx_list_init((CxList*)list, &cx_linked_list_class,
1275 allocator, comparator, elem_size); 1281 allocator, comparator, elem_size);
1276 1282
1277 return (CxList *) list; 1283 return (CxList *) list;
1278 } 1284 }
1285
1286 void cx_linked_list_extra_data(cx_linked_list *list, size_t len) {
1287 list->extra_data_len = len;
1288
1289 off_t loc_extra = list->loc_data + list->base.collection.elem_size;
1290 size_t alignment = alignof(void*);
1291 size_t padding = alignment - (loc_extra % alignment);
1292 list->loc_extra = loc_extra + padding;
1293 }

mercurial