/* tree.h   by Michael Thorpe   2000-06-10 */

#ifndef TREE_VALUETYPE
#error You need to define TREE_VALUETYPE
#endif

/***********************************************************************/
/* If you set TREE_WILDCARD to '\0', wildcard support will be disabled */
/***********************************************************************/
#ifndef TREE_WILDCARD
#define TREE_WILDCARD '*'
#endif

typedef struct tree tree;

/**************************************************************/
/* tree_create() allocates a new tree, or returns 0 for error */
/**************************************************************/
tree *tree_create(void);

/****************************************************************************/
/* tree_del() removes a string from a tree and returns its value (0==error) */
/****************************************************************************/
TREE_VALUETYPE tree_del(tree *tree,const char *s);

/*****************************************************************************/
/* tree_getsize() returns the number of bytes allocated to nodes in the tree */
/*****************************************************************************/
size_t tree_getsize(tree *tree);

/***********************************************************/
/* tree_getnodes() returns the number of nodes in the tree */
/***********************************************************/
int tree_getnodes(tree *tree);

/*************************************/
/* tree_destroy() deallocates a tree */
/*************************************/
int tree_destroy(tree *tree);

/********************************************************/
/* tree_add() adds a string to a tree, and assigning it */
/* a value if appropriate; returns non-zero on error    */
/********************************************************/
int tree_add(tree *tree,const char *s,TREE_VALUETYPE value);

/********************************************************/
/* tree_match() returns the value of a given string (1  */
/* if TREE_VALUETYPE is not defined), or 0 if not found */
/********************************************************/
TREE_VALUETYPE tree_match(tree *tree,const char *s);

/**********************************************************/
/* tree_change() changes the value of a given string, and */
/* returns the old value of the string (0 if not found)   */
/**********************************************************/
TREE_VALUETYPE tree_change(tree *tree,const char *s,TREE_VALUETYPE newvalue);

/**************************************************************/
/* tree_dump() calls func() for each node in the tree, giving */
/* its string, depth, and value (0 for non-endnodes). If you  */
/* want to print whole strings, then for non-zero values      */
/* you'll need to print the last of each lower depth first    */
/**************************************************************/
int tree_dump(tree *tree,int (*func)(const char *,int,TREE_VALUETYPE));

