Thread: [digraphanalysis-cvs] digraphanalysis/src node.c, node.h,
Status: Planning
Brought to you by:
jbreker
|
From: Jeff B. <jb...@us...> - 2005-04-15 19:32:42
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31221 Modified Files: node.c node.h Log Message: node.c compiles Index: node.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/node.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** node.h 15 Apr 2005 19:00:56 -0000 1.3 --- node.h 15 Apr 2005 19:32:32 -0000 1.4 *************** *** 39,43 **** --- 39,47 ---- struct node *node_new(char *); + struct node *nodelist_add(struct nodelist *, struct node *); + struct node *nodelist_find(struct nodelist *, struct node *); + struct nodelist *nodelist_merge(struct nodelist *, struct nodelist *); struct nodelist *nodelist_new(void); + unsigned int nodelist_size(struct nodelist *); #endif /* _NODE_H_ */ Index: node.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/node.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** node.c 14 Apr 2005 03:24:28 -0000 1.2 --- node.c 15 Apr 2005 19:32:32 -0000 1.3 *************** *** 20,72 **** #include <string.h> - #include "list.h" #include "node.h" ! int pgpkey_compare(void *key1, void *key2) { ! return strcmp(((pgpkey_t *) key1)->keyid, ((pgpkey_t *) key2)->keyid); } ! int pgpkey_compare_msd(void *key1, void *key2) { ! float tmp; ! tmp = ((pgpkey_t *) key1)->msd - ((pgpkey_t *) key2)->msd; ! if(tmp == (float) 0) ! return strcmp(((pgpkey_t *) key1)->keyid, ((pgpkey_t *) key2)->keyid); else ! if(tmp > (float) 0) ! return 1; else ! return (-1); } ! unsigned int pgpkey_distance(pgpkey_t *keyto, pgpkey_t *keyfrom) { unsigned int distance; unsigned int last_known_size, tmpsize; ! struct list_t *traversed_keys, *tmp_keys; ! struct node_t *tmp_node; ! traversed_keys = list_new(); last_known_size = 0; distance = 1; ! list_merge_list(traversed_keys, keyto->signatures, &pgpkey_compare); ! while((tmpsize = list_size(traversed_keys)) != last_known_size) { ! if(list_find_object(traversed_keys, keyfrom, &pgpkey_compare) != NULL) return distance; last_known_size = tmpsize; ++distance; ! tmp_keys = traversed_keys; ! tmp_node = LIST_FIRST(tmp_keys); ! traversed_keys = list_new(); while(tmp_node != NULL) { ! list_add_object(traversed_keys, tmp_node->object, &pgpkey_compare); ! list_merge_list(traversed_keys, ((pgpkey_t *) tmp_node->object)->signatures, &pgpkey_compare); ! tmp_node = LIST_NEXT(tmp_node, entries); } } --- 20,92 ---- #include <string.h> #include "node.h" ! /* DONE ! */ ! struct nodelist *nodelist_new() { ! struct nodelist *list; ! ! if((list = (struct nodelist *) malloc(sizeof(struct nodelist))) != NULL) ! LIST_INIT(list); ! ! return list; } ! int node_compare(struct node *node1, struct node *node2) { ! return strcmp(node1->uid, node2->uid); ! } ! int node_compare_msd(struct node *node1, struct node *node2) ! { ! int i; ! float float_tmp; ! ! float_tmp = node1->msd - node2->msd; ! if(float_tmp == (float) 0) ! i = node_compare(node1, node2); else ! if(float_tmp > (float) 0) ! i = 1; else ! i = (-1); ! ! return i; } ! /* keyto == node1 ! * keyfrom == node2 ! * traversed_keys == traversed_nodes ! * tmp_keys == tmp_nodes ! * list_merge_list == nodelist_merge ! */ ! unsigned int node_distance(struct node *node1, struct node *node2) { unsigned int distance; unsigned int last_known_size, tmpsize; ! struct nodelist *traversed_nodes, *tmp_nodes; ! struct nodelink *tmp_node; ! traversed_nodes = nodelist_new(); last_known_size = 0; distance = 1; ! nodelist_merge(traversed_nodes, node1->links); ! while((tmpsize = nodelist_size(traversed_nodes)) != last_known_size) { ! if(nodelist_find(traversed_nodes, node2) != NULL) return distance; last_known_size = tmpsize; ++distance; ! tmp_nodes = traversed_nodes; ! tmp_node = LIST_FIRST(tmp_nodes); ! traversed_nodes = nodelist_new(); while(tmp_node != NULL) { ! nodelist_add(traversed_nodes, tmp_node->node); ! nodelist_merge(traversed_nodes, ((struct node *) tmp_node->node)->links); ! tmp_node = LIST_NEXT(tmp_node, list); } } *************** *** 75,116 **** } ! void pgpkey_msd(pgpkey_t *key, struct list_t *keys) { ! unsigned int distance, i, num_keys; ! struct node_t *iter; distance = 0; ! num_keys = 0; ! iter = LIST_FIRST(keys); while(iter != NULL) { ! i = pgpkey_distance(key, (pgpkey_t *) iter->object); if(i > 0) { distance += i; ! num_keys++; } ! iter = LIST_NEXT(iter, entries); } ! key->msd = ((float) distance) / ((float) num_keys); return; } - pgpkey_t *pgpkey_new(char *keyid, char *name) - { - pgpkey_t *pgpkey; - - pgpkey = (pgpkey_t *) malloc(sizeof(pgpkey_t)); - pgpkey->keyid = (char *) malloc(17); - strncpy(pgpkey->keyid, keyid, 16); - *(pgpkey->keyid + 16) = '\0'; - pgpkey->name = (char *) malloc(strlen(name) + 1); - strncpy(pgpkey->name, name, strlen(name)); - *(pgpkey->name + strlen(name)) = '\0'; - pgpkey->signatures = list_new(); - pgpkey->msd = 0; - - return pgpkey; - } --- 95,121 ---- } ! void node_msd(struct node *node, struct nodelist *nodes) { ! unsigned int distance, i, num_nodes; ! struct nodelink *iter; distance = 0; ! num_nodes = 0; ! iter = LIST_FIRST(nodes); while(iter != NULL) { ! i = node_distance(node, iter->node); if(i > 0) { distance += i; ! num_nodes++; } ! iter = LIST_NEXT(iter, list); } ! node->msd = ((float) distance) / ((float) num_nodes); ! return; } |
|
From: Jeff B. <jb...@us...> - 2005-04-25 04:53:22
|
Update of /cvsroot/digraphanalysis/digraphanalysis/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10101 Modified Files: node.c node.h Log Message: woops commited when it didn't compile... Index: node.h =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/node.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** node.h 21 Apr 2005 18:44:42 -0000 1.6 --- node.h 25 Apr 2005 04:53:14 -0000 1.7 *************** *** 38,47 **** --- 38,51 ---- }; + int node_compare(struct node *, struct node *); + int node_compare_msd(struct node *, struct node *); unsigned int node_distance(struct node *, struct node *); void node_free(struct node *); struct node *node_new(char *); + void node_print(FILE *, struct node *); struct node *nodelist_add(struct nodelist *, struct node *); struct node *nodelist_add_msd(struct nodelist *, struct node *); + int nodelist_compare(struct nodelist *, struct nodelist *); struct nodelist *nodelist_duplicate(struct nodelist *); struct node *nodelist_find(struct nodelist *, struct node *); Index: node.c =================================================================== RCS file: /cvsroot/digraphanalysis/digraphanalysis/src/node.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** node.c 25 Apr 2005 04:40:03 -0000 1.8 --- node.c 25 Apr 2005 04:53:14 -0000 1.9 *************** *** 49,52 **** --- 49,60 ---- } + void + node_print(FILE *filep, struct node *node) + { + fprintf(filep, "%s\n", node->uid); + + return; + } + struct node * nodelist_add(struct nodelist *node_list, struct node *node) *************** *** 222,225 **** --- 230,234 ---- { int i; + struct node *tmp_node; struct nodelink *node_link; *************** *** 258,261 **** --- 267,271 ---- nodelist_subtract(struct nodelist *node_list1, struct nodelist *node_list2) { + return NULL; } *************** *** 263,266 **** --- 273,277 ---- nodelist_union(struct nodelist *node_list1, struct nodelist *node_list2) { + return NULL; } |