searchtree.h

/* Notice of Copyright, License and Warranty
**
** This software is Copyright 1999, 2001 Jeffrey S. Dutky
** This software is licensed for use under the terms of the GNU Library
** General Public License (also called the LGPL), a copy of which must
** be included with any distribution of this software. You may also find
** a copy of the LGPL at the Free Software Foundation's web site at
** http://www.fsf.org/ or http://www.gnu.org.
**
** This software is provided "as is" and without any express or implied
** warranties, including, without limitation, the implied waranties of
** merchantability and fitness for a particular purpose.
*/

/*
** Jeffrey S. Dutky, August 1999, June 2001
**
** the serach tree library implements some form of efficient search tree
** which can contian user defined data types as both key and data values.
** The user must provide a range of 'methods' when creating a new tree,
** including a label comparisson method and destructors for both the key
** and data values.
*/

#ifndef SEARCHTREE_H
#define SEARCHTREE_H

#include <stdio.h>

#define STERR_BADTREEPTR -1
#define STERR_CORRUPTNODE -2
#define STERR_BADMEMALLOC -3
#define STERR_KEYNOTFOUND -4
#define STERR_UNBALANCED -5
#define STERR_NODECYCLE -6
#define STERR_BADNODECOUNT -7
#define STERR_ORPHANEDNODE -8
#define STERR_UNLINKEDNODE -9
#define STERR_BADNODEDEPTH -10
#define STERR_BADTREELINK -11
#define STERR_KEYEXISTS -12
#define STERR_CORRUPTTREE -13
#define STERR_BADCMPFUNC -14
#define STERR_BADPARAM -15

#define LESSER (-1)
#define GREATER 1
#define NONE 0

#ifndef SEARCHTREE_C
typedef void SearchTree;
typedef void SearchNode;
#endif

SearchTree *createTree(int (*cmp)(void*,void*),
   int (*kfree)(void*), int (*dfree)(void*));

int deleteTree(SearchTree *st);

int insertNode(SearchTree *st, void *k, void *d);

int removeNode(SearchTree *st, void *k);

int findNode(SearchTree *st, void *k, void **d);

int verifyTree(SearchTree *st);

const char *treeError(int e);

#define FULL 0
#define BRIEF 1

int treeDump(FILE *f, SearchTree *st, int mode);

SearchNode *rotatedNode(SearchTree *st);

void *nodeKey(SearchNode *node);

void *nodeData(SearchNode *node);

int treeRotated(SearchTree *st);

int deadNodes(SearchTree *st);

int treeNodes(SearchTree *st);

#define PREORDER 0
#define INORDER 1
#define POSTORDER 2

int traverseTree(FILE *f, SearchTree *st, int ord, int (*print)(FILE *f, void *k, void *d, void *n));

#endif