diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2020-04-28 14:58:19 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2020-04-28 14:58:19 -0700 |
commit | a6d9c8be245ef171423ddeb8466a27ad715012e0 (patch) | |
tree | 8f8f701cd7ff1be1fcd6e611eb352d8d81399782 /sys | |
parent | 3ef4582ce52d89a7ac576b0f0c517773112a171c (diff) |
fix: finished remove child function
Diffstat (limited to 'sys')
-rw-r--r-- | sys/libbio/phylo.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/sys/libbio/phylo.c b/sys/libbio/phylo.c index d03bc48..316537c 100644 --- a/sys/libbio/phylo.c +++ b/sys/libbio/phylo.c @@ -4,6 +4,8 @@ // ----------------------------------------------------------------------- // subtree manipulation methods +// NOTE: As of now these don't update nnode & nleaf stats. +// It is the caller's responsibility to refresh counts. error phylo·addchild(bio·Node* parent, bio·Node* child) @@ -26,22 +28,28 @@ SUCCESS: } error -phylo·rmchild(bio·Node* parent, bio·Node* child) +phylo·rmchild(bio·Node *parent, bio·Node *child) { bio·Node *it, *prev; enum { error·nil, error·notfound, + error·nochildren, }; prev = nil; - for (it = parent->child; it != nil && it != child; it = it->sibling) { + for (it = parent->child; it != nil; it = it->sibling) { + if (it == child) goto FOUND; prev = it; } - if (it == nil) return error·notfound; - - + return error·notfound; +FOUND: + if (prev == nil) { + parent->child = child->sibling; + } else { + prev->sibling = child->sibling; + } return error·nil; } |