diff options
Diffstat (limited to 'sys/libbio/phylo.c')
-rw-r--r-- | sys/libbio/phylo.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/sys/libbio/phylo.c b/sys/libbio/phylo.c index 374cd08..c5fd3ed 100644 --- a/sys/libbio/phylo.c +++ b/sys/libbio/phylo.c @@ -2,6 +2,9 @@ #include <libn.h> #include <libbio.h> +// ----------------------------------------------------------------------- +// subtree manipulation methods + error phylo·addchild(bio·Node* parent, bio·Node* child) { @@ -25,3 +28,43 @@ phylo·addchild(bio·Node* parent, bio·Node* child) child->parent = parent; return 0; } + +error +phylo·countnodes(bio·Node *node, int *n) +{ + error err; + bio·Node *child; + + *n += 1; + for (child = node->child[0]; child != nil; child = child->sibling) { + if (err = phylo·countnodes(child, n), err) { + errorf("node count: failure at '%s'", child->name); + return 1; + } + } + + return 0; +} + +error +phylo·countleafs(bio·Node *node, int *n) +{ + error err; + bio·Node *child; + + if (node->nchild) { + *n += 1; + } + + for (child = node->child[0]; child != nil; child = child->sibling) { + if (err = phylo·countleafs(child, n), err) { + errorf("leaf count: failure at '%s'", child->name); + return 1; + } + } + + return 0; +} + +// ----------------------------------------------------------------------- +// tree statistics |