[dhcp-agent-commits] dhcp-agent dhcp-agent.h,1.75,1.76 dhcp-list.c,1.9,1.10
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2002-10-26 18:13:25
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv22743 Modified Files: dhcp-agent.h dhcp-list.c Log Message: updated list routines Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.75 retrieving revision 1.76 diff -C2 -d -r1.75 -r1.76 *** dhcp-agent.h 25 Oct 2002 13:20:08 -0000 1.75 --- dhcp-agent.h 26 Oct 2002 18:13:21 -0000 1.76 *************** *** 789,792 **** --- 789,793 ---- extern list_t *join_lists(list_t *first_list, list_t *second_list); extern list_t *list_find_datum_by(list_t *list, int (*find_func)(void *, void *), void *arg); + extern list_t *sort_list(list_t *list, int (*compare)(void *, void *)); /* Logging functions. */ Index: dhcp-list.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-list.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** dhcp-list.c 26 Oct 2002 14:26:41 -0000 1.9 --- dhcp-list.c 26 Oct 2002 18:13:21 -0000 1.10 *************** *** 138,139 **** --- 138,169 ---- return NULL; } + + /* we use a fairly dumb sorting algorithm. optimize later. the + * real problem is we're using a list which sucks for these kinds + * of things :-) */ + list_t *sort_list(list_t *list, int (*compare)(void *, void *)) + { + list_t *new_list = NULL; + list_t *highest, *ptr; + + while(1) { + /* keep looping until list is NULL. */ + highest = list; + + if(list == NULL) + break; + + /* otherwise move down list and compare values. */ + for(ptr = list->next;ptr;ptr = ptr->next) { + if(compare(highest->data, ptr->data) == -1) { + highest = ptr; + } + } + + new_list = add_to_list(new_list, highest->data); + list = remove_from_list(list, highest->data); + + } + + return new_list; + } |