uint8_t ngdb_read(char *ngdbfile, graph_t *graph) { ngdb_t *ngdb; uint32_t i; uint32_t nnodes; ngdb = NULL; memset(graph, 0, sizeof(graph_t)); ngdb = ngdb_open(ngdbfile); if (ngdb == NULL) goto fail; nnodes = ngdb_num_nodes(ngdb); if (graph_create(graph, nnodes, 0)) goto fail; if (_read_hdr(ngdb, graph)) goto fail; for (i = 0; i < nnodes; i++) { if (_read_refs (ngdb, graph, i) != 0) goto fail; if (_read_label(ngdb, graph, i) != 0) goto fail; } ngdb_close(ngdb); return 0; fail: if (ngdb != NULL) ngdb_close(ngdb); graph_free(graph); return 1; }
uint8_t _partition_to_graph( node_partition_t *part, graph_t *g, graph_t *conn) { uint64_t i; uint32_t *group; uint32_t groupsz; g->neighbours = NULL; if (graph_create(g, part->nnodes, 0)) goto fail; for (i = 0; i < part->nparts; i++) { group = (uint32_t *)part->parts[i].data; groupsz = part->parts[i].size; if (conn == NULL) { if (graph_connect(g, group, groupsz)) goto fail; } else { if (graph_connect_from(g, conn, group, groupsz)) goto fail; } } return 0; fail: if (g->neighbours != NULL) graph_free(g); return 1; }
void test_graph_search_sccs() { GRAPH* graph = graph_create(); graph_add_edge(graph, 6, 0); graph_add_edge(graph, 3, 6); graph_add_edge(graph, 0, 3); graph_add_edge(graph, 8, 6); graph_add_edge(graph, 5, 8); graph_add_edge(graph, 2, 5); graph_add_edge(graph, 8, 2); graph_add_edge(graph, 7, 5); graph_add_edge(graph, 1, 7); graph_add_edge(graph, 4, 1); graph_add_edge(graph, 7, 4); GRAPH* reverse = graph_reverse(graph); GRAPH_SEARCH* graph_search1 = graph_search_create(reverse); graph_search_finish_times(reverse, graph_search1); graph_destroy(reverse); GRAPH_SEARCH* graph_search2 = graph_search_create(graph); graph_search_sccs(graph, graph_search2, graph_search1->finish_times); graph_search_destroy(graph_search1); graph_search_destroy(graph_search2); graph_destroy(graph); }
void test_graph_search_finish_times() { GRAPH* graph = graph_create(); graph_add_edge(graph, 0, 6); graph_add_edge(graph, 6, 3); graph_add_edge(graph, 3, 0); graph_add_edge(graph, 6, 8); graph_add_edge(graph, 8, 5); graph_add_edge(graph, 5, 2); graph_add_edge(graph, 2, 8); graph_add_edge(graph, 5, 7); graph_add_edge(graph, 7, 1); graph_add_edge(graph, 1, 4); graph_add_edge(graph, 4, 7); GRAPH_SEARCH* graph_search = graph_search_create(graph); graph_search_finish_times(graph, graph_search); assert(6 == graph_search->finish_times[0]); assert(3 == graph_search->finish_times[1]); assert(0 == graph_search->finish_times[2]); assert(8 == graph_search->finish_times[3]); assert(5 == graph_search->finish_times[4]); assert(7 == graph_search->finish_times[5]); assert(1 == graph_search->finish_times[6]); assert(4 == graph_search->finish_times[7]); assert(2 == graph_search->finish_times[8]); graph_destroy(graph); graph_search_destroy(graph_search); }
decision_input_model_t * model_dummy_exec(model_t *m, prediction_list_t *input) { prediction_metric_result_t *metric; decision_input_metric_t *di_metric; decision_input_model_t *dim; dim = decision_input_model_create(m); if (!dim) return NULL; do { metric = prediction_list_extract_head(input); if (!metric) continue; /* Real work goes here ! */ graph_t * output = graph_create(); const sample_t *s = graph_read_first(metric->high); while (s) { graph_add_point(output, s->time, s->value * 0.8); graph_add_point(output, s->time + 500000, s->value * 1.2); graph_add_point(output, s->time + 1000000, s->value * 1.2); s = graph_read_next(metric->high, s); } di_metric = decision_input_metric_create(metric->name, metric, output); decision_input_model_add_metric(dim, di_metric); } while (metric); return dim; }
static uint8_t _merge( graph_t *gin, graph_t *gout, merge_set_t *mergesets, uint8_t nmergesets) { uint32_t *nodemap; uint32_t ninnodes; uint32_t noutnodes; nodemap = NULL; memset(gout, 0, sizeof(graph_t)); ninnodes = graph_num_nodes(gin); nodemap = calloc(ninnodes, sizeof(uint32_t)); if (nodemap == NULL) goto fail; if (_create_nodemap( gin, mergesets, nmergesets, nodemap, ninnodes, &noutnodes)) goto fail; if (graph_create(gout, noutnodes, 0)) goto fail; if (_copy_edges( gin, gout, nodemap, ninnodes)) goto fail; if (_copy_nodelabels(gin, gout, nodemap, ninnodes, mergesets, nmergesets)) goto fail; free(nodemap); return 0; fail: if (nodemap != NULL) free(nodemap); graph_free(gout); return 1; }
static sexpr sexpr_to_graph (sexpr sx) { sexpr g = graph_create (); sexpr c = car(sx); while (consp(c)) { sexpr cx = car (c); sexpr cxcar = car (cx); graph_add_node (g, cxcar); c = cdr (c); } c = cdr(sx); while (consp(c)) { sexpr cx = car (c); sexpr cxcar = car (cx); sexpr cxcdr = cdr (cx); sexpr cxcadr = car (cxcdr); sexpr cxcddr = cdr (cxcdr); struct graph_node *ns = graph_search_node (g, cxcar); struct graph_node *nt = graph_search_node (g, cxcadr); if ((ns != (struct graph_node *)0) && (nt != (struct graph_node *)0)) { graph_node_add_edge (ns, nt, cxcddr); } c = cdr (c); } c = car(sx); while (consp(c)) { sexpr cx = car (c); sexpr cxcar = car (cx); sexpr cxcdr = cdr (cx); struct graph_node *n = graph_search_node (g, cxcar); if (n != (struct graph_node *)0) { n->label = cxcdr; } c = cdr (c); } return g; }
void test_graph_search_create() { GRAPH* graph = graph_create(); graph_add_edge(graph, 0, 1); graph_add_edge(graph, 0, 2); graph_add_edge(graph, 1, 2); graph_add_edge(graph, 2, 1); GRAPH_SEARCH* graph_search = graph_search_create(graph); graph_destroy(graph); }
struct _graph * x8664_graph (uint64_t address, struct _map * memory) { struct _graph * graph; graph = graph_create(); x8664_graph_0(graph, address, memory); x8664_graph_1(graph, address); return graph; }
/* creates graph structure from a file*/ graph_t * graph_create_file (const char *filename) { int i, j, c; FILE *file; graph_t *g; if (!filename) { fprintf (stderr, "file name is null \n"); _FLINE_; exit (0); } file = fopen (filename, "r"); if (!file) { fprintf (stderr, "file %s can not open\n", filename); _FLINE_; exit (0); } c = fscanf (file, "%d %d", &i, &j); if (!(i > 0 && j > 0)) { fprintf (stderr, "Node number and Edge number should be positive \n"); _FLINE_; exit (0); } g = graph_create (i, j); if (!g) { fprintf (stderr, "graph creation failed for nodes %2d and edges %2d \n", i, j); _FLINE_; exit (0); } c = fscanf (file, "%d %d", &i, &j); while (c != EOF) { if ((i < 0 || j < 0)) { fprintf (stderr, "Nodes should be positive \n"); _FLINE_; exit (0); } graph_add_edge (g, i, j); c = fscanf (file, "%d %d", &i, &j); } (void)fclose (file); return g; }
/** * * @return int */ int main() { int num_cidades, num_arestas, cidade, vizinho, capacidade; menu_principal(); ler_entradas(&num_cidades, &num_arestas); Graph g = graph_create(num_cidades); cidade = vizinho = 1; do { printf("Criando a aresta\n"); } while(criar_aresta(&g)); return (EXIT_SUCCESS); }
static struct sys * sys_create_empty(void) { struct sys *sys; sys = calloc(1, sizeof(*sys)); sys->graph = graph_create(); sys->sel = sel_create(0); sys->visible = sel_create(0); sys->nframesalloc = 8; sys->frames = calloc(sys->nframesalloc, sizeof(struct frame)); return (sys); }
uint8_t graph_threshold_weight( graph_t *gin, graph_t *gout, double threshold, uint8_t absval, uint8_t reverse) { if (graph_create( gout, graph_num_nodes(gin), 0)) goto fail; if (graph_copy_nodelabels(gin, gout)) goto fail; if (_threshold_edges( gin, gout, threshold, absval, reverse)) goto fail; return 0; fail: return 1; }
struct graph * graph_copy(struct graph *graph) { struct graph *copy; struct edge *edge; int i; copy = graph_create(); for (i = 0; i < graph_get_vertex_count(graph); i++) graph_vertex_add(copy); for (i = 0; i < graph_get_vertex_count(graph); i++) for (edge = graph->edges[i]; edge; edge = edge->next) graph_edge_create(copy, edge->i, edge->j, edge->type); return (copy); }
int main(int argc, char **argv){ Graph g; int i; int j; g = graph_create(TEST_SIZE); assert(graph_vertex_count(g) == TEST_SIZE); for (i = 0; i < TEST_SIZE; i++){ for (j = 0; j < TEST_SIZE; j++){ assert(graph_has_edge(g, i, j) == 0); } } for (i = 0; i < TEST_SIZE; i++){ assert(graph_out_degree(g, i) == 0); graph_foreach(g, i, match_sink, 0); } assert(graph_edge_count(g) == 0); for (i = 0; i < TEST_SIZE; i++){ for (j = 0; j < TEST_SIZE; j++){ if (i < j){ graph_add_edge(g, i, j); } } } for (i = 0; i < TEST_SIZE; i++){ for (j = 0; j < TEST_SIZE; j++){ assert(graph_has_edge(g, i, j) == (i < j)); } } assert(graph_edge_count(g) == (TEST_SIZE*(TEST_SIZE-1)/2)); graph2dot(g); graph_destroy(g); return 0; }
int main() { struct graph *g = graph_create(); if (g == NULL) { printf("malloc error\n"); return 1; } int values[] = {0, 1, 2, 3, 4, 5, 6, 7}; int len = sizeof(values)/sizeof(values[0]); struct vertex *vertices[len]; for (int i = 0; i < len; ++i) { vertices[i] = graph_vertex_add(g, values[i]); assert(vertices[i]); printf("Added vertex %p\n", vertices[i]); } graph_edge_add(g, vertices[0], vertices[7], 7); graph_edge_add(g, vertices[0], vertices[5], 5); graph_edge_add(g, vertices[0], vertices[3], 3); graph_edge_add(g, vertices[2], vertices[6], 8); graph_edge_add(g, vertices[5], vertices[4], 9); graph_edge_remove(g, vertices[0], vertices[7]); graph_edge_remove(g, vertices[0], vertices[5]); graph_edge_remove(g, vertices[2], vertices[6]); graph_edge_remove(g, vertices[5], vertices[4]); graph_edge_add(g, vertices[0], vertices[7], 7); graph_vertex_remove(g, vertices[0]); graph_print(g); graph_vertex_remove(g, vertices[1]); graph_vertex_remove(g, vertices[2]); graph_vertex_remove(g, vertices[3]); graph_vertex_remove(g, vertices[4]); graph_vertex_remove(g, vertices[5]); graph_vertex_remove(g, vertices[6]); graph_vertex_remove(g, vertices[7]); assert(graph_vertex_num(g) == 0); graph_destroy(g); return 0; }
int main(int argc, char *argv[]) { graph_t *graph; int i, n, *dist, *parent; graph = graph_create(NUM_ELEM); graph_add_weighted_edge(graph, 0, 9, 200); graph_add_edge(graph, 0, 2); graph_add_edge(graph, 0, 4); graph_add_edge(graph, 0, 6); graph_add_edge(graph, 2, 4); graph_add_edge(graph, 2, 7); graph_add_edge(graph, 7, 9); printf("\nAll edges: \n"); graph_print_edges(graph); printf("\nAll edges from 0: \n"); graph_foreach_weighted(graph, 0, &graph_print_edge_weight, NULL); printf("\nDijkstra: \n"); n = graph_vertex_count(graph); dist = malloc(sizeof(int) * n); parent = malloc(sizeof(int) * n); dijkstra(graph, 0, dist, parent); for (i=0; i<n; i++) if (dist[i] == INT_MAX) printf(" no "); else printf("%3d ", dist[i]); printf("\n"); for (i=0; i<n; i++) printf("%3d ", parent[i]); printf("\n"); graph_destroy(graph); return EXIT_SUCCESS; }
uint8_t _mk_avg_graph( char **inputs, uint16_t ninputs, graph_t *gavg, nlbl_map_t *map, edge_weight_t edgeweight) { uint64_t i; uint32_t nnodes; graph_label_t *lbl; array_t *nodemap; graph_t gin; nnodes = map->labels.size; if (graph_create(gavg, nnodes, 0)) goto fail; for (i = 0; i < nnodes; i++) { lbl = array_getd(&(map->labels), i); if (graph_set_nodelabel(gavg, i, lbl)) goto fail; } for (i = 0; i < ninputs; i++) { nodemap = array_getd(&(map->idmap), i); if (ngdb_read(inputs[i], &gin)) goto fail; if (_update_avg_graph(&gin, gavg, nodemap, edgeweight, ninputs)) goto fail; graph_free(&gin); } return 0; fail: return 1; }
int main() { #ifndef ONLINE_JUDGE freopen("input", "rt", stdin); #endif int N, buf; scanf("%d", &N); Graph graph = graph_create(N); for (int i = 0; i < N; i++) { buf = 1; for (int j = 0; buf != 0; j++) { scanf("%d", &buf); graph_add_edge(graph, i, buf - 1); } } int next_delete = 0; for (int i = 0; i < graph->num_vertices; i++) { next_delete = find_vert_no_parents(graph); printf("%d ", next_delete + 1); graph_del_for_vertic_edge(graph, next_delete); } return 0; }
int main(){ struct graph* graph; struct graph* clone; char node_desc[NODE_DESCRIPTION_LENGTH]; char edge_desc[EDGE_DESCRIPTION_LENGTH]; struct node* node_asterix; struct node* node_obelix; struct node* node_idefix; struct node* node_abraracourcix; graph = graph_create(NODE_DESCRIPTION_LENGTH, EDGE_DESCRIPTION_LENGTH); graph_register_dotPrint_callback(graph, NULL, asterix_dotPrint_node, asterix_dotPrint_edge, NULL) /* add nodes */ snprintf(node_desc, NODE_DESCRIPTION_LENGTH, "asterix"); node_asterix = graph_add_node(graph, &node_desc); if (node_asterix == NULL){ log_err("unable to add node to graph"); } snprintf(node_desc, NODE_DESCRIPTION_LENGTH, "obelix"); node_obelix = graph_add_node(graph, &node_desc); if (node_obelix == NULL){ log_err("unable to add node to graph"); } snprintf(node_desc, NODE_DESCRIPTION_LENGTH, "idefix"); node_idefix = graph_add_node(graph, &node_desc); if (node_idefix == NULL){ log_err("unable to add node to graph"); } snprintf(node_desc, NODE_DESCRIPTION_LENGTH, "abraracourcix"); node_abraracourcix = graph_add_node(graph, &node_desc); if (node_abraracourcix == NULL){ log_err("unable to add node to graph"); } /* add edges */ snprintf(edge_desc, EDGE_DESCRIPTION_LENGTH, "friend"); if (graph_add_edge(graph, node_obelix, node_asterix, &edge_desc) == NULL){ log_err("unable to add edge to graph"); } snprintf(edge_desc, EDGE_DESCRIPTION_LENGTH, "obey"); if (graph_add_edge(graph, node_idefix, node_obelix, &edge_desc) == NULL){ log_err("unable to add edge to graph"); } snprintf(edge_desc, EDGE_DESCRIPTION_LENGTH, "rule"); if (graph_add_edge(graph, node_abraracourcix, node_obelix, &edge_desc) == NULL){ log_err("unable to add edge to graph"); } snprintf(edge_desc, EDGE_DESCRIPTION_LENGTH, "rule"); if (graph_add_edge(graph, node_abraracourcix, node_asterix, &edge_desc) == NULL){ log_err("unable to add edge to graph"); } clone = graph_clone(graph, asterix_copy_node, asterix_copy_edge, NULL); graph_delete(graph); /* print graph */ if (graphPrintDot_print(clone, "asterix.dot", NULL)){ log_err("unable to print graph to dot format"); } graph_delete(clone); return 0; }
/** * Builds a snp graph from the snps array */ graph *graph_from_snps(GapIO *io, snp_t *snp, int nsnps, double c_offset) { graph *g = NULL; int i, j; int ntemplates, *templates = NULL; node **tmpl_map = NULL; int lookup[256]; if (verbosity) puts("Building graph"); /* lookup table for fast base to index conversion */ for (i = 0; i < 256; i++) lookup[i] = 0; lookup['A'] = lookup['a'] = 1; lookup['C'] = lookup['c'] = 2; lookup['G'] = lookup['g'] = 3; lookup['T'] = lookup['t'] = 4; lookup['*'] = 5; g = graph_create(); g->correlation_offset = c_offset; /* * Obtain a list of unique template numbers, by collecting and sorting. * For each unique template we initialise the graph node. * * At the end of this we have ntemplates unique templates and * tmpl_map[] indexed by Gap4 template number maps us to the * node in the graph. */ for (ntemplates = i = 0; i < nsnps; i++) { ntemplates += snp[i].nseqs; } templates = (int *)malloc(ntemplates * sizeof(int)); for (ntemplates = i = 0; i < nsnps; i++) { for (j = 0; j < snp[i].nseqs; j++) { templates[ntemplates++] = snp[i].seqs[j].tmplate; } } tmpl_map = (node **)xcalloc(Ntemplates(io)+1, sizeof(*tmpl_map)); qsort(templates, ntemplates, sizeof(int), int_compare); for (i = j = 0; i < ntemplates; j++) { tmpl_map[templates[i]] = graph_add_node(g); tmpl_map[templates[i]]->number = j; tmpl_map[templates[i]]->tname = strdup(get_template_name(io, templates[i])); do { i++; } while (i < ntemplates && templates[i] == templates[i-1]); } xfree(templates); ntemplates = j; g->nsnps = nsnps; g->ntemplates = ntemplates; /* * The matrix is of size nsnps by ntemplates. It initially will consist * of entirely empty vectors. */ g->matrix = (int (*)[6])malloc(ntemplates * nsnps * sizeof(*g->matrix)); memset(&g->matrix[0][0], 0, ntemplates * nsnps * 6 * sizeof(int)); for (i = j = 0; j < ntemplates; i++) { if (!tmpl_map[i]) continue; tmpl_map[i]->matrix = &g->matrix[j * nsnps]; j++; } /* Create the snp_score array */ g->snp_scores = (double *)malloc(nsnps * sizeof(*g->snp_scores)); for (i = 0; i < nsnps; i++) { g->snp_scores[i] = snp[i].score; } /* Now add basecalls to the matrix from snp info */ for (i = 0; i < nsnps; i++) { for (j = 0; j < snp[i].nseqs; j++) { node *n = tmpl_map[snp[i].seqs[j].tmplate]; n->matrix[i][lookup[snp[i].seqs[j].base]]++; n->tscore = snp[i].seqs[j].tscore; /* FIXME: confidence not yet used */ } for (j = 0; j < ntemplates; j++) { if (!g->nodes->node[j]->matrix[i][1] && !g->nodes->node[j]->matrix[i][2] && !g->nodes->node[j]->matrix[i][3] && !g->nodes->node[j]->matrix[i][4] && !g->nodes->node[j]->matrix[i][5]) g->nodes->node[j]->matrix[i][0]++; } } return g; }
uint8_t _prune( graph_t *gin, graph_t *gout, uint32_t threshold, uint32_t *components, uint32_t ncomponents, uint32_t *sizes) { uint64_t i; uint64_t j; uint32_t *nidmap; uint32_t ninnodes; uint32_t noutnodes; uint32_t *nbrs; float *wts; uint32_t nnbrs; graph_label_t *lbl; nidmap = NULL; ninnodes = graph_num_nodes(gin); /*calculate the size of the output graph*/ noutnodes = 0; for (i = 0; i < ncomponents; i++) { if (sizes[i] > threshold) noutnodes += sizes[i]; } if (graph_create(gout, noutnodes, 0)) goto fail; /* * create the nid map - a mapping from * gin node indices to gout node indices */ nidmap = malloc(ninnodes*sizeof(uint32_t)); if (nidmap == NULL) goto fail; j = 0; for (i = 0; i < ninnodes; i++) { if (sizes[components[i]-1] <= threshold) nidmap[i] = 0xFFFFFFFF; else nidmap[i] = j++; } /*copy edges from gin to gout*/ for (i = 0; i < ninnodes; i++) { /*ignore nodes from thresholded components*/ if (nidmap[i] == 0xFFFFFFFF) continue; nnbrs = graph_num_neighbours(gin, i); nbrs = graph_get_neighbours(gin, i); wts = graph_get_weights( gin, i); for (j = 0; j < nnbrs; j++) { /*ignore edges to thresholded components*/ if (nidmap[nbrs[j]] == 0xFFFFFFFF) continue; if (graph_add_edge(gout, nidmap[i], nidmap[nbrs[j]], wts[j])) goto fail; } } /*copy nodelabels from gin to gout*/ for (i = 0; i < ninnodes; i++) { if (nidmap[i] == 0xFFFFFFFF) continue; /*assume that there are no node labels to copy, if the get call fails*/ lbl = graph_get_nodelabel(gin, i); if (lbl == NULL) break; if (graph_set_nodelabel(gout, nidmap[i], lbl)) goto fail; } free(nidmap); return 0; fail: if (nidmap != NULL) free(nidmap); return 1; }
void main() { item vertex[9]; graph_create(vertex,9,14); prim(vertex,9,0); }
struct _graph * recursive_disassemble (const struct _map * mem_map, uint64_t entry, struct _ins * (* ins_callback) (const struct _map *, uint64_t)) { struct _queue * queue = queue_create(); struct _map * map = map_create(); struct _index * index = index_create(entry); queue_push(queue, index); object_delete(index); while (queue->size > 0) { struct _index * index = queue_peek(queue); if (map_fetch(map, index->index)) { queue_pop(queue); continue; } struct _ins * ins = ins_callback(mem_map, index->index); if (ins == NULL) { queue_pop(queue); continue; } map_insert(map, index->index, ins); struct _list_it * lit; for (lit = list_iterator(ins->successors); lit != NULL; lit = lit->next) { struct _ins_value * successor = lit->data; if (successor->type == INS_SUC_CALL) continue; struct _index * index = index_create(successor->address); queue_push(queue, index); object_delete(index); } queue_pop(queue); } object_delete(queue); // create graph nodes struct _graph * graph = graph_create(); struct _map_it * mit; for (mit = map_iterator(map); mit != NULL; mit = map_it_next(mit)) { graph_add_node(graph, map_it_key(mit), map_it_data(mit)); } // create graph edges for (mit = map_iterator(map); mit != NULL; mit = map_it_next(mit)) { struct _ins * ins = map_it_data(mit); struct _list_it * lit; for (lit = list_iterator(ins->successors); lit != NULL; lit = lit->next) { struct _ins_value * successor = lit->data; // don't add call edges if (successor->type == INS_SUC_CALL) continue; graph_add_edge(graph, ins->address, successor->address, successor); } } object_delete(map); return graph; }
struct _graph * redis_x86_graph (uint64_t address, struct _map * memory) { uint64_t next_index = 1; uint64_t this_index = 0; uint64_t last_index = 0; struct _redis_x86 * redis_x86 = redis_x86_create(); redis_x86_mem_from_mem_map(redis_x86, memory); redis_x86->regs[RED_EIP] = address; redis_x86_false_stack(redis_x86); struct _map * ins_map = map_create(); struct _graph * graph = graph_create(); while (redis_x86_step(redis_x86) == REDIS_SUCCESS) { uint64_t address = redis_x86->ins_addr; // do we have an instruction at this address already? struct _index * index = map_fetch(ins_map, address); // we have an instruction, fetch it, make sure it matches if (index) { struct _graph_node * node = graph_fetch_node(graph, index->index); struct _ins * ins = list_first(node->data); // instructions diverge, create new instruction if ( (ins->size != redis_x86->ins_size) || (memcmp(ins->bytes, redis_x86->ins_bytes, redis_x86->ins_size))) { ins = redis_x86_create_ins(redis_x86); if (ins == NULL) { fprintf(stderr, "could not create ins, eip=%llx\n", (unsigned long long) redis_x86->ins_addr); break; } struct _list * list = list_create(); list_append(list, ins); object_delete(ins); graph_add_node(graph, next_index, list); object_delete(list); map_remove(ins_map, redis_x86->ins_addr); index = index_create(next_index++); map_insert(ins_map, redis_x86->ins_addr, index); this_index = index->index; object_delete(index); } else this_index = index->index; } // no instruction at this address, create it else { struct _ins * ins = redis_x86_create_ins(redis_x86); if (ins == NULL) { fprintf(stderr, "could not create ins eip=%llx\n", (unsigned long long) redis_x86->ins_addr); break; } struct _list * list = list_create(); list_append(list, ins); object_delete(ins); graph_add_node(graph, next_index, list); object_delete(list); index = index_create(next_index++); map_insert(ins_map, redis_x86->ins_addr, index); this_index = index->index; object_delete(index); } /* * create an edge from last index to this index * because our graph library enforces both the condition that the head * and tail nodes are valid, and that there exists only one edge per * head->tail combination, we can blindly add edges here and let the * graph library work out the details */ printf("[edge] %llx -> %llx\n", (unsigned long long) last_index, (unsigned long long) this_index); struct _ins_edge * ins_edge = ins_edge_create(INS_EDGE_NORMAL); graph_add_edge(graph, last_index, this_index, ins_edge); object_delete(ins_edge); last_index = this_index; printf("%llx -> %llx\n", (unsigned long long) last_index, (unsigned long long) this_index); } object_delete(ins_map); object_delete(redis_x86); return graph; }