~ubuntu-branches/ubuntu/natty/postgresql-8.4/natty-security

« back to all changes in this revision

Viewing changes to contrib/cube/cube.c

Tags: upstream-8.4.0
ImportĀ upstreamĀ versionĀ 8.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
  $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.36 2008/05/29 18:46:40 tgl Exp $
 
2
  $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.37 2009/06/11 14:48:50 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
134
134
/*
135
135
** For internal use only
136
136
*/
137
 
int32           cube_cmp_v0(NDBOX * a, NDBOX * b);
138
 
bool            cube_contains_v0(NDBOX * a, NDBOX * b);
139
 
bool            cube_overlap_v0(NDBOX * a, NDBOX * b);
140
 
NDBOX      *cube_union_v0(NDBOX * a, NDBOX * b);
141
 
void            rt_cube_size(NDBOX * a, double *sz);
142
 
NDBOX      *g_cube_binary_union(NDBOX * r1, NDBOX * r2, int *sizep);
143
 
bool            g_cube_leaf_consistent(NDBOX * key, NDBOX * query, StrategyNumber strategy);
144
 
bool            g_cube_internal_consistent(NDBOX * key, NDBOX * query, StrategyNumber strategy);
 
137
int32           cube_cmp_v0(NDBOX *a, NDBOX *b);
 
138
bool            cube_contains_v0(NDBOX *a, NDBOX *b);
 
139
bool            cube_overlap_v0(NDBOX *a, NDBOX *b);
 
140
NDBOX      *cube_union_v0(NDBOX *a, NDBOX *b);
 
141
void            rt_cube_size(NDBOX *a, double *sz);
 
142
NDBOX      *g_cube_binary_union(NDBOX *r1, NDBOX *r2, int *sizep);
 
143
bool            g_cube_leaf_consistent(NDBOX *key, NDBOX *query, StrategyNumber strategy);
 
144
bool            g_cube_internal_consistent(NDBOX *key, NDBOX *query, StrategyNumber strategy);
145
145
 
146
146
/*
147
147
** Auxiliary funxtions
201
201
        dur = ARRPTR(ur);
202
202
        dll = ARRPTR(ll);
203
203
 
204
 
        size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
 
204
        size = offsetof(NDBOX, x[0]) +sizeof(double) * 2 * dim;
205
205
        result = (NDBOX *) palloc0(size);
206
206
        SET_VARSIZE(result, size);
207
207
        result->dim = dim;
237
237
 
238
238
        dur = ARRPTR(ur);
239
239
 
240
 
        size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
 
240
        size = offsetof(NDBOX, x[0]) +sizeof(double) * 2 * dim;
241
241
        result = (NDBOX *) palloc0(size);
242
242
        SET_VARSIZE(result, size);
243
243
        result->dim = dim;
270
270
        dx = (int4 *) ARR_DATA_PTR(idx);
271
271
 
272
272
        dim = ARRNELEMS(idx);
273
 
        size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
 
273
        size = offsetof(NDBOX, x[0]) +sizeof(double) * 2 * dim;
274
274
        result = (NDBOX *) palloc0(size);
275
275
        SET_VARSIZE(result, size);
276
276
        result->dim = dim;
359
359
        GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
360
360
        NDBOX      *query = PG_GETARG_NDBOX(1);
361
361
        StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
 
362
 
362
363
        /* Oid          subtype = PG_GETARG_OID(3); */
363
364
        bool       *recheck = (bool *) PG_GETARG_POINTER(4);
364
365
        bool            res;
652
653
** SUPPORT ROUTINES
653
654
*/
654
655
bool
655
 
g_cube_leaf_consistent(NDBOX * key,
656
 
                                           NDBOX * query,
 
656
g_cube_leaf_consistent(NDBOX *key,
 
657
                                           NDBOX *query,
657
658
                                           StrategyNumber strategy)
658
659
{
659
660
        bool            retval;
684
685
}
685
686
 
686
687
bool
687
 
g_cube_internal_consistent(NDBOX * key,
688
 
                                                   NDBOX * query,
 
688
g_cube_internal_consistent(NDBOX *key,
 
689
                                                   NDBOX *query,
689
690
                                                   StrategyNumber strategy)
690
691
{
691
692
        bool            retval;
714
715
}
715
716
 
716
717
NDBOX *
717
 
g_cube_binary_union(NDBOX * r1, NDBOX * r2, int *sizep)
 
718
g_cube_binary_union(NDBOX *r1, NDBOX *r2, int *sizep)
718
719
{
719
720
        NDBOX      *retval;
720
721
 
727
728
 
728
729
/* cube_union_v0 */
729
730
NDBOX *
730
 
cube_union_v0(NDBOX * a, NDBOX * b)
 
731
cube_union_v0(NDBOX *a, NDBOX *b)
731
732
{
732
733
        int                     i;
733
734
        NDBOX      *result;
887
888
}
888
889
 
889
890
void
890
 
rt_cube_size(NDBOX * a, double *size)
 
891
rt_cube_size(NDBOX *a, double *size)
891
892
{
892
893
        int                     i,
893
894
                                j;
906
907
/* make up a metric in which one box will be 'lower' than the other
907
908
   -- this can be useful for sorting and to determine uniqueness */
908
909
int32
909
 
cube_cmp_v0(NDBOX * a, NDBOX * b)
 
910
cube_cmp_v0(NDBOX *a, NDBOX *b)
910
911
{
911
912
        int                     i;
912
913
        int                     dim;
1093
1094
/* Contains */
1094
1095
/* Box(A) CONTAINS Box(B) IFF pt(A) < pt(B) */
1095
1096
bool
1096
 
cube_contains_v0(NDBOX * a, NDBOX * b)
 
1097
cube_contains_v0(NDBOX *a, NDBOX *b)
1097
1098
{
1098
1099
        int                     i;
1099
1100
 
1163
1164
/* Overlap */
1164
1165
/* Box(A) Overlap Box(B) IFF (pt(a)LL < pt(B)UR) && (pt(b)LL < pt(a)UR) */
1165
1166
bool
1166
 
cube_overlap_v0(NDBOX * a, NDBOX * b)
 
1167
cube_overlap_v0(NDBOX *a, NDBOX *b)
1167
1168
{
1168
1169
        int                     i;
1169
1170
 
1374
1375
                dim = n;
1375
1376
        if (a->dim > dim)
1376
1377
                dim = a->dim;
1377
 
        size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2;
 
1378
        size = offsetof(NDBOX, x[0]) +sizeof(double) * dim * 2;
1378
1379
        result = (NDBOX *) palloc0(size);
1379
1380
        SET_VARSIZE(result, size);
1380
1381
        result->dim = dim;
1415
1416
        NDBOX      *result;
1416
1417
        int                     size;
1417
1418
 
1418
 
        size = offsetof(NDBOX, x[0]) + sizeof(double) * 2;
 
1419
        size = offsetof(NDBOX, x[0]) +sizeof(double) * 2;
1419
1420
        result = (NDBOX *) palloc0(size);
1420
1421
        SET_VARSIZE(result, size);
1421
1422
        result->dim = 1;
1433
1434
        NDBOX      *result;
1434
1435
        int                     size;
1435
1436
 
1436
 
        size = offsetof(NDBOX, x[0]) + sizeof(double) * 2;
 
1437
        size = offsetof(NDBOX, x[0]) +sizeof(double) * 2;
1437
1438
        result = (NDBOX *) palloc0(size);
1438
1439
        SET_VARSIZE(result, size);
1439
1440
        result->dim = 1;
1454
1455
        int                     size;
1455
1456
        int                     i;
1456
1457
 
1457
 
        size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) *2;
 
1458
        size = offsetof(NDBOX, x[0]) +sizeof(double) * (c->dim + 1) *2;
1458
1459
        result = (NDBOX *) palloc0(size);
1459
1460
        SET_VARSIZE(result, size);
1460
1461
        result->dim = c->dim + 1;
1481
1482
        int                     size;
1482
1483
        int                     i;
1483
1484
 
1484
 
        size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) *2;
 
1485
        size = offsetof(NDBOX, x[0]) +sizeof(double) * (c->dim + 1) *2;
1485
1486
        result = (NDBOX *) palloc0(size);
1486
1487
        SET_VARSIZE(result, size);
1487
1488
        result->dim = c->dim + 1;