From 3ef4582ce52d89a7ac576b0f0c517773112a171c Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 28 Apr 2020 14:50:38 -0700 Subject: fix: moved nnodes into a property of node --- include/libbio.h | 1 - sys/libbio/io/newick.c | 4 ++-- sys/libbio/phylo.c | 8 +++++--- sys/libbio/test.c | 2 +- 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]); -- cgit v1.2.1