-
Notifications
You must be signed in to change notification settings - Fork 35
/
kdtree.h
48 lines (41 loc) · 1.14 KB
/
kdtree.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
/*
* Copyright (C) 2017, Leo Ma <[email protected]>
*/
#ifndef _KD_TREE_H
#define _KD_TREE_H
#define KDTREE_MAX_LEVEL 64
#define KDTREE_LEFT_INDEX 0
#define KDTREE_RIGHT_INDEX 1
typedef struct knn_list {
struct kdnode *node;
double distance;
struct knn_list *prev;
struct knn_list *next;
} knn_list_t;
typedef struct kdnode {
long coord_index;
double *coord;
struct kdnode *left;
struct kdnode *right;
int r;
} kdnode_t;
typedef struct kdtree {
struct kdnode *root;
size_t count;
size_t capacity;
double *coords;
double **coord_table;
long *coord_indexes;
unsigned char *coord_deleted;
unsigned char *coord_passed;
struct knn_list knn_list_head;
int dim;
int knn_num;
} kdtree_t;
struct kdtree *kdtree_init(int dim);
void kdtree_insert(struct kdtree *tree, double *coord);
void kdtree_rebuild(struct kdtree *tree);
void kdtree_knn_search(struct kdtree *tree, double *coord, int k);
void kdtree_destroy(struct kdtree *tree);
void kdtree_dump(struct kdtree *tree);
#endif /* _KD_TREE_H */