aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/yasm/libyasm/inttree.h
blob: 44d45527ecaaec118b78c6bcc45cf01c32036882 (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
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
67
68
69
70
#ifndef YASM_INTTREE_H 
#define YASM_INTTREE_H 
 
#ifndef YASM_LIB_DECL 
#define YASM_LIB_DECL 
#endif 
 
/* The interval_tree.h and interval_tree.cc files contain code for  
 * interval trees implemented using red-black-trees as described in 
 * the book _Introduction_To_Algorithms_ by Cormen, Leisserson,  
 * and Rivest. 
 */ 
 
typedef struct IntervalTreeNode { 
    struct IntervalTreeNode *left, *right, *parent; 
    void *data; 
    long low; 
    long high; 
    long maxHigh; 
    int red; /* if red=0 then the node is black */ 
} IntervalTreeNode; 
 
typedef struct it_recursion_node { 
    /* This structure stores the information needed when we take the 
     * right branch in searching for intervals but possibly come back 
     * and check the left branch as well. 
     */ 
    IntervalTreeNode *start_node; 
    unsigned int parentIndex; 
    int tryRightBranch; 
} it_recursion_node; 
 
typedef struct IntervalTree { 
    /* A sentinel is used for root and for nil.  These sentinels are 
     * created when ITTreeCreate is called.  root->left should always 
     * point to the node which is the root of the tree.  nil points to a 
     * node which should always be black but has aribtrary children and 
     * parent and no key or info.  The point of using these sentinels is so 
     * that the root and nil nodes do not require special cases in the code 
     */ 
    IntervalTreeNode *root; 
    IntervalTreeNode *nil; 
 
/*private:*/ 
    unsigned int recursionNodeStackSize; 
    it_recursion_node * recursionNodeStack; 
    unsigned int currentParent; 
    unsigned int recursionNodeStackTop; 
} IntervalTree; 
 
YASM_LIB_DECL 
IntervalTree *IT_create(void); 
YASM_LIB_DECL 
void IT_destroy(IntervalTree *); 
YASM_LIB_DECL 
void IT_print(const IntervalTree *); 
YASM_LIB_DECL 
void *IT_delete_node(IntervalTree *, IntervalTreeNode *, long *low, 
                     long *high); 
YASM_LIB_DECL 
IntervalTreeNode *IT_insert(IntervalTree *, long low, long high, void *data); 
YASM_LIB_DECL 
IntervalTreeNode *IT_get_predecessor(const IntervalTree *, IntervalTreeNode *); 
YASM_LIB_DECL 
IntervalTreeNode *IT_get_successor(const IntervalTree *, IntervalTreeNode *); 
YASM_LIB_DECL 
void IT_enumerate(IntervalTree *, long low, long high, void *cbd, 
                  void (*callback) (IntervalTreeNode *node, void *cbd)); 
 
#endif