ucx/linked_list.c

changeset 1040
473d8cb58a6c
parent 1016
ccde46662db7
equal deleted inserted replaced
1039:6691e007cef7 1040:473d8cb58a6c
103 size_t *found_index, 103 size_t *found_index,
104 cx_compare_func cmp_func 104 cx_compare_func cmp_func
105 ) { 105 ) {
106 cx_compare_func_wrapper wrapper = {cmp_func}; 106 cx_compare_func_wrapper wrapper = {cmp_func};
107 return cx_linked_list_find_c(start, loc_advance, loc_data, 107 return cx_linked_list_find_c(start, loc_advance, loc_data,
108 elem, found_index, cx_acmp_wrap, &wrapper); 108 elem, found_index, cx_cmp_wrap, &wrapper);
109 } 109 }
110 110
111 void *cx_linked_list_first( 111 void *cx_linked_list_first(
112 const void *node, 112 const void *node,
113 ptrdiff_t loc_prev 113 ptrdiff_t loc_prev
250 *end = insert_end; 250 *end = insert_end;
251 } 251 }
252 } else { 252 } else {
253 cx_linked_list_link(insert_end, successor, loc_prev, loc_next); 253 cx_linked_list_link(insert_end, successor, loc_prev, loc_next);
254 } 254 }
255 }
256
257 void cx_linked_list_insert_sorted(
258 void **begin,
259 void **end,
260 ptrdiff_t loc_prev,
261 ptrdiff_t loc_next,
262 void *new_node,
263 cx_compare_func cmp_func
264 ) {
265 assert(ll_next(new_node) == NULL);
266 cx_linked_list_insert_sorted_chain(
267 begin, end, loc_prev, loc_next, new_node, cmp_func);
268 } 255 }
269 256
270 static void *cx_linked_list_insert_sorted_chain_impl( 257 static void *cx_linked_list_insert_sorted_chain_impl(
271 void **begin, 258 void **begin,
272 void **end, 259 void **end,
407 *end = new_end; 394 *end = new_end;
408 } 395 }
409 return dup_begin; 396 return dup_begin;
410 } 397 }
411 398
399 void cx_linked_list_insert_sorted(
400 void **begin,
401 void **end,
402 ptrdiff_t loc_prev,
403 ptrdiff_t loc_next,
404 void *new_node,
405 cx_compare_func cmp_func
406 ) {
407 assert(ll_next(new_node) == NULL);
408 cx_linked_list_insert_sorted_chain(
409 begin, end, loc_prev, loc_next, new_node, cmp_func);
410 }
411
412 void cx_linked_list_insert_sorted_chain( 412 void cx_linked_list_insert_sorted_chain(
413 void **begin, 413 void **begin,
414 void **end, 414 void **end,
415 ptrdiff_t loc_prev, 415 ptrdiff_t loc_prev,
416 ptrdiff_t loc_next, 416 ptrdiff_t loc_next,
418 cx_compare_func cmp_func 418 cx_compare_func cmp_func
419 ) { 419 ) {
420 cx_compare_func_wrapper wrapper = {cmp_func}; 420 cx_compare_func_wrapper wrapper = {cmp_func};
421 cx_linked_list_insert_sorted_chain_impl( 421 cx_linked_list_insert_sorted_chain_impl(
422 begin, end, loc_prev, loc_next, 422 begin, end, loc_prev, loc_next,
423 insert_begin, cx_acmp_wrap, &wrapper, true); 423 insert_begin, cx_cmp_wrap, &wrapper, true);
424 } 424 }
425 425
426 int cx_linked_list_insert_unique( 426 int cx_linked_list_insert_unique(
427 void **begin, 427 void **begin,
428 void **end, 428 void **end,
445 cx_compare_func cmp_func 445 cx_compare_func cmp_func
446 ) { 446 ) {
447 cx_compare_func_wrapper wrapper = {cmp_func}; 447 cx_compare_func_wrapper wrapper = {cmp_func};
448 return cx_linked_list_insert_sorted_chain_impl( 448 return cx_linked_list_insert_sorted_chain_impl(
449 begin, end, loc_prev, loc_next, 449 begin, end, loc_prev, loc_next,
450 insert_begin, cx_acmp_wrap, &wrapper, false); 450 insert_begin, cx_cmp_wrap, &wrapper, false);
451 }
452
453 void cx_linked_list_insert_sorted_c(
454 void **begin,
455 void **end,
456 ptrdiff_t loc_prev,
457 ptrdiff_t loc_next,
458 void *new_node,
459 cx_compare_func2 cmp_func,
460 void *context
461 ) {
462 assert(ll_next(new_node) == NULL);
463 cx_linked_list_insert_sorted_chain_c(
464 begin, end, loc_prev, loc_next, new_node, cmp_func, context);
465 }
466
467 void cx_linked_list_insert_sorted_chain_c(
468 void **begin,
469 void **end,
470 ptrdiff_t loc_prev,
471 ptrdiff_t loc_next,
472 void *insert_begin,
473 cx_compare_func2 cmp_func,
474 void *context
475 ) {
476 cx_linked_list_insert_sorted_chain_impl(
477 begin, end, loc_prev, loc_next,
478 insert_begin, cmp_func, context, true);
479 }
480
481 int cx_linked_list_insert_unique_c(
482 void **begin,
483 void **end,
484 ptrdiff_t loc_prev,
485 ptrdiff_t loc_next,
486 void *new_node,
487 cx_compare_func2 cmp_func,
488 void *context
489 ) {
490 assert(ll_next(new_node) == NULL);
491 return NULL != cx_linked_list_insert_unique_chain_c(
492 begin, end, loc_prev, loc_next, new_node, cmp_func, context);
493 }
494
495 void *cx_linked_list_insert_unique_chain_c(
496 void **begin,
497 void **end,
498 ptrdiff_t loc_prev,
499 ptrdiff_t loc_next,
500 void *insert_begin,
501 cx_compare_func2 cmp_func,
502 void *context
503 ) {
504 return cx_linked_list_insert_sorted_chain_impl(
505 begin, end, loc_prev, loc_next,
506 insert_begin, cmp_func, context, false);
451 } 507 }
452 508
453 size_t cx_linked_list_remove_chain( 509 size_t cx_linked_list_remove_chain(
454 void **begin, 510 void **begin,
455 void **end, 511 void **end,
659 ptrdiff_t loc_next, 715 ptrdiff_t loc_next,
660 ptrdiff_t loc_data, 716 ptrdiff_t loc_data,
661 cx_compare_func cmp_func 717 cx_compare_func cmp_func
662 ) { 718 ) {
663 cx_compare_func_wrapper wrapper = {cmp_func}; 719 cx_compare_func_wrapper wrapper = {cmp_func};
664 cx_linked_list_sort_c(begin, end, loc_prev, loc_next, loc_data, cx_acmp_wrap, &wrapper); 720 cx_linked_list_sort_c(begin, end, loc_prev, loc_next, loc_data, cx_cmp_wrap, &wrapper);
665 } 721 }
666 722
667 int cx_linked_list_compare_c( 723 int cx_linked_list_compare_c(
668 const void *begin_left, 724 const void *begin_left,
669 const void *begin_right, 725 const void *begin_right,
695 ptrdiff_t loc_data, 751 ptrdiff_t loc_data,
696 cx_compare_func cmp_func 752 cx_compare_func cmp_func
697 ) { 753 ) {
698 cx_compare_func_wrapper wrapper = {cmp_func}; 754 cx_compare_func_wrapper wrapper = {cmp_func};
699 return cx_linked_list_compare_c(begin_left, begin_right, 755 return cx_linked_list_compare_c(begin_left, begin_right,
700 loc_advance, loc_data, cx_acmp_wrap, &wrapper); 756 loc_advance, loc_data, cx_cmp_wrap, &wrapper);
701 } 757 }
702 758
703 void cx_linked_list_reverse( 759 void cx_linked_list_reverse(
704 void **begin, 760 void **begin,
705 void **end, 761 void **end,
1326 } 1382 }
1327 1383
1328 void cx_linked_list_extra_data(cx_linked_list *list, size_t len) { 1384 void cx_linked_list_extra_data(cx_linked_list *list, size_t len) {
1329 list->extra_data_len = len; 1385 list->extra_data_len = len;
1330 1386
1331 off_t loc_extra = list->loc_data + list->base.collection.elem_size; 1387 off_t loc_extra = list->loc_data + (off_t) list->base.collection.elem_size;
1332 size_t alignment = alignof(void*); 1388 size_t alignment = alignof(void*);
1333 size_t padding = alignment - (loc_extra % alignment); 1389 size_t padding = alignment - ((size_t)loc_extra % alignment);
1334 list->loc_extra = loc_extra + padding; 1390 list->loc_extra = loc_extra + (off_t) padding;
1335 } 1391 }

mercurial