Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/lamont/src/compiler/c-target/fragments/seq-kdtree.in
ViewVC logotype

View of /branches/lamont/src/compiler/c-target/fragments/seq-kdtree.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2562 - (download) (annotate)
Mon Mar 10 04:10:03 2014 UTC (5 years, 4 months ago) by lamonts
File size: 1695 byte(s)
Fixed bug with queryPool not allocating correctly and fixed deadlock of spatail data structure
KDNode_t * Diderot_KDTree_BuildHelper(
	KDTree_t * tree,  
	@STRANDTY@ ** strands, 
	uint32_t len, 
	uint32_t axis,
	uint32_t dim)
{
	@STRANDTY@ ** median; 
	KDNode_t * newNode = 0; 

   	if(!len) return 0; 

	if((median = Diderot_KDTree_Seq_FindMedian(strands,strands + len,axis,dim))) { 
		newNode = Diderot_KDTree_GrabNode(tree); 
		newNode->strandId = median[0]->strandId; 
		axis = (axis + 1) % tree->dim; 
		newNode->left = Diderot_KDTree_BuildHelper(tree,strands, median - strands, axis,dim); 
		newNode->right = Diderot_KDTree_BuildHelper(tree,median + 1, strands + len - (median + 1),axis,dim); 
	}
	return newNode; 
} 
void printTree(KDNode_t* newNode){
	if(newNode != NULL){
		printf("id=%d\n",newNode->strandId); 
		printTree(newNode->right); 
		printTree(newNode->left); 
	}
}
void Diderot_KDTree_Build(@PREFIX@World_t *wrld) 
{
   KDTree_t * tree  = wrld->spatialTree; 
   memcpy(wrld->spatialStrandsCpy,wrld->inState, sizeof(@STRANDTY@ *) * wrld->numStrands);
   Diderot_KDTree_PoolClear(tree); 
   tree->root = Diderot_KDTree_BuildHelper(tree,wrld->spatialStrandsCpy,*(tree->numOfStrands),0,tree->dim); 
}
void Diderot_KDTree_Init(@PREFIX@World_t *wrld) 
{
   Diderot_KDTree_Alloc(&wrld->spatialTree,&wrld->numStrands,2);
   wrld->spatialStrandsCpy= (@STRANDTY@**)CheckedAlloc(sizeof(@STRANDTY@ *)* wrld->numStrands);
   memcpy(wrld->spatialStrandsCpy,wrld->inState, sizeof(@STRANDTY@ *) * wrld->numStrands);
}
void Diderot_KDTree_Realloc(@PREFIX@World_t *wrld) 
{
  wrld->spatialStrandsCpy= (@STRANDTY@ **)CheckedReAlloc(wrld->spatialStrandsCpy,sizeof(@STRANDTY@ *)* wrld->numStrands);
  memcpy(wrld->spatialStrandsCpy,wrld->inState,sizeof(@STRANDTY@ *) * wrld->numStrands);
}


root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0