You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cIGraph_attribute_handler.c 4.8 kB

19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #include "igraph.h"
  2. #include "ruby.h"
  3. #include "cIGraph.h"
  4. VALUE cIGraph_get_edge_attr(VALUE self, VALUE from, VALUE to){
  5. int idx;
  6. igraph_t *graph;
  7. VALUE e_ary;
  8. Data_Get_Struct(self, igraph_t, graph);
  9. e_ary = ((VALUE*)graph->attr)[1];
  10. idx = NUM2INT(cIGraph_get_eid(self, from, to, 1));
  11. return rb_ary_entry(e_ary,idx);
  12. }
  13. VALUE cIGraph_set_edge_attr(VALUE self, VALUE from, VALUE to, VALUE attr){
  14. int idx;
  15. igraph_t *graph;
  16. VALUE e_ary;
  17. Data_Get_Struct(self, igraph_t, graph);
  18. e_ary = ((VALUE*)graph->attr)[1];
  19. idx = NUM2INT(cIGraph_get_eid(self, from, to, 1));
  20. rb_ary_store(e_ary,idx,attr);
  21. return Qtrue;
  22. }
  23. igraph_attribute_table_t cIGraph_attribute_table = {
  24. cIGraph_attribute_init,
  25. cIGraph_attribute_destroy,
  26. cIGraph_attribute_copy,
  27. cIGraph_attribute_add_vertices,
  28. cIGraph_attribute_delete_vertices,
  29. cIGraph_attribute_add_edges,
  30. cIGraph_attribute_delete_edges,
  31. cIGraph_attribute_permute_edges,
  32. cIGraph_attribute_get_info,
  33. cIGraph_attribute_has_attr,
  34. cIGraph_attribute_get_type,
  35. cIGraph_get_numeric_graph_attr,
  36. cIGraph_get_string_graph_attr,
  37. cIGraph_get_numeric_vertex_attr,
  38. cIGraph_get_string_vertex_attr,
  39. cIGraph_get_numeric_edge_attr,
  40. cIGraph_get_string_edge_attr,
  41. };
  42. int cIGraph_attribute_init(igraph_t *graph, igraph_vector_ptr_t *attr) {
  43. VALUE* attrs;
  44. attrs = (VALUE*)calloc(2, sizeof(VALUE));
  45. if(!attrs)
  46. IGRAPH_ERROR("Error allocating Arrays\n", IGRAPH_ENOMEM);
  47. //[0] is vertex array, [1] is edge array
  48. attrs[0] = rb_ary_new();
  49. attrs[1] = rb_ary_new();
  50. graph->attr = attrs;
  51. return IGRAPH_SUCCESS;
  52. }
  53. /* Destruction */
  54. void cIGraph_attribute_destroy(igraph_t *graph) {
  55. free(graph->attr);
  56. return;
  57. }
  58. /* Copying */
  59. int cIGraph_attribute_copy(igraph_t *to, const igraph_t *from) {
  60. return IGRAPH_SUCCESS;
  61. }
  62. /* Adding vertices */
  63. int cIGraph_attribute_add_vertices(igraph_t *graph, long int nv, igraph_vector_ptr_t *attr) {
  64. int i;
  65. VALUE vertex_array = ((VALUE*)graph->attr)[0];
  66. if(attr){
  67. for(i=0;i<nv;i++){
  68. rb_ary_push(vertex_array,(VALUE)VECTOR(*attr)[i]);
  69. }
  70. }
  71. return IGRAPH_SUCCESS;
  72. }
  73. /* Deleting vertices */
  74. void cIGraph_attribute_delete_vertices(igraph_t *graph,
  75. const igraph_vector_t *eidx,
  76. const igraph_vector_t *vidx) {
  77. return;
  78. }
  79. /* Adding edges */
  80. int cIGraph_attribute_add_edges(igraph_t *graph,
  81. const igraph_vector_t *edges,
  82. igraph_vector_ptr_t *attr) {
  83. int i;
  84. VALUE edge_array = ((VALUE*)graph->attr)[1];
  85. if(attr){
  86. for(i=0;i<igraph_vector_size(edges)/2;i++){
  87. rb_ary_push(edge_array,(VALUE)VECTOR(*attr)[i]);
  88. }
  89. }
  90. return IGRAPH_SUCCESS;
  91. }
  92. /* Deleting edges */
  93. void cIGraph_attribute_delete_edges(igraph_t *graph, const igraph_vector_t *idx) {
  94. return;
  95. }
  96. /* Permuting edges */
  97. int cIGraph_attribute_permute_edges(igraph_t *graph,
  98. const igraph_vector_t *idx) { return 0;
  99. }
  100. /* Getting attribute names and types */
  101. int cIGraph_attribute_get_info(const igraph_t *graph,
  102. igraph_strvector_t *gnames,
  103. igraph_vector_t *gtypes,
  104. igraph_strvector_t *vnames,
  105. igraph_vector_t *vtypes,
  106. igraph_strvector_t *enames,
  107. igraph_vector_t *etypes) {
  108. return 0;
  109. }
  110. /* Checks whether the graph has a graph/vertex/edge attribute with the given name */
  111. igraph_bool_t cIGraph_attribute_has_attr(const igraph_t *graph,
  112. igraph_attribute_elemtype_t type,
  113. const char* name) {
  114. return 0;
  115. }
  116. /* Returns the type of a given attribute */
  117. int cIGraph_attribute_get_type(const igraph_t *graph,
  118. igraph_attribute_type_t *type,
  119. igraph_attribute_elemtype_t elemtype,
  120. const char *name) {
  121. return 0;
  122. }
  123. /* Getting numeric graph attributes */
  124. int cIGraph_get_numeric_graph_attr(const igraph_t *graph,
  125. const char *name, igraph_vector_t *value) {
  126. return 0;
  127. }
  128. /* Getting string graph attributes */
  129. int cIGraph_get_string_graph_attr(const igraph_t *graph,
  130. const char *name, igraph_strvector_t *value) {
  131. return 0;
  132. }
  133. /* Getting numeric vertex attributes */
  134. int cIGraph_get_numeric_vertex_attr(const igraph_t *graph,
  135. const char *name,
  136. igraph_vs_t vs,
  137. igraph_vector_t *value) {
  138. return 0;
  139. }
  140. /* Getting string vertex attributes */
  141. int cIGraph_get_string_vertex_attr(const igraph_t *graph,
  142. const char *name,
  143. igraph_vs_t vs,
  144. igraph_strvector_t *value) {
  145. return 0;
  146. }
  147. /* Getting numeric edge attributes */
  148. int cIGraph_get_numeric_edge_attr(const igraph_t *graph,
  149. const char *name,
  150. igraph_es_t es,
  151. igraph_vector_t *value) {
  152. return 0;
  153. }
  154. /* Getting string edge attributes */
  155. int cIGraph_get_string_edge_attr(const igraph_t *graph,
  156. const char *name,
  157. igraph_es_t es,
  158. igraph_strvector_t *value) {
  159. return 0;
  160. }

Ruby binding for the igraph library.