-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.h
More file actions
62 lines (51 loc) · 1.78 KB
/
tree.h
File metadata and controls
62 lines (51 loc) · 1.78 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
/*
** Decision tree for loading/saving, etc
** Pointers all done as indexes into chunks to allow
** realloc of chunks, and easy serialisation.
**
** Wed 9 Mar 2011 10:31:25 EST
*/
#define MAX_PRIOR_FILENAME_LENGTH 512
typedef unsigned char uchar;
typedef unsigned int uint;
typedef struct treeNode {
uchar location;
uchar dbIndex;
uchar type;
uchar valid;
uint data; // could be a pdf (index into pdfs chunk) or a leaf (index into leaves chunk)
uint yes, no, parent; // ptrs as indexes into nodes[] chunk
} TreeNode;
// Tree consists of two blocks of memory
// nodes[], leaves[]
// The tree structure is threaded through nodes[] with data pointers
// into leaves[].
// This makes load/save easier.
typedef struct tree {
uint numLocations; // stored so we know length of leaves
uint numDbValues; // stored so we can calc length of pdfs
Chunk *nodes;
Chunk *leaves;
char priorType; // so we can validate on load
char lfType;
char stopType;
double stopValue;
int maxDepth;
int *dbValues;
} Tree;
#define TREE_INITIAL_NUM_NODES (1 << 9)
#define TREE_INITIAL_NUM_LEAVES (1 << 9)
#define TREE_INITIAL_NUM_PDFS (1 << 9)
#define TREE_NULL ((uint)0) // index of NULL in nodes[]. 0 is the index of the root, but we are reusing it as NULL
#define TREE_NODE_INVALID 0
#define TREE_NODE_VALID 1
#define TREE_NODE_TYPE_ROOT 0
#define TREE_NODE_TYPE_NO_PDF 1
#define TREE_NODE_TYPE_YES_PDF 2
#define TREE_NODE_TYPE_LEAF 4
Tree *treeMakeOrLoad(uint n, uint d, int *dbValues, char pType, char lfType, char stopT, double stopV, int maxD);
int treeHasValidRoot(Tree *t);
void treeCreateRoot(Tree *t, int location, int dbIndex);
uint treeGetRoot(Tree *t);
void treeSave(Tree *t);
Tree *treeLoad(char *filename);