PostgreSQL Source Code  git master
btree_float8.c File Reference
#include "postgres.h"
#include "btree_gist.h"
#include "btree_utils_num.h"
Include dependency graph for btree_float8.c:

Go to the source code of this file.

Data Structures

struct  float8key
 

Typedefs

typedef struct float8key float8KEY
 

Functions

 PG_FUNCTION_INFO_V1 (gbt_float8_compress)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_fetch)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_union)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_picksplit)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_consistent)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_distance)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_penalty)
 
 PG_FUNCTION_INFO_V1 (gbt_float8_same)
 
static bool gbt_float8gt (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8ge (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8eq (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8le (const void *a, const void *b, FmgrInfo *flinfo)
 
static bool gbt_float8lt (const void *a, const void *b, FmgrInfo *flinfo)
 
static int gbt_float8key_cmp (const void *a, const void *b, FmgrInfo *flinfo)
 
static float8 gbt_float8_dist (const void *a, const void *b, FmgrInfo *flinfo)
 
 PG_FUNCTION_INFO_V1 (float8_dist)
 
Datum float8_dist (PG_FUNCTION_ARGS)
 
Datum gbt_float8_compress (PG_FUNCTION_ARGS)
 
Datum gbt_float8_fetch (PG_FUNCTION_ARGS)
 
Datum gbt_float8_consistent (PG_FUNCTION_ARGS)
 
Datum gbt_float8_distance (PG_FUNCTION_ARGS)
 
Datum gbt_float8_union (PG_FUNCTION_ARGS)
 
Datum gbt_float8_penalty (PG_FUNCTION_ARGS)
 
Datum gbt_float8_picksplit (PG_FUNCTION_ARGS)
 
Datum gbt_float8_same (PG_FUNCTION_ARGS)
 

Variables

static const gbtree_ninfo tinfo
 

Typedef Documentation

◆ float8KEY

typedef struct float8key float8KEY

Function Documentation

◆ float8_dist()

Datum float8_dist ( PG_FUNCTION_ARGS  )

Definition at line 102 of file btree_float8.c.

References Abs, CHECKFLOATVAL, isinf(), PG_GETARG_FLOAT8, and PG_RETURN_FLOAT8.

103 {
104  float8 a = PG_GETARG_FLOAT8(0);
105  float8 b = PG_GETARG_FLOAT8(1);
106  float8 r;
107 
108  r = a - b;
109  CHECKFLOATVAL(r, isinf(a) || isinf(b), true);
110 
111  PG_RETURN_FLOAT8(Abs(r));
112 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
#define Abs(x)
Definition: c.h:910
double float8
Definition: c.h:491
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)

◆ gbt_float8_compress()

Datum gbt_float8_compress ( PG_FUNCTION_ARGS  )

Definition at line 120 of file btree_float8.c.

References gbt_num_compress(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

121 {
122  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
123 
125 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
static const gbtree_ninfo tinfo
Definition: btree_float8.c:85
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
GISTENTRY * gbt_num_compress(GISTENTRY *entry, const gbtree_ninfo *tinfo)

◆ gbt_float8_consistent()

Datum gbt_float8_consistent ( PG_FUNCTION_ARGS  )

Definition at line 136 of file btree_float8.c.

References DatumGetPointer, gbt_num_consistent(), GIST_LEAF, sort-test::key, GISTENTRY::key, float8key::lower, GBT_NUMKEY_R::lower, PG_GETARG_FLOAT8, PG_GETARG_POINTER, PG_GETARG_UINT16, PG_RETURN_BOOL, float8key::upper, and GBT_NUMKEY_R::upper.

137 {
138  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
139  float8 query = PG_GETARG_FLOAT8(1);
141 
142  /* Oid subtype = PG_GETARG_OID(3); */
143  bool *recheck = (bool *) PG_GETARG_POINTER(4);
144  float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
146 
147  /* All cases served by this function are exact */
148  *recheck = false;
149 
150  key.lower = (GBT_NUMKEY *) &kkk->lower;
151  key.upper = (GBT_NUMKEY *) &kkk->upper;
152 
154  gbt_num_consistent(&key, (void *) &query, &strategy, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
155  );
156 }
#define GIST_LEAF(entry)
Definition: gist.h:141
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
static const gbtree_ninfo tinfo
Definition: btree_float8.c:85
const GBT_NUMKEY * lower
uint16 StrategyNumber
Definition: stratnum.h:22
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
bool gbt_num_consistent(const GBT_NUMKEY_R *key, const void *query, const StrategyNumber *strategy, bool is_leaf, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
double float8
Definition: c.h:491
Datum key
Definition: gist.h:131
char GBT_NUMKEY
float8 upper
Definition: btree_float8.c:12
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define PG_GETARG_UINT16(n)
Definition: fmgr.h:267
#define DatumGetPointer(X)
Definition: postgres.h:549
float8 lower
Definition: btree_float8.c:11

◆ gbt_float8_dist()

static float8 gbt_float8_dist ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 72 of file btree_float8.c.

References Abs, CHECKFLOATVAL, and isinf().

73 {
74  float8 arg1 = *(const float8 *) a;
75  float8 arg2 = *(const float8 *) b;
76  float8 r;
77 
78  r = arg1 - arg2;
79  CHECKFLOATVAL(r, isinf(arg1) || isinf(arg2), true);
80 
81  return Abs(r);
82 }
#define Abs(x)
Definition: c.h:910
double float8
Definition: c.h:491
int isinf(double x)
#define CHECKFLOATVAL(val, inf_is_valid, zero_is_valid)

◆ gbt_float8_distance()

Datum gbt_float8_distance ( PG_FUNCTION_ARGS  )

Definition at line 160 of file btree_float8.c.

References DatumGetPointer, gbt_num_distance(), GIST_LEAF, sort-test::key, GISTENTRY::key, float8key::lower, GBT_NUMKEY_R::lower, PG_GETARG_FLOAT8, PG_GETARG_POINTER, PG_RETURN_FLOAT8, float8key::upper, and GBT_NUMKEY_R::upper.

161 {
162  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
163  float8 query = PG_GETARG_FLOAT8(1);
164 
165  /* Oid subtype = PG_GETARG_OID(3); */
166  float8KEY *kkk = (float8KEY *) DatumGetPointer(entry->key);
168 
169  key.lower = (GBT_NUMKEY *) &kkk->lower;
170  key.upper = (GBT_NUMKEY *) &kkk->upper;
171 
173  gbt_num_distance(&key, (void *) &query, GIST_LEAF(entry), &tinfo, fcinfo->flinfo)
174  );
175 }
#define GIST_LEAF(entry)
Definition: gist.h:141
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
static const gbtree_ninfo tinfo
Definition: btree_float8.c:85
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:356
const GBT_NUMKEY * upper
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
double float8
Definition: c.h:491
Datum key
Definition: gist.h:131
char GBT_NUMKEY
float8 upper
Definition: btree_float8.c:12
#define DatumGetPointer(X)
Definition: postgres.h:549
float8 lower
Definition: btree_float8.c:11

◆ gbt_float8_fetch()

Datum gbt_float8_fetch ( PG_FUNCTION_ARGS  )

Definition at line 128 of file btree_float8.c.

References gbt_num_fetch(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

129 {
130  GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
131 
133 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
static const gbtree_ninfo tinfo
Definition: btree_float8.c:85
GISTENTRY * gbt_num_fetch(GISTENTRY *entry, const gbtree_ninfo *tinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271

◆ gbt_float8_penalty()

Datum gbt_float8_penalty ( PG_FUNCTION_ARGS  )

Definition at line 190 of file btree_float8.c.

References DatumGetPointer, sort-test::key, float8key::lower, penalty_num, PG_GETARG_POINTER, PG_RETURN_POINTER, and float8key::upper.

191 {
192  float8KEY *origentry = (float8KEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
194  float *result = (float *) PG_GETARG_POINTER(2);
195 
196  penalty_num(result, origentry->lower, origentry->upper, newentry->lower, newentry->upper);
197 
198  PG_RETURN_POINTER(result);
199 
200 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define penalty_num(result, olower, oupper, nlower, nupper)
float8 upper
Definition: btree_float8.c:12
#define DatumGetPointer(X)
Definition: postgres.h:549
float8 lower
Definition: btree_float8.c:11

◆ gbt_float8_picksplit()

Datum gbt_float8_picksplit ( PG_FUNCTION_ARGS  )

Definition at line 203 of file btree_float8.c.

References gbt_num_picksplit(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

204 {
208  &tinfo, fcinfo->flinfo
209  ));
210 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
static const gbtree_ninfo tinfo
Definition: btree_float8.c:85
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
GIST_SPLITVEC * gbt_num_picksplit(const GistEntryVector *entryvec, GIST_SPLITVEC *v, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

◆ gbt_float8_same()

Datum gbt_float8_same ( PG_FUNCTION_ARGS  )

Definition at line 213 of file btree_float8.c.

References gbt_num_same(), PG_GETARG_POINTER, and PG_RETURN_POINTER.

214 {
217  bool *result = (bool *) PG_GETARG_POINTER(2);
218 
219  *result = gbt_num_same((void *) b1, (void *) b2, &tinfo, fcinfo->flinfo);
220  PG_RETURN_POINTER(result);
221 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
static const gbtree_ninfo tinfo
Definition: btree_float8.c:85
bool gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271

◆ gbt_float8_union()

Datum gbt_float8_union ( PG_FUNCTION_ARGS  )

Definition at line 179 of file btree_float8.c.

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

180 {
182  void *out = palloc(sizeof(float8KEY));
183 
184  *(int *) PG_GETARG_POINTER(1) = sizeof(float8KEY);
185  PG_RETURN_POINTER(gbt_num_union((void *) out, entryvec, &tinfo, fcinfo->flinfo));
186 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
static const gbtree_ninfo tinfo
Definition: btree_float8.c:85
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
struct float8key float8KEY
void * palloc(Size size)
Definition: mcxt.c:949
void * gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_ninfo *tinfo, FmgrInfo *flinfo)

◆ gbt_float8eq()

static bool gbt_float8eq ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 39 of file btree_float8.c.

40 {
41  return (*((const float8 *) a) == *((const float8 *) b));
42 }
double float8
Definition: c.h:491

◆ gbt_float8ge()

static bool gbt_float8ge ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 34 of file btree_float8.c.

35 {
36  return (*((const float8 *) a) >= *((const float8 *) b));
37 }
double float8
Definition: c.h:491

◆ gbt_float8gt()

static bool gbt_float8gt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 29 of file btree_float8.c.

30 {
31  return (*((const float8 *) a) > *((const float8 *) b));
32 }
double float8
Definition: c.h:491

◆ gbt_float8key_cmp()

static int gbt_float8key_cmp ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 55 of file btree_float8.c.

References float8key::lower, and float8key::upper.

56 {
57  float8KEY *ia = (float8KEY *) (((const Nsrt *) a)->t);
58  float8KEY *ib = (float8KEY *) (((const Nsrt *) b)->t);
59 
60  if (ia->lower == ib->lower)
61  {
62  if (ia->upper == ib->upper)
63  return 0;
64 
65  return (ia->upper > ib->upper) ? 1 : -1;
66  }
67 
68  return (ia->lower > ib->lower) ? 1 : -1;
69 }
float8 upper
Definition: btree_float8.c:12
float8 lower
Definition: btree_float8.c:11

◆ gbt_float8le()

static bool gbt_float8le ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 44 of file btree_float8.c.

45 {
46  return (*((const float8 *) a) <= *((const float8 *) b));
47 }
double float8
Definition: c.h:491

◆ gbt_float8lt()

static bool gbt_float8lt ( const void *  a,
const void *  b,
FmgrInfo flinfo 
)
static

Definition at line 49 of file btree_float8.c.

50 {
51  return (*((const float8 *) a) < *((const float8 *) b));
52 }
double float8
Definition: c.h:491

◆ PG_FUNCTION_INFO_V1() [1/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_compress  )

◆ PG_FUNCTION_INFO_V1() [2/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_fetch  )

◆ PG_FUNCTION_INFO_V1() [3/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_union  )

◆ PG_FUNCTION_INFO_V1() [4/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_picksplit  )

◆ PG_FUNCTION_INFO_V1() [5/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_consistent  )

◆ PG_FUNCTION_INFO_V1() [6/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_distance  )

◆ PG_FUNCTION_INFO_V1() [7/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_penalty  )

◆ PG_FUNCTION_INFO_V1() [8/9]

PG_FUNCTION_INFO_V1 ( gbt_float8_same  )

◆ PG_FUNCTION_INFO_V1() [9/9]

PG_FUNCTION_INFO_V1 ( float8_dist  )

Variable Documentation

◆ tinfo

const gbtree_ninfo tinfo
static
Initial value:
=
{
sizeof(float8),
16,
}
static float8 gbt_float8_dist(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:72
static bool gbt_float8lt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:49
double float8
Definition: c.h:491
static int gbt_float8key_cmp(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:55
static bool gbt_float8eq(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:39
static bool gbt_float8le(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:44
static bool gbt_float8ge(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:34
static bool gbt_float8gt(const void *a, const void *b, FmgrInfo *flinfo)
Definition: btree_float8.c:29

Definition at line 85 of file btree_float8.c.