Example #1
0
int main() {

  igraph_strvector_t sv1, sv2;
  char *str1;
  int i;

  /* igraph_strvector_init, igraph_strvector_destroy */
  igraph_strvector_init(&sv1, 10);
  igraph_strvector_destroy(&sv1);
  igraph_strvector_init(&sv1, 0);
  igraph_strvector_destroy(&sv1);

  /* igraph_strvector_get, igraph_strvector_set */
  igraph_strvector_init(&sv1, 5);
  for (i=0; i<igraph_strvector_size(&sv1); i++) {
    igraph_strvector_get(&sv1, i, &str1);
    printf("---%s---\n", str1);
  }
  igraph_strvector_set(&sv1, 0, "zero");
  igraph_strvector_set(&sv1, 1, "one");
  igraph_strvector_set(&sv1, 2, "two");
  igraph_strvector_set(&sv1, 3, "three");
  igraph_strvector_set(&sv1, 4, "four");
  for (i=0; i<igraph_strvector_size(&sv1); i++) {
    igraph_strvector_get(&sv1, i, &str1);
    printf("---%s---\n", str1);
  }

  /* igraph_strvector_remove_section, igraph_strvector_remove, 
     igraph_strvector_resize, igraph_strvector_size */
  igraph_strvector_remove_section(&sv1, 0, 5);
  if (igraph_strvector_size(&sv1) != 0) {
    return 1;
  }
  igraph_strvector_resize(&sv1, 10);
  igraph_strvector_set(&sv1, 0, "zero");
  igraph_strvector_set(&sv1, 1, "one");
  igraph_strvector_set(&sv1, 2, "two");
  igraph_strvector_set(&sv1, 3, "three");
  igraph_strvector_set(&sv1, 4, "four");
  igraph_strvector_resize(&sv1, 5);
  for (i=0; i<igraph_strvector_size(&sv1); i++) {
    igraph_strvector_get(&sv1, i, &str1);
    printf("---%s---\n", str1);
  }
  igraph_strvector_resize(&sv1, 0);
  if (igraph_strvector_size(&sv1) != 0) {
    return 1;
  }
  igraph_strvector_resize(&sv1, 10);
  igraph_strvector_set(&sv1, 0, "zero");
  igraph_strvector_set(&sv1, 1, "one");
  igraph_strvector_set(&sv1, 2, "two");
  igraph_strvector_set(&sv1, 3, "three");
  igraph_strvector_set(&sv1, 4, "four");
  igraph_strvector_resize(&sv1, 5);
  for (i=0; i<igraph_strvector_size(&sv1); i++) {
    igraph_strvector_get(&sv1, i, &str1);
    printf("---%s---\n", str1);
  }  

  /* igraph_strvector_move_interval */
  igraph_strvector_move_interval(&sv1, 3, 5, 0);
  for (i=0; i<igraph_strvector_size(&sv1); i++) {
    igraph_strvector_get(&sv1, i, &str1);
    printf("---%s---\n", str1);
  }

  /* igraph_strvector_copy */
  igraph_strvector_copy(&sv2, &sv1);
  for (i=0; i<igraph_strvector_size(&sv2); i++) {
    igraph_strvector_get(&sv2, i, &str1);
    printf("---%s---\n", str1);
  }
  igraph_strvector_resize(&sv1, 0);
  igraph_strvector_destroy(&sv2);
  igraph_strvector_copy(&sv2, &sv1);
  if (igraph_strvector_size(&sv2) != 0) {
    return 2;
  }
  igraph_strvector_destroy(&sv2);

  /* igraph_strvector_add */
  igraph_strvector_add(&sv1, "zeroth");
  igraph_strvector_add(&sv1, "first");
  igraph_strvector_add(&sv1, "second");
  igraph_strvector_add(&sv1, "third");
  igraph_strvector_add(&sv1, "fourth");
  for (i=0; i<igraph_strvector_size(&sv1); i++) {
    igraph_strvector_get(&sv1, i, &str1);
    printf("---%s---\n", str1);
  }

  /* TODO: igraph_strvector_permdelete */
  /* TODO: igraph_strvector_remove_negidx */
  
  igraph_strvector_destroy(&sv1);

  /* append */
  printf("---\n");
  igraph_strvector_init(&sv1, 0);
  igraph_strvector_init(&sv2, 0);
  igraph_strvector_append(&sv1, &sv2);
  strvector_print(&sv1);
  printf("---\n");
  
  igraph_strvector_resize(&sv1, 3);
  igraph_strvector_append(&sv1, &sv2);
  strvector_print(&sv1);
  printf("---\n");   

  igraph_strvector_append(&sv2, &sv1);
  strvector_print(&sv2);
  printf("---\n");   
  
  igraph_strvector_set(&sv1, 0, "0");
  igraph_strvector_set(&sv1, 1, "1");
  igraph_strvector_set(&sv1, 2, "2");
  igraph_strvector_set(&sv2, 0, "3");
  igraph_strvector_set(&sv2, 1, "4");
  igraph_strvector_set(&sv2, 2, "5");
  igraph_strvector_append(&sv1, &sv2);
  strvector_print(&sv1);
  
  igraph_strvector_destroy(&sv1);
  igraph_strvector_destroy(&sv2);
  
  /* clear */
  igraph_strvector_init(&sv1, 3);
  igraph_strvector_set(&sv1, 0, "0");
  igraph_strvector_set(&sv1, 1, "1");
  igraph_strvector_set(&sv1, 2, "2");
  igraph_strvector_clear(&sv1);
  if (igraph_strvector_size(&sv1) != 0) {
    return 3;
  }
  igraph_strvector_resize(&sv1, 4);
  strvector_print(&sv1);
  igraph_strvector_set(&sv1, 0, "one");
  igraph_strvector_set(&sv1, 2, "two");
  strvector_print(&sv1);
  igraph_strvector_destroy(&sv1);

  /* STR */
  
  igraph_strvector_init(&sv1, 5);
  igraph_strvector_set(&sv1, 0, "one");
  igraph_strvector_set(&sv1, 1, "two");
  igraph_strvector_set(&sv1, 2, "three");
  igraph_strvector_set(&sv1, 3, "four");
  igraph_strvector_set(&sv1, 4, "five");
  strvector_print(&sv1);
  igraph_strvector_destroy(&sv1);

  if (!IGRAPH_FINALLY_STACK_EMPTY) return 4;
  
  return 0;
}
Example #2
0
static GError* _tgengraph_parseGraphProperties(TGenGraph* g) {
    TGEN_ASSERT(g);
    gint result = 0;

    tgen_debug("checking graph properties...");

    /* IGRAPH_WEAK means the undirected version of the graph is connected
     * IGRAPH_STRONG means a vertex can reach all others via a directed path */
    result = igraph_is_connected(g->graph, &(g->isConnected), IGRAPH_WEAK);
    if(result != IGRAPH_SUCCESS) {
        return g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
                "igraph_is_connected return non-success code %i", result);
    }

    igraph_integer_t clusterCount;
    result = igraph_clusters(g->graph, NULL, NULL, &(g->clusterCount), IGRAPH_WEAK);
    if(result != IGRAPH_SUCCESS) {
        return g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
                "igraph_clusters return non-success code %i", result);
    }

    /* it must be connected */
    if(!g->isConnected || g->clusterCount > 1) {
        return g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                "graph must be but is not connected");
    }

    g->isDirected = igraph_is_directed(g->graph);

    tgen_debug("checking graph attributes...");

    /* now check list of all attributes */
    igraph_strvector_t gnames, vnames, enames;
    igraph_vector_t gtypes, vtypes, etypes;
    igraph_strvector_init(&gnames, 25);
    igraph_vector_init(&gtypes, 25);
    igraph_strvector_init(&vnames, 25);
    igraph_vector_init(&vtypes, 25);
    igraph_strvector_init(&enames, 25);
    igraph_vector_init(&etypes, 25);

    result = igraph_cattribute_list(g->graph, &gnames, &gtypes, &vnames, &vtypes, &enames, &etypes);
    if(result != IGRAPH_SUCCESS) {
        return g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
                "igraph_cattribute_list return non-success code %i", result);
    }

    gint i = 0;
    for(i = 0; i < igraph_strvector_size(&gnames); i++) {
        gchar* name = NULL;
        igraph_strvector_get(&gnames, (glong) i, &name);

        tgen_debug("found graph attribute '%s'", name);
    }
    for(i = 0; i < igraph_strvector_size(&vnames); i++) {
        gchar* name = NULL;
        igraph_strvector_get(&vnames, (glong) i, &name);

        tgen_debug("found vertex attribute '%s'", name);
        g->knownAttributes |= _tgengraph_vertexAttributeToFlag(name);
    }
    for(i = 0; i < igraph_strvector_size(&enames); i++) {
        gchar* name = NULL;
        igraph_strvector_get(&enames, (glong) i, &name);

        tgen_debug("found edge attribute '%s'", name);
        g->knownAttributes |= _tgengraph_edgeAttributeToFlag(name);
    }

    igraph_strvector_destroy(&gnames);
    igraph_vector_destroy(&gtypes);
    igraph_strvector_destroy(&vnames);
    igraph_vector_destroy(&vtypes);
    igraph_strvector_destroy(&enames);
    igraph_vector_destroy(&etypes);

    tgen_info("successfully verified graph properties and attributes");

    return NULL;
}