static void st_depth_helper(StrNode *node, int *maxdepth, int *mindepth, int *avgdepth, int *leaves, unsigned long *perms, unsigned long *nperms, int count) { if (!node) return; if (node->info >= ST_USE_LIMIT) (*perms)++; else (*nperms) += node->info >> ST_COLOR; if (count > *maxdepth) *maxdepth = count; if (node->left) { /* Inner node */ st_depth_helper(node->left, maxdepth, mindepth, avgdepth, leaves, perms, nperms, count + 1); } if (node->right) { /* Inner node */ st_depth_helper(node->right, maxdepth, mindepth, avgdepth, leaves, perms, nperms, count + 1); } if (!node->left && !node->right) { /* This is a leaf node */ (*leaves)++; (*avgdepth) += count; if (*mindepth > count) *mindepth = count; } }
static void st_depth_helper(StrNode *node, int *maxdepth, int *mindepth, int *avgdepth, int *leaves, int count) { if (!node) return; if (count > *maxdepth) *maxdepth = count; if (node->left) { /* Inner node */ st_depth_helper(node->left, maxdepth, mindepth, avgdepth, leaves, count + 1); } if (node->right) { /* Inner node */ st_depth_helper(node->right, maxdepth, mindepth, avgdepth, leaves, count + 1); } if (!node->left && !node->right) { /* This is a leaf node */ (*leaves)++; (*avgdepth) += count; if (*mindepth > count) *mindepth = count; } }
/* Find the depth and number of permanment nodes */ static void st_traverse_stats(StrNode *node, int *maxdepth, int *mindepth, int *avgdepth, int *leaves) { *maxdepth = 0; *mindepth = node ? (ST_MAX_DEPTH + 1) : 0; *avgdepth = 0; *leaves = 0; st_depth_helper(node, maxdepth, mindepth, avgdepth, leaves, 1); if (*avgdepth) *avgdepth = *avgdepth / *leaves; }