//_________________________________________________________________________ void graph_molloy_hash::print(FILE *f) { int i,j; for(i=0; i<n; i++) { fprintf(f,"%d",i); for(j=0; j<HASH_SIZE(deg[i]); j++) if(neigh[i][j]!=HASH_NONE) fprintf(f," %d",neigh[i][j]); fprintf(f,"\n"); } }
//_________________________________________________________________________ int* graph_molloy_hash::backup() { int *b = new int[a/2]; int *c = b; int *p = links; for(int i=0; i<n; i++) for(int d=HASH_SIZE(deg[i]); d--; p++) if(*p!=HASH_NONE && *p>i) *(c++)=*p; assert(c==b+(a/2)); return b; }
void hashmap_free_hash_and_data(struct hashmap *hashmap, free_data_fn_t free_data) { int i; for (i = 0; i < HASH_SIZE(hashmap->mask_bits); i++) { list_free_list_and_data(hashmap->map[i], free_data); } free(hashmap); }
//_________________________________________________________________________ int *graph_molloy_hash::hard_copy() { int *hc = new int[2+n+a/2]; // to store n,a,deg[] and links[] hc[0] = n; hc[1] = a; memcpy(hc+2,deg,sizeof(int)*n); int *p = hc+2+n; int *l = links; for(int i=0; i<n; i++) for(int j=HASH_SIZE(deg[i]); j--; l++) { register int d; if((d = *l)!=HASH_NONE && d>=i) *(p++)=d; } assert(p==hc+2+n+a/2); return hc; }
struct hashmap *hashmap_new(size_t capacity, hash_equal_fn_t equal, hash_fn_t hash) { struct hashmap *hashmap; unsigned int mask_bits = calc_bits(capacity); size_t real_capacity = HASH_SIZE(mask_bits); hashmap = calloc(1, sizeof(struct hashmap) + real_capacity * sizeof(struct list *)); if (!hashmap) { abort(); return NULL; } hashmap->mask_bits = mask_bits; hashmap->hash = hash; hashmap->equal = equal; return hashmap; }
static int svc_connect(void* handle, int fd, Cs_id_t* id, int clone, char** argv) { register State_t* state = (State_t*)handle; register File_t* fp; register char* s; int ad; int flags = 0; Fid_t fid; struct stat st; NoP(id); NoP(clone); if (!argv) return(-1); while ((s = *argv++) && *s != '/') switch (*s) { case 'm': flags |= CAT_MSG; break; } if (!s || (ad = csopen(s, 0)) < 0 && (ad = open(s, O_CREAT|O_APPEND|O_WRONLY|O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) return(-1); if (fstat(ad, &st)) { close(ad); return(-1); } fid.dev = st.st_dev; fid.ino = st.st_ino; if (!(fp = (File_t*)hashlook(state->files, (char*)&fid, HASH_CREATE|HASH_SIZE(sizeof(File_t)), NiL))) { close(ad); return(-1); } if (!fp->reference++) fp->fd = ad; else close(ad); fp->flags |= flags; state->cat[fd] = fp; state->active++; state->dormant = 0; return(0); }
//_________________________________________________________________________ int graph_molloy_hash::depth_search(bool *visited, int *buff, int v0) { for(int i=0; i<n; i++) visited[i] = false; int *to_visit = buff; int nb_visited = 1; visited[v0]=true; *(to_visit++)=v0; while(to_visit != buff && nb_visited<n) { int v = *(--to_visit); int *ww = neigh[v]; int w; for(int k=HASH_SIZE(deg[v]); k--; ww++) { if(HASH_NONE!=(w=*ww) && !visited[w]) { visited[w]=true; nb_visited++; *(to_visit++)=w; } } } return nb_visited; }
int graph_molloy_hash::print(igraph_t *graph) { int i, j; long int ptr=0; igraph_vector_t edges; IGRAPH_VECTOR_INIT_FINALLY(&edges, a); // every edge is counted twice.... for (i=0; i<n; i++) { for (j=0; j<HASH_SIZE(deg[i]); j++) { if (neigh[i][j]!=HASH_NONE) { if (neigh[i][j] > i) { VECTOR(edges)[ptr++] = i; VECTOR(edges)[ptr++] = neigh[i][j]; } } } } IGRAPH_CHECK(igraph_create(graph, &edges, n, /*undirected=*/ 0)); igraph_vector_destroy(&edges); IGRAPH_FINALLY_CLEAN(1); return 0; }
bool hash_iter_next(lref_t hash, hash_iter_t * iter, lref_t * key, lref_t * val) { assert(HASHP(hash)); while (*iter < HASH_SIZE(hash)) { if (hash_entry_used_p(HASH_ENTRY(hash, *iter))) { if (key) *key = HASH_ENTRY(hash, *iter)->key; if (val) *val = HASH_ENTRY(hash, *iter)->val; *iter = *iter + 1; return true; } *iter = *iter + 1; } return false; }
//_________________________________________________________________________ void graph_molloy_hash::compute_size() { size = 0; for(int i=0; i<n; i++) size += HASH_SIZE(deg[i]); }
//_________________________________________________________________________ bool graph_molloy_hash::isolated(int v, int K, int *Kbuff, bool *visited) { if(K<2) return false; #ifdef OPT_ISOLATED if(K<=deg[v]+1) return false; #endif //OPT_ISOLATED int *seen = Kbuff; int *known = Kbuff; int *max = Kbuff + K; *(known++) = v; visited[v] = true; bool is_isolated = true; while(known != seen) { v = *(seen++); int *ww = neigh[v]; int w; for(int d=HASH_SIZE(deg[v]); d--; ww++) if((w=*ww)!=HASH_NONE && !visited[w]) { #ifdef OPT_ISOLATED if(K<=deg[w]+1 || known == max) { #else //OPT_ISOLATED if(known == max) { #endif //OPT_ISOLATED is_isolated = false; goto end_isolated; } visited[w] = true; *(known++) = w; } } end_isolated: // Undo the changes to visited[]... while(known != Kbuff) visited[*(--known)] = false; return is_isolated; } //_________________________________________________________________________ int graph_molloy_hash::random_edge_swap(int K, int *Kbuff, bool *visited) { // Pick two random vertices a and c int f1 = pick_random_vertex(); int f2 = pick_random_vertex(); // Check that f1 != f2 if(f1==f2) return 0; // Get two random edges (f1,*f1t1) and (f2,*f2t2) int *f1t1 = random_neighbour(f1); int t1 = *f1t1; int *f2t2 = random_neighbour(f2); int t2 = *f2t2; // Check simplicity if(t1==t2 || f1==t2 || f2==t1) return 0; if(is_edge(f1,t2) || is_edge(f2,t1)) return 0; // Swap int *f1t2 = H_rpl(neigh[f1],deg[f1],f1t1,t2); int *f2t1 = H_rpl(neigh[f2],deg[f2],f2t2,t1); int *t1f2 = H_rpl(neigh[t1],deg[t1],f1,f2); int *t2f1 = H_rpl(neigh[t2],deg[t2],f2,f1); // isolation test if(K<=2) return 1; if( !isolated(f1, K, Kbuff, visited) && !isolated(f2, K, Kbuff, visited) ) return 1; // undo swap H_rpl(neigh[f1],deg[f1],f1t2,t1); H_rpl(neigh[f2],deg[f2],f2t1,t2); H_rpl(neigh[t1],deg[t1],t1f2,f1); H_rpl(neigh[t2],deg[t2],t2f1,f2); return 0; }