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.2 kB

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

Ruby binding for the igraph library.