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

Go to the source code of this file.

Functions

 PG_FUNCTION_INFO_V1 (_int_different)
 
 PG_FUNCTION_INFO_V1 (_int_same)
 
 PG_FUNCTION_INFO_V1 (_int_contains)
 
 PG_FUNCTION_INFO_V1 (_int_contained)
 
 PG_FUNCTION_INFO_V1 (_int_overlap)
 
 PG_FUNCTION_INFO_V1 (_int_union)
 
 PG_FUNCTION_INFO_V1 (_int_inter)
 
Datum _int_contained (PG_FUNCTION_ARGS)
 
Datum _int_contains (PG_FUNCTION_ARGS)
 
Datum _int_different (PG_FUNCTION_ARGS)
 
Datum _int_same (PG_FUNCTION_ARGS)
 
Datum _int_overlap (PG_FUNCTION_ARGS)
 
Datum _int_union (PG_FUNCTION_ARGS)
 
Datum _int_inter (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (intset)
 
 PG_FUNCTION_INFO_V1 (icount)
 
 PG_FUNCTION_INFO_V1 (sort)
 
 PG_FUNCTION_INFO_V1 (sort_asc)
 
 PG_FUNCTION_INFO_V1 (sort_desc)
 
 PG_FUNCTION_INFO_V1 (uniq)
 
 PG_FUNCTION_INFO_V1 (idx)
 
 PG_FUNCTION_INFO_V1 (subarray)
 
 PG_FUNCTION_INFO_V1 (intarray_push_elem)
 
 PG_FUNCTION_INFO_V1 (intarray_push_array)
 
 PG_FUNCTION_INFO_V1 (intarray_del_elem)
 
 PG_FUNCTION_INFO_V1 (intset_union_elem)
 
 PG_FUNCTION_INFO_V1 (intset_subtract)
 
Datum intset (PG_FUNCTION_ARGS)
 
Datum icount (PG_FUNCTION_ARGS)
 
Datum sort (PG_FUNCTION_ARGS)
 
Datum sort_asc (PG_FUNCTION_ARGS)
 
Datum sort_desc (PG_FUNCTION_ARGS)
 
Datum uniq (PG_FUNCTION_ARGS)
 
Datum idx (PG_FUNCTION_ARGS)
 
Datum subarray (PG_FUNCTION_ARGS)
 
Datum intarray_push_elem (PG_FUNCTION_ARGS)
 
Datum intarray_push_array (PG_FUNCTION_ARGS)
 
Datum intarray_del_elem (PG_FUNCTION_ARGS)
 
Datum intset_union_elem (PG_FUNCTION_ARGS)
 
Datum intset_subtract (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 

Function Documentation

Datum _int_contained ( PG_FUNCTION_ARGS  )

Definition at line 20 of file _int_op.c.

References _int_contains(), DirectFunctionCall2, and PG_GETARG_DATUM.

21 {
22  /* just reverse the operands and call _int_contains */
24  PG_GETARG_DATUM(1),
25  PG_GETARG_DATUM(0));
26 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:233
Datum _int_contains(PG_FUNCTION_ARGS)
Definition: _int_op.c:29
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum _int_contains ( PG_FUNCTION_ARGS  )

Definition at line 29 of file _int_op.c.

References CHECKARRVALID, inner_int_contains(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_BOOL, and PREPAREARR.

Referenced by _int_contained().

30 {
31  /* Force copy so we can modify the arrays in-place */
34  bool res;
35 
36  CHECKARRVALID(a);
37  CHECKARRVALID(b);
38  PREPAREARR(a);
39  PREPAREARR(b);
40  res = inner_int_contains(a, b);
41  pfree(a);
42  pfree(b);
43  PG_RETURN_BOOL(res);
44 }
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
#define PREPAREARR(x)
Definition: _int.h:37
void pfree(void *pointer)
Definition: mcxt.c:950
bool inner_int_contains(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:13
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum _int_different ( PG_FUNCTION_ARGS  )

Definition at line 47 of file _int_op.c.

References _int_same(), DatumGetBool, DirectFunctionCall2, PG_GETARG_POINTER, PG_RETURN_BOOL, and PointerGetDatum.

48 {
51  _int_same,
54  )
55  ));
56 }
#define PointerGetDatum(X)
Definition: postgres.h:562
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
#define DatumGetBool(X)
Definition: postgres.h:399
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum _int_same(PG_FUNCTION_ARGS)
Definition: _int_op.c:59
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:586
Datum _int_inter ( PG_FUNCTION_ARGS  )

Definition at line 148 of file _int_op.c.

References CHECKARRVALID, inner_int_inter(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, result, and SORT.

149 {
152  ArrayType *result;
153 
154  CHECKARRVALID(a);
155  CHECKARRVALID(b);
156 
157  SORT(a);
158  SORT(b);
159 
160  result = inner_int_inter(a, b);
161 
162  pfree(a);
163  pfree(b);
164 
165  PG_RETURN_POINTER(result);
166 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
return result
Definition: formatting.c:1633
ArrayType * inner_int_inter(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:134
#define SORT(x)
Definition: _int.h:29
void pfree(void *pointer)
Definition: mcxt.c:950
Datum _int_overlap ( PG_FUNCTION_ARGS  )

Definition at line 104 of file _int_op.c.

References ARRISEMPTY, CHECKARRVALID, FALSE, inner_int_overlap(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_BOOL, result, and SORT.

105 {
108  bool result;
109 
110  CHECKARRVALID(a);
111  CHECKARRVALID(b);
112  if (ARRISEMPTY(a) || ARRISEMPTY(b))
113  return FALSE;
114 
115  SORT(a);
116  SORT(b);
117 
118  result = inner_int_overlap(a, b);
119 
120  pfree(a);
121  pfree(b);
122 
123  PG_RETURN_BOOL(result);
124 }
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
return result
Definition: formatting.c:1633
#define SORT(x)
Definition: _int.h:29
void pfree(void *pointer)
Definition: mcxt.c:950
#define FALSE
Definition: c.h:221
bool inner_int_overlap(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:48
#define ARRISEMPTY(x)
Definition: _int.h:26
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
Datum _int_same ( PG_FUNCTION_ARGS  )

Definition at line 59 of file _int_op.c.

References ARRNELEMS, ARRPTR, CHECKARRVALID, FALSE, pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_BOOL, result, SORT, and TRUE.

Referenced by _int_different().

60 {
63  int na,
64  nb;
65  int n;
66  int *da,
67  *db;
68  bool result;
69 
70  CHECKARRVALID(a);
71  CHECKARRVALID(b);
72  na = ARRNELEMS(a);
73  nb = ARRNELEMS(b);
74  da = ARRPTR(a);
75  db = ARRPTR(b);
76 
77  result = FALSE;
78 
79  if (na == nb)
80  {
81  SORT(a);
82  SORT(b);
83  result = TRUE;
84 
85  for (n = 0; n < na; n++)
86  {
87  if (da[n] != db[n])
88  {
89  result = FALSE;
90  break;
91  }
92  }
93  }
94 
95  pfree(a);
96  pfree(b);
97 
98  PG_RETURN_BOOL(result);
99 }
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
return result
Definition: formatting.c:1633
#define SORT(x)
Definition: _int.h:29
void pfree(void *pointer)
Definition: mcxt.c:950
#define FALSE
Definition: c.h:221
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:319
#define ARRNELEMS(x)
Definition: cube.c:27
#define TRUE
Definition: c.h:217
#define ARRPTR(x)
Definition: cube.c:26
Datum _int_union ( PG_FUNCTION_ARGS  )

Definition at line 127 of file _int_op.c.

References CHECKARRVALID, inner_int_union(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, result, and SORT.

128 {
131  ArrayType *result;
132 
133  CHECKARRVALID(a);
134  CHECKARRVALID(b);
135 
136  SORT(a);
137  SORT(b);
138 
139  result = inner_int_union(a, b);
140 
141  pfree(a);
142  pfree(b);
143 
144  PG_RETURN_POINTER(result);
145 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
return result
Definition: formatting.c:1633
#define SORT(x)
Definition: _int.h:29
void pfree(void *pointer)
Definition: mcxt.c:950
ArrayType * inner_int_union(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:77
Datum icount ( PG_FUNCTION_ARGS  )

Definition at line 190 of file _int_op.c.

References ARRNELEMS, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

191 {
193  int32 count = ARRNELEMS(a);
194 
195  PG_FREE_IF_COPY(a, 0);
196  PG_RETURN_INT32(count);
197 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
signed int int32
Definition: c.h:256
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
#define ARRNELEMS(x)
Definition: cube.c:27

Definition at line 264 of file _int_op.c.

References ARRNELEMS, CHECKARRVALID, intarray_match_first(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, PG_RETURN_INT32, and result.

Referenced by aclexplode(), AllocSetFreeIndex(), appendStringInfoRegexpSubstr(), avlCollectFields(), brin_revmap_data(), cube_subset(), disable_timeouts(), ExecHashIncreaseNumBatches(), ExecHashIncreaseNumBuckets(), GetXLogBuffer(), hstore_contains(), hstore_defined(), hstore_exists(), hstore_exists_all(), hstore_exists_any(), hstore_fetchval(), hstore_populate_record(), hstore_slice_to_array(), hstore_slice_to_hstore(), indexOfColumn(), jsonb_delete_idx(), Lookahead(), percentile_cont_multi_final_common(), percentile_disc_multi_final(), pg_mb_radix_conv(), PLySequence_ToComposite(), printCrosstab(), range_gist_double_sorting_split(), range_gist_single_sorting_split(), ResourceArrayAdd(), ResourceArrayRemove(), ri_ReportViolation(), setPathArray(), SlabAlloc(), SlabFree(), tbm_prepare_shared_iterate(), and transformArraySubscripts().

265 {
267  int32 result;
268 
269  CHECKARRVALID(a);
270  result = ARRNELEMS(a);
271  if (result)
272  result = intarray_match_first(a, PG_GETARG_INT32(1));
273  PG_FREE_IF_COPY(a, 0);
274  PG_RETURN_INT32(result);
275 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define CHECKARRVALID(x)
Definition: _int.h:18
#define PG_RETURN_INT32(x)
Definition: fmgr.h:314
return result
Definition: formatting.c:1633
signed int int32
Definition: c.h:256
int32 intarray_match_first(ArrayType *a, int32 elem)
Definition: _int_tool.c:329
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
#define ARRNELEMS(x)
Definition: cube.c:27
Datum intarray_del_elem ( PG_FUNCTION_ARGS  )

Definition at line 352 of file _int_op.c.

References ARRISEMPTY, ARRNELEMS, ARRPTR, CHECKARRVALID, i, PG_GETARG_ARRAYTYPE_P_COPY, PG_GETARG_INT32, PG_RETURN_POINTER, and resize_intArrayType().

353 {
355  int32 elem = PG_GETARG_INT32(1);
356  int32 c;
357  int32 *aa;
358  int32 n = 0,
359  i;
360 
361  CHECKARRVALID(a);
362  if (!ARRISEMPTY(a))
363  {
364  c = ARRNELEMS(a);
365  aa = ARRPTR(a);
366  for (i = 0; i < c; i++)
367  {
368  if (aa[i] != elem)
369  {
370  if (i > n)
371  aa[n++] = aa[i];
372  else
373  n++;
374  }
375  }
376  a = resize_intArrayType(a, n);
377  }
379 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
signed int int32
Definition: c.h:256
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:238
char * c
#define ARRISEMPTY(x)
Definition: _int.h:26
#define ARRNELEMS(x)
Definition: cube.c:27
int i
#define ARRPTR(x)
Definition: cube.c:26
Datum intarray_push_array ( PG_FUNCTION_ARGS  )

Definition at line 339 of file _int_op.c.

References intarray_concat_arrays(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_RETURN_POINTER, and result.

340 {
343  ArrayType *result;
344 
345  result = intarray_concat_arrays(a, b);
346  PG_FREE_IF_COPY(a, 0);
347  PG_FREE_IF_COPY(b, 1);
348  PG_RETURN_POINTER(result);
349 }
ArrayType * intarray_concat_arrays(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:362
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
return result
Definition: formatting.c:1633
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
Datum intarray_push_elem ( PG_FUNCTION_ARGS  )

Definition at line 328 of file _int_op.c.

References intarray_add_elem(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, PG_RETURN_POINTER, and result.

329 {
331  ArrayType *result;
332 
333  result = intarray_add_elem(a, PG_GETARG_INT32(1));
334  PG_FREE_IF_COPY(a, 0);
335  PG_RETURN_POINTER(result);
336 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
return result
Definition: formatting.c:1633
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
ArrayType * intarray_add_elem(ArrayType *a, int32 elem)
Definition: _int_tool.c:345
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
Datum intset ( PG_FUNCTION_ARGS  )

Definition at line 184 of file _int_op.c.

References int_to_intset(), PG_GETARG_INT32, and PG_RETURN_POINTER.

185 {
187 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
ArrayType * int_to_intset(int32 elem)
Definition: _int_tool.c:379
Datum intset_subtract ( PG_FUNCTION_ARGS  )

Definition at line 394 of file _int_op.c.

References _int_unique(), ARRNELEMS, ARRPTR, CHECKARRVALID, i, new_intArrayType(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, QSORT, resize_intArrayType(), and result.

395 {
398  ArrayType *result;
399  int32 ca;
400  int32 cb;
401  int32 *aa,
402  *bb,
403  *r;
404  int32 n = 0,
405  i = 0,
406  k = 0;
407 
408  CHECKARRVALID(a);
409  CHECKARRVALID(b);
410 
411  QSORT(a, 1);
412  a = _int_unique(a);
413  ca = ARRNELEMS(a);
414  QSORT(b, 1);
415  b = _int_unique(b);
416  cb = ARRNELEMS(b);
417  result = new_intArrayType(ca);
418  aa = ARRPTR(a);
419  bb = ARRPTR(b);
420  r = ARRPTR(result);
421  while (i < ca)
422  {
423  if (k == cb || aa[i] < bb[k])
424  r[n++] = aa[i++];
425  else if (aa[i] == bb[k])
426  {
427  i++;
428  k++;
429  }
430  else
431  k++;
432  }
433  result = resize_intArrayType(result, n);
434  pfree(a);
435  pfree(b);
436  PG_RETURN_POINTER(result);
437 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
return result
Definition: formatting.c:1633
signed int int32
Definition: c.h:256
#define QSORT(a, direction)
Definition: _int.h:168
void pfree(void *pointer)
Definition: mcxt.c:950
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:238
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:220
ArrayType * _int_unique(ArrayType *a)
Definition: _int_tool.c:294
#define ARRNELEMS(x)
Definition: cube.c:27
int i
#define ARRPTR(x)
Definition: cube.c:26
Datum intset_union_elem ( PG_FUNCTION_ARGS  )

Definition at line 382 of file _int_op.c.

References _int_unique(), intarray_add_elem(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, PG_RETURN_POINTER, QSORT, and result.

383 {
385  ArrayType *result;
386 
387  result = intarray_add_elem(a, PG_GETARG_INT32(1));
388  PG_FREE_IF_COPY(a, 0);
389  QSORT(result, 1);
391 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
return result
Definition: formatting.c:1633
#define QSORT(a, direction)
Definition: _int.h:168
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
ArrayType * _int_unique(ArrayType *a)
Definition: _int_tool.c:294
ArrayType * intarray_add_elem(ArrayType *a, int32 elem)
Definition: _int_tool.c:345
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
PG_FUNCTION_INFO_V1 ( _int_different  )
PG_FUNCTION_INFO_V1 ( _int_same  )
PG_FUNCTION_INFO_V1 ( _int_contains  )
PG_FUNCTION_INFO_V1 ( _int_contained  )
PG_FUNCTION_INFO_V1 ( _int_overlap  )
PG_FUNCTION_INFO_V1 ( _int_union  )
PG_FUNCTION_INFO_V1 ( _int_inter  )
PG_FUNCTION_INFO_V1 ( intset  )
PG_FUNCTION_INFO_V1 ( icount  )
PG_FUNCTION_INFO_V1 ( sort  )
PG_FUNCTION_INFO_V1 ( sort_asc  )
PG_FUNCTION_INFO_V1 ( sort_desc  )
PG_FUNCTION_INFO_V1 ( uniq  )
PG_FUNCTION_INFO_V1 ( idx  )
PG_FUNCTION_INFO_V1 ( subarray  )
PG_FUNCTION_INFO_V1 ( intarray_push_elem  )
PG_FUNCTION_INFO_V1 ( intarray_push_array  )
PG_FUNCTION_INFO_V1 ( intarray_del_elem  )
PG_FUNCTION_INFO_V1 ( intset_union_elem  )
PG_FUNCTION_INFO_V1 ( intset_subtract  )
Datum sort ( PG_FUNCTION_ARGS  )

Definition at line 200 of file _int_op.c.

References ARRNELEMS, CHECKARRVALID, ereport, errcode(), errmsg(), ERROR, NULL, PG_GETARG_ARRAYTYPE_P_COPY, PG_GETARG_TEXT_PP, PG_RETURN_POINTER, QSORT, VARDATA_ANY, and VARSIZE_ANY_EXHDR.

Referenced by create_merge_append_plan(), create_mergejoin_plan(), and create_unique_plan().

201 {
203  text *dirstr = (fcinfo->nargs == 2) ? PG_GETARG_TEXT_PP(1) : NULL;
204  int32 dc = (dirstr) ? VARSIZE_ANY_EXHDR(dirstr) : 0;
205  char *d = (dirstr) ? VARDATA_ANY(dirstr) : NULL;
206  int dir = -1;
207 
208  CHECKARRVALID(a);
209  if (ARRNELEMS(a) < 2)
211 
212  if (dirstr == NULL || (dc == 3
213  && (d[0] == 'A' || d[0] == 'a')
214  && (d[1] == 'S' || d[1] == 's')
215  && (d[2] == 'C' || d[2] == 'c')))
216  dir = 1;
217  else if (dc == 4
218  && (d[0] == 'D' || d[0] == 'd')
219  && (d[1] == 'E' || d[1] == 'e')
220  && (d[2] == 'S' || d[2] == 's')
221  && (d[3] == 'C' || d[3] == 'c'))
222  dir = 0;
223  if (dir == -1)
224  ereport(ERROR,
225  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
226  errmsg("second parameter must be \"ASC\" or \"DESC\"")));
227  QSORT(a, dir);
229 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define VARDATA_ANY(PTR)
Definition: postgres.h:347
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
int errcode(int sqlerrcode)
Definition: elog.c:575
signed int int32
Definition: c.h:256
#define QSORT(a, direction)
Definition: _int.h:168
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:273
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
#define NULL
Definition: c.h:229
#define ARRNELEMS(x)
Definition: cube.c:27
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:340
int errmsg(const char *fmt,...)
Definition: elog.c:797
Definition: c.h:439
Datum sort_asc ( PG_FUNCTION_ARGS  )

Definition at line 232 of file _int_op.c.

References CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, and QSORT.

233 {
235 
236  CHECKARRVALID(a);
237  QSORT(a, 1);
239 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
#define QSORT(a, direction)
Definition: _int.h:168
Datum sort_desc ( PG_FUNCTION_ARGS  )

Definition at line 242 of file _int_op.c.

References CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, and QSORT.

243 {
245 
246  CHECKARRVALID(a);
247  QSORT(a, 0);
249 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
#define QSORT(a, direction)
Definition: _int.h:168
Datum subarray ( PG_FUNCTION_ARGS  )

Definition at line 278 of file _int_op.c.

References ARRISEMPTY, ARRNELEMS, ARRPTR, CHECKARRVALID, new_intArrayType(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, PG_RETURN_POINTER, and result.

279 {
281  int32 start = PG_GETARG_INT32(1);
282  int32 len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
283  int32 end = 0;
284  int32 c;
285  ArrayType *result;
286 
287  start = (start > 0) ? start - 1 : start;
288 
289  CHECKARRVALID(a);
290  if (ARRISEMPTY(a))
291  {
292  PG_FREE_IF_COPY(a, 0);
294  }
295 
296  c = ARRNELEMS(a);
297 
298  if (start < 0)
299  start = c + start;
300 
301  if (len < 0)
302  end = c + len;
303  else if (len == 0)
304  end = c;
305  else
306  end = start + len;
307 
308  if (end > c)
309  end = c;
310 
311  if (start < 0)
312  start = 0;
313 
314  if (start >= end || end <= 0)
315  {
316  PG_FREE_IF_COPY(a, 0);
318  }
319 
320  result = new_intArrayType(end - start);
321  if (end - start > 0)
322  memcpy(ARRPTR(result), ARRPTR(a) + start, (end - start) * sizeof(int32));
323  PG_FREE_IF_COPY(a, 0);
324  PG_RETURN_POINTER(result);
325 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define CHECKARRVALID(x)
Definition: _int.h:18
return result
Definition: formatting.c:1633
signed int int32
Definition: c.h:256
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:244
char * c
#define ARRISEMPTY(x)
Definition: _int.h:26
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:220
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:225
#define ARRNELEMS(x)
Definition: cube.c:27
#define ARRPTR(x)
Definition: cube.c:26
Datum uniq ( PG_FUNCTION_ARGS  )

Definition at line 252 of file _int_op.c.

References _int_unique(), ARRNELEMS, CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, and PG_RETURN_POINTER.

253 {
255 
256  CHECKARRVALID(a);
257  if (ARRNELEMS(a) < 2)
259  a = _int_unique(a);
261 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:245
#define CHECKARRVALID(x)
Definition: _int.h:18
ArrayType * _int_unique(ArrayType *a)
Definition: _int_tool.c:294
#define ARRNELEMS(x)
Definition: cube.c:27

Variable Documentation

PG_MODULE_MAGIC

Definition at line 9 of file _int_op.c.