~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to contrib/btree_gist/btree_int8.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "btree_gist.h"
 
2
#include "btree_utils_num.h"
 
3
 
 
4
typedef struct int64key
 
5
{
 
6
        int64           lower;
 
7
        int64           upper;
 
8
}       int64KEY;
 
9
 
 
10
/*
 
11
** int64 ops
 
12
*/
 
13
PG_FUNCTION_INFO_V1(gbt_int8_compress);
 
14
PG_FUNCTION_INFO_V1(gbt_int8_union);
 
15
PG_FUNCTION_INFO_V1(gbt_int8_picksplit);
 
16
PG_FUNCTION_INFO_V1(gbt_int8_consistent);
 
17
PG_FUNCTION_INFO_V1(gbt_int8_penalty);
 
18
PG_FUNCTION_INFO_V1(gbt_int8_same);
 
19
 
 
20
Datum           gbt_int8_compress(PG_FUNCTION_ARGS);
 
21
Datum           gbt_int8_union(PG_FUNCTION_ARGS);
 
22
Datum           gbt_int8_picksplit(PG_FUNCTION_ARGS);
 
23
Datum           gbt_int8_consistent(PG_FUNCTION_ARGS);
 
24
Datum           gbt_int8_penalty(PG_FUNCTION_ARGS);
 
25
Datum           gbt_int8_same(PG_FUNCTION_ARGS);
 
26
 
 
27
 
 
28
static bool
 
29
gbt_int8gt(const void *a, const void *b)
 
30
{
 
31
        return (*((int64 *) a) > *((int64 *) b));
 
32
}
 
33
static bool
 
34
gbt_int8ge(const void *a, const void *b)
 
35
{
 
36
        return (*((int64 *) a) >= *((int64 *) b));
 
37
}
 
38
static bool
 
39
gbt_int8eq(const void *a, const void *b)
 
40
{
 
41
        return (*((int64 *) a) == *((int64 *) b));
 
42
}
 
43
static bool
 
44
gbt_int8le(const void *a, const void *b)
 
45
{
 
46
        return (*((int64 *) a) <= *((int64 *) b));
 
47
}
 
48
static bool
 
49
gbt_int8lt(const void *a, const void *b)
 
50
{
 
51
        return (*((int64 *) a) < *((int64 *) b));
 
52
}
 
53
 
 
54
static int
 
55
gbt_int8key_cmp(const void *a, const void *b)
 
56
{
 
57
 
 
58
        if (*(int64 *) &(((Nsrt *) a)->t[0]) > *(int64 *) &(((Nsrt *) b)->t[0]))
 
59
                return 1;
 
60
        else if (*(int64 *) &(((Nsrt *) a)->t[0]) < *(int64 *) &(((Nsrt *) b)->t[0]))
 
61
                return -1;
 
62
        return 0;
 
63
 
 
64
}
 
65
 
 
66
 
 
67
static const gbtree_ninfo tinfo =
 
68
{
 
69
        gbt_t_int8,
 
70
        sizeof(int64),
 
71
        gbt_int8gt,
 
72
        gbt_int8ge,
 
73
        gbt_int8eq,
 
74
        gbt_int8le,
 
75
        gbt_int8lt,
 
76
        gbt_int8key_cmp
 
77
};
 
78
 
 
79
 
 
80
/**************************************************
 
81
 * int64 ops
 
82
 **************************************************/
 
83
 
 
84
 
 
85
Datum
 
86
gbt_int8_compress(PG_FUNCTION_ARGS)
 
87
{
 
88
        GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
 
89
        GISTENTRY  *retval = NULL;
 
90
 
 
91
        PG_RETURN_POINTER(gbt_num_compress(retval, entry, &tinfo));
 
92
}
 
93
 
 
94
 
 
95
Datum
 
96
gbt_int8_consistent(PG_FUNCTION_ARGS)
 
97
{
 
98
        GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
 
99
        int64           query = PG_GETARG_INT64(1);
 
100
        int64KEY   *kkk = (int64KEY *) DatumGetPointer(entry->key);
 
101
        GBT_NUMKEY_R key;
 
102
        StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
 
103
 
 
104
        key.lower = (GBT_NUMKEY *) & kkk->lower;
 
105
        key.upper = (GBT_NUMKEY *) & kkk->upper;
 
106
 
 
107
        PG_RETURN_BOOL(
 
108
                                   gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo)
 
109
                );
 
110
}
 
111
 
 
112
 
 
113
Datum
 
114
gbt_int8_union(PG_FUNCTION_ARGS)
 
115
{
 
116
        GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 
117
        void       *out = palloc(sizeof(int64KEY));
 
118
 
 
119
        *(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY);
 
120
        PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo));
 
121
}
 
122
 
 
123
 
 
124
Datum
 
125
gbt_int8_penalty(PG_FUNCTION_ARGS)
 
126
{
 
127
        int64KEY   *origentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
 
128
        int64KEY   *newentry = (int64KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
 
129
        float      *result = (float *) PG_GETARG_POINTER(2);
 
130
        int64           res;
 
131
 
 
132
        *result = 0.0;
 
133
 
 
134
        penalty_range_enlarge(origentry->lower, origentry->upper, newentry->lower, newentry->upper);
 
135
 
 
136
        if (res > 0)
 
137
        {
 
138
                *result += FLT_MIN;
 
139
                *result += (float) (res / ((double) (res + origentry->upper - origentry->lower)));
 
140
                *result *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1));
 
141
        }
 
142
 
 
143
        PG_RETURN_POINTER(result);
 
144
 
 
145
}
 
146
 
 
147
Datum
 
148
gbt_int8_picksplit(PG_FUNCTION_ARGS)
 
149
{
 
150
        PG_RETURN_POINTER(gbt_num_picksplit(
 
151
                                                                (GistEntryVector *) PG_GETARG_POINTER(0),
 
152
                                                                  (GIST_SPLITVEC *) PG_GETARG_POINTER(1),
 
153
                                                                                &tinfo
 
154
                                                                                ));
 
155
}
 
156
 
 
157
Datum
 
158
gbt_int8_same(PG_FUNCTION_ARGS)
 
159
{
 
160
        int64KEY   *b1 = (int64KEY *) PG_GETARG_POINTER(0);
 
161
        int64KEY   *b2 = (int64KEY *) PG_GETARG_POINTER(1);
 
162
        bool       *result = (bool *) PG_GETARG_POINTER(2);
 
163
 
 
164
        *result = gbt_num_same((void *) b1, (void *) b2, &tinfo);
 
165
        PG_RETURN_POINTER(result);
 
166
}