forked from akorotkov/pgsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey.h
172 lines (142 loc) · 4.22 KB
/
key.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#ifndef __PGS_KEY_H__
#define __PGS_KEY_H__
#include "types.h"
/* Declarations of key build functions */
#define KEYSIZE 24 /* the key size for one entry */
#define BPCKSIZE (KEYSIZE/6) /* the key size for one entry per coordinate */
/*
* The coordinate value has to be between -MAXCVALUE .. MAXCVALUE
*/
#define MAXCVALUE ( (1 << (8 * BPCKSIZE - 2)) - 1 )
typedef struct
{
int32 vl_len_;
union
{
struct
{
float4 lat,
lng;
};
struct
{
int32 k[6];
};
};
} GiSTSPointKey;
#define INTERNAL_KEY_SIZE (VARHDRSZ + sizeof(int32) * 6)
#define LEAF_KEY_SIZE (VARHDRSZ + sizeof(float4) * 2)
#define IS_LEAF(key) (VARSIZE(key) == LEAF_KEY_SIZE)
#define ALLOC_LEAF_KEY(key) do { \
key = (GiSTSPointKey *)palloc0(LEAF_KEY_SIZE); \
SET_VARSIZE(key, LEAF_KEY_SIZE); \
} while (0) ;
#define ALLOC_INTERNAL_KEY(key) do { \
key = (GiSTSPointKey *)palloc0(INTERNAL_KEY_SIZE); \
SET_VARSIZE(key, INTERNAL_KEY_SIZE); \
} while (0) ;
/*
* Returns the union of two keys. Result is placed into 'kunion'.
*/
void spherekey_union_two(int32 *kunion, const int32 *key);
/*
* Returns the intersection of two keys. Returns NULL if there is
* no intersection. Result is placed into 'kinter'.
*/
bool spherekey_inter_two(int32 *kinter, const int32 *key);
/*
* Generates the key of a spherical point and returns it. Result is placed
* into 'k'.
*/
void spherepoint_gen_key(int32 *k, const SPoint *sp);
/*
* Generates the circle's key and returns it. Result is placed into 'k'.
*/
void spherecircle_gen_key(int32 *k, const SCIRCLE *c);
/*
* Generates the key of a spherical ellipse and returns it. Result is placed
* into 'k'.
*/
void sphereellipse_gen_key(int32 *k, const SELLIPSE *e);
/*
* Generates the key of a spherical line and returns it. Result is placed
* into 'k'.
*/
void sphereline_gen_key(int32 *k, const SLine *sl);
/*
* Generates the key of a polygon and returns it. Result is placed into 'k'.
*/
void spherepoly_gen_key(int32 *k, const SPOLY *sp);
/*
* Generates the key of a path and returns it. Result is placed into 'k'.
*/
void spherepath_gen_key(int32 *k, const SPATH *sp);
/*
* Generates the key of a box and returns it. Result is placed into 'k'.
*/
void spherebox_gen_key(int32 *key, const SBOX *box);
/*
* Returns true if the first key is less than the second key.
*/
Datum spherekey_lt(PG_FUNCTION_ARGS);
/*
* Returns true if the first key is less or equal than the second key.
*/
Datum spherekey_le(PG_FUNCTION_ARGS);
/*
* Returns true if two keys are equal.
*/
Datum spherekey_eq(PG_FUNCTION_ARGS);
/*
* Returns true if two keys are not equal.
*/
Datum spherekey_eq_neg(PG_FUNCTION_ARGS);
/*
* Returns true if the first key is greater or equal than the second key.
*/
Datum spherekey_ge(PG_FUNCTION_ARGS);
/*
* Returns true if the first key is greater than the second key.
*/
Datum spherekey_gt(PG_FUNCTION_ARGS);
/*
* Returns relationship between the two keys.
* Calls skey_cmp(const int32 *, const int32 *) for two keys.
*/
Datum spherekey_cmp(PG_FUNCTION_ARGS);
/*
* Returns relationship between the keys of two spherical points.
* Calls skey_cmp(const int32 *, const int32 *) for two points.
*/
Datum spherepoint_cmp(PG_FUNCTION_ARGS);
/*
* Returns relationship between the keys of two spherical circles.
* Calls skey_cmp(const int32 *, const int32 *) for two circles.
*/
Datum spherecircle_cmp(PG_FUNCTION_ARGS);
/*
* Returns relationship between the keys of two spherical ellipses.
* Calls skey_cmp(const int32 *, const int32 *) for two ellipses.
*/
Datum sphereellipse_cmp(PG_FUNCTION_ARGS);
/*
* Returns relationship between the keys of two spherical lines.
* Calls skey_cmp(const int32 *, const int32 *) for two lines.
*/
Datum sphereline_cmp(PG_FUNCTION_ARGS);
/*
* Returns relationship between the keys of two spherical paths.
* Calls skey_cmp(const int32 *, const int32 *) for two paths.
*/
Datum spherepath_cmp(PG_FUNCTION_ARGS);
/*
* Returns relationship between the keys of two spherical polygons.
* Calls skey_cmp(const int32 *, const int32 *) for two polygons.
*/
Datum spherepoly_cmp(PG_FUNCTION_ARGS);
/*
* Returns relationship between the keys of two spherical boxes.
* Calls skey_cmp(const int32 *, const int32 *) for two boxes.
*/
Datum spherebox_cmp(PG_FUNCTION_ARGS);
#endif