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

« back to all changes in this revision

Viewing changes to contrib/seg/seg.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-11 16:59:35 UTC
  • mfrom: (5.1.1 karmic)
  • Revision ID: james.westby@ubuntu.com-20090711165935-jfwin6gfrxf0gfsi
Tags: 8.4.0-2
* debian/libpq-dev.install: Ship catalog/genbki.h. (Closes: #536139)
* debian/rules: Drop --enable-cassert for final release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $PostgreSQL: pgsql/contrib/seg/seg.c,v 1.24 2008/05/17 01:28:22 adunstan Exp $ 
 
2
 * $PostgreSQL: pgsql/contrib/seg/seg.c,v 1.25 2009/06/11 14:48:52 momjian Exp $
3
3
 *
4
4
 ******************************************************************************
5
5
  This file contains routines that can be bound to a Postgres backend and
53
53
/*
54
54
** GiST support methods
55
55
*/
56
 
bool            gseg_consistent(GISTENTRY *entry,
57
 
                                                        SEG * query,
58
 
                                                        StrategyNumber strategy,
59
 
                                                        Oid subtype,
60
 
                                                        bool *recheck);
 
56
bool gseg_consistent(GISTENTRY *entry,
 
57
                                SEG *query,
 
58
                                StrategyNumber strategy,
 
59
                                Oid subtype,
 
60
                                bool *recheck);
61
61
GISTENTRY  *gseg_compress(GISTENTRY *entry);
62
62
GISTENTRY  *gseg_decompress(GISTENTRY *entry);
63
63
float      *gseg_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result);
64
64
GIST_SPLITVEC *gseg_picksplit(GistEntryVector *entryvec, GIST_SPLITVEC *v);
65
 
bool            gseg_leaf_consistent(SEG * key, SEG * query, StrategyNumber strategy);
66
 
bool            gseg_internal_consistent(SEG * key, SEG * query, StrategyNumber strategy);
 
65
bool            gseg_leaf_consistent(SEG *key, SEG *query, StrategyNumber strategy);
 
66
bool            gseg_internal_consistent(SEG *key, SEG *query, StrategyNumber strategy);
67
67
SEG                *gseg_union(GistEntryVector *entryvec, int *sizep);
68
 
SEG                *gseg_binary_union(SEG * r1, SEG * r2, int *sizep);
69
 
bool       *gseg_same(SEG * b1, SEG * b2, bool *result);
 
68
SEG                *gseg_binary_union(SEG *r1, SEG *r2, int *sizep);
 
69
bool       *gseg_same(SEG *b1, SEG *b2, bool *result);
70
70
 
71
71
 
72
72
/*
73
73
** R-tree support functions
74
74
*/
75
 
bool            seg_same(SEG * a, SEG * b);
76
 
bool            seg_contains_int(SEG * a, int *b);
77
 
bool            seg_contains_float4(SEG * a, float4 *b);
78
 
bool            seg_contains_float8(SEG * a, float8 *b);
79
 
bool            seg_contains(SEG * a, SEG * b);
80
 
bool            seg_contained(SEG * a, SEG * b);
81
 
bool            seg_overlap(SEG * a, SEG * b);
82
 
bool            seg_left(SEG * a, SEG * b);
83
 
bool            seg_over_left(SEG * a, SEG * b);
84
 
bool            seg_right(SEG * a, SEG * b);
85
 
bool            seg_over_right(SEG * a, SEG * b);
86
 
SEG                *seg_union(SEG * a, SEG * b);
87
 
SEG                *seg_inter(SEG * a, SEG * b);
88
 
void            rt_seg_size(SEG * a, float *sz);
 
75
bool            seg_same(SEG *a, SEG *b);
 
76
bool            seg_contains_int(SEG *a, int *b);
 
77
bool            seg_contains_float4(SEG *a, float4 *b);
 
78
bool            seg_contains_float8(SEG *a, float8 *b);
 
79
bool            seg_contains(SEG *a, SEG *b);
 
80
bool            seg_contained(SEG *a, SEG *b);
 
81
bool            seg_overlap(SEG *a, SEG *b);
 
82
bool            seg_left(SEG *a, SEG *b);
 
83
bool            seg_over_left(SEG *a, SEG *b);
 
84
bool            seg_right(SEG *a, SEG *b);
 
85
bool            seg_over_right(SEG *a, SEG *b);
 
86
SEG                *seg_union(SEG *a, SEG *b);
 
87
SEG                *seg_inter(SEG *a, SEG *b);
 
88
void            rt_seg_size(SEG *a, float *sz);
89
89
 
90
90
/*
91
91
** Various operators
92
92
*/
93
 
int32           seg_cmp(SEG * a, SEG * b);
94
 
bool            seg_lt(SEG * a, SEG * b);
95
 
bool            seg_le(SEG * a, SEG * b);
96
 
bool            seg_gt(SEG * a, SEG * b);
97
 
bool            seg_ge(SEG * a, SEG * b);
98
 
bool            seg_different(SEG * a, SEG * b);
 
93
int32           seg_cmp(SEG *a, SEG *b);
 
94
bool            seg_lt(SEG *a, SEG *b);
 
95
bool            seg_le(SEG *a, SEG *b);
 
96
bool            seg_gt(SEG *a, SEG *b);
 
97
bool            seg_ge(SEG *a, SEG *b);
 
98
bool            seg_different(SEG *a, SEG *b);
99
99
 
100
100
/*
101
101
** Auxiliary funxtions
168
168
Datum
169
169
seg_center(PG_FUNCTION_ARGS)
170
170
{
171
 
        SEG     *seg = (SEG *) PG_GETARG_POINTER(0);
 
171
        SEG                *seg = (SEG *) PG_GETARG_POINTER(0);
172
172
 
173
173
        PG_RETURN_FLOAT4(((float) seg->lower + (float) seg->upper) / 2.0);
174
174
}
176
176
Datum
177
177
seg_lower(PG_FUNCTION_ARGS)
178
178
{
179
 
        SEG     *seg = (SEG *) PG_GETARG_POINTER(0);
 
179
        SEG                *seg = (SEG *) PG_GETARG_POINTER(0);
180
180
 
181
181
        PG_RETURN_FLOAT4(seg->lower);
182
182
}
184
184
Datum
185
185
seg_upper(PG_FUNCTION_ARGS)
186
186
{
187
 
        SEG             *seg = (SEG *) PG_GETARG_POINTER(0);
 
187
        SEG                *seg = (SEG *) PG_GETARG_POINTER(0);
188
188
 
189
189
        PG_RETURN_FLOAT4(seg->upper);
190
190
}
202
202
*/
203
203
bool
204
204
gseg_consistent(GISTENTRY *entry,
205
 
                                SEG * query,
 
205
                                SEG *query,
206
206
                                StrategyNumber strategy,
207
207
                                Oid subtype,
208
208
                                bool *recheck)
449
449
** Equality methods
450
450
*/
451
451
bool *
452
 
gseg_same(SEG * b1, SEG * b2, bool *result)
 
452
gseg_same(SEG *b1, SEG *b2, bool *result)
453
453
{
454
454
        if (seg_same(b1, b2))
455
455
                *result = TRUE;
467
467
** SUPPORT ROUTINES
468
468
*/
469
469
bool
470
 
gseg_leaf_consistent(SEG * key,
471
 
                                         SEG * query,
 
470
gseg_leaf_consistent(SEG *key,
 
471
                                         SEG *query,
472
472
                                         StrategyNumber strategy)
473
473
{
474
474
        bool            retval;
512
512
}
513
513
 
514
514
bool
515
 
gseg_internal_consistent(SEG * key,
516
 
                                                 SEG * query,
 
515
gseg_internal_consistent(SEG *key,
 
516
                                                 SEG *query,
517
517
                                                 StrategyNumber strategy)
518
518
{
519
519
        bool            retval;
555
555
}
556
556
 
557
557
SEG *
558
 
gseg_binary_union(SEG * r1, SEG * r2, int *sizep)
 
558
gseg_binary_union(SEG *r1, SEG *r2, int *sizep)
559
559
{
560
560
        SEG                *retval;
561
561
 
567
567
 
568
568
 
569
569
bool
570
 
seg_contains(SEG * a, SEG * b)
 
570
seg_contains(SEG *a, SEG *b)
571
571
{
572
572
        return ((a->lower <= b->lower) && (a->upper >= b->upper));
573
573
}
574
574
 
575
575
bool
576
 
seg_contained(SEG * a, SEG * b)
 
576
seg_contained(SEG *a, SEG *b)
577
577
{
578
578
        return (seg_contains(b, a));
579
579
}
583
583
 *****************************************************************************/
584
584
 
585
585
bool
586
 
seg_same(SEG * a, SEG * b)
 
586
seg_same(SEG *a, SEG *b)
587
587
{
588
588
        return seg_cmp(a, b) == 0;
589
589
}
591
591
/*      seg_overlap -- does a overlap b?
592
592
 */
593
593
bool
594
 
seg_overlap(SEG * a, SEG * b)
 
594
seg_overlap(SEG *a, SEG *b)
595
595
{
596
596
        return (
597
597
                        ((a->upper >= b->upper) && (a->lower <= b->upper))
603
603
/*      seg_overleft -- is the right edge of (a) located at or left of the right edge of (b)?
604
604
 */
605
605
bool
606
 
seg_over_left(SEG * a, SEG * b)
 
606
seg_over_left(SEG *a, SEG *b)
607
607
{
608
608
        return (a->upper <= b->upper);
609
609
}
611
611
/*      seg_left -- is (a) entirely on the left of (b)?
612
612
 */
613
613
bool
614
 
seg_left(SEG * a, SEG * b)
 
614
seg_left(SEG *a, SEG *b)
615
615
{
616
616
        return (a->upper < b->lower);
617
617
}
619
619
/*      seg_right -- is (a) entirely on the right of (b)?
620
620
 */
621
621
bool
622
 
seg_right(SEG * a, SEG * b)
 
622
seg_right(SEG *a, SEG *b)
623
623
{
624
624
        return (a->lower > b->upper);
625
625
}
627
627
/*      seg_overright -- is the left edge of (a) located at or right of the left edge of (b)?
628
628
 */
629
629
bool
630
 
seg_over_right(SEG * a, SEG * b)
 
630
seg_over_right(SEG *a, SEG *b)
631
631
{
632
632
        return (a->lower >= b->lower);
633
633
}
634
634
 
635
635
 
636
636
SEG *
637
 
seg_union(SEG * a, SEG * b)
 
637
seg_union(SEG *a, SEG *b)
638
638
{
639
639
        SEG                *n;
640
640
 
673
673
 
674
674
 
675
675
SEG *
676
 
seg_inter(SEG * a, SEG * b)
 
676
seg_inter(SEG *a, SEG *b)
677
677
{
678
678
        SEG                *n;
679
679
 
711
711
}
712
712
 
713
713
void
714
 
rt_seg_size(SEG * a, float *size)
 
714
rt_seg_size(SEG *a, float *size)
715
715
{
716
716
        if (a == (SEG *) NULL || a->upper <= a->lower)
717
717
                *size = 0.0;
724
724
Datum
725
725
seg_size(PG_FUNCTION_ARGS)
726
726
{
727
 
        SEG     *seg = (SEG *) PG_GETARG_POINTER(0);
 
727
        SEG                *seg = (SEG *) PG_GETARG_POINTER(0);
728
728
 
729
729
        PG_RETURN_FLOAT4((float) Abs(seg->upper - seg->lower));
730
730
}
734
734
 *                                 Miscellaneous operators
735
735
 *****************************************************************************/
736
736
int32
737
 
seg_cmp(SEG * a, SEG * b)
 
737
seg_cmp(SEG *a, SEG *b)
738
738
{
739
739
        /*
740
740
         * First compare on lower boundary position
853
853
}
854
854
 
855
855
bool
856
 
seg_lt(SEG * a, SEG * b)
 
856
seg_lt(SEG *a, SEG *b)
857
857
{
858
858
        return seg_cmp(a, b) < 0;
859
859
}
860
860
 
861
861
bool
862
 
seg_le(SEG * a, SEG * b)
 
862
seg_le(SEG *a, SEG *b)
863
863
{
864
864
        return seg_cmp(a, b) <= 0;
865
865
}
866
866
 
867
867
bool
868
 
seg_gt(SEG * a, SEG * b)
 
868
seg_gt(SEG *a, SEG *b)
869
869
{
870
870
        return seg_cmp(a, b) > 0;
871
871
}
872
872
 
873
873
bool
874
 
seg_ge(SEG * a, SEG * b)
 
874
seg_ge(SEG *a, SEG *b)
875
875
{
876
876
        return seg_cmp(a, b) >= 0;
877
877
}
878
878
 
879
879
bool
880
 
seg_different(SEG * a, SEG * b)
 
880
seg_different(SEG *a, SEG *b)
881
881
{
882
882
        return seg_cmp(a, b) != 0;
883
883
}
1042
1042
*/
1043
1043
 
1044
1044
bool
1045
 
seg_contains_int(SEG * a, int *b)
1046
 
{
1047
 
        return ((a->lower <= *b) && (a->upper >= *b));
1048
 
}
1049
 
 
1050
 
bool
1051
 
seg_contains_float4(SEG * a, float4 *b)
1052
 
{
1053
 
        return ((a->lower <= *b) && (a->upper >= *b));
1054
 
}
1055
 
 
1056
 
bool
1057
 
seg_contains_float8(SEG * a, float8 *b)
 
1045
seg_contains_int(SEG *a, int *b)
 
1046
{
 
1047
        return ((a->lower <= *b) && (a->upper >= *b));
 
1048
}
 
1049
 
 
1050
bool
 
1051
seg_contains_float4(SEG *a, float4 *b)
 
1052
{
 
1053
        return ((a->lower <= *b) && (a->upper >= *b));
 
1054
}
 
1055
 
 
1056
bool
 
1057
seg_contains_float8(SEG *a, float8 *b)
1058
1058
{
1059
1059
        return ((a->lower <= *b) && (a->upper >= *b));
1060
1060
}