Thread: [digraphanalysis-cvs] digraphanalysis/src alias.c, alias.h, graph.c, list.c, list.h, node.c,
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-05-18 01:47:12
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13279 Modified Files: alias.c alias.h graph.c list.c list.h node.c Log Message: misc changes Index: alias.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/alias.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** alias.c 17 May 2005 15:16:28 -0000 1.8 --- alias.c 18 May 2005 01:46:55 -0000 1.9 *************** *** 20,27 **** #include "alias.h" int ! alias_compare(struct alias *alias1, struct alias *alias2) { return strcmp(alias1->uid, alias2->uid); } --- 20,31 ---- #include "alias.h" + #include "list.h" int ! alias_compare(void *obj1, void *obj2) { + struct alias *alias1 = obj1; + struct alias *alias2 = obj2; + return strcmp(alias1->uid, alias2->uid); } *************** *** 62,159 **** } - struct alias * - aliaslist_add(struct list *alias_list, struct alias *alias) - { - int i; - struct listlink *alias_iter, *alias_link; - - alias_link = (struct listlink *) malloc(sizeof(struct listlink)); - alias_link->object = alias; - - if(LIST_EMPTY(alias_list)) - LIST_INSERT_HEAD(alias_list, alias_link, list); - else - LIST_FOREACH(alias_iter, alias_list, list) - { - if((i = alias_compare(alias, alias_iter->object)) < 0) - { - if(alias_iter == LIST_FIRST(alias_list)) - LIST_INSERT_HEAD(alias_list, alias_link, list); - else - LIST_INSERT_BEFORE(alias_iter, alias_link, list); - break; - } - else - if(i == 0) - return alias_iter->object; - else - if(LIST_NEXT(alias_iter, list) == NULL) - LIST_INSERT_AFTER(alias_iter, alias_link, list); - } - - return alias; - } - - struct aliaslist * - aliaslist_duplicate(struct aliaslist *alias_list1) - { - struct aliaslist *alias_list2; - struct aliaslink *alias_link; - - alias_list2 = aliaslist_new(); - - LIST_FOREACH(alias_link, alias_list1, list) - aliaslist_add(alias_list2, alias_link->alias); - - return alias_list2; - } - - /* This should take a struct alias, not a char */ - struct alias * - aliaslist_find(struct aliaslist *alias_list, char *uid) - { - int i; - struct aliaslink *alias_link; - - alias_link = LIST_FIRST(alias_list); - - LIST_FOREACH(alias_link, alias_list, list) - { - if((i = strcmp(((struct alias *) alias_link->alias)->uid, uid)) == 0) - return alias_link->alias; - else - if(i > 0) - break; - } - - return NULL; - } - - void - aliaslist_free(struct aliaslist *alias_list) - { - struct aliaslink *alias_link; - - LIST_FOREACH(alias_link, alias_list, list) - { - LIST_REMOVE(alias_link, list); - alias_free(alias_link->alias); - free(alias_link); - alias_link = NULL; - } - free(alias_list); - - return; - } - - struct aliaslist * - aliaslist_new() - { - struct aliaslist *list; - - if((list = (struct aliaslist *) malloc(sizeof(struct aliaslist))) != NULL) - LIST_INIT(list); - - return list; - } - --- 66,67 ---- Index: node.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/node.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** node.c 14 May 2005 02:56:24 -0000 1.11 --- node.c 18 May 2005 01:46:55 -0000 1.12 *************** *** 59,294 **** } - struct node * - nodelist_add(struct nodelist *node_list, struct node *node) - { - int i; - struct nodelink *node_iter, *node_link; - - node_link = (struct nodelink *) malloc(sizeof(struct nodelink)); - node_link->node = node; - - if(LIST_EMPTY(node_list)) - LIST_INSERT_HEAD(node_list, node_link, list); - else - LIST_FOREACH(node_iter, node_list, list) - { - if((i = node_compare(node, node_iter->node)) < 0) - { - if(node_iter == LIST_FIRST(node_list)) - LIST_INSERT_HEAD(node_list, node_link, list); - else - LIST_INSERT_BEFORE(node_iter, node_link, list); - break; - } - else - if(i == 0) - return node_iter->node; - else - if(LIST_NEXT(node_iter, list) == NULL) - LIST_INSERT_AFTER(node_iter, node_link, list); - } - - return node; - } - - struct node * - nodelist_add_msd(struct nodelist *node_list, struct node *node) - { - int i; - struct nodelink *node_iter, *node_link; - - node_link = (struct nodelink *) malloc(sizeof(struct nodelink)); - node_link->node = node; - - if(LIST_EMPTY(node_list)) - LIST_INSERT_HEAD(node_list, node_link, list); - else - LIST_FOREACH(node_iter, node_list, list) - { - if((i = node_compare_msd(node, node_iter->node)) < 0) - { - if(node_iter == LIST_FIRST(node_list)) - LIST_INSERT_HEAD(node_list, node_link, list); - else - LIST_INSERT_BEFORE(node_iter, node_link, list); - break; - } - else - if(i == 0) - return node_iter->node; - else - if(LIST_NEXT(node_iter, list) == NULL) - LIST_INSERT_AFTER(node_iter, node_link, list); - } - - return node; - } - - int - nodelist_compare(struct nodelist *node_list1, struct nodelist *node_list2) - { - return nodelist_size(node_list2) - nodelist_size(node_list1); - } - - /* How should we go about duplicating a msd organized list. - */ - struct nodelist * - nodelist_duplicate(struct nodelist *node_list1) - { - struct nodelist *node_list2; - struct nodelink *node_link; - - node_list2 = nodelist_new(); - - LIST_FOREACH(node_link, node_list1, list) - nodelist_add(node_list2, node_link->node); - - return node_list2; - } - - struct node * - nodelist_find(struct nodelist *node_list, struct node *node) - { - int i; - struct nodelink *node_link; - - LIST_FOREACH(node_link, node_list, list) - if((i = node_compare(node_link->node, node)) == 0) - return node_link->node; - else - if(i > 0) - break; - - return NULL; - } - - void - nodelist_free(struct nodelist *node_list) - { - struct nodelink *node_link, *tmp_link; - - tmp_link = NULL; - - LIST_FOREACH(node_link, node_list, list) - { - free(tmp_link); - tmp_link = node_link; - LIST_REMOVE(node_link, list); - } - - free(node_link); - free(node_list); - } - - struct nodelist * - nodelist_intersection(struct nodelist *node_list1, struct nodelist *node_list2) - { - struct nodelink *node_iter; - struct nodelist *node_list; - - node_list = nodelist_new(); - LIST_FOREACH(node_iter, node_list1, list) - if(nodelist_find(node_list2, node_iter->node) != NULL) - nodelist_add(node_list, node_iter->node); - - return node_list; - } - - struct nodelist * - nodelist_merge(struct nodelist *node_list1, struct nodelist *node_list2) - { - struct nodelink *node_iter; - - LIST_FOREACH(node_iter, node_list2, list) - nodelist_add(node_list1, node_iter->node); - - return node_list1; - } - - struct nodelist * - nodelist_new() - { - struct nodelist *list; - - if((list = (struct nodelist *) malloc(sizeof(struct nodelist))) != NULL) - LIST_INIT(list); - - return list; - } - - void - nodelist_print(FILE *filep, struct nodelist *node_list) - { - struct nodelink *node_link; - - LIST_FOREACH(node_link, node_list, list) - node_print(filep, node_link->node); - - return; - } - - struct node * - nodelist_remove(struct nodelist *node_list, struct node *node) - { - int i; - struct node *tmp_node; - struct nodelink *node_link; - - LIST_FOREACH(node_link, node_list, list) - { - tmp_node = node_link->node; - if((i = node_compare(tmp_node, node)) == 0) - { - LIST_REMOVE(node_link, list); - free(node_link); - return tmp_node; - } - else - if(i > 0) - break; - } - - return NULL; - } - - unsigned int - nodelist_size(struct nodelist *node_list) - { - struct nodelink *node_iter; - unsigned int size; - - size = 0; - - LIST_FOREACH(node_iter, node_list, list) - ++size; - - return size; - } - - struct nodelist * - nodelist_subtract(struct nodelist *node_list1, struct nodelist *node_list2) - { - struct nodelink *node_link; - struct nodelist *node_list; - - node_list = nodelist_duplicate(node_list1); - - LIST_FOREACH(node_link, node_list2, list) - nodelist_remove(node_list, node_link->node); - - return node_list; - } - - struct nodelist * - nodelist_union(struct nodelist *node_list1, struct nodelist *node_list2) - { - struct nodelist *node_list; - - node_list = nodelist_duplicate(node_list1); - nodelist_merge(node_list, node_list2); - - return node_list; - } - int node_compare(struct node *node1, struct node *node2) { --- 59,62 ---- *************** *** 376,378 **** return; } ! --- 144,146 ---- return; } ! Index: list.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/list.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** list.c 17 May 2005 14:30:26 -0000 1.3 --- list.c 18 May 2005 01:46:55 -0000 1.4 *************** *** 222,224 **** return list; ! } --- 222,598 ---- return list; ! } ! ! ! struct alias * ! aliaslist_add(struct list *alias_list, struct alias *alias) ! { ! int i; ! struct listlink *alias_iter, *alias_link; ! ! alias_link = (struct listlink *) malloc(sizeof(struct listlink)); ! alias_link->object = alias; ! ! if(LIST_EMPTY(alias_list)) ! LIST_INSERT_HEAD(alias_list, alias_link, list); ! else ! LIST_FOREACH(alias_iter, alias_list, list) ! { ! if((i = alias_compare(alias, alias_iter->object)) < 0) ! { ! if(alias_iter == LIST_FIRST(alias_list)) ! LIST_INSERT_HEAD(alias_list, alias_link, list); ! else ! LIST_INSERT_BEFORE(alias_iter, alias_link, list); ! break; ! } ! else ! if(i == 0) ! return alias_iter->object; ! else ! if(LIST_NEXT(alias_iter, list) == NULL) ! LIST_INSERT_AFTER(alias_iter, alias_link, list); ! } ! ! return alias; ! } ! ! struct list * ! aliaslist_duplicate(struct list *alias_list1) ! { ! struct list *alias_list2; ! struct link *alias_link; ! ! alias_list2 = list_new(alias_compare); ! ! LIST_FOREACH(alias_link, alias_list1, list) ! aliaslist_add(alias_list2, alias_link->alias); ! ! return alias_list2; ! } ! ! /* This should take a struct alias, not a char */ ! struct alias * ! aliaslist_find(struct aliaslist *alias_list, char *uid) ! { ! int i; ! struct aliaslink *alias_link; ! ! alias_link = LIST_FIRST(alias_list); ! ! LIST_FOREACH(alias_link, alias_list, list) ! { ! if((i = strcmp(((struct alias *) alias_link->alias)->uid, uid)) == 0) ! return alias_link->alias; ! else ! if(i > 0) ! break; ! } ! ! return NULL; ! } ! ! void ! aliaslist_free(struct aliaslist *alias_list) ! { ! struct aliaslink *alias_link; ! ! LIST_FOREACH(alias_link, alias_list, list) ! { ! LIST_REMOVE(alias_link, list); ! alias_free(alias_link->alias); ! free(alias_link); ! alias_link = NULL; ! } ! free(alias_list); ! ! return; ! } ! ! struct aliaslist * ! aliaslist_new() ! { ! struct aliaslist *list; ! ! if((list = (struct aliaslist *) malloc(sizeof(struct aliaslist))) != NULL) ! LIST_INIT(list); ! ! return list; ! } ! ! struct graph * ! graphlist_add(struct graphlist *graph_list, struct graph *graph) ! { ! int i; ! struct graphlink *graph_iter, *graph_link; ! ! graph_link = (struct graphlink *) malloc(sizeof(struct graphlink)); ! graph_link->graph = graph; ! ! if(LIST_EMPTY(graph_list)) ! LIST_INSERT_HEAD(graph_list, graph_link, list); ! else ! LIST_FOREACH(graph_iter, graph_list, list) ! { ! if((i = graph_compare(graph, graph_iter->graph)) < 0) ! { ! if(graph_iter == LIST_FIRST(graph_list)) ! LIST_INSERT_HEAD(graph_list, graph_link, list); ! else ! LIST_INSERT_BEFORE(graph_iter, graph_link, list); ! break; ! } ! else ! if(i == 0) ! return graph_iter->graph; ! else ! if(LIST_NEXT(graph_iter, list) == NULL) ! LIST_INSERT_AFTER(graph_iter, graph_link, list); ! } ! ! return graph; ! } ! ! struct graphlist * ! graphlist_new() ! { ! struct graphlist *graphlist; ! ! if((graphlist = (struct graphlist *) malloc(sizeof(struct graphlist))) != NULL) ! LIST_INIT(graphlist); ! ! return graphlist; ! } ! struct node * ! nodelist_add(struct nodelist *node_list, struct node *node) ! { ! int i; ! struct nodelink *node_iter, *node_link; ! ! node_link = (struct nodelink *) malloc(sizeof(struct nodelink)); ! node_link->node = node; ! ! if(LIST_EMPTY(node_list)) ! LIST_INSERT_HEAD(node_list, node_link, list); ! else ! LIST_FOREACH(node_iter, node_list, list) ! { ! if((i = node_compare(node, node_iter->node)) < 0) ! { ! if(node_iter == LIST_FIRST(node_list)) ! LIST_INSERT_HEAD(node_list, node_link, list); ! else ! LIST_INSERT_BEFORE(node_iter, node_link, list); ! break; ! } ! else ! if(i == 0) ! return node_iter->node; ! else ! if(LIST_NEXT(node_iter, list) == NULL) ! LIST_INSERT_AFTER(node_iter, node_link, list); ! } ! ! return node; ! } ! ! struct node * ! nodelist_add_msd(struct nodelist *node_list, struct node *node) ! { ! int i; ! struct nodelink *node_iter, *node_link; ! ! node_link = (struct nodelink *) malloc(sizeof(struct nodelink)); ! node_link->node = node; ! ! if(LIST_EMPTY(node_list)) ! LIST_INSERT_HEAD(node_list, node_link, list); ! else ! LIST_FOREACH(node_iter, node_list, list) ! { ! if((i = node_compare_msd(node, node_iter->node)) < 0) ! { ! if(node_iter == LIST_FIRST(node_list)) ! LIST_INSERT_HEAD(node_list, node_link, list); ! else ! LIST_INSERT_BEFORE(node_iter, node_link, list); ! break; ! } ! else ! if(i == 0) ! return node_iter->node; ! else ! if(LIST_NEXT(node_iter, list) == NULL) ! LIST_INSERT_AFTER(node_iter, node_link, list); ! } ! ! return node; ! } ! ! int ! nodelist_compare(struct nodelist *node_list1, struct nodelist *node_list2) ! { ! return nodelist_size(node_list2) - nodelist_size(node_list1); ! } ! ! /* How should we go about duplicating a msd organized list. ! */ ! struct nodelist * ! nodelist_duplicate(struct nodelist *node_list1) ! { ! struct nodelist *node_list2; ! struct nodelink *node_link; ! ! node_list2 = nodelist_new(); ! ! LIST_FOREACH(node_link, node_list1, list) ! nodelist_add(node_list2, node_link->node); ! ! return node_list2; ! } ! ! struct node * ! nodelist_find(struct nodelist *node_list, struct node *node) ! { ! int i; ! struct nodelink *node_link; ! ! LIST_FOREACH(node_link, node_list, list) ! if((i = node_compare(node_link->node, node)) == 0) ! return node_link->node; ! else ! if(i > 0) ! break; ! ! return NULL; ! } ! ! void ! nodelist_free(struct nodelist *node_list) ! { ! struct nodelink *node_link, *tmp_link; ! ! tmp_link = NULL; ! ! LIST_FOREACH(node_link, node_list, list) ! { ! free(tmp_link); ! tmp_link = node_link; ! LIST_REMOVE(node_link, list); ! } ! ! free(node_link); ! free(node_list); ! } ! ! struct nodelist * ! nodelist_intersection(struct nodelist *node_list1, struct nodelist *node_list2) ! { ! struct nodelink *node_iter; ! struct nodelist *node_list; ! ! node_list = nodelist_new(); ! LIST_FOREACH(node_iter, node_list1, list) ! if(nodelist_find(node_list2, node_iter->node) != NULL) ! nodelist_add(node_list, node_iter->node); ! ! return node_list; ! } ! ! struct nodelist * ! nodelist_merge(struct nodelist *node_list1, struct nodelist *node_list2) ! { ! struct nodelink *node_iter; ! ! LIST_FOREACH(node_iter, node_list2, list) ! nodelist_add(node_list1, node_iter->node); ! ! return node_list1; ! } ! ! struct nodelist * ! nodelist_new() ! { ! struct nodelist *list; ! ! if((list = (struct nodelist *) malloc(sizeof(struct nodelist))) != NULL) ! LIST_INIT(list); ! ! return list; ! } ! ! void ! nodelist_print(FILE *filep, struct nodelist *node_list) ! { ! struct nodelink *node_link; ! ! LIST_FOREACH(node_link, node_list, list) ! node_print(filep, node_link->node); ! ! return; ! } ! ! struct node * ! nodelist_remove(struct nodelist *node_list, struct node *node) ! { ! int i; ! struct node *tmp_node; ! struct nodelink *node_link; ! ! LIST_FOREACH(node_link, node_list, list) ! { ! tmp_node = node_link->node; ! if((i = node_compare(tmp_node, node)) == 0) ! { ! LIST_REMOVE(node_link, list); ! free(node_link); ! return tmp_node; ! } ! else ! if(i > 0) ! break; ! } ! ! return NULL; ! } ! ! unsigned int ! nodelist_size(struct nodelist *node_list) ! { ! struct nodelink *node_iter; ! unsigned int size; ! ! size = 0; ! ! LIST_FOREACH(node_iter, node_list, list) ! ++size; ! ! return size; ! } ! ! struct nodelist * ! nodelist_subtract(struct nodelist *node_list1, struct nodelist *node_list2) ! { ! struct nodelink *node_link; ! struct nodelist *node_list; ! ! node_list = nodelist_duplicate(node_list1); ! ! LIST_FOREACH(node_link, node_list2, list) ! nodelist_remove(node_list, node_link->node); ! ! return node_list; ! } ! ! struct nodelist * ! nodelist_union(struct nodelist *node_list1, struct nodelist *node_list2) ! { ! struct nodelist *node_list; ! ! node_list = nodelist_duplicate(node_list1); ! nodelist_merge(node_list, node_list2); ! ! return node_list; ! } ! ! Index: alias.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/alias.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** alias.h 17 May 2005 14:30:26 -0000 1.6 --- alias.h 18 May 2005 01:46:55 -0000 1.7 *************** *** 30,42 **** }; ! int alias_compare(struct alias *, struct alias *); void alias_free(struct alias *); struct alias *alias_new(char *, char *, struct node *); - struct alias *aliaslist_add(struct list *, struct alias *); - struct list *aliaslist_duplicate(struct list *); - struct alias *aliaslist_find(struct list *, char *); - void aliaslist_free(struct list *); - struct list *aliaslist_new(void); - #endif /* _ALIAS_H_ */ --- 30,36 ---- }; ! int alias_compare(void *, void *); void alias_free(struct alias *); struct alias *alias_new(char *, char *, struct node *); #endif /* _ALIAS_H_ */ Index: graph.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/graph.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** graph.c 22 Apr 2005 01:55:21 -0000 1.3 --- graph.c 18 May 2005 01:46:55 -0000 1.4 *************** *** 42,87 **** } - struct graph * - graphlist_add(struct graphlist *graph_list, struct graph *graph) - { - int i; - struct graphlink *graph_iter, *graph_link; - - graph_link = (struct graphlink *) malloc(sizeof(struct graphlink)); - graph_link->graph = graph; - - if(LIST_EMPTY(graph_list)) - LIST_INSERT_HEAD(graph_list, graph_link, list); - else - LIST_FOREACH(graph_iter, graph_list, list) - { - if((i = graph_compare(graph, graph_iter->graph)) < 0) - { - if(graph_iter == LIST_FIRST(graph_list)) - LIST_INSERT_HEAD(graph_list, graph_link, list); - else - LIST_INSERT_BEFORE(graph_iter, graph_link, list); - break; - } - else - if(i == 0) - return graph_iter->graph; - else - if(LIST_NEXT(graph_iter, list) == NULL) - LIST_INSERT_AFTER(graph_iter, graph_link, list); - } - - return graph; - } - - struct graphlist * - graphlist_new() - { - struct graphlist *graphlist; - - if((graphlist = (struct graphlist *) malloc(sizeof(struct graphlist))) != NULL) - LIST_INIT(graphlist); - - return graphlist; - } --- 42,44 ---- Index: list.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/list.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** list.h 17 May 2005 15:16:28 -0000 1.5 --- list.h 18 May 2005 01:46:55 -0000 1.6 *************** *** 33,37 **** { struct listlink *lh_first; ! (int) (*compare) (void *, void *); }; --- 33,37 ---- { struct listlink *lh_first; ! int (*compare) (void *, void *); }; *************** *** 41,45 **** struct list *); struct list *list_duplicate(struct list *); ! void *list_find(struct list_t *, void *); void list_free(struct list *); --- 41,45 ---- struct list *); struct list *list_duplicate(struct list *); ! void *list_find(struct list *, void *); void list_free(struct list *); *************** *** 48,52 **** struct list *list_merge(struct list *, struct list *); ! struct list *list_new((int) (*) (void *, void *)); void list_print(FILE *, struct list *); --- 48,52 ---- struct list *list_merge(struct list *, struct list *); ! struct list *list_new(int (*) (void *, void *)); void list_print(FILE *, struct list *); |