From f64f5abd9987903ef75f52473efba4dbdeebf0fc Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 28 Apr 2020 14:03:23 -0700 Subject: feat: prototype of remove child function --- sys/libbio/phylo.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'sys/libbio/phylo.c') diff --git a/sys/libbio/phylo.c b/sys/libbio/phylo.c index c1ace7a..d623712 100644 --- a/sys/libbio/phylo.c +++ b/sys/libbio/phylo.c @@ -29,6 +29,29 @@ phylo·addchild(bio·Node* parent, bio·Node* child) return 0; } +error +phylo·rmchild(bio·Node* parent, bio·Node* child) +{ + bio·Node *it, *prev; + enum { + error·nil, + error·notfound, + }; + + prev = nil; + for (it = parent->child[0]; it != nil && it != child; it = it->sibling) { + prev = it; + } + if (it == nil) return error·notfound; + + + + return error·nil; +} + +// ----------------------------------------------------------------------- +// subtree statistics + error phylo·countnodes(bio·Node *node, int *n) { @@ -67,4 +90,26 @@ phylo·countleafs(bio·Node *node, int *n) } // ----------------------------------------------------------------------- -// tree statistics +// tree editing + +error +phylo·ladderize(bio·Node *root) +{ + int i; + error err; + bio·Node *child; + double dists[50]; + + if (!root->nchild) return 0; + Assert(root->nchild < arrlen(dists)); + + for (i = 0, child = root->child[0]; child != nil; child = child->sibling, i++) { + if (err = phylo·ladderize(child), err) { + errorf("ladderize: failure at '%s'", child->name); + return 1; + } + dists[i] = child->dist; + } + + return 0; +} -- cgit v1.2.1