aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-28 14:03:23 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-28 14:03:23 -0700
commitf64f5abd9987903ef75f52473efba4dbdeebf0fc (patch)
treee55b33f363260839e9a9cb6d7d4adbffe309cc9f /sys
parenta0bfa46946d1434f320cfbdd54c9f0cbcdcf815e (diff)
feat: prototype of remove child function
Diffstat (limited to 'sys')
-rw-r--r--sys/libbio/phylo.c47
1 files changed, 46 insertions, 1 deletions
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
@@ -30,6 +30,29 @@ phylo·addchild(bio·Node* parent, bio·Node* child)
}
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)
{
error err;
@@ -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;
+}