PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nbtcompare.c File Reference
#include "postgres.h"
#include "utils/builtins.h"
#include "utils/sortsupport.h"
Include dependency graph for nbtcompare.c:

Go to the source code of this file.

Functions

Datum btboolcmp (PG_FUNCTION_ARGS)
 
Datum btint2cmp (PG_FUNCTION_ARGS)
 
static int btint2fastcmp (Datum x, Datum y, SortSupport ssup)
 
Datum btint2sortsupport (PG_FUNCTION_ARGS)
 
Datum btint4cmp (PG_FUNCTION_ARGS)
 
static int btint4fastcmp (Datum x, Datum y, SortSupport ssup)
 
Datum btint4sortsupport (PG_FUNCTION_ARGS)
 
Datum btint8cmp (PG_FUNCTION_ARGS)
 
static int btint8fastcmp (Datum x, Datum y, SortSupport ssup)
 
Datum btint8sortsupport (PG_FUNCTION_ARGS)
 
Datum btint48cmp (PG_FUNCTION_ARGS)
 
Datum btint84cmp (PG_FUNCTION_ARGS)
 
Datum btint24cmp (PG_FUNCTION_ARGS)
 
Datum btint42cmp (PG_FUNCTION_ARGS)
 
Datum btint28cmp (PG_FUNCTION_ARGS)
 
Datum btint82cmp (PG_FUNCTION_ARGS)
 
Datum btoidcmp (PG_FUNCTION_ARGS)
 
static int btoidfastcmp (Datum x, Datum y, SortSupport ssup)
 
Datum btoidsortsupport (PG_FUNCTION_ARGS)
 
Datum btoidvectorcmp (PG_FUNCTION_ARGS)
 
Datum btcharcmp (PG_FUNCTION_ARGS)
 
Datum btnamecmp (PG_FUNCTION_ARGS)
 
static int btnamefastcmp (Datum x, Datum y, SortSupport ssup)
 
Datum btnamesortsupport (PG_FUNCTION_ARGS)
 

Function Documentation

Datum btboolcmp ( PG_FUNCTION_ARGS  )

Definition at line 56 of file nbtcompare.c.

References PG_GETARG_BOOL, and PG_RETURN_INT32.

57 {
58  bool a = PG_GETARG_BOOL(0);
59  bool b = PG_GETARG_BOOL(1);
60 
61  PG_RETURN_INT32((int32) a - (int32) b);
62 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:239
signed int int32
Definition: c.h:256
Datum btcharcmp ( PG_FUNCTION_ARGS  )

Definition at line 311 of file nbtcompare.c.

References PG_GETARG_CHAR, and PG_RETURN_INT32.

312 {
313  char a = PG_GETARG_CHAR(0);
314  char b = PG_GETARG_CHAR(1);
315 
316  /* Be careful to compare chars as unsigned */
317  PG_RETURN_INT32((int32) ((uint8) a) - (int32) ((uint8) b));
318 }
unsigned char uint8
Definition: c.h:266
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
#define PG_GETARG_CHAR(n)
Definition: fmgr.h:238
Datum btint24cmp ( PG_FUNCTION_ARGS  )

Definition at line 194 of file nbtcompare.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT32.

195 {
196  int16 a = PG_GETARG_INT16(0);
197  int32 b = PG_GETARG_INT32(1);
198 
199  if (a > b)
200  PG_RETURN_INT32(1);
201  else if (a == b)
202  PG_RETURN_INT32(0);
203  else
204  PG_RETURN_INT32(-1);
205 }
signed short int16
Definition: c.h:255
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
Datum btint28cmp ( PG_FUNCTION_ARGS  )

Definition at line 222 of file nbtcompare.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_INT32.

223 {
224  int16 a = PG_GETARG_INT16(0);
225  int64 b = PG_GETARG_INT64(1);
226 
227  if (a > b)
228  PG_RETURN_INT32(1);
229  else if (a == b)
230  PG_RETURN_INT32(0);
231  else
232  PG_RETURN_INT32(-1);
233 }
signed short int16
Definition: c.h:255
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
Datum btint2cmp ( PG_FUNCTION_ARGS  )

Definition at line 65 of file nbtcompare.c.

References PG_GETARG_INT16, and PG_RETURN_INT32.

66 {
67  int16 a = PG_GETARG_INT16(0);
68  int16 b = PG_GETARG_INT16(1);
69 
70  PG_RETURN_INT32((int32) a - (int32) b);
71 }
signed short int16
Definition: c.h:255
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
static int btint2fastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 74 of file nbtcompare.c.

References DatumGetInt16.

Referenced by btint2sortsupport().

75 {
76  int16 a = DatumGetInt16(x);
77  int16 b = DatumGetInt16(y);
78 
79  return (int) a - (int) b;
80 }
signed short int16
Definition: c.h:255
#define DatumGetInt16(X)
Definition: postgres.h:450
Datum btint2sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 83 of file nbtcompare.c.

References btint2fastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

84 {
86 
87  ssup->comparator = btint2fastcmp;
89 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:107
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_VOID()
Definition: fmgr.h:309
static int btint2fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:74
Datum btint42cmp ( PG_FUNCTION_ARGS  )

Definition at line 208 of file nbtcompare.c.

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT32.

209 {
210  int32 a = PG_GETARG_INT32(0);
211  int16 b = PG_GETARG_INT16(1);
212 
213  if (a > b)
214  PG_RETURN_INT32(1);
215  else if (a == b)
216  PG_RETURN_INT32(0);
217  else
218  PG_RETURN_INT32(-1);
219 }
signed short int16
Definition: c.h:255
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
Datum btint48cmp ( PG_FUNCTION_ARGS  )

Definition at line 166 of file nbtcompare.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT32.

167 {
168  int32 a = PG_GETARG_INT32(0);
169  int64 b = PG_GETARG_INT64(1);
170 
171  if (a > b)
172  PG_RETURN_INT32(1);
173  else if (a == b)
174  PG_RETURN_INT32(0);
175  else
176  PG_RETURN_INT32(-1);
177 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
Datum btint4cmp ( PG_FUNCTION_ARGS  )

Definition at line 92 of file nbtcompare.c.

References PG_GETARG_INT32, and PG_RETURN_INT32.

93 {
94  int32 a = PG_GETARG_INT32(0);
95  int32 b = PG_GETARG_INT32(1);
96 
97  if (a > b)
98  PG_RETURN_INT32(1);
99  else if (a == b)
100  PG_RETURN_INT32(0);
101  else
102  PG_RETURN_INT32(-1);
103 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
static int btint4fastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 106 of file nbtcompare.c.

References DatumGetInt32.

Referenced by btint4sortsupport().

107 {
108  int32 a = DatumGetInt32(x);
109  int32 b = DatumGetInt32(y);
110 
111  if (a > b)
112  return 1;
113  else if (a == b)
114  return 0;
115  else
116  return -1;
117 }
#define DatumGetInt32(X)
Definition: postgres.h:478
signed int int32
Definition: c.h:256
Datum btint4sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 120 of file nbtcompare.c.

References btint4fastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

121 {
123 
124  ssup->comparator = btint4fastcmp;
125  PG_RETURN_VOID();
126 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:107
static int btint4fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:106
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_VOID()
Definition: fmgr.h:309
Datum btint82cmp ( PG_FUNCTION_ARGS  )

Definition at line 236 of file nbtcompare.c.

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_INT32.

237 {
238  int64 a = PG_GETARG_INT64(0);
239  int16 b = PG_GETARG_INT16(1);
240 
241  if (a > b)
242  PG_RETURN_INT32(1);
243  else if (a == b)
244  PG_RETURN_INT32(0);
245  else
246  PG_RETURN_INT32(-1);
247 }
signed short int16
Definition: c.h:255
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
Datum btint84cmp ( PG_FUNCTION_ARGS  )

Definition at line 180 of file nbtcompare.c.

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT32.

181 {
182  int64 a = PG_GETARG_INT64(0);
183  int32 b = PG_GETARG_INT32(1);
184 
185  if (a > b)
186  PG_RETURN_INT32(1);
187  else if (a == b)
188  PG_RETURN_INT32(0);
189  else
190  PG_RETURN_INT32(-1);
191 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
Datum btint8cmp ( PG_FUNCTION_ARGS  )

Definition at line 129 of file nbtcompare.c.

References PG_GETARG_INT64, and PG_RETURN_INT32.

130 {
131  int64 a = PG_GETARG_INT64(0);
132  int64 b = PG_GETARG_INT64(1);
133 
134  if (a > b)
135  PG_RETURN_INT32(1);
136  else if (a == b)
137  PG_RETURN_INT32(0);
138  else
139  PG_RETURN_INT32(-1);
140 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
static int btint8fastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 143 of file nbtcompare.c.

References DatumGetInt64.

Referenced by btint8sortsupport().

144 {
145  int64 a = DatumGetInt64(x);
146  int64 b = DatumGetInt64(y);
147 
148  if (a > b)
149  return 1;
150  else if (a == b)
151  return 0;
152  else
153  return -1;
154 }
#define DatumGetInt64(X)
Definition: postgres.h:613
Datum btint8sortsupport ( PG_FUNCTION_ARGS  )

Definition at line 157 of file nbtcompare.c.

References btint8fastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

158 {
160 
161  ssup->comparator = btint8fastcmp;
162  PG_RETURN_VOID();
163 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:107
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define PG_RETURN_VOID()
Definition: fmgr.h:309
static int btint8fastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:143
Datum btnamecmp ( PG_FUNCTION_ARGS  )

Definition at line 321 of file nbtcompare.c.

References NAMEDATALEN, NameStr, PG_GETARG_NAME, and PG_RETURN_INT32.

322 {
323  Name a = PG_GETARG_NAME(0);
324  Name b = PG_GETARG_NAME(1);
325 
326  PG_RETURN_INT32(strncmp(NameStr(*a), NameStr(*b), NAMEDATALEN));
327 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define NAMEDATALEN
Definition: c.h:493
#define NameStr(name)
Definition: c.h:499
#define PG_GETARG_NAME(n)
Definition: fmgr.h:243
static int btnamefastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 330 of file nbtcompare.c.

References DatumGetName, NAMEDATALEN, and NameStr.

Referenced by btnamesortsupport().

331 {
332  Name a = DatumGetName(x);
333  Name b = DatumGetName(y);
334 
335  return strncmp(NameStr(*a), NameStr(*b), NAMEDATALEN);
336 }
#define NAMEDATALEN
#define DatumGetName(X)
Definition: postgres.h:591
Definition: c.h:493
#define NameStr(name)
Definition: c.h:499
Datum btnamesortsupport ( PG_FUNCTION_ARGS  )

Definition at line 339 of file nbtcompare.c.

References btnamefastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

340 {
342 
343  ssup->comparator = btnamefastcmp;
344  PG_RETURN_VOID();
345 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:107
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static int btnamefastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:330
#define PG_RETURN_VOID()
Definition: fmgr.h:309
Datum btoidcmp ( PG_FUNCTION_ARGS  )

Definition at line 250 of file nbtcompare.c.

References PG_GETARG_OID, and PG_RETURN_INT32.

251 {
252  Oid a = PG_GETARG_OID(0);
253  Oid b = PG_GETARG_OID(1);
254 
255  if (a > b)
256  PG_RETURN_INT32(1);
257  else if (a == b)
258  PG_RETURN_INT32(0);
259  else
260  PG_RETURN_INT32(-1);
261 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
unsigned int Oid
Definition: postgres_ext.h:31
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
static int btoidfastcmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 264 of file nbtcompare.c.

References DatumGetObjectId.

Referenced by btoidsortsupport().

265 {
266  Oid a = DatumGetObjectId(x);
267  Oid b = DatumGetObjectId(y);
268 
269  if (a > b)
270  return 1;
271  else if (a == b)
272  return 0;
273  else
274  return -1;
275 }
#define DatumGetObjectId(X)
Definition: postgres.h:506
unsigned int Oid
Definition: postgres_ext.h:31
Datum btoidsortsupport ( PG_FUNCTION_ARGS  )

Definition at line 278 of file nbtcompare.c.

References btoidfastcmp(), SortSupportData::comparator, PG_GETARG_POINTER, and PG_RETURN_VOID.

279 {
281 
282  ssup->comparator = btoidfastcmp;
283  PG_RETURN_VOID();
284 }
struct SortSupportData * SortSupport
Definition: sortsupport.h:58
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Definition: sortsupport.h:107
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
static int btoidfastcmp(Datum x, Datum y, SortSupport ssup)
Definition: nbtcompare.c:264
#define PG_RETURN_VOID()
Definition: fmgr.h:309
Datum btoidvectorcmp ( PG_FUNCTION_ARGS  )

Definition at line 287 of file nbtcompare.c.

References oidvector::dim1, i, PG_GETARG_POINTER, PG_RETURN_INT32, and oidvector::values.

Referenced by oidvectoreq(), oidvectorge(), oidvectorgt(), oidvectorle(), oidvectorlt(), and oidvectorne().

288 {
291  int i;
292 
293  /* We arbitrarily choose to sort first by vector length */
294  if (a->dim1 != b->dim1)
295  PG_RETURN_INT32(a->dim1 - b->dim1);
296 
297  for (i = 0; i < a->dim1; i++)
298  {
299  if (a->values[i] != b->values[i])
300  {
301  if (a->values[i] > b->values[i])
302  PG_RETURN_INT32(1);
303  else
304  PG_RETURN_INT32(-1);
305  }
306  }
307  PG_RETURN_INT32(0);
308 }
Definition: c.h:478
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:486
int dim1
Definition: c.h:484
int i