#include "igraph.h" #include "ruby.h" #include "cIGraph.h" igraph_integer_t cIGraph_get_vertex_id(VALUE graph, VALUE v){ VALUE v_ary; VALUE idx; igraph_t *igraph; Data_Get_Struct(graph, igraph_t, igraph); v_ary = ((VALUE*)igraph->attr)[0]; idx = rb_funcall(v_ary,rb_intern("index"),1,v); if(idx != Qnil) return NUM2INT(idx); rb_raise(cIGraphError, "Unable to find vertex\n"); return -1; } VALUE cIGraph_get_vertex_object(VALUE graph, igraph_integer_t n){ VALUE v_ary; VALUE obj; igraph_t *igraph; Data_Get_Struct(graph, igraph_t, igraph); v_ary = ((VALUE*)igraph->attr)[0]; obj = rb_ary_entry(v_ary,n); return obj; } int cIGraph_vertex_arr_to_id_vec(VALUE graph, VALUE va, igraph_vector_t *nv){ VALUE vertex; VALUE tmp; VALUE i; tmp = rb_check_array_type(va); if(NIL_P(tmp)) rb_raise(cIGraphError, "Array expected\n"); //Initialize edge vector //igraph_vector_init_int(nv,0); for (i=0; iattr)[0]; return rb_ary_includes(v_ary,v); }