aboutsummaryrefslogtreecommitdiffstats
path: root/src/tree.h
blob: 737f914d211a74866caf2fdd54b1a2e62037a131 (plain) (blame)
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
#define CHILDREN_PER_NODE 3
#define DATA_PER_NODE 2

typedef struct _TreeNode
{
	void * data[DATA_PER_NODE];
	struct _TreeNode * parent;
	struct _TreeNode * children[CHILDREN_PER_NODE];
	unsigned dataCount;
} TreeNode;

typedef int (*TreeCompareDataFunction)(void * data1, void * data2);
typedef void (*TreeFreeDataFunction)(void * data);

typedef struct _Tree
{
	TreeCompareDataFunction compareData;
	TreeFreeDataFunction freeData;
	TreeNode * rootNode;
} Tree;

typedef struct _TreeIterator
{
	Tree * tree;
	TreeNode * node;
	unsigned which;
} TreeIterator;

Tree * MakeTree(TreeCompareDataFunction compareFunc, 
		TreeFreeDataFunction freeData);

void SetIteratorToBegin(TreeIterator * iter, Tree * tree);

int InsertIntoTree(Tree * tree, void * data);

void DeleteFromTree(Tree * tree, void * data);