treestack.c - tree stack functions
Version Tag $Id: treestack.c,v 1.14 2006/02/06 19:55:47 db60 Exp $
Provides operations for accessing and maintaining a stack of tree topologies.
long treestack_cnt(Treestack s);
Return the number of trees currently stored on the stack s
.
The tree stack whose size we wish to know.
Returns number of trees on stack s
.
Treestack treestack_new(void);
Returns a new tree stack.
None.
Returns a new, empty tree stack.
long treestack_push(Treestack *sp, const Branch *const barray, const long root);
Push copy of a tree onto an existing tree stack. Will not push if its topology is already present on the stack. The stack will increase its own memory allocation if necessary.
Pointer to first element of array containing tree to be pushed.
Root branch number of tree to be pushed.
Pointer to tree stack that will receive a new copy of the tree.
Returns 1 if the tree was pushed, or 0 if not.
long treestack_pop(Branch *barray, long *root, Treestack *sp); =head2 DESCRIPTION
Pop a tree off a tree stack.
Pointer to first element of array to contain the popped tree. There must be sufficient space in this array prior to the call.
Pointer to scalar that will receive the index of the root in barray
.
Pointer to tree stack from which we will pop the tree.
Returns 1 if a tree was popped, or 0 if the stack was empty.
long treestack_print(Treestack *sp, FILE *const outfp);
Print all trees on a tree stack. The stack itself is not altered.
The stack to be printed.
Pointer to the file to which we wish to output trees.
Returns the number of trees printed.
long treestack_dump(Treestack *sp, FILE *const outfp);
Pop all trees off a stack and dump them.
Pointer to the file to which we wish to output trees.
The stack to be emptied and dumped.
Returns the number of trees dumped.
void treestack_free(Treestack *sp);
Clear a tree stack and deallocate dynamically allocated heap memory associated with it.
The stack to be emptied and deallocated.
None.
void treestack_clear(Treestack *sp);
Empty a tree stack but do not deallocate memory associated with it. This memory will be available for re-use when trees are pushed onto the stack again.
The stack to be emptied.
None.
void treestack_transfer(Treestack *destp, Treestack *sourcep);
Transfer one tree stack in its entirety to another. Order of the transferred trees is not preserved. Current contents and current order of the destination stack are preserved. The source stack is emptied but not deallocated.
Pointer to the stack to be added to.
Pointer to the stack to be transferred to destp
and cleared.
None.