[digraphanalysis-cvs] digraphanalysis/src list.c,JBREKER list.h,JBREKER
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-03-28 00:48:31
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13798/src Modified Files: Tag: JBREKER list.c list.h Log Message: implement LIST_* macros... Index: list.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/list.h,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** list.h 18 Mar 2005 20:42:22 -0000 1.1 --- list.h 28 Mar 2005 00:48:23 -0000 1.1.2.1 *************** *** 20,49 **** #define _LIST_H_ ! struct node_s { void *object; ! struct node_s *next, *prev; ! }; ! ! struct list_s ! { ! int (*compare) (void *, void *); ! unsigned int size; ! struct node_s *head, *tail; }; ! typedef struct list_s list_t; ! typedef struct node_s node_t; ! int list_add_object(list_t *, void *); ! list_t *list_duplicate(list_t *); ! void *list_find_object(list_t *, void *); ! void list_free(list_t *); ! list_t *list_merge_list(list_t *, list_t *); ! list_t *list_new(int (*) (void *, void *)); ! node_t *list_new_node(void *, node_t *, node_t *); ! void list_remove(list_t *, void *); ! list_t *list_resort(list_t *); ! list_t *list_union(list_t *, list_t *); #endif --- 20,41 ---- #define _LIST_H_ ! struct node_t { void *object; ! LIST_ENTRY(node_t) entries; }; ! LIST_HEAD(list_t, node_t); ! int list_add_object(struct list_t *, void *); ! struct list_t *list_duplicate(struct list_t *); ! void *list_find_object(struct list_t *, void *); ! void list_free(struct list_t *); ! struct list_t *list_merge_list(struct list_t *, struct list_t *); ! struct list_t *list_new(int (*) (void *, void *)); ! struct node_t *list_new_node(void *, struct node_t *, struct node_t *); ! void list_remove(struct list_t *, void *); ! struct list_t *list_resort(struct list_t *); ! struct list_t *list_union(struct list_t *, struct list_t *); #endif Index: list.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/list.c,v retrieving revision 1.1 retrieving revision 1.1.2.1 diff -C2 -d -r1.1 -r1.1.2.1 *** list.c 18 Mar 2005 20:42:22 -0000 1.1 --- list.c 28 Mar 2005 00:48:22 -0000 1.1.2.1 *************** *** 29,45 **** * This might be more usefull if we returned the object that is in the list or NULL on error */ ! int list_add_object(list_t *list, void *object) { int i; ! node_t *iter; ! iter = list->head; ! if(iter == NULL) { ! if((list->head = list->tail = list_new_node(object, NULL, NULL)) == NULL) ! return -1; ! ++(list->size); ! return 1; } --- 29,42 ---- * This might be more usefull if we returned the object that is in the list or NULL on error */ ! int list_add_object(struct list_t *list, void *object) { int i; ! struct node_t *iter; ! iter = LIST_FIRST(list); ! if(LIST_EMPTY(list)) { ! LIST_INSERT_HEAD(list, list_new_node(object), entries); return 1; } *************** *** 87,93 **** /* Returns NULL on error */ ! list_t *list_duplicate(list_t *list) { ! list_t *ret_list; if((ret_list = list_new(list->compare)) == NULL) --- 84,90 ---- /* Returns NULL on error */ ! struct list_t *list_duplicate(struct list_t *list) { ! struct list_t *ret_list; if((ret_list = list_new(list->compare)) == NULL) *************** *** 99,103 **** } ! void list_free(list_t *list) { node_t *iter; --- 96,100 ---- } ! void list_free(struct list_t *list) { node_t *iter; *************** *** 118,122 **** } ! void *list_find_object(list_t *list, void *object) { int i; --- 115,119 ---- } ! void *list_find_object(struct list_t *list, void *object) { int i; *************** *** 142,146 **** * list1 on success */ ! list_t *list_merge_list(list_t *list1, list_t *list2) { node_t *iter; --- 139,143 ---- * list1 on success */ ! struct list_t *list_merge_list(struct list_t *list1, struct list_t *list2) { node_t *iter; *************** *** 160,168 **** /* Returns NULL on error */ ! list_t *list_new(int (*compare) (void *, void *)) { ! list_t *list; ! if((list = (list_t *) malloc(sizeof(list_t))) == NULL) return NULL; --- 157,165 ---- /* Returns NULL on error */ ! struct list_t *list_new(int (*compare) (void *, void *)) { ! struct list_t *list; ! if((list = (stuct list_t *) malloc(sizeof(struct list_t))) == NULL) return NULL; *************** *** 190,194 **** } ! void list_remove(list_t *list, void *object) { node_t *iter; --- 187,191 ---- } ! void list_remove(struct list_t *list, void *object) { node_t *iter; *************** *** 223,227 **** /* Optimize with quicksort or heapsort I think */ ! list_t *list_resort(list_t *list) { node_t *iter, *tmpiter; --- 220,224 ---- /* Optimize with quicksort or heapsort I think */ ! struct list_t *list_resort(struct list_t *list) { node_t *iter, *tmpiter; *************** *** 247,253 **** * list on success */ ! list_t *list_union(list_t *list1, list_t *list2) { ! list_t *list; if((list = list_new(list1->compare)) == NULL) --- 244,250 ---- * list on success */ ! struct list_t *list_union(struct list_t *list1, struct list_t *list2) { ! struct list_t *list; if((list = list_new(list1->compare)) == NULL) |