-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrbtree.hpp
90 lines (72 loc) · 1.54 KB
/
rbtree.hpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef _RBTREE_H
#define _RBTREE_H
#include <ctime>
#include "spfc.hpp"
/* value struct for nodes */
typedef struct value_t {
double x, y;
long long id;
long long obj_id;
unsigned long long cat;
time_t start, end;
value_t(){
x = y = 0;
id = 0;
obj_id = 0;
cat = 0;
start = end = 0;
}
value_t(const value_t &other){
x = other.x;
y = other.y;
id = other.id;
obj_id = other.obj_id;
cat = other.cat;
start = other.start;
end = other.end;
}
value_t& operator=(const value_t &other){
x = other.x;
y = other.y;
id = other.id;
obj_id = other.obj_id;
cat = other.cat;
start = other.start;
end = other.end;
return *this;
}
} Value;
typedef struct query_region_t {
double x_lower, x_upper;
double y_lower, y_upper;
time_t t_lower, t_upper;
} QueryRegion;
typedef struct rbnode_t {
Seqn s;
Seqn maxseqn;
Value val;
long long count;
bool red;
rbnode_t *left, *right;
} RBNode;
/* aux. structure to keep track of state of a node w.r.t. which child nodes
have been visited in a query */
typedef struct node_state_t {
RBNode *node;
int visited; // 0 - no children visited, 1 - left visited, 2 - both visited
} NodeSt;
typedef struct result_t {
Seqn s;
Value val;
} Result;
int GetNodeCount(RBNode *h);
bool IsRed(RBNode *h);
RBNode* RotateLeft(RBNode *h);
RBNode* RotateRight(RBNode *h);
void FlipColors(RBNode *h);
RBNode* balance(RBNode *h);
RBNode* MoveRedLeft(RBNode *h);
RBNode* MoveRedRight(RBNode *h);
RBNode* minimum(RBNode *node);
long long RBTreeDepth(const RBNode *node);
#endif /* _RBTREE_H */