openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/sysfsutils/2.1.0-r5/sysfsutils-2.1.0/lib/dlist.c
void dlist_sort_custom(struct dlist* list, int (*compare)(void*, void*))
{

    struct dlist *listsource, *listdest, *swap;
    struct dlist* templist;
    unsigned int passcount = 1;
    unsigned int mergecount = 1;

    if (list->count < 2)
        return;

    dlist_start(list);
    templist = dlist_new(list->data_size);

    templist->del_func = list->del_func;

    // do nothing if there isn't anything to sort
    listsource = list;
    listdest = templist;
    while (mergecount > 0)
    {
        mergecount = _dlist_merge(listsource, listdest, passcount, compare);
        if (mergecount > 1)
        {
            passcount = passcount * 2;
            // start new pass
            swap = listsource;
            listsource = listdest;
            listdest = swap;
        }
    }
    // now put the input list pointers right
    // list pointers = newlist pointers
    // including the forward and next nodes prev and back pointers
    if (list->count == 0)
    { // copy
        list->marker = listdest->marker;
        list->count = listdest->count;
        list->data_size = listdest->data_size;
        list->del_func = listdest->del_func;
        list->head->prev = listdest->head->prev;
        list->head->next = listdest->head->next;
        list->head->data = listdest->head->data;
        list->head->next->prev = list->head;
        list->head->prev->next = list->head;
        templist->head->next = NULL;
        templist->head->prev = NULL;
        templist->count = 0;
    }
    else
    { // no need to copy
    }

    dlist_destroy(templist);
}
/**
 * mergesort the list based on compare
 * compare function in form int sorter(void * a,void * b)
 *       must return >0 for a after b
 *       must return <0 for a before b
 *       else 0

 * NOTE: mergesort changes the mark pointer
 */
mergesort the list based on compare
compare function in form int sorter(void * a,void * b)
must return >0 for a after b
must return <0 for a before b
else 0

mergesort changes the mark pointer
mergesort the list based on compare compare function in form int sorter ( void * a void * b ) must return > 0 for a after b must return <0 for a before b else 0 mergesort changes the mark pointer
void dlist_sort_custom(struct dlist* list, int (*compare)(void*, void*))
{
    struct dlist *listsource, *listdest, *swap;
    struct dlist* templist;
    unsigned int passcount = 1;
    unsigned int mergecount = 1;
    if (list->count < 2)
        return;
    dlist_start(list);
    templist = dlist_new(list->data_size);
    templist->del_func = list->del_func;
    listsource = list;
    listdest = templist;
    while (mergecount > 0)
    {
        mergecount = _dlist_merge(listsource, listdest, passcount, compare);
        if (mergecount > 1)
        {
            passcount = passcount * 2;
            swap = listsource;
            listsource = listdest;
            listdest = swap;
        }
    }
    if (list->count == 0)
    { 
        list->marker = listdest->marker;
        list->count = listdest->count;
        list->data_size = listdest->data_size;
        list->del_func = listdest->del_func;
        list->head->prev = listdest->head->prev;
        list->head->next = listdest->head->next;
        list->head->data = listdest->head->data;
        list->head->next->prev = list->head;
        list->head->prev->next = list->head;
        templist->head->next = NULL;
        templist->head->prev = NULL;
        templist->count = 0;
    }
    else
    { 
    }
    dlist_destroy(templist);
}
void dlist_sort_custom ( struct dlist * list , int ( * compare ) ( void * , void * ) ) { struct dlist * listsource , * listdest , * swap ; struct dlist * templist ; unsigned int passcount = 1 ; unsigned int mergecount = 1 ; if ( list -> count < 2 ) return ; dlist_start ( list ) ; templist = dlist_new ( list -> data_size ) ; templist -> del_func = list -> del_func ; listsource = list ; listdest = templist ; while ( mergecount > 0 ) { mergecount = _dlist_merge ( listsource , listdest , passcount , compare ) ; if ( mergecount > 1 ) { passcount = passcount * 2 ; swap = listsource ; listsource = listdest ; listdest = swap ; } } if ( list -> count == 0 ) { list -> marker = listdest -> marker ; list -> count = listdest -> count ; list -> data_size = listdest -> data_size ; list -> del_func = listdest -> del_func ; list -> head -> prev = listdest -> head -> prev ; list -> head -> next = listdest -> head -> next ; list -> head -> data = listdest -> head -> data ; list -> head -> next -> prev = list -> head ; list -> head -> prev -> next = list -> head ; templist -> head -> next = NULL ; templist -> head -> prev = NULL ; templist -> count = 0 ; } else { } dlist_destroy ( templist ) ; }
mergesort the list based on compare
 compare function in form int sorter(void * a,void * b)
       must return >0 for a after b
       must return <0 for a before b
       else 0
mergesort the list based on compare compare function in form int sorter ( void * a void * b ) must return > 0 for a after b must return <0 for a before b else 0
// do nothing if there isn't anything to sort // start new pass // now put the input list pointers right // list pointers = newlist pointers // including the forward and next nodes prev and back pointers // copy // no need to copy