bbtree.h 1.33 KB
#ifndef _BBTREE_H_
#define _BBTREE_H_

/* this is only here for testing. In final version
 * it should be in bbtree.c */
typedef
struct bbTreeNode
{
	void * value;

	long height;

	struct bbTreeNode * left;
	struct bbTreeNode * right;

} s_bbTreeNode;

#define BBTREE_LEFT_HEIGHT(t)		((t)->left ? (t)->left->height : -1)
#define BBTREE_RIGHT_HEIGHT(t)	((t)->right ? (t)->right->height : -1)
#define BBTREE_AVL(t)				(BBTREE_RIGHT_HEIGHT ((t)) - \
		BBTREE_LEFT_HEIGHT ((t)))


/*
 * comparison for tree-node values.
 * Has to be defined by user and set
 * with bbTreeNew.
 *
 * params:
 * 	left:		pointer to left value
 * 	right:	pointer to right value
 *
 * returns:
 * 	 0:	if values equal
 * 	 1:	if right greater left
 * 	-1:	if left greater right
 */
typedef int (* t_bbTreeCmp) (void *, void *);

typedef
struct bbTree
{
	struct bbTreeNode * root;

	t_bbTreeCmp cmp;
} s_bbTree;


/* constructor, destructor */
s_bbTree *	bbTreeNew		(t_bbTreeCmp);
void			bbTreeFree		(s_bbTree *);

/* data manipulation */
void *		bbTreeInsert	(s_bbTree *, void *);
void *		bbTreeSeek		(s_bbTree *, void *);
void *		bbTreeRemove	(s_bbTree *, void *);

/* analysation */
void *		bbTreeMin		(s_bbTree *);
void *		bbTreeMax		(s_bbTree *);
int			bbTreeSize		(s_bbTree *);

/* bbTree to other Datastructure */
void **		bbTreeInOrder	(s_bbTree *, void **);

#endif /* _BBTREE_H_ */