int igraph_attribute_combination_remove(igraph_attribute_combination_t *comb, const char *name) { long int i, n=igraph_vector_ptr_size(&comb->list); /* Search, in case it is already there */ for (i=0; i<n; i++) { igraph_attribute_combination_record_t *r=VECTOR(comb->list)[i]; const char *n=r->name; if ( (!name && !n) || (name && n && !strcmp(n, name)) ) { break; } } if (i!=n) { igraph_attribute_combination_record_t *r=VECTOR(comb->list)[i]; if (r->name) { igraph_Free(r->name); } igraph_Free(r); igraph_vector_ptr_remove(&comb->list, i); } else { /* It is not there, we don't do anything */ } return 0; }
/* Removes the pair belonging to community k from the neighborhood list * of community c (that is, clist[c]) and recalculates maxdq */ void igraph_i_fastgreedy_community_remove_nei( igraph_i_fastgreedy_community_list* list, long int c, long int k) { long int i, n; igraph_bool_t rescan=0; igraph_i_fastgreedy_commpair *p; igraph_i_fastgreedy_community *comm; igraph_real_t olddq; comm=&list->e[c]; n=igraph_vector_ptr_size(&comm->neis); for (i=0; i<n; i++) { p=(igraph_i_fastgreedy_commpair*)VECTOR(comm->neis)[i]; if (p->second == k) { /* Check current maxdq */ if (comm->maxdq == p) rescan=1; break; } } if (i<n) { olddq = *comm->maxdq->dq; igraph_vector_ptr_remove(&comm->neis, i); if (rescan) { igraph_i_fastgreedy_community_rescan_max(comm); i=igraph_i_fastgreedy_community_list_find_in_heap(list, c); if (comm->maxdq) { if (*comm->maxdq->dq > olddq) igraph_i_fastgreedy_community_list_sift_up(list, i); else igraph_i_fastgreedy_community_list_sift_down(list, i); } else { /* no more neighbors for this community. we should remove this * community from the heap and restore the heap property */ debug("REMOVING (NO MORE NEIS): %ld\n", i); igraph_i_fastgreedy_community_list_remove2(list, i, c); } } } }
int main() { igraph_vector_ptr_t v1, v2; igraph_vector_ptr_t v3=IGRAPH_VECTOR_PTR_NULL; int i; void ** ptr; int d1=1, d2=2, d3=3, d4=4, d5=5; char *block1=0, *block2=0; /* igraph_vector_ptr_init, igraph_vector_ptr_destroy */ igraph_vector_ptr_init(&v1, 10); igraph_vector_ptr_destroy(&v1); igraph_vector_ptr_init(&v1, 0); igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_free_all, igraph_vector_ptr_destroy_all */ igraph_vector_ptr_init(&v1, 5); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { VECTOR(v1)[i]=(void*)malloc(i*10); } igraph_vector_ptr_free_all(&v1); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { VECTOR(v1)[i]=(void*)malloc(i*10); } igraph_vector_ptr_destroy_all(&v1); /* igraph_vector_ptr_reserve */ igraph_vector_ptr_init(&v1, 0); igraph_vector_ptr_reserve(&v1, 5); igraph_vector_ptr_reserve(&v1, 15); igraph_vector_ptr_reserve(&v1, 1); igraph_vector_ptr_reserve(&v1, 0); igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_empty, igraph_vector_ptr_clear */ igraph_vector_ptr_init(&v1, 10); if (igraph_vector_ptr_empty(&v1)) { return 1; } igraph_vector_ptr_clear(&v1); if (!igraph_vector_ptr_empty(&v1)) { return 2; } /* igraph_vector_ptr_size */ if (igraph_vector_ptr_size(&v1) != 0) { return 3; } igraph_vector_ptr_resize(&v1, 10); if (igraph_vector_ptr_size(&v1) != 10) { return 4; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_push_back */ igraph_vector_ptr_init(&v1, 0); for (i=0; i<10; i++) { igraph_vector_ptr_push_back(&v1, (void*)malloc(i*10)); } igraph_vector_ptr_destroy_all(&v1); /* igraph_vector_ptr_e */ igraph_vector_ptr_init(&v1, 5); VECTOR(v1)[0]=&d1; VECTOR(v1)[1]=&d2; VECTOR(v1)[2]=&d3; VECTOR(v1)[3]=&d4; VECTOR(v1)[4]=&d5; if (igraph_vector_ptr_e(&v1, 0) != &d1) { return 5; } if (igraph_vector_ptr_e(&v1, 1) != &d2) { return 6; } if (igraph_vector_ptr_e(&v1, 2) != &d3) { return 7; } if (igraph_vector_ptr_e(&v1, 3) != &d4) { return 8; } if (igraph_vector_ptr_e(&v1, 4) != &d5) { return 9; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_set */ igraph_vector_ptr_init(&v1, 5); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); if (igraph_vector_ptr_e(&v1, 0) != &d1) { return 5; } if (igraph_vector_ptr_e(&v1, 1) != &d2) { return 6; } if (igraph_vector_ptr_e(&v1, 2) != &d3) { return 7; } if (igraph_vector_ptr_e(&v1, 3) != &d4) { return 8; } if (igraph_vector_ptr_e(&v1, 4) != &d5) { return 9; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_null */ igraph_vector_ptr_init(&v1, 5); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); igraph_vector_ptr_null(&v1); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { if (VECTOR(v1)[i] != 0) { return 10; } } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_resize */ igraph_vector_ptr_init(&v1, 10); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); igraph_vector_ptr_resize(&v1, 10); igraph_vector_ptr_resize(&v1, 15); igraph_vector_ptr_resize(&v1, 5); if (igraph_vector_ptr_size(&v1) != 5) { return 11; } if (igraph_vector_ptr_e(&v1, 0) != &d1) { return 12; } if (igraph_vector_ptr_e(&v1, 1) != &d2) { return 13; } if (igraph_vector_ptr_e(&v1, 2) != &d3) { return 14; } if (igraph_vector_ptr_e(&v1, 3) != &d4) { return 15; } if (igraph_vector_ptr_e(&v1, 4) != &d5) { return 16; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_view */ ptr=(void**) malloc(5 * sizeof(void*)); igraph_vector_ptr_view(&v3, ptr, 5); ptr[0]=&d1; ptr[1]=&d2; ptr[2]=&d3; ptr[3]=&d4; ptr[4]=&d5; for (i=0; i<igraph_vector_ptr_size(&v3); i++) { if ( *((int*)VECTOR(v3)[i]) != i+1) { return 17; } } /* igraph_vector_ptr_init_copy */ igraph_vector_ptr_init_copy(&v1, ptr, 5); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { if ( *((int*)VECTOR(v1)[i]) != i+1) { return 18; } } /* igraph_vector_ptr_copy_to */ igraph_vector_ptr_copy_to(&v1, ptr); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { if ( *((int*)ptr[i]) != i+1) { return 19; } } free(ptr); igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_copy */ igraph_vector_ptr_init(&v1, 5); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); igraph_vector_ptr_copy(&v2, &v1); igraph_vector_ptr_destroy(&v1); for (i=0; i<igraph_vector_ptr_size(&v2); i++) { if ( *((int*)VECTOR(v2)[i]) != i+1) { return 20; } } /* igraph_vector_ptr_remove */ igraph_vector_ptr_remove(&v2, 0); igraph_vector_ptr_remove(&v2, 3); if ( *((int*)VECTOR(v2)[0]) != 2) { return 21; } if ( *((int*)VECTOR(v2)[1]) != 3) { return 22; } if ( *((int*)VECTOR(v2)[2]) != 4) { return 23; } igraph_vector_ptr_destroy(&v2); /* Testing destructor */ igraph_vector_ptr_init(&custom_destructor_stack, 0); igraph_vector_ptr_init(&v1, 2); block1 = igraph_Calloc(32, char); block2 = igraph_Calloc(64, char); VECTOR(v1)[0] = block1; VECTOR(v1)[1] = block2; if (igraph_vector_ptr_get_item_destructor(&v1) != 0) { return 24; } if (igraph_vector_ptr_set_item_destructor(&v1, &custom_destructor) != 0) { return 25; } /* Okay, let's clear the vector. This should push the blocks in the * custom destructor stack */ igraph_vector_ptr_clear(&v1); /* Put the blocks back and destroy the vector */ igraph_vector_ptr_push_back(&v1, block1); igraph_vector_ptr_push_back(&v1, block2); igraph_vector_ptr_destroy_all(&v1); if (VECTOR(custom_destructor_stack)[0] != block1 || VECTOR(custom_destructor_stack)[1] != block2 || VECTOR(custom_destructor_stack)[2] != block1 || VECTOR(custom_destructor_stack)[3] != block2 ) return 26; igraph_vector_ptr_destroy(&custom_destructor_stack); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 27; return 0; }