-
Notifications
You must be signed in to change notification settings - Fork 0
/
radixTree.h
58 lines (44 loc) · 1.7 KB
/
radixTree.h
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
//
// Created by paul on 3/7/23.
//
#ifndef PROCESSNEWFILES_RADIXTREE_H
#define PROCESSNEWFILES_RADIXTREE_H
typedef unsigned long tRadixOffset; // from the start of stringSpace
typedef unsigned short tRadixLength;
typedef unsigned short tRadixIndex; // index into nodeArray
typedef char tRadixKey; // a C-style string
typedef void * tRadixValue; // an arbitrary pointer to some data structure
typedef struct sNode {
tRadixIndex parent; // zero indicates top-of-tree
tRadixIndex next; // linked list of siblings
tRadixIndex children; // linked list of children
tRadixOffset start; // start of string segment
tRadixLength length; // string segment length
tRadixValue value; // the value if this is an exact tail match
} tRadixNode;
enum tConstRadixIndex {
freeIndex = 0,
rootIndex = 1,
firstFreeNode = 2
};
typedef struct {
tRadixKey * stringSpace;
tRadixOffset size;
tRadixOffset highWater;
tRadixLength nodeCount;
tRadixNode * nodeArray;
} tRadixTree;
typedef struct {
tRadixTree * tree;
tRadixLength depth;
tRadixIndex * stack;
} tRadixIterator;
tRadixTree * newRadixTree(void);
void freeRadixTree( tRadixTree * tree );
tError radixTreeAdd( tRadixTree * tree, const tRadixKey * key, tRadixValue value );
tError radixTreeFind( tRadixTree * tree, const tRadixKey * key, tRadixValue *value );
tRadixIterator * newRadixIterator( const char * path );
void freeRadixInterator( tRadixIterator * iterator );
tRadixValue radixNext( tRadixIterator * iterator );
void radixTreeDump( const tRadixTree * tree );
#endif //PROCESSNEWFILES_RADIXTREE_H