Пример #1
0
void
treeFree (TreeNode *tree)
{
	if (NULL != tree) {
		if (NULL != tree->left) {
			treeFree (tree->left);
		}
		if (NULL != tree->right) {
			treeFree (tree->right);
		}
		free (tree);
	}
}
Пример #2
0
void
testStore2(void)
{
	int	i;
	long	bO, bF, grossBytes;
 
	bO = stoBytesAlloc - stoBytesFree - stoBytesGc;
 
	printforest = 1;
	grossBytes = 0;
 
	forest = (struct tree **)stoAlloc(int0,
					  FOREST_SIZE*sizeof(struct tree *));
	for (i = 0; i < FOREST_SIZE; i++) forest[i] = 0;
 
	randomForest();

	for (i = 0; i < FOREST_SIZE; i++) {
		long sz = treeSize(forest[i]);
		printf("%d: %ld bytes\n", i, sz);
		grossBytes += sz;
		if (printforest) treePrint(osStdout, forest[i]);
	}
 
	for (i = 0; i < FOREST_SIZE; i++) {
		treeCheck(forest[i], treeNo);
		treeFree(forest[i]);
	}

	bF = stoBytesAlloc - stoBytesFree - stoBytesGc;
	printf("Memory: %lu (owned) %lu (alloc) %ld (net) %ld (gross)\n",
	       stoBytesOwn, bF - bO, treeBytes, grossBytes);
 
	stoFree(forest);
}
Пример #3
0
void nbodyBarnesHut(particle * particles,
	int count,
	int n,
	double timeDiff,
	double eps,
	char * outputPath)
{
	int step;
	sprintf(fileParamBuff, "%s_%%0%dd.vtk", outputPath, ((int) log10(n) + 1));
	bodyptr bodies = convertStruct(particles, count);
	/* End converting */
	/* Do the stepping */
	bodyptr p;
	for (step = 1; step <= 1; step++) {
		cellptr root;
		real rootSize;
		/* Make the tree */
		treeInit(&root, bodies, count, &rootSize);
		/* Calculate force */
		calculateForce(root, eps, rootSize);
		/* Advance each body */
		for (p = bodies; p < bodies + count; p++) {
			/* Advance the speed */
			/* Advance the position */
		}
		/* Free the tree */
		treeFree(&root);
	}
}
Пример #4
0
void treeFree(cellptr * cell)
{
	int i;

	nodeptr q;
	for (i = 0; i < NCHILD; i++) {
		if (Child(*cell)[i] != NULL)
			if (Type(Child(*cell)[i]) == CELL) {
				cellptr a = (cellptr) Child(*cell)[i];
				treeFree(&a);
			}
	}
	free(*cell);
}
Пример #5
0
static void
treeFree(struct tree *t)
{
        if (!t || --t->refc) return;
 
	if (t->isLeaf) {
		treeBytes -= sizeof(*t)-sizeof(t)+t->argc;
	}
	else {
		int		i;
		for (i = 0; i < t->argc; i++)
			treeFree(t->u.argv[i]);
		treeBytes -= sizeof(*t)-sizeof(t)+t->argc*sizeof(t);
	}
	stoFree(t);
}