#include "igraph.h" #include "ruby.h" #include "cIGraph.h" VALUE cIGraph_vcount(VALUE self){ igraph_t *graph; Data_Get_Struct(self, igraph_t, graph); return INT2NUM(igraph_vcount(graph)); } VALUE cIGraph_ecount(VALUE self){ igraph_t *graph; Data_Get_Struct(self, igraph_t, graph); return INT2NUM(igraph_ecount(graph)); } VALUE cIGraph_edge(VALUE self, VALUE eid){ igraph_t *graph; igraph_integer_t from = 0; igraph_integer_t to = 0; VALUE from_r; VALUE to_r; Data_Get_Struct(self, igraph_t, graph); igraph_edge(graph,NUM2INT(eid),&from,&to); from_r = cIGraph_get_vertex_object(self,from); to_r = cIGraph_get_vertex_object(self,to); return rb_ary_new3(2, from_r, to_r); } VALUE cIGraph_get_eid(VALUE self, VALUE from, VALUE to, VALUE directed){ igraph_t *graph; igraph_integer_t eid = 0; int from_i; int to_i; igraph_bool_t directed_b = 0; Data_Get_Struct(self, igraph_t, graph); from_i = cIGraph_get_vertex_id(self,from); to_i = cIGraph_get_vertex_id(self,to); if(directed) directed_b = 1; igraph_get_eid(graph,&eid,from_i,to_i,directed_b); return INT2NUM(eid); } VALUE cIGraph_neighbors(VALUE self, VALUE v, VALUE mode){ igraph_t *graph; igraph_integer_t pnode; igraph_neimode_t pmode = NUM2INT(mode); igraph_vector_t neis; int i; VALUE neighbors = rb_ary_new(); igraph_vector_init_int(&neis,0); Data_Get_Struct(self, igraph_t, graph); pnode = cIGraph_get_vertex_id(self,v); igraph_neighbors(graph,&neis,pnode,pmode); for(i=0;i