4 #include "btree_gist.h"
5 #include "btree_utils_num.h"
7 typedef struct int64key
16 PG_FUNCTION_INFO_V1(gbt_int8_compress
);
17 PG_FUNCTION_INFO_V1(gbt_int8_union
);
18 PG_FUNCTION_INFO_V1(gbt_int8_picksplit
);
19 PG_FUNCTION_INFO_V1(gbt_int8_consistent
);
20 PG_FUNCTION_INFO_V1(gbt_int8_penalty
);
21 PG_FUNCTION_INFO_V1(gbt_int8_same
);
23 Datum
gbt_int8_compress(PG_FUNCTION_ARGS
);
24 Datum
gbt_int8_union(PG_FUNCTION_ARGS
);
25 Datum
gbt_int8_picksplit(PG_FUNCTION_ARGS
);
26 Datum
gbt_int8_consistent(PG_FUNCTION_ARGS
);
27 Datum
gbt_int8_penalty(PG_FUNCTION_ARGS
);
28 Datum
gbt_int8_same(PG_FUNCTION_ARGS
);
32 gbt_int8gt(const void *a
, const void *b
)
34 return (*((int64
*) a
) > *((int64
*) b
));
37 gbt_int8ge(const void *a
, const void *b
)
39 return (*((int64
*) a
) >= *((int64
*) b
));
42 gbt_int8eq(const void *a
, const void *b
)
44 return (*((int64
*) a
) == *((int64
*) b
));
47 gbt_int8le(const void *a
, const void *b
)
49 return (*((int64
*) a
) <= *((int64
*) b
));
52 gbt_int8lt(const void *a
, const void *b
)
54 return (*((int64
*) a
) < *((int64
*) b
));
58 gbt_int8key_cmp(const void *a
, const void *b
)
61 if (*(int64
*) &(((Nsrt
*) a
)->t
[0]) > *(int64
*) &(((Nsrt
*) b
)->t
[0]))
63 else if (*(int64
*) &(((Nsrt
*) a
)->t
[0]) < *(int64
*) &(((Nsrt
*) b
)->t
[0]))
70 static const gbtree_ninfo tinfo
=
83 /**************************************************
85 **************************************************/
89 gbt_int8_compress(PG_FUNCTION_ARGS
)
91 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
92 GISTENTRY
*retval
= NULL
;
94 PG_RETURN_POINTER(gbt_num_compress(retval
, entry
, &tinfo
));
99 gbt_int8_consistent(PG_FUNCTION_ARGS
)
101 GISTENTRY
*entry
= (GISTENTRY
*) PG_GETARG_POINTER(0);
102 int64 query
= PG_GETARG_INT64(1);
103 StrategyNumber strategy
= (StrategyNumber
) PG_GETARG_UINT16(2);
104 /* Oid subtype = PG_GETARG_OID(3); */
105 bool *recheck
= (bool *) PG_GETARG_POINTER(4);
106 int64KEY
*kkk
= (int64KEY
*) 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_int8_union(PG_FUNCTION_ARGS
)
124 GistEntryVector
*entryvec
= (GistEntryVector
*) PG_GETARG_POINTER(0);
125 void *out
= palloc(sizeof(int64KEY
));
127 *(int *) PG_GETARG_POINTER(1) = sizeof(int64KEY
);
128 PG_RETURN_POINTER(gbt_num_union((void *) out
, entryvec
, &tinfo
));
133 gbt_int8_penalty(PG_FUNCTION_ARGS
)
135 int64KEY
*origentry
= (int64KEY
*) DatumGetPointer(((GISTENTRY
*) PG_GETARG_POINTER(0))->key
);
136 int64KEY
*newentry
= (int64KEY
*) 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
);
145 gbt_int8_picksplit(PG_FUNCTION_ARGS
)
147 PG_RETURN_POINTER(gbt_num_picksplit(
148 (GistEntryVector
*) PG_GETARG_POINTER(0),
149 (GIST_SPLITVEC
*) PG_GETARG_POINTER(1),
155 gbt_int8_same(PG_FUNCTION_ARGS
)
157 int64KEY
*b1
= (int64KEY
*) PG_GETARG_POINTER(0);
158 int64KEY
*b2
= (int64KEY
*) PG_GETARG_POINTER(1);
159 bool *result
= (bool *) PG_GETARG_POINTER(2);
161 *result
= gbt_num_same((void *) b1
, (void *) b2
, &tinfo
);
162 PG_RETURN_POINTER(result
);