1
1
/******************************************************************************
2
- $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.33 2007/06/05 21:31:03 tgl Exp $
2
+ $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.34 2007/11/15 21:14:29 momjian Exp $
3
3
4
4
This file contains routines that can be bound to a Postgres backend and
5
5
called by the backend in the process of processing queries. The calling
@@ -306,7 +306,7 @@ cube_subset(PG_FUNCTION_ARGS)
306
306
result -> x [i + dim ] = c -> x [dx [i ] + c -> dim - 1 ];
307
307
}
308
308
309
- PG_FREE_IF_COPY (c ,0 );
309
+ PG_FREE_IF_COPY (c , 0 );
310
310
PG_RETURN_NDBOX (result );
311
311
}
312
312
@@ -360,7 +360,7 @@ cube_out(PG_FUNCTION_ARGS)
360
360
appendStringInfoChar (& buf , ')' );
361
361
}
362
362
363
- PG_FREE_IF_COPY (cube ,0 );
363
+ PG_FREE_IF_COPY (cube , 0 );
364
364
PG_RETURN_CSTRING (buf .data );
365
365
}
366
366
@@ -381,20 +381,20 @@ g_cube_consistent(PG_FUNCTION_ARGS)
381
381
GISTENTRY * entry = (GISTENTRY * ) PG_GETARG_POINTER (0 );
382
382
NDBOX * query = PG_GETARG_NDBOX (1 );
383
383
StrategyNumber strategy = (StrategyNumber ) PG_GETARG_UINT16 (2 );
384
- bool res ;
384
+ bool res ;
385
385
386
386
/*
387
387
* if entry is not leaf, use g_cube_internal_consistent, else use
388
388
* g_cube_leaf_consistent
389
389
*/
390
390
if (GIST_LEAF (entry ))
391
- res = g_cube_leaf_consistent ( DatumGetNDBOX (entry -> key ),
392
- query , strategy );
391
+ res = g_cube_leaf_consistent (DatumGetNDBOX (entry -> key ),
392
+ query , strategy );
393
393
else
394
- res = g_cube_internal_consistent ( DatumGetNDBOX (entry -> key ),
395
- query , strategy );
394
+ res = g_cube_internal_consistent (DatumGetNDBOX (entry -> key ),
395
+ query , strategy );
396
396
397
- PG_FREE_IF_COPY (query ,1 );
397
+ PG_FREE_IF_COPY (query , 1 );
398
398
PG_RETURN_BOOL (res );
399
399
}
400
400
@@ -451,14 +451,15 @@ Datum
451
451
g_cube_decompress (PG_FUNCTION_ARGS )
452
452
{
453
453
GISTENTRY * entry = (GISTENTRY * ) PG_GETARG_POINTER (0 );
454
- NDBOX * key = DatumGetNDBOX (PG_DETOAST_DATUM (entry -> key ));
454
+ NDBOX * key = DatumGetNDBOX (PG_DETOAST_DATUM (entry -> key ));
455
455
456
456
if (key != DatumGetNDBOX (entry -> key ))
457
457
{
458
458
GISTENTRY * retval = (GISTENTRY * ) palloc (sizeof (GISTENTRY ));
459
+
459
460
gistentryinit (* retval , PointerGetDatum (key ),
460
- entry -> rel , entry -> page ,
461
- entry -> offset , FALSE);
461
+ entry -> rel , entry -> page ,
462
+ entry -> offset , FALSE);
462
463
PG_RETURN_POINTER (retval );
463
464
}
464
465
PG_RETURN_POINTER (entry );
@@ -479,8 +480,8 @@ g_cube_penalty(PG_FUNCTION_ARGS)
479
480
double tmp1 ,
480
481
tmp2 ;
481
482
482
- ud = cube_union_v0 ( DatumGetNDBOX (origentry -> key ),
483
- DatumGetNDBOX (newentry -> key ));
483
+ ud = cube_union_v0 (DatumGetNDBOX (origentry -> key ),
484
+ DatumGetNDBOX (newentry -> key ));
484
485
rt_cube_size (ud , & tmp1 );
485
486
rt_cube_size (DatumGetNDBOX (origentry -> key ), & tmp2 );
486
487
* result = (float ) (tmp1 - tmp2 );
@@ -812,12 +813,12 @@ cube_union(PG_FUNCTION_ARGS)
812
813
{
813
814
NDBOX * a = PG_GETARG_NDBOX (0 ),
814
815
* b = PG_GETARG_NDBOX (1 );
815
- NDBOX * res ;
816
+ NDBOX * res ;
816
817
817
818
res = cube_union_v0 (a , b );
818
819
819
- PG_FREE_IF_COPY (a ,0 );
820
- PG_FREE_IF_COPY (b ,1 );
820
+ PG_FREE_IF_COPY (a , 0 );
821
+ PG_FREE_IF_COPY (b , 1 );
821
822
PG_RETURN_NDBOX (res );
822
823
}
823
824
@@ -876,8 +877,9 @@ cube_inter(PG_FUNCTION_ARGS)
876
877
a -> x [i + a -> dim ]), result -> x [i + a -> dim ]);
877
878
}
878
879
879
- PG_FREE_IF_COPY (a ,0 );
880
- PG_FREE_IF_COPY (b ,1 );
880
+ PG_FREE_IF_COPY (a , 0 );
881
+ PG_FREE_IF_COPY (b , 1 );
882
+
881
883
/*
882
884
* Is it OK to return a non-null intersection for non-overlapping boxes?
883
885
*/
@@ -899,7 +901,7 @@ cube_size(PG_FUNCTION_ARGS)
899
901
for (i = 0 , j = a -> dim ; i < a -> dim ; i ++ , j ++ )
900
902
result = result * Abs ((a -> x [j ] - a -> x [i ]));
901
903
902
- PG_FREE_IF_COPY (a ,0 );
904
+ PG_FREE_IF_COPY (a , 0 );
903
905
PG_RETURN_FLOAT8 (result );
904
906
}
905
907
@@ -1011,8 +1013,8 @@ cube_cmp(PG_FUNCTION_ARGS)
1011
1013
1012
1014
res = cube_cmp_v0 (a , b );
1013
1015
1014
- PG_FREE_IF_COPY (a ,0 );
1015
- PG_FREE_IF_COPY (b ,1 );
1016
+ PG_FREE_IF_COPY (a , 0 );
1017
+ PG_FREE_IF_COPY (b , 1 );
1016
1018
PG_RETURN_INT32 (res );
1017
1019
}
1018
1020
@@ -1026,8 +1028,8 @@ cube_eq(PG_FUNCTION_ARGS)
1026
1028
1027
1029
res = cube_cmp_v0 (a , b );
1028
1030
1029
- PG_FREE_IF_COPY (a ,0 );
1030
- PG_FREE_IF_COPY (b ,1 );
1031
+ PG_FREE_IF_COPY (a , 0 );
1032
+ PG_FREE_IF_COPY (b , 1 );
1031
1033
PG_RETURN_BOOL (res == 0 );
1032
1034
}
1033
1035
@@ -1041,8 +1043,8 @@ cube_ne(PG_FUNCTION_ARGS)
1041
1043
1042
1044
res = cube_cmp_v0 (a , b );
1043
1045
1044
- PG_FREE_IF_COPY (a ,0 );
1045
- PG_FREE_IF_COPY (b ,1 );
1046
+ PG_FREE_IF_COPY (a , 0 );
1047
+ PG_FREE_IF_COPY (b , 1 );
1046
1048
PG_RETURN_BOOL (res != 0 );
1047
1049
}
1048
1050
@@ -1056,8 +1058,8 @@ cube_lt(PG_FUNCTION_ARGS)
1056
1058
1057
1059
res = cube_cmp_v0 (a , b );
1058
1060
1059
- PG_FREE_IF_COPY (a ,0 );
1060
- PG_FREE_IF_COPY (b ,1 );
1061
+ PG_FREE_IF_COPY (a , 0 );
1062
+ PG_FREE_IF_COPY (b , 1 );
1061
1063
PG_RETURN_BOOL (res < 0 );
1062
1064
}
1063
1065
@@ -1071,8 +1073,8 @@ cube_gt(PG_FUNCTION_ARGS)
1071
1073
1072
1074
res = cube_cmp_v0 (a , b );
1073
1075
1074
- PG_FREE_IF_COPY (a ,0 );
1075
- PG_FREE_IF_COPY (b ,1 );
1076
+ PG_FREE_IF_COPY (a , 0 );
1077
+ PG_FREE_IF_COPY (b , 1 );
1076
1078
PG_RETURN_BOOL (res > 0 );
1077
1079
}
1078
1080
@@ -1086,8 +1088,8 @@ cube_le(PG_FUNCTION_ARGS)
1086
1088
1087
1089
res = cube_cmp_v0 (a , b );
1088
1090
1089
- PG_FREE_IF_COPY (a ,0 );
1090
- PG_FREE_IF_COPY (b ,1 );
1091
+ PG_FREE_IF_COPY (a , 0 );
1092
+ PG_FREE_IF_COPY (b , 1 );
1091
1093
PG_RETURN_BOOL (res <= 0 );
1092
1094
}
1093
1095
@@ -1101,8 +1103,8 @@ cube_ge(PG_FUNCTION_ARGS)
1101
1103
1102
1104
res = cube_cmp_v0 (a , b );
1103
1105
1104
- PG_FREE_IF_COPY (a ,0 );
1105
- PG_FREE_IF_COPY (b ,1 );
1106
+ PG_FREE_IF_COPY (a , 0 );
1107
+ PG_FREE_IF_COPY (b , 1 );
1106
1108
PG_RETURN_BOOL (res >= 0 );
1107
1109
}
1108
1110
@@ -1157,8 +1159,8 @@ cube_contains(PG_FUNCTION_ARGS)
1157
1159
1158
1160
res = cube_contains_v0 (a , b );
1159
1161
1160
- PG_FREE_IF_COPY (a ,0 );
1161
- PG_FREE_IF_COPY (b ,1 );
1162
+ PG_FREE_IF_COPY (a , 0 );
1163
+ PG_FREE_IF_COPY (b , 1 );
1162
1164
PG_RETURN_BOOL (res );
1163
1165
}
1164
1166
@@ -1173,8 +1175,8 @@ cube_contained(PG_FUNCTION_ARGS)
1173
1175
1174
1176
res = cube_contains_v0 (b , a );
1175
1177
1176
- PG_FREE_IF_COPY (a ,0 );
1177
- PG_FREE_IF_COPY (b ,1 );
1178
+ PG_FREE_IF_COPY (a , 0 );
1179
+ PG_FREE_IF_COPY (b , 1 );
1178
1180
PG_RETURN_BOOL (res );
1179
1181
}
1180
1182
@@ -1234,8 +1236,8 @@ cube_overlap(PG_FUNCTION_ARGS)
1234
1236
1235
1237
res = cube_overlap_v0 (a , b );
1236
1238
1237
- PG_FREE_IF_COPY (a ,0 );
1238
- PG_FREE_IF_COPY (b ,1 );
1239
+ PG_FREE_IF_COPY (a , 0 );
1240
+ PG_FREE_IF_COPY (b , 1 );
1239
1241
PG_RETURN_BOOL (res );
1240
1242
}
1241
1243
@@ -1281,8 +1283,8 @@ cube_distance(PG_FUNCTION_ARGS)
1281
1283
distance += d * d ;
1282
1284
}
1283
1285
1284
- PG_FREE_IF_COPY (a ,0 );
1285
- PG_FREE_IF_COPY (b ,1 );
1286
+ PG_FREE_IF_COPY (a , 0 );
1287
+ PG_FREE_IF_COPY (b , 1 );
1286
1288
PG_RETURN_FLOAT8 (sqrt (distance ));
1287
1289
}
1288
1290
@@ -1317,7 +1319,7 @@ cube_is_point(PG_FUNCTION_ARGS)
1317
1319
PG_RETURN_BOOL (FALSE);
1318
1320
}
1319
1321
1320
- PG_FREE_IF_COPY (a ,0 );
1322
+ PG_FREE_IF_COPY (a , 0 );
1321
1323
PG_RETURN_BOOL (TRUE);
1322
1324
}
1323
1325
@@ -1331,7 +1333,7 @@ cube_dim(PG_FUNCTION_ARGS)
1331
1333
c = PG_GETARG_NDBOX (0 );
1332
1334
dim = c -> dim ;
1333
1335
1334
- PG_FREE_IF_COPY (c ,0 );
1336
+ PG_FREE_IF_COPY (c , 0 );
1335
1337
PG_RETURN_INT32 (c -> dim );
1336
1338
}
1337
1339
@@ -1350,7 +1352,7 @@ cube_ll_coord(PG_FUNCTION_ARGS)
1350
1352
if (c -> dim >= n && n > 0 )
1351
1353
result = Min (c -> x [n - 1 ], c -> x [c -> dim + n - 1 ]);
1352
1354
1353
- PG_FREE_IF_COPY (c ,0 );
1355
+ PG_FREE_IF_COPY (c , 0 );
1354
1356
PG_RETURN_FLOAT8 (result );
1355
1357
}
1356
1358
@@ -1369,7 +1371,7 @@ cube_ur_coord(PG_FUNCTION_ARGS)
1369
1371
if (c -> dim >= n && n > 0 )
1370
1372
result = Max (c -> x [n - 1 ], c -> x [c -> dim + n - 1 ]);
1371
1373
1372
- PG_FREE_IF_COPY (c ,0 );
1374
+ PG_FREE_IF_COPY (c , 0 );
1373
1375
PG_RETURN_FLOAT8 (result );
1374
1376
}
1375
1377
@@ -1384,7 +1386,7 @@ cube_enlarge(PG_FUNCTION_ARGS)
1384
1386
j ,
1385
1387
k ;
1386
1388
NDBOX * a ;
1387
- double r ;
1389
+ double r ;
1388
1390
int4 n ;
1389
1391
1390
1392
a = PG_GETARG_NDBOX (0 );
@@ -1426,7 +1428,7 @@ cube_enlarge(PG_FUNCTION_ARGS)
1426
1428
result -> x [j ] = r ;
1427
1429
}
1428
1430
1429
- PG_FREE_IF_COPY (a ,0 );
1431
+ PG_FREE_IF_COPY (a , 0 );
1430
1432
PG_RETURN_NDBOX (result );
1431
1433
}
1432
1434
@@ -1490,7 +1492,7 @@ cube_c_f8(PG_FUNCTION_ARGS)
1490
1492
result -> x [result -> dim - 1 ] = x ;
1491
1493
result -> x [2 * result -> dim - 1 ] = x ;
1492
1494
1493
- PG_FREE_IF_COPY (c ,0 );
1495
+ PG_FREE_IF_COPY (c , 0 );
1494
1496
PG_RETURN_NDBOX (result );
1495
1497
}
1496
1498
@@ -1521,6 +1523,6 @@ cube_c_f8_f8(PG_FUNCTION_ARGS)
1521
1523
result -> x [result -> dim - 1 ] = x1 ;
1522
1524
result -> x [2 * result -> dim - 1 ] = x2 ;
1523
1525
1524
- PG_FREE_IF_COPY (c ,0 );
1526
+ PG_FREE_IF_COPY (c , 0 );
1525
1527
PG_RETURN_NDBOX (result );
1526
1528
}
0 commit comments