-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtree.h
59 lines (50 loc) · 1 KB
/
rtree.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
59
/**
* rtree.h
*
* Header for orthogonal 2D range searching with static trees
*/
#pragma once
#include <stdlib.h>
typedef struct {
double x, y;
} point_t;
typedef struct {
point_t *pts;
size_t num;
} result_t;
typedef struct bst_s {
struct bst_s *left;
struct bst_s *right;
struct bst_s *parent;
point_t *min;
point_t *max;
} bst_t;
typedef struct {
point_t *pts;
bst_t *bst;
size_t npts;
size_t nbst;
} tree_t;
/**
* tree_new
*
* args:
* n (size_t): number of points in data
* data (point_t*): the n points to statically store, sorted by x then y
*
* returns a tree_t, the range tree representing data
*/
tree_t tree_new(size_t n, point_t *data);
/**
* tree_query2
*
* 2-sided tree range query
*
* args:
* tree (tree_t*): the tree_t to search
* p (point_t*): the point representing the 2-sided query
*
* returns a result_t, which contains the set of points in tree with both
* coordinates <= the coordinates of p
*/
result_t tree_query(tree_t *tree, point_t *p);