aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-28 14:50:38 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-28 14:50:38 -0700
commit3ef4582ce52d89a7ac576b0f0c517773112a171c (patch)
tree37454fd6af68898e4dc78c6998b75fa526672464
parent9fd30c9e0ec9c5716b8cb7b8896318178d4b08bd (diff)
fix: moved nnodes into a property of node
-rw-r--r--include/libbio.h1
-rw-r--r--sys/libbio/io/newick.c4
-rw-r--r--sys/libbio/phylo.c8
-rw-r--r--sys/libbio/test.c2
4 files changed, 8 insertions, 7 deletions
diff --git a/include/libbio.h b/include/libbio.h
index 9ce96b5..5d6f6f8 100644
--- a/include/libbio.h
+++ b/include/libbio.h
@@ -20,7 +20,6 @@ typedef struct bio·Tree
{
bio·Node *root;
int nleaf;
- int nnode;
} bio·Tree;
// clade functions
diff --git a/sys/libbio/io/newick.c b/sys/libbio/io/newick.c
index 806feaa..cc6d3ff 100644
--- a/sys/libbio/io/newick.c
+++ b/sys/libbio/io/newick.c
@@ -361,10 +361,10 @@ bio·readnewick(io·Peeker stream, void *s, mem·Allocator heap, void *h, bio·T
tree->root = p.root;
tree->nleaf = 0;
- tree->nnode = 0;
+ tree->root->nnode = 0;
- phylo·countnodes(tree->root, &tree->nnode);
phylo·countleafs(tree->root, &tree->nleaf);
+ phylo·countnodes(tree->root, &tree->root->nnode);
return error·nil;
}
diff --git a/sys/libbio/phylo.c b/sys/libbio/phylo.c
index 71901ba..d03bc48 100644
--- a/sys/libbio/phylo.c
+++ b/sys/libbio/phylo.c
@@ -51,18 +51,20 @@ phylo·rmchild(bio·Node* parent, bio·Node* child)
error
phylo·countnodes(bio·Node *node, int *n)
{
+ int m;
error err;
bio·Node *child;
- node->nnode = 0;
+ m = *n;
for (child = node->child; child != nil; child = child->sibling) {
- if (err = phylo·countnodes(child, &node->nnode), err) {
+ if (err = phylo·countnodes(child, n), err) {
errorf("node count: failure at '%s'", child->name);
return 1;
}
}
+ node->nnode = *n - m;
+ *n += 1;
- *n += node->nnode + 1;
return 0;
}
diff --git a/sys/libbio/test.c b/sys/libbio/test.c
index 2efcdb6..baccd42 100644
--- a/sys/libbio/test.c
+++ b/sys/libbio/test.c
@@ -111,7 +111,7 @@ test·newick()
err = bio·readnewick(rdr, fd[0], al, mem, &t);
phylo·ladderize(t.root);
- printf("Loaded tree with %d leafs and %d nodes\n", t.nleaf, t.nnode);
+ printf("Loaded tree with %d leafs and %d nodes\n", t.nleaf, t.root->nnode);
err = bio·writenewick(t, wtr, fd[1]);
io·flush(fd[1]);