示例#1
0
int main() {
  
  igraph_trie_t trie;
  long int id;
  int i;
  char *str;

  /* init */
  igraph_trie_init(&trie, 0);

  /* add and get values */
  igraph_trie_get(&trie, "hello", &id);  printf("hello: %li\n", id);
  igraph_trie_get(&trie, "hepp", &id);   printf("hepp:  %li\n", id);
  igraph_trie_get(&trie, "alma", &id);   printf("alma:  %li\n", id);
  igraph_trie_get(&trie, "also", &id);   printf("also:  %li\n", id);

  igraph_trie_get(&trie, "hello", &id);  printf("hello: %li\n", id);
  igraph_trie_get(&trie, "hepp", &id);   printf("hepp:  %li\n", id);
  igraph_trie_get(&trie, "alma", &id);   printf("alma:  %li\n", id);
  igraph_trie_get(&trie, "also", &id);   printf("also:  %li\n", id);

  igraph_trie_get(&trie, "a", &id);      printf("a:     %li\n", id);
  igraph_trie_get(&trie, "axon", &id);   printf("axon:  %li\n", id);

  igraph_trie_get(&trie, "hello", &id);  printf("hello: %li\n", id);
  igraph_trie_get(&trie, "hepp", &id);   printf("hepp:  %li\n", id);
  igraph_trie_get(&trie, "alma", &id);   printf("alma:  %li\n", id);
  igraph_trie_get(&trie, "also", &id);   printf("also:  %li\n", id);

  /* check for existence */
  igraph_trie_check(&trie, "head", &id); printf("head:  %li\n", id);
  igraph_trie_check(&trie, "alma", &id); printf("alma:  %li\n", id);
   
  /* destroy */
  igraph_trie_destroy(&trie);

  /* the same with index */
  igraph_trie_init(&trie, 1);

  igraph_trie_get(&trie, "hello", &id);  printf("hello: %li\n", id);
  igraph_trie_get(&trie, "hepp", &id);   printf("hepp:  %li\n", id);
  igraph_trie_get(&trie, "alma", &id);   printf("alma:  %li\n", id);
  igraph_trie_get(&trie, "also", &id);   printf("also:  %li\n", id);

  igraph_trie_get(&trie, "hello", &id);  printf("hello: %li\n", id);
  igraph_trie_get(&trie, "hepp", &id);   printf("hepp:  %li\n", id);
  igraph_trie_get(&trie, "alma", &id);   printf("alma:  %li\n", id);
  igraph_trie_get(&trie, "also", &id);   printf("also:  %li\n", id);

  igraph_trie_get(&trie, "a", &id);      printf("a:     %li\n", id);
  igraph_trie_get(&trie, "axon", &id);   printf("axon:  %li\n", id);

  igraph_trie_get(&trie, "hello", &id);  printf("hello: %li\n", id);
  igraph_trie_get(&trie, "hepp", &id);   printf("hepp:  %li\n", id);
  igraph_trie_get(&trie, "alma", &id);   printf("alma:  %li\n", id);
  igraph_trie_get(&trie, "also", &id);   printf("also:  %li\n", id);

  /* check for existence */
  igraph_trie_check(&trie, "head", &id); printf("head:  %li\n", id);
  igraph_trie_check(&trie, "alma", &id); printf("alma:  %li\n", id);

  for (i=0; i<igraph_trie_size(&trie); i++) {
    igraph_trie_idx(&trie, i, &str);
    printf("%d: %s\n", i, str);
  }
  igraph_trie_destroy(&trie);

  if (!IGRAPH_FINALLY_STACK_EMPTY) return 1;
  
  return 0;
}
void igraph_i_graphml_destroy_state(struct igraph_i_graphml_parser_state* state) {
  long int i;

  if (state->destroyed) return;
  state->destroyed=1;

  /* this is the easy part */
  igraph_trie_destroy(&state->node_trie);
  igraph_strvector_destroy(&state->edgeids);
  igraph_trie_destroy(&state->v_names);
  igraph_trie_destroy(&state->e_names);
  igraph_trie_destroy(&state->g_names);
  igraph_vector_destroy(&state->edgelist);
   
  if (state->error_message) { free(state->error_message); }
  if (state->data_key) { free(state->data_key); }
  if (state->data_char) { free(state->data_char); }
  
  for (i=0; i<igraph_vector_ptr_size(&state->v_attrs); i++) {
    igraph_i_graphml_attribute_record_t *rec=VECTOR(state->v_attrs)[i];
    if (rec->record.type==IGRAPH_ATTRIBUTE_NUMERIC) {
      if (rec->record.value != 0) {
	igraph_vector_destroy((igraph_vector_t*)rec->record.value);
	igraph_Free(rec->record.value);
      }
    } else if (rec->record.type==IGRAPH_ATTRIBUTE_STRING) {
      if (rec->record.value != 0) {
	igraph_strvector_destroy((igraph_strvector_t*)rec->record.value);
	igraph_Free(rec->record.value);
      }
    }
    if (rec->id != 0) igraph_Free(rec->id);
    if (rec->record.name != 0) igraph_Free(rec->record.name);
    igraph_Free(rec);
  }	 

  for (i=0; i<igraph_vector_ptr_size(&state->e_attrs); i++) {
    igraph_i_graphml_attribute_record_t *rec=VECTOR(state->e_attrs)[i];
    if (rec->record.type==IGRAPH_ATTRIBUTE_NUMERIC) {
      if (rec->record.value != 0) {
	igraph_vector_destroy((igraph_vector_t*)rec->record.value);
	igraph_Free(rec->record.value);
      }
    } else if (rec->record.type==IGRAPH_ATTRIBUTE_STRING) {
      if (rec->record.value != 0) {
	igraph_strvector_destroy((igraph_strvector_t*)rec->record.value);
	igraph_Free(rec->record.value);
      }
    }
    if (rec->id != 0) igraph_Free(rec->id);
    if (rec->record.name != 0) igraph_Free(rec->record.name);
    igraph_Free(rec);
  }

  for (i=0; i<igraph_vector_ptr_size(&state->g_attrs); i++) {
    igraph_i_graphml_attribute_record_t *rec=VECTOR(state->g_attrs)[i];
    if (rec->record.type==IGRAPH_ATTRIBUTE_NUMERIC) {
      if (rec->record.value != 0) {
	igraph_vector_destroy((igraph_vector_t*)rec->record.value);
	igraph_Free(rec->record.value);
      }
    } else if (rec->record.type==IGRAPH_ATTRIBUTE_STRING) {
      if (rec->record.value != 0) {
	igraph_strvector_destroy((igraph_strvector_t*)rec->record.value);
	igraph_Free(rec->record.value);
      }
    }
    if (rec->id != 0) igraph_Free(rec->id);
    if (rec->record.name != 0) igraph_Free(rec->record.name);
    igraph_Free(rec);
  }

  igraph_vector_ptr_destroy(&state->v_attrs);
  igraph_vector_ptr_destroy(&state->e_attrs);
  igraph_vector_ptr_destroy(&state->g_attrs);
  
  IGRAPH_FINALLY_CLEAN(1);
}