bbtree.h
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#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_ */