void print_xtree(node* n, int depth){ if (n == NULL) return; for (int i = 0; i<depth; i++) printf(">"); printf("%lf, leaves = %d\n", n->pivot.x, n->leaves); for (int i = 0; i<depth; i++) printf(">"); printf("ytree:\n"); for (int i = 0; i<depth; i++) printf(">"); printf("========\n"); print_ytree(n->d, depth); for (int i = 0; i<depth; i++) printf(">"); printf("========\n"); print_xtree(n->l, depth+1); print_xtree(n->r, depth+1); }
/* treecopy assumes that n[0-n] is filled with zeros*/ void __treecopy(caps_t o, struct _XTreeHandle *n, int len, unsigned int tid, struct hashtable **h) { int i; //initialize fresh memory memset(n,0,len*sizeof(struct _XTreeHandle)); // create new tree with the appropriate capabilities for(i=0;i<len;i++) { struct _XTreeHandle *t = th(o,i); n[i].caps.rcnt = o[i].rc; n[i].caps.wr_cnt = o[i].wc; n[i].caps.rd_cnt= o[i].lc; n[i].h = t->h; hashtable_insert(h,n+i); // create mapping //increment ref count of this region __sync_fetch_and_add(&t->h->caps.rcnt,1); t->h->single_thread_key = 0; //not thread local if(o[i].wc) { // transfer writer capabilities if( tcb()->tid == t->h->caps.writer_cv) { t->h->caps.writer_cv = tid; } else errquit("_treecopy: writer_cv"); } //if there exist read capabilities, increment read count if(o[i].lc) __sync_fetch_and_add(&t->h->caps.rd_cnt,1); #ifdef __RUNTIME_MEMORY_DEBUG_LOCKOP print_xtree(n+i,0); #endif struct _XTreeHandle *parent= t->parent_key; int idx; if(parent) for(idx=0;idx<len && th(o,idx) != parent;idx++); else idx = len; if(idx < len) { n[i].parent_key = n + idx; n[i].next_key = n[idx].sub_keys; n[idx].sub_keys = n + i; } else n[i].parent_key = 0; } //remove capabilities transferred from this tree //start off child nodes so that we don't bump into //a deallocated node (if a parent gets deallocated //its subregions are also removed). Notice that the //array "o" is already sorted in the natural //allocation order. for(i=len-1;i>-1;i--) _xregion_cap_th(-o[i].rc,-o[i].wc,-o[i].lc,th(o,i)); }
int main(void){ double xs[15] = {4.0,14.0,2.0,11.0,0.0,1.0,7.0,10.0,15.0,3.0,6.0,5.0,12.0,8.0,9.0}; //Protip: x=13 is missing point* ps = malloc(15*sizeof(point)); for (int i=0; i<15; i++){ ps[i].x = xs[i]; ps[i].y = (double) i; } node* root = build_xtree(ps, 15); print_xtree(root, 0); return 0; }