4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
7 typedef struct float4key
16 PG_FUNCTION_INFO_V1(gbt_float4_compress
);
17 PG_FUNCTION_INFO_V1(gbt_float4_union
);
18 PG_FUNCTION_INFO_V1(gbt_float4_picksplit
);
19 PG_FUNCTION_INFO_V1(gbt_float4_consistent
);
20 PG_FUNCTION_INFO_V1(gbt_float4_penalty
);
21 PG_FUNCTION_INFO_V1(gbt_float4_same
);
23 Datum
gbt_float4_compress(PG_FUNCTION_ARGS
);
24 Datum
gbt_float4_union(PG_FUNCTION_ARGS
);
25 Datum
gbt_float4_picksplit(PG_FUNCTION_ARGS
);
26 Datum
gbt_float4_consistent(PG_FUNCTION_ARGS
);
27 Datum
gbt_float4_penalty(PG_FUNCTION_ARGS
);
28 Datum
gbt_float4_same(PG_FUNCTION_ARGS
);
31 gbt_float4gt(const void *a
, const void *b
)
33 return (*((float4
*) a
) > *((float4
*) b
));
36 gbt_float4ge(const void *a
, const void *b
)
38 return (*((float4
*) a
) >= *((float4
*) b
));
41 gbt_float4eq(const void *a
, const void *b
)
43 return (*((float4
*) a
) == *((float4
*) b
));
46 gbt_float4le(const void *a
, const void *b
)
48 return (*((float4
*) a
) <= *((float4
*) b
));
51 gbt_float4lt(const void *a
, const void *b
)
53 return (*((float4
*) a
) < *((float4
*) b
));
57 gbt_float4key_cmp(const void *a
, const void *b
)
60 if (*(float4
*) &(((Nsrt
*) a
)->t
[0]) > *(float4
*) &(((Nsrt
*) b
)->t
[0]))
62 else if (*(float4
*) &(((Nsrt
*) a
)->t
[0]) < *(float4
*) &(((Nsrt
*) b
)->t
[0]))
69 static const gbtree_ninfo tinfo
=
82 /**************************************************
84 **************************************************/
88 gbt_float4_compress(PG_FUNCTION_ARGS
)
90 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
91 GISTENTRY
*retval
= NULL
;
93 PG_RETURN_POINTER(gbt_num_compress(retval
, entry
, &tinfo
));
98 gbt_float4_consistent(PG_FUNCTION_ARGS
)
100 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
101 float4 query
= PG_GETARG_FLOAT4(1);
102 StrategyNumber strategy
= (StrategyNumber
) PG_GETARG_UINT16(2);
104 /* Oid subtype = PG_GETARG_OID(3); */
105 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
106 float4KEY
*kkk
= (float4KEY
*) DatumGetPointer(entry
->key
);
109 /* All cases served by this function are exact */
112 key
.lower
= (GBT_NUMKEY
*) &kkk
->lower
;
113 key
.upper
= (GBT_NUMKEY
*) &kkk
->upper
;
116 gbt_num_consistent(&key
, (void *) &query
, &strategy
, GIST_LEAF(entry
), &tinfo
)
122 gbt_float4_union(PG_FUNCTION_ARGS
)
124 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
125 void *out
= palloc(sizeof(float4KEY
));
127 *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY
);
128 PG_RETURN_POINTER(gbt_num_union((void *) out
, entryvec
, &tinfo
));
133 gbt_float4_penalty(PG_FUNCTION_ARGS
)
135 float4KEY
*origentry
= (float4KEY
*) DatumGetPointer(((GISTENTRY
*) PG_GETARG_POINTER(0))->key
);
136 float4KEY
*newentry
= (float4KEY
*) DatumGetPointer(((GISTENTRY
*) PG_GETARG_POINTER(1))->key
);
137 float *result
= (float *) PG_GETARG_POINTER(2);
139 penalty_num(result
, origentry
->lower
, origentry
->upper
, newentry
->lower
, newentry
->upper
);
141 PG_RETURN_POINTER(result
);
146 gbt_float4_picksplit(PG_FUNCTION_ARGS
)
148 PG_RETURN_POINTER(gbt_num_picksplit(
149 (GistEntryVector
*) PG_GETARG_POINTER(0),
150 (GIST_SPLITVEC
*) PG_GETARG_POINTER(1),
156 gbt_float4_same(PG_FUNCTION_ARGS
)
158 float4KEY
*b1
= (float4KEY
*) PG_GETARG_POINTER(0);
159 float4KEY
*b2
= (float4KEY
*) PG_GETARG_POINTER(1);
160 bool *result
= (bool *) PG_GETARG_POINTER(2);
162 *result
= gbt_num_same((void *) b1
, (void *) b2
, &tinfo
);
163 PG_RETURN_POINTER(result
);