Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite57ab04

Browse files
committed
This is a comprehensive set of diffs (versus current CVS) that replaces those
attached to the same message with the Earth Distance patches.Recent changes include changing the subscript in one place I forgotin the previous bugfix patch. A couple of added regression tests, whichshould help catch this mistake if it reappears.I also put in a limit of 100 dimensions in cube_large and cube_in toprevent making it easy to create very large cubes. Changing one definein cubedata.h will raise the limit if some needs more dimensions.Bruno Wolff III
1 parenteb5bf51 commite57ab04

File tree

8 files changed

+160
-59
lines changed

8 files changed

+160
-59
lines changed

‎contrib/cube/CHANGES

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Changes that were made in August 2002.
1+
Changes that were made in August/September 2002 by Bruno Wolff III.
22

33
Note that this was based on a 7.3 development version and changes may not
44
directly work with earlier versions.
@@ -7,9 +7,6 @@ I fixed a bug in cubescan.pl that prevented signed numbers with no digits
77
before a decimal point from being accepted. This was submitted as a separate
88
patch and may already be applied.
99

10-
I reported but did not fix a potential buffer overrun problem in cube_yyerror
11-
in cubeparse.y.
12-
1310
cube_inter should really return NULL if the two cubes don't overlap. However
1411
this requires changing to the new calling sequence and I don't know enough
1512
about how to do it to make the change.
@@ -42,7 +39,9 @@ larger or smaller coordinate as needed, since swap_corners was doing the
4239
same thing with the overhead of a function call and memory allocation.
4340

4441
I added memset calls to zero out newly allocated NDBOXes as the documentation
45-
on functions indicates should be done.
42+
on functions indicates should be done. This still doesn't allow a hash
43+
index for equality since there are multiple representations of the
44+
same cube.
4645

4746
I got rid of a call to cube_same in cube_lt and cube_gt since the test
4847
was redundant with other checks being made. The call to cube_same would
@@ -94,4 +93,14 @@ I added regression tests for the new functions.
9493
I added documentation for cube_distance and the new functions to README.cube
9594
as well as making a few other minor changes.
9695

96+
I changed create function to create or replace function in the install
97+
script.
98+
99+
I limited the number of dimensions allowed in cube_enlarge and cube_in
100+
to 100 to make it harder for people to mess up the database. The constant
101+
is defined in cubedata.h and can be increased if you need something larger.
102+
103+
I added grant statements to the install script to make the functions
104+
executable to everyone.
105+
97106
Bruno Wolff III <bruno@wolff.to>

‎contrib/cube/README.cube

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ For this to work, make sure that:
4242
postgres binaries in the PATH.
4343

4444
This only installs the type implementation and documentation. To make the
45-
type available in any particular database,do
45+
type available in any particular database,as a postgres superuser do:
4646

4747
psql -d databasename < cube.sql
4848

@@ -57,6 +57,7 @@ If it fails, examine the file regression.diffs to find out the reason (the
5757
test code is a direct adaptation of the regression tests from the main
5858
source tree).
5959

60+
By default the external functions are made executable by anyone.
6061

6162
SYNTAX
6263
======
@@ -289,7 +290,9 @@ cube_enlarge(cube, double, int) returns cube
289290
LL coordinates are decreased by r and UR coordinates are increased by r. If
290291
a LL coordinate is increased to larger than the corresponding UR coordinate
291292
(this can only happen when r < 0) than both coordinates are set to their
292-
average.
293+
average. To make it harder for people to break things there is an effective
294+
maximum on the dimension of cubes of 100. This is set in cubedata.h if
295+
you need something bigger.
293296

294297
There are a few other potentially useful functions defined in cube.c
295298
that vanished from the schema because I stopped using them. Some of
@@ -329,7 +332,7 @@ selkovjr@mcs.anl.gov
329332
------------------------------------------------------------------------
330333

331334
Minor updates to this package were made by Bruno Wolff III <bruno@wolff.to>
332-
in August of 2002.
335+
in August/September of 2002.
333336

334337
These include changing the precision from single precision to double
335338
precision and adding some new functions.

‎contrib/cube/cube.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ boolcube_right(NDBOX * a, NDBOX * b);
7373
boolcube_lt(NDBOX*a,NDBOX*b);
7474
boolcube_gt(NDBOX*a,NDBOX*b);
7575
double*cube_distance(NDBOX*a,NDBOX*b);
76-
intcube_dim(NDBOX*a);
77-
double*cube_ll_coord(NDBOX*a,intn);
78-
double*cube_ur_coord(NDBOX*a,intn);
76+
int4cube_dim(NDBOX*a);
77+
double*cube_ll_coord(NDBOX*a,int4n);
78+
double*cube_ur_coord(NDBOX*a,int4n);
7979
boolcube_is_point(NDBOX*a);
80-
NDBOX*cube_enlarge(NDBOX*a,double*r,intn);
80+
NDBOX*cube_enlarge(NDBOX*a,double*r,int4n);
8181

8282

8383
/*
@@ -1139,7 +1139,7 @@ cube_is_point(NDBOX * a)
11391139
}
11401140

11411141
/* Return dimensions in use in the data structure */
1142-
int
1142+
int4
11431143
cube_dim(NDBOX*a)
11441144
{
11451145
/* Other things will break before unsigned int doesn't fit. */
@@ -1148,7 +1148,7 @@ cube_dim(NDBOX * a)
11481148

11491149
/* Return a specific normalized LL coordinate */
11501150
double*
1151-
cube_ll_coord(NDBOX*a,intn)
1151+
cube_ll_coord(NDBOX*a,int4n)
11521152
{
11531153
double*result;
11541154

@@ -1161,7 +1161,7 @@ cube_ll_coord(NDBOX * a, int n)
11611161

11621162
/* Return a specific normalized UR coordinate */
11631163
double*
1164-
cube_ur_coord(NDBOX*a,intn)
1164+
cube_ur_coord(NDBOX*a,int4n)
11651165
{
11661166
double*result;
11671167

@@ -1174,14 +1174,16 @@ cube_ur_coord(NDBOX * a, int n)
11741174

11751175
/* Increase or decrease box size by a radius in at least n dimensions. */
11761176
NDBOX*
1177-
cube_enlarge(NDBOX*a,double*r,intn)
1177+
cube_enlarge(NDBOX*a,double*r,int4n)
11781178
{
11791179
NDBOX*result;
11801180
intdim=0;
11811181
intsize;
11821182
inti,
1183-
j;
1183+
j,
1184+
k;
11841185

1186+
if (n>CUBE_MAX_DIM)n=CUBE_MAX_DIM;
11851187
if (*r>0&&n>0)
11861188
dim=n;
11871189
if (a->dim>dim)
@@ -1191,17 +1193,17 @@ cube_enlarge(NDBOX * a, double *r, int n)
11911193
memset(result,0,size);
11921194
result->size=size;
11931195
result->dim=dim;
1194-
for (i=0,j=dim;i<a->dim;i++,j++)
1196+
for (i=0,j=dim,k=a->dim;i<a->dim;i++,j++,k++)
11951197
{
1196-
if (a->x[i] >=a->x[j])
1198+
if (a->x[i] >=a->x[k])
11971199
{
1198-
result->x[i]=a->x[j]-*r;
1200+
result->x[i]=a->x[k]-*r;
11991201
result->x[j]=a->x[i]+*r;
12001202
}
12011203
else
12021204
{
12031205
result->x[i]=a->x[i]-*r;
1204-
result->x[j]=a->x[j]+*r;
1206+
result->x[j]=a->x[k]+*r;
12051207
}
12061208
if (result->x[i]>result->x[j])
12071209
{

‎contrib/cube/cube.sql.in

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
-- Create the user-defined type for N-dimensional boxes
22
--
3-
BEGIN TRANSACTION;
3+
BEGIN;
44

55
-- Adjust this setting to control where the objects get created.
66
SET search_path = public;
77

8-
CREATE FUNCTION cube_in(cstring)
8+
CREATEOR REPLACEFUNCTION cube_in(cstring)
99
RETURNS cube
1010
AS 'MODULE_PATHNAME'
1111
LANGUAGE 'c'IMMUTABLE STRICT;
1212

13-
CREATE FUNCTION cube_out(cube)
13+
CREATEOR REPLACEFUNCTION cube_out(cube)
1414
RETURNS cstring
1515
AS 'MODULE_PATHNAME'
1616
LANGUAGE 'c'IMMUTABLE STRICT;
@@ -26,8 +26,7 @@ COMMENT ON TYPE cube IS
2626

2727
-- Convert from text to cube
2828

29-
CREATE FUNCTION cube(text)
30-
RETURNS cube
29+
CREATE OR REPLACE FUNCTION cube(text) RETURNS cube
3130
AS 'MODULE_PATHNAME'
3231
LANGUAGE 'c' IMMUTABLE STRICT;
3332

@@ -40,25 +39,25 @@ COMMENT ON FUNCTION cube(text) IS
4039

4140
-- Left/Right methods
4241

43-
CREATE FUNCTION cube_over_left(cube, cube) RETURNS bool
42+
CREATEOR REPLACEFUNCTION cube_over_left(cube, cube) RETURNS bool
4443
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
4544

4645
COMMENT ON FUNCTION cube_over_left(cube, cube) IS
4746
'is over and left of (NOT IMPLEMENTED)';
4847

49-
CREATE FUNCTION cube_over_right(cube, cube) RETURNS bool
48+
CREATEOR REPLACEFUNCTION cube_over_right(cube, cube) RETURNS bool
5049
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
5150

5251
COMMENT ON FUNCTION cube_over_right(cube, cube) IS
5352
'is over and right of (NOT IMPLEMENTED)';
5453

55-
CREATE FUNCTION cube_left(cube, cube) RETURNS bool
54+
CREATEOR REPLACEFUNCTION cube_left(cube, cube) RETURNS bool
5655
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
5756

5857
COMMENT ON FUNCTION cube_left(cube, cube) IS
5958
'is left of (NOT IMPLEMENTED)';
6059

61-
CREATE FUNCTION cube_right(cube, cube) RETURNS bool
60+
CREATEOR REPLACEFUNCTION cube_right(cube, cube) RETURNS bool
6261
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
6362

6463
COMMENT ON FUNCTION cube_right(cube, cube) IS
@@ -67,86 +66,86 @@ COMMENT ON FUNCTION cube_right(cube, cube) IS
6766

6867
-- Comparison methods
6968

70-
CREATE FUNCTION cube_lt(cube, cube) RETURNS bool
69+
CREATEOR REPLACEFUNCTION cube_lt(cube, cube) RETURNS bool
7170
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
7271

7372
COMMENT ON FUNCTION cube_lt(cube, cube) IS
7473
'lower than';
7574

76-
CREATE FUNCTION cube_gt(cube, cube) RETURNS bool
75+
CREATEOR REPLACEFUNCTION cube_gt(cube, cube) RETURNS bool
7776
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
7877

7978
COMMENT ON FUNCTION cube_gt(cube, cube) IS
8079
'greater than';
8180

82-
CREATE FUNCTION cube_contains(cube, cube) RETURNS bool
81+
CREATEOR REPLACEFUNCTION cube_contains(cube, cube) RETURNS bool
8382
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
8483

8584
COMMENT ON FUNCTION cube_contains(cube, cube) IS
8685
'contains';
8786

88-
CREATE FUNCTION cube_contained(cube, cube) RETURNS bool
87+
CREATEOR REPLACEFUNCTION cube_contained(cube, cube) RETURNS bool
8988
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
9089

9190
COMMENT ON FUNCTION cube_contained(cube, cube) IS
9291
'contained in';
9392

94-
CREATE FUNCTION cube_overlap(cube, cube) RETURNS bool
93+
CREATEOR REPLACEFUNCTION cube_overlap(cube, cube) RETURNS bool
9594
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
9695

9796
COMMENT ON FUNCTION cube_overlap(cube, cube) IS
9897
'overlaps';
9998

100-
CREATE FUNCTION cube_same(cube, cube) RETURNS bool
99+
CREATEOR REPLACEFUNCTION cube_same(cube, cube) RETURNS bool
101100
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
102101

103102
COMMENT ON FUNCTION cube_same(cube, cube) IS
104103
'same as';
105104

106-
CREATE FUNCTION cube_different(cube, cube) RETURNS bool
105+
CREATEOR REPLACEFUNCTION cube_different(cube, cube) RETURNS bool
107106
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
108107

109108
COMMENT ON FUNCTION cube_different(cube, cube) IS
110109
'different';
111110

112111
-- support routines for indexing
113112

114-
CREATE FUNCTION cube_union(cube, cube) RETURNS cube
113+
CREATEOR REPLACEFUNCTION cube_union(cube, cube) RETURNS cube
115114
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
116115

117-
CREATE FUNCTION cube_inter(cube, cube) RETURNS cube
116+
CREATEOR REPLACEFUNCTION cube_inter(cube, cube) RETURNS cube
118117
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
119118

120-
CREATE FUNCTION cube_size(cube) RETURNS float8
119+
CREATEOR REPLACEFUNCTION cube_size(cube) RETURNS float8
121120
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
122121

123122

124123
-- Misc N-dimensional functions
125124

126125
-- proximity routines
127126

128-
CREATE FUNCTION cube_distance(cube, cube) RETURNS float8
127+
CREATEOR REPLACEFUNCTION cube_distance(cube, cube) RETURNS float8
129128
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
130129

131130
-- Extracting elements functions
132131

133-
CREATE FUNCTION cube_dim(cube) RETURNS int4
132+
CREATEOR REPLACEFUNCTION cube_dim(cube) RETURNS int4
134133
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
135134

136-
CREATE FUNCTION cube_ll_coord(cube, int4) RETURNS float8
135+
CREATEOR REPLACEFUNCTION cube_ll_coord(cube, int4) RETURNS float8
137136
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
138137

139-
CREATE FUNCTION cube_ur_coord(cube, int4) RETURNS float8
138+
CREATEOR REPLACEFUNCTION cube_ur_coord(cube, int4) RETURNS float8
140139
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
141140

142141
-- Test if cube is also a point
143142

144-
CREATE FUNCTION cube_is_point(cube) RETURNS bool
143+
CREATEOR REPLACEFUNCTION cube_is_point(cube) RETURNS bool
145144
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
146145

147146
-- Increasing the size of a cube by a radius in at least n dimensions
148147

149-
CREATE FUNCTION cube_enlarge(cube, float8, int4) RETURNS cube
148+
CREATEOR REPLACEFUNCTION cube_enlarge(cube, float8, int4) RETURNS cube
150149
AS 'MODULE_PATHNAME' LANGUAGE 'c' IMMUTABLE STRICT;
151150

152151
--
@@ -222,25 +221,25 @@ CREATE OPERATOR ~ (
222221

223222

224223
-- define the GiST support methods
225-
CREATE FUNCTION g_cube_consistent(internal,cube,int4) RETURNS bool
224+
CREATEOR REPLACEFUNCTION g_cube_consistent(internal,cube,int4) RETURNS bool
226225
AS 'MODULE_PATHNAME' LANGUAGE 'c';
227226

228-
CREATE FUNCTION g_cube_compress(internal) RETURNS internal
227+
CREATEOR REPLACEFUNCTION g_cube_compress(internal) RETURNS internal
229228
AS 'MODULE_PATHNAME' LANGUAGE 'c';
230229

231-
CREATE FUNCTION g_cube_decompress(internal) RETURNS internal
230+
CREATEOR REPLACEFUNCTION g_cube_decompress(internal) RETURNS internal
232231
AS 'MODULE_PATHNAME' LANGUAGE 'c';
233232

234-
CREATE FUNCTION g_cube_penalty(internal,internal,internal) RETURNS internal
233+
CREATEOR REPLACEFUNCTION g_cube_penalty(internal,internal,internal) RETURNS internal
235234
AS 'MODULE_PATHNAME' LANGUAGE 'c' STRICT;
236235

237-
CREATE FUNCTION g_cube_picksplit(internal, internal) RETURNS internal
236+
CREATEOR REPLACEFUNCTION g_cube_picksplit(internal, internal) RETURNS internal
238237
AS 'MODULE_PATHNAME' LANGUAGE 'c';
239238

240-
CREATE FUNCTION g_cube_union(bytea, internal) RETURNS cube
239+
CREATEOR REPLACEFUNCTION g_cube_union(bytea, internal) RETURNS cube
241240
AS 'MODULE_PATHNAME' LANGUAGE 'c';
242241

243-
CREATE FUNCTION g_cube_same(cube, cube, internal) RETURNS internal
242+
CREATEOR REPLACEFUNCTION g_cube_same(cube, cube, internal) RETURNS internal
244243
AS 'MODULE_PATHNAME' LANGUAGE 'c';
245244

246245

@@ -264,5 +263,31 @@ CREATE OPERATOR CLASS gist_cube_ops
264263
FUNCTION6g_cube_picksplit (internal, internal),
265264
FUNCTION7g_cube_same (cube, cube, internal);
266265

266+
--
267+
-- By default the externally visible functions are made executable by
268+
-- anyone. To restrict their access comment out the following grant commands.
269+
--
267270

268-
END TRANSACTION;
271+
GRANT EXECUTE ON FUNCTION cube(text) TO PUBLIC;
272+
GRANT EXECUTE ON FUNCTION cube_over_left(cube, cube) TO PUBLIC;
273+
GRANT EXECUTE ON FUNCTION cube_over_right(cube, cube) TO PUBLIC;
274+
GRANT EXECUTE ON FUNCTION cube_left(cube, cube) TO PUBLIC;
275+
GRANT EXECUTE ON FUNCTION cube_right(cube, cube) TO PUBLIC;
276+
GRANT EXECUTE ON FUNCTION cube_lt(cube, cube) TO PUBLIC;
277+
GRANT EXECUTE ON FUNCTION cube_gt(cube, cube) TO PUBLIC;
278+
GRANT EXECUTE ON FUNCTION cube_contains(cube, cube) TO PUBLIC;
279+
GRANT EXECUTE ON FUNCTION cube_contained(cube, cube) TO PUBLIC;
280+
GRANT EXECUTE ON FUNCTION cube_overlap(cube, cube) TO PUBLIC;
281+
GRANT EXECUTE ON FUNCTION cube_same(cube, cube) TO PUBLIC;
282+
GRANT EXECUTE ON FUNCTION cube_different(cube, cube) TO PUBLIC;
283+
GRANT EXECUTE ON FUNCTION cube_union(cube, cube) TO PUBLIC;
284+
GRANT EXECUTE ON FUNCTION cube_inter(cube, cube) TO PUBLIC;
285+
GRANT EXECUTE ON FUNCTION cube_size(cube) TO PUBLIC;
286+
GRANT EXECUTE ON FUNCTION cube_distance(cube, cube) TO PUBLIC;
287+
GRANT EXECUTE ON FUNCTION cube_dim(cube) TO PUBLIC;
288+
GRANT EXECUTE ON FUNCTION cube_ll_coord(cube, int4) TO PUBLIC;
289+
GRANT EXECUTE ON FUNCTION cube_ur_coord(cube, int4) TO PUBLIC;
290+
GRANT EXECUTE ON FUNCTION cube_is_point(cube) TO PUBLIC;
291+
GRANT EXECUTE ON FUNCTION cube_enlarge(cube, float8, int4) TO PUBLIC;
292+
293+
COMMIT;

‎contrib/cube/cubedata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#defineCUBE_MAX_DIM (100)
12
typedefstructNDBOX
23
{
34
unsignedintsize;/* required to be a Postgres varlena type */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp