#include "igraph.h" #include "ruby.h" #include "cIGraph.h" VALUE cIGraph_get_edge_attr(VALUE self, VALUE from, VALUE to){ int idx; igraph_t *graph; VALUE e_ary; Data_Get_Struct(self, igraph_t, graph); e_ary = ((VALUE*)graph->attr)[1]; idx = NUM2INT(cIGraph_get_eid(self, from, to, 1)); return rb_ary_entry(e_ary,idx); } VALUE cIGraph_set_edge_attr(VALUE self, VALUE from, VALUE to, VALUE attr){ int idx; igraph_t *graph; VALUE e_ary; Data_Get_Struct(self, igraph_t, graph); e_ary = ((VALUE*)graph->attr)[1]; idx = NUM2INT(cIGraph_get_eid(self, from, to, 1)); rb_ary_store(e_ary,idx,attr); return Qtrue; } igraph_attribute_table_t cIGraph_attribute_table = { cIGraph_attribute_init, cIGraph_attribute_destroy, cIGraph_attribute_copy, cIGraph_attribute_add_vertices, cIGraph_attribute_delete_vertices, cIGraph_attribute_add_edges, cIGraph_attribute_delete_edges, cIGraph_attribute_permute_edges, cIGraph_attribute_get_info, cIGraph_attribute_has_attr, cIGraph_attribute_get_type, cIGraph_get_numeric_graph_attr, cIGraph_get_string_graph_attr, cIGraph_get_numeric_vertex_attr, cIGraph_get_string_vertex_attr, cIGraph_get_numeric_edge_attr, cIGraph_get_string_edge_attr, }; int cIGraph_attribute_init(igraph_t *graph, igraph_vector_ptr_t *attr) { VALUE* attrs; attrs = (VALUE*)calloc(2, sizeof(VALUE)); if(!attrs) IGRAPH_ERROR("Error allocating Arrays\n", IGRAPH_ENOMEM); //[0] is vertex array, [1] is edge array attrs[0] = rb_ary_new(); attrs[1] = rb_ary_new(); graph->attr = attrs; return IGRAPH_SUCCESS; } /* Destruction */ void cIGraph_attribute_destroy(igraph_t *graph) { free(graph->attr); return; } /* Copying */ int cIGraph_attribute_copy(igraph_t *to, const igraph_t *from) { return IGRAPH_SUCCESS; } /* Adding vertices */ int cIGraph_attribute_add_vertices(igraph_t *graph, long int nv, igraph_vector_ptr_t *attr) { int i; VALUE vertex_array = ((VALUE*)graph->attr)[0]; if(attr){ for(i=0;iattr)[1]; if(attr){ for(i=0;i