PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
btree_float4.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
Include dependency graph for btree_float4.c:

Go to the source code of this file.

Data Structures

struct  float4key
 

Typedefs

typedef struct float4key float4KEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_float4_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_union)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_distance)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_float4_same)
 
static bool gbt_float4gt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float4ge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float4eq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float4le (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float4lt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_float4key_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
static float8 gbt_float4_dist (const void *a, const void *b, FmgrInfo *flinfo)
 
 PG_FUNCTION_INFO_V1 (float4_dist)
 
Datum float4_dist (PG_FUNCTION_ARGS)
 
Datum gbt_float4_compress (PG_FUNCTION_ARGS)
 
Datum gbt_float4_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_float4_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_float4_distance (PG_FUNCTION_ARGS)
 
Datum gbt_float4_union (PG_FUNCTION_ARGS)
 
Datum gbt_float4_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_float4_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_float4_same (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Typedef Documentation

Function Documentation

Datum float4_dist ( PG_FUNCTION_ARGS  )

Definition at line 94 of file btree_float4.c.

References Abs, CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT4, and PG_RETURN_FLOAT4.

95 {
96  float4 a = PG_GETARG_FLOAT4(0);
97  float4 b = PG_GETARG_FLOAT4(1);
98  float4 r;
99 
100  r = a - b;
101  CHECKFLOATVAL(r, isinf(a) || isinf(b), true);
102 
103  PG_RETURN_FLOAT4(Abs(r));
104 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
#define Abs(x)
Definition: c.h:813
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float float4
Definition: c.h:380
Datum gbt_float4_compress ( PG_FUNCTION_ARGS  )

Definition at line 113 of file btree_float4.c.

References gbt_num_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

114 {
115  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
116 
118 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)
static const gbtree_ninfo tinfo
Definition: btree_float4.c:77
Datum gbt_float4_consistent ( PG_FUNCTION_ARGS  )

Definition at line 129 of file btree_float4.c.

References DatumGetPointer, gbt_num_consistent(), GIST_LEAF, GISTENTRY::key, float4key::lower, GBT_NUMKEY_R::lower, PG_GETARG_FLOAT4, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, float4key::upper, and GBT_NUMKEY_R::upper.

130 {
131  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
132  float4 query = PG_GETARG_FLOAT4(1);
134 
135  /* Oid subtype = PG_GETARG_OID(3); */
136  bool *recheck = (bool *) PG_GETARG_POINTER(4);
137  float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
138  GBT_NUMKEY_R key;
139 
140  /* All cases served by this function are exact */
141  *recheck = false;
142 
143  key.lower = (GBT_NUMKEY *) &kkk->lower;
144  key.upper = (GBT_NUMKEY *) &kkk->upper;
145 
147  gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
148  );
149 }
#define GIST_LEAF(entry)
Definition: gist.h:133
float4 lower
Definition: btree_float4.c:11
const GBT_NUMKEY * lower
uint16 StrategyNumber
Definition: stratnum.h:22
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float4 upper
Definition: btree_float4.c:12
float float4
Definition: c.h:380
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:237
#define DatumGetPointer(X)
Definition: postgres.h:555
static const gbtree_ninfo tinfo
Definition: btree_float4.c:77
static float8 gbt_float4_dist ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 71 of file btree_float4.c.

References GET_FLOAT_DISTANCE.

72 {
73  return GET_FLOAT_DISTANCE(float4, a, b);
74 }
float float4
Definition: c.h:380
#define GET_FLOAT_DISTANCE(t, arg1, arg2)
Datum gbt_float4_distance ( PG_FUNCTION_ARGS  )

Definition at line 153 of file btree_float4.c.

References DatumGetPointer, gbt_num_distance(), GIST_LEAF, GISTENTRY::key, float4key::lower, GBT_NUMKEY_R::lower, PG_GETARG_FLOAT4, PG_GETARG_POINTER, PG_RETURN_FLOAT8, float4key::upper, and GBT_NUMKEY_R::upper.

154 {
155  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
156  float4 query = PG_GETARG_FLOAT4(1);
157 
158  /* Oid subtype = PG_GETARG_OID(3); */
159  float4KEY *kkk = (float4KEY *) DatumGetPointer(entry->key);
160  GBT_NUMKEY_R key;
161 
162  key.lower = (GBT_NUMKEY *) &kkk->lower;
163  key.upper = (GBT_NUMKEY *) &kkk->upper;
164 
166  gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
167  );
168 }
#define GIST_LEAF(entry)
Definition: gist.h:133
float4 lower
Definition: btree_float4.c:11
const GBT_NUMKEY * lower
float8 gbt_num_distance(const GBT_NUMKEY_R *key, const void *query, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Datum key
Definition: gist.h:123
char GBT_NUMKEY
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
float4 upper
Definition: btree_float4.c:12
float float4
Definition: c.h:380
#define DatumGetPointer(X)
Definition: postgres.h:555
static const gbtree_ninfo tinfo
Definition: btree_float4.c:77
Datum gbt_float4_fetch ( PG_FUNCTION_ARGS  )

Definition at line 121 of file btree_float4.c.

References gbt_num_fetch(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

122 {
123  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
124 
126 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_float4.c:77
Datum gbt_float4_penalty ( PG_FUNCTION_ARGS  )

Definition at line 183 of file btree_float4.c.

References DatumGetPointer, float4key::lower, penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, result, and float4key::upper.

184 {
185  float4KEY *origentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
186  float4KEY *newentry = (float4KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
187  float *result = (float *) PG_GETARG_POINTER(2);
188 
189  penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
190 
191  PG_RETURN_POINTER(result);
192 
193 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
float4 lower
Definition: btree_float4.c:11
return result
Definition: formatting.c:1633
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define penalty_num(result, olower, oupper, nlower, nupper)
float4 upper
Definition: btree_float4.c:12
#define DatumGetPointer(X)
Definition: postgres.h:555
Datum gbt_float4_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 196 of file btree_float4.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

197 {
201  &tinfo, fcinfo->flinfo
202  ));
203 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static const gbtree_ninfo tinfo
Definition: btree_float4.c:77
Datum gbt_float4_same ( PG_FUNCTION_ARGS  )

Definition at line 206 of file btree_float4.c.

References gbt_num_same(), PG_GETARG_POINTER, PG_RETURN_POINTER, and result.

207 {
210  bool *result = (bool *) PG_GETARG_POINTER(2);
211 
212  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
213  PG_RETURN_POINTER(result);
214 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
return result
Definition: formatting.c:1633
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_float4.c:77
Datum gbt_float4_union ( PG_FUNCTION_ARGS  )

Definition at line 172 of file btree_float4.c.

References gbt_num_union(), palloc(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

173 {
175  void *out = palloc(sizeof(float4KEY));
176 
177  *(int *) PG_GETARG_POINTER(1) = sizeof(float4KEY);
178  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
179 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
struct float4key float4KEY
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static const gbtree_ninfo tinfo
Definition: btree_float4.c:77
void * palloc(Size size)
Definition: mcxt.c:849
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
static bool gbt_float4eq ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 38 of file btree_float4.c.

39 {
40  return (*((const float4 *) a) == *((const float4 *) b));
41 }
float float4
Definition: c.h:380
static bool gbt_float4ge ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 33 of file btree_float4.c.

34 {
35  return (*((const float4 *) a) >= *((const float4 *) b));
36 }
float float4
Definition: c.h:380
static bool gbt_float4gt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 28 of file btree_float4.c.

29 {
30  return (*((const float4 *) a) > *((const float4 *) b));
31 }
float float4
Definition: c.h:380
static int gbt_float4key_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 54 of file btree_float4.c.

References float4key::lower, and float4key::upper.

55 {
56  float4KEY *ia = (float4KEY *) (((const Nsrt *) a)->t);
57  float4KEY *ib = (float4KEY *) (((const Nsrt *) b)->t);
58 
59  if (ia->lower == ib->lower)
60  {
61  if (ia->upper == ib->upper)
62  return 0;
63 
64  return (ia->upper > ib->upper) ? 1 : -1;
65  }
66 
67  return (ia->lower > ib->lower) ? 1 : -1;
68 }
float4 lower
Definition: btree_float4.c:11
float4 upper
Definition: btree_float4.c:12
static bool gbt_float4le ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 43 of file btree_float4.c.

44 {
45  return (*((const float4 *) a) <= *((const float4 *) b));
46 }
float float4
Definition: c.h:380
static bool gbt_float4lt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 48 of file btree_float4.c.

49 {
50  return (*((const float4 *) a) < *((const float4 *) b));
51 }
float float4
Definition: c.h:380
PG_FUNCTION_INFO_V1 ( gbt_float4_compress  )
PG_FUNCTION_INFO_V1 ( gbt_float4_fetch  )
PG_FUNCTION_INFO_V1 ( gbt_float4_union  )
PG_FUNCTION_INFO_V1 ( gbt_float4_picksplit  )
PG_FUNCTION_INFO_V1 ( gbt_float4_consistent  )
PG_FUNCTION_INFO_V1 ( gbt_float4_distance  )
PG_FUNCTION_INFO_V1 ( gbt_float4_penalty  )
PG_FUNCTION_INFO_V1 ( gbt_float4_same  )
PG_FUNCTION_INFO_V1 ( float4_dist  )

Variable Documentation

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(float4),
8,
}
static bool gbt_float4eq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:38
static bool gbt_float4le(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:43
static bool gbt_float4lt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:48
static bool gbt_float4gt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:28
static int gbt_float4key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:54
float float4
Definition: c.h:380
static bool gbt_float4ge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:33
static float8 gbt_float4_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float4.c:71

Definition at line 77 of file btree_float4.c.