void cilkred_map::rehash(__cilkrts_worker *w)
{
#if REDPAR_DEBUG >= 1
    fprintf(stderr, "[W=%d, desc=rehash, this_map=%p, g=%p, w->g=%p]\n",
	    w->self, this, g, w->g);
    verify_current_wkr(w);
#endif
    CILK_ASSERT((w == 0 && g == 0) || w->g == g);
    
    size_t onbuckets = nbuckets;
    size_t onelem = nelem;
    bucket **obuckets = buckets;
    size_t i;
    bucket *b;

    make_buckets(w, nextsz(nbuckets));
     
    for (i = 0; i < onbuckets; ++i) {
        b = obuckets[i];
        if (b) {
            elem *oel;
            for (oel = b->el; oel->key; ++oel)
                insert_no_rehash(w, oel->key, oel->hb, oel->val);
        }
    }

    CILK_ASSERT(nelem == onelem);

    free_buckets(w, obuckets, onbuckets);
}
Beispiel #2
0
/* This builds all of the edges in the graph by calling addEdge a bunch of
   times. It's an unholy mess because I refused to use c99, so I'm declaring a
   boatload of values up front.  In short, it iterates over the buckets created
   by the preceeding function, calling add edge on every valid edge in the
   graph. The horribly nested for loops save you a bunch of work and let you
   tackle truly huge graphs in reasonable times. */
struct edges* makeEdges(struct points* p, double max_dist){
	struct edges* to_ret = 0;
	int x = 0, y = 0, dx = 0, dy = 0, xp = 0, yp = 0, num_edges = 0,
	    i = 0, j = 0, p1 = 0, p2 = 0, num_buckets = ceil(1 / max_dist);
	double d = 0;
	struct vect **buckets = make_buckets(p,max_dist,num_buckets);
	for(x = 0; x < num_buckets; x++){
	   for(y = 0; y < num_buckets; y++){  /* for each grid cell */
	      for(dx = 0; dx <= 1; dx++){
		 for(dy = 0; dy <= 1; dy++){  /* for each neighbor */
		    xp = x + dx;
		    yp = y + dy;
		    if(xp < num_buckets && yp < num_buckets){
		      for(i = 0; i < buckets[x][y].num_elms; i++){
		  	 for(j = 0; j < buckets[xp][yp].num_elms; j++){
			    /* this next one cuts down the points to compare
			       incase we're calculating edges in a region */
			    if(xp != x || yp != y || (j > i)){
			      p1 = buckets[x][y].elms[i];
			      p2 = buckets[xp][yp].elms[j];
			      d = distance(p,p1,p2);
			      if(d <= max_dist && p1 != p2){
				      /* this is the important bit */
				      num_edges = addEdge(to_ret,d,p1,p2);
			      }
			    }
			 }
		      }
		    }
		 }
	      }
	   }
	}
	/* free the buckets, you don't need them */
	for(i = 0; i < num_buckets; i++){
		for(j = 0; j < num_buckets; j++)
			free(buckets[i][j].elms);
		free(buckets[i]);
	}
	free(buckets);
	/* depending on what you do in add edge, you may want to do
	   some additional work on to_ret */
	return to_ret;
}