src/linked_list.c

changeset 474
9c1fccda16bc
parent 473
1bd4b8c28722
child 475
31bf97fdbf71
equal deleted inserted replaced
473:1bd4b8c28722 474:9c1fccda16bc
454 node = node->next; 454 node = node->next;
455 } 455 }
456 return index; 456 return index;
457 } 457 }
458 458
459 static void *cx_ll_last(cx_list_s *list) {
460 cx_linked_list *ll = (cx_linked_list *) list;
461 cx_linked_list_node *last = ll->end;
462 return last == NULL ? NULL : last->payload;
463 }
464
465 static void *cx_pll_last(cx_list_s *list) {
466 cx_linked_list *ll = (cx_linked_list *) list;
467 cx_linked_list_node *last = ll->end;
468 return last == NULL ? NULL : *(void **) last->payload;
469 }
470
471 static void cx_ll_sort(cx_list_s *list) { 459 static void cx_ll_sort(cx_list_s *list) {
472 cx_linked_list *ll = (cx_linked_list *) list; 460 cx_linked_list *ll = (cx_linked_list *) list;
473 cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end, 461 cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end,
474 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, 462 CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
475 0, list->cmpfunc); 463 0, list->cmpfunc);
486 cx_ll_add, 474 cx_ll_add,
487 cx_ll_insert, 475 cx_ll_insert,
488 cx_ll_remove, 476 cx_ll_remove,
489 cx_ll_at, 477 cx_ll_at,
490 cx_ll_find, 478 cx_ll_find,
491 cx_ll_last,
492 cx_ll_sort 479 cx_ll_sort
493 }; 480 };
494 481
495 static cx_list_class cx_pointer_linked_list_class = { 482 static cx_list_class cx_pointer_linked_list_class = {
496 cx_pll_add, 483 cx_pll_add,
497 cx_pll_insert, 484 cx_pll_insert,
498 cx_ll_remove, 485 cx_ll_remove,
499 cx_pll_at, 486 cx_pll_at,
500 cx_pll_find, 487 cx_pll_find,
501 cx_pll_last,
502 cx_pll_sort 488 cx_pll_sort
503 }; 489 };
504 490
505 CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size) { 491 CxList cxLinkedListCreate(CxAllocator allocator, CxListComparator comparator, size_t item_size) {
506 cx_linked_list *list = cxMalloc(allocator, sizeof(cx_linked_list)); 492 cx_linked_list *list = cxMalloc(allocator, sizeof(cx_linked_list));

mercurial