示例#1
0
文件: KDTree.c 项目: orrbarkat/c
SPKDTreeNode spKDTreeCreateFromArray(SPKDArray kdArr, int prevDim,
					SPConfig config, SP_CONFIG_MSG *msg, int* problem ){
    SPKDTreeNode res = NULL;
    SPKDArray *children;
    if (spKDArrayGetNumOfFeatures(kdArr)==1){
        res = spKDTreeCreateLeaf(spKDArrayGetPoint(kdArr, 0));
        if(!res){
        	spLoggerPrintError(ALLOC_FAIL, __FILE__, __FUNCTION__, __LINE__);
        	spKDArrayDestroy(kdArr, ALL_ROWS);
        	*problem = true;
        	return NULL;
        }
        spKDArrayDestroy(kdArr, ALL_ROWS);
        return res;
    }
    else{			//** KD Array is larger than 1 point **//
        res = spKDTreeCreateNode();
        if(!res){
        	spLoggerPrintError(ALLOC_FAIL, __FILE__, __FUNCTION__, __LINE__);
        	spKDArrayDestroy(kdArr, ALL_ROWS);
        	*problem = true;
        	return NULL;
        }
        res->dim = spKDArrayFindSplitDim(kdArr, prevDim, config, msg);
        children = spKDArraySplit(kdArr, res->dim);
        if(!children){
        	spKDTreeDestroy(res);
        	spKDArrayDestroy(kdArr, ALL_ROWS);
        	*problem = true;
        	return NULL;
        }
        res->val = spKDArrayGetMedianVal(children[LEFT], res->dim);
        spKDArrayDestroy(kdArr, ALL_ROWS);
        res->left = spKDTreeCreateFromArray(children[LEFT],
        		res->dim, config, msg, problem);
        if(!(res->left)){
        	spKDTreeDestroy(res);
        	spKDArrayDestroy(kdArr, ALL_ROWS);
			spKDMultiArrayDestroy(children, true, ALL_ROWS, true, ALL_ROWS);
			*problem = true;
			return NULL;
        }
        res->right  = spKDTreeCreateFromArray(children[RIGHT],
        		res->dim, config, msg, problem);
        if(!(res->right)){
        	spKDTreeDestroy(res);
        	spKDArrayDestroy(kdArr, ALL_ROWS);
			spKDMultiArrayDestroy(children, true, ALL_ROWS, true, ALL_ROWS);
			*problem = true;
			return NULL;
        }
        spKDMultiArrayDestroy(children, false, false, false, false);
        return res;
    }
}
示例#2
0
文件: KDTree.c 项目: orrbarkat/c
void spKDTreeDestroy(SPKDTreeNode node){
    if(!node){
        return;
    }
    if(node->dim == INVALID){
        spPointDestroy(node->data);
    }
    if(node->left){
        spKDTreeDestroy(node->left);
    }
    if(node->right){
        spKDTreeDestroy(node->right);
    }
    free(node);
}
void destroyCaseData(SPKDTreeNode tree,SPKDArray kdArr,SPPoint* pointsArray,int size,
		SPBPQueue queue,SPPoint queryPoint){
	if (tree) spKDTreeDestroy(tree, false);
	if (kdArr) spKDArrayDestroy(kdArr);
	if (pointsArray) destroyPointsArray(pointsArray,size);
	if (queue) spBPQueueDestroy(queue);
	if (queryPoint) spPointDestroy(queryPoint);
}
示例#4
0
void endControlFlow(SPConfig config, SPImageData image,
		bool isCurrentImageFeaturesArrayAllocated, SPKDTreeNode kdTree, SPBPQueue bpq,
		int returnValue) {
	if (returnValue < 0) {
		printf(MAIN_RETURNED_ERROR);
	}
	printf("%s", EXITING);
	spConfigDestroy(config);
	freeImageData(image, !isCurrentImageFeaturesArrayAllocated, true);
	spKDTreeDestroy(kdTree, true);
	spBPQueueDestroy(bpq);
	spLoggerDestroy();
}