[digraphanalysis-cvs] digraphanalysis/src node.c,
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-04-22 14:58:42
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22490/src Modified Files: node.c Log Message: function implementation Index: node.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/node.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** node.c 22 Apr 2005 01:55:21 -0000 1.5 --- node.c 22 Apr 2005 14:58:32 -0000 1.6 *************** *** 25,28 **** --- 25,31 ---- node_free(struct node *node) { + free(node->uid); + nodelist_free(node->links); + free(node); } *************** *** 30,33 **** --- 33,50 ---- node_new(char *uid) { + struct node *node; + size_t len; + + node = (struct node *) malloc(sizeof(struct node *)); + + len = strlen(uid) + 1; + node->uid = (char *) malloc(len); + strlcpy(node->uid, uid, len); + + node->msd = 0; + + node->links = nodelist_new(); + + return node; } *************** *** 35,38 **** --- 52,83 ---- 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; } *************** *** 40,43 **** --- 85,116 ---- 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; } *************** *** 45,53 **** nodelist_compare(struct nodelist *node_list1, struct nodelist *node_list2) { } struct nodelist * ! nodelist_duplicate(struct nodelist *node_list) { } --- 118,138 ---- 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; } *************** *** 55,58 **** --- 140,154 ---- 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; } *************** *** 60,63 **** --- 156,172 ---- 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); } |