PostgreSQL Source Code  git master
_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

◆ _int_contained()

Datum _int_contained ( PG_FUNCTION_ARGS  )

Definition at line 19 of file _int_op.c.

References _int_contains(), DirectFunctionCall2, and PG_GETARG_DATUM.

20 {
21  /* just reverse the operands and call _int_contains */
23  PG_GETARG_DATUM(1),
24  PG_GETARG_DATUM(0));
25 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:263
Datum _int_contains(PG_FUNCTION_ARGS)
Definition: _int_op.c:28
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:617

◆ _int_contains()

Datum _int_contains ( PG_FUNCTION_ARGS  )

Definition at line 28 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().

29 {
30  /* Force copy so we can modify the arrays in-place */
33  bool res;
34 
35  CHECKARRVALID(a);
36  CHECKARRVALID(b);
37  PREPAREARR(a);
38  PREPAREARR(b);
39  res = inner_int_contains(a, b);
40  pfree(a);
41  pfree(b);
42  PG_RETURN_BOOL(res);
43 }
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
#define PREPAREARR(x)
Definition: _int.h:37
void pfree(void *pointer)
Definition: mcxt.c:1056
bool inner_int_contains(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:14
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ _int_different()

Datum _int_different ( PG_FUNCTION_ARGS  )

Definition at line 46 of file _int_op.c.

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

47 {
50  _int_same,
53  )
54  ));
55 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
#define DatumGetBool(X)
Definition: postgres.h:393
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
Datum _int_same(PG_FUNCTION_ARGS)
Definition: _int_op.c:58
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:617

◆ _int_inter()

Datum _int_inter ( PG_FUNCTION_ARGS  )

Definition at line 147 of file _int_op.c.

References CHECKARRVALID, icount(), idx(), inner_int_inter(), intarray_del_elem(), intarray_push_array(), intarray_push_elem(), intset(), intset_subtract(), intset_union_elem(), pfree(), PG_FUNCTION_INFO_V1(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, SORT, sort(), sort_asc(), sort_desc(), subarray(), and uniq().

148 {
151  ArrayType *result;
152 
153  CHECKARRVALID(a);
154  CHECKARRVALID(b);
155 
156  SORT(a);
157  SORT(b);
158 
159  result = inner_int_inter(a, b);
160 
161  pfree(a);
162  pfree(b);
163 
164  PG_RETURN_POINTER(result);
165 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
ArrayType * inner_int_inter(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:135
#define SORT(x)
Definition: _int.h:29
void pfree(void *pointer)
Definition: mcxt.c:1056

◆ _int_overlap()

Datum _int_overlap ( PG_FUNCTION_ARGS  )

Definition at line 103 of file _int_op.c.

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

104 {
107  bool result;
108 
109  CHECKARRVALID(a);
110  CHECKARRVALID(b);
111  if (ARRISEMPTY(a) || ARRISEMPTY(b))
112  return false;
113 
114  SORT(a);
115  SORT(b);
116 
117  result = inner_int_overlap(a, b);
118 
119  pfree(a);
120  pfree(b);
121 
122  PG_RETURN_BOOL(result);
123 }
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
#define SORT(x)
Definition: _int.h:29
void pfree(void *pointer)
Definition: mcxt.c:1056
bool inner_int_overlap(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:49
#define ARRISEMPTY(x)
Definition: _int.h:26
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349

◆ _int_same()

Datum _int_same ( PG_FUNCTION_ARGS  )

Definition at line 58 of file _int_op.c.

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

Referenced by _int_different().

59 {
62  int na,
63  nb;
64  int n;
65  int *da,
66  *db;
67  bool result;
68 
69  CHECKARRVALID(a);
70  CHECKARRVALID(b);
71  na = ARRNELEMS(a);
72  nb = ARRNELEMS(b);
73  da = ARRPTR(a);
74  db = ARRPTR(b);
75 
76  result = false;
77 
78  if (na == nb)
79  {
80  SORT(a);
81  SORT(b);
82  result = true;
83 
84  for (n = 0; n < na; n++)
85  {
86  if (da[n] != db[n])
87  {
88  result = false;
89  break;
90  }
91  }
92  }
93 
94  pfree(a);
95  pfree(b);
96 
97  PG_RETURN_BOOL(result);
98 }
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
#define SORT(x)
Definition: _int.h:29
void pfree(void *pointer)
Definition: mcxt.c:1056
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
#define ARRNELEMS(x)
Definition: cube.c:25
#define ARRPTR(x)
Definition: cube.c:24

◆ _int_union()

Datum _int_union ( PG_FUNCTION_ARGS  )

Definition at line 126 of file _int_op.c.

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

127 {
130  ArrayType *result;
131 
132  CHECKARRVALID(a);
133  CHECKARRVALID(b);
134 
135  SORT(a);
136  SORT(b);
137 
138  result = inner_int_union(a, b);
139 
140  pfree(a);
141  pfree(b);
142 
143  PG_RETURN_POINTER(result);
144 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
#define SORT(x)
Definition: _int.h:29
void pfree(void *pointer)
Definition: mcxt.c:1056
ArrayType * inner_int_union(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:78

◆ icount()

Datum icount ( PG_FUNCTION_ARGS  )

Definition at line 189 of file _int_op.c.

References ARRNELEMS, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

Referenced by _int_inter().

190 {
192  int32 count = ARRNELEMS(a);
193 
194  PG_FREE_IF_COPY(a, 0);
195  PG_RETURN_INT32(count);
196 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define ARRNELEMS(x)
Definition: cube.c:25

◆ idx()

Definition at line 263 of file _int_op.c.

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

Referenced by _int_inter(), aclexplode(), AllocSetFreeIndex(), appendStringInfoRegexpSubstr(), ATExecDetachPartition(), AttachPartitionEnsureIndexes(), avlCollectFields(), brin_revmap_data(), bsearch_arg(), build_sorted_items(), cube_subset(), ExecHashIncreaseNumBatches(), ExecHashIncreaseNumBuckets(), ExecParallelHashIncreaseNumBuckets(), ExecParallelHashRepartitionFirst(), 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(), lazy_cleanup_all_indexes(), lazy_vacuum_all_indexes(), Lookahead(), mcv_get_match_bitmap(), parallel_vacuum_index(), percentile_cont_multi_final_common(), percentile_disc_multi_final(), pg_mb_radix_conv(), pg_nextoid(), PLySequence_ToComposite(), printCrosstab(), range_gist_double_sorting_split(), range_gist_single_sorting_split(), ResourceArrayAdd(), ResourceArrayRemove(), ri_ReportViolation(), scan_available_timezones(), setalarm(), setPathArray(), SlabAlloc(), SlabFree(), SlabStats(), tbm_prepare_shared_iterate(), test_pattern(), and transformContainerSubscripts().

264 {
266  int32 result;
267 
268  CHECKARRVALID(a);
269  result = ARRNELEMS(a);
270  if (result)
271  result = intarray_match_first(a, PG_GETARG_INT32(1));
272  PG_FREE_IF_COPY(a, 0);
273  PG_RETURN_INT32(result);
274 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define CHECKARRVALID(x)
Definition: _int.h:18
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
signed int int32
Definition: c.h:347
int32 intarray_match_first(ArrayType *a, int32 elem)
Definition: _int_tool.c:335
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define ARRNELEMS(x)
Definition: cube.c:25

◆ intarray_del_elem()

Datum intarray_del_elem ( PG_FUNCTION_ARGS  )

Definition at line 351 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().

Referenced by _int_inter().

352 {
354  int32 elem = PG_GETARG_INT32(1);
355  int32 c;
356  int32 *aa;
357  int32 n = 0,
358  i;
359 
360  CHECKARRVALID(a);
361  if (!ARRISEMPTY(a))
362  {
363  c = ARRNELEMS(a);
364  aa = ARRPTR(a);
365  for (i = 0; i < c; i++)
366  {
367  if (aa[i] != elem)
368  {
369  if (i > n)
370  aa[n++] = aa[i];
371  else
372  n++;
373  }
374  }
375  a = resize_intArrayType(a, n);
376  }
378 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
signed int int32
Definition: c.h:347
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:249
char * c
#define ARRISEMPTY(x)
Definition: _int.h:26
#define ARRNELEMS(x)
Definition: cube.c:25
int i
#define ARRPTR(x)
Definition: cube.c:24

◆ intarray_push_array()

Datum intarray_push_array ( PG_FUNCTION_ARGS  )

Definition at line 338 of file _int_op.c.

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

Referenced by _int_inter().

339 {
342  ArrayType *result;
343 
344  result = intarray_concat_arrays(a, b);
345  PG_FREE_IF_COPY(a, 0);
346  PG_FREE_IF_COPY(b, 1);
347  PG_RETURN_POINTER(result);
348 }
ArrayType * intarray_concat_arrays(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:368
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255

◆ intarray_push_elem()

Datum intarray_push_elem ( PG_FUNCTION_ARGS  )

Definition at line 327 of file _int_op.c.

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

Referenced by _int_inter().

328 {
330  ArrayType *result;
331 
332  result = intarray_add_elem(a, PG_GETARG_INT32(1));
333  PG_FREE_IF_COPY(a, 0);
334  PG_RETURN_POINTER(result);
335 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
ArrayType * intarray_add_elem(ArrayType *a, int32 elem)
Definition: _int_tool.c:351
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255

◆ intset()

Datum intset ( PG_FUNCTION_ARGS  )

Definition at line 183 of file _int_op.c.

References int_to_intset(), PG_GETARG_INT32, and PG_RETURN_POINTER.

Referenced by _int_inter(), intset_create(), test_empty(), test_huge_distances(), test_pattern(), test_single_value(), and test_single_value_and_filler().

184 {
186 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
ArrayType * int_to_intset(int32 elem)
Definition: _int_tool.c:385

◆ intset_subtract()

Datum intset_subtract ( PG_FUNCTION_ARGS  )

Definition at line 393 of file _int_op.c.

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

Referenced by _int_inter().

394 {
397  ArrayType *result;
398  int32 ca;
399  int32 cb;
400  int32 *aa,
401  *bb,
402  *r;
403  int32 n = 0,
404  i = 0,
405  k = 0;
406 
407  CHECKARRVALID(a);
408  CHECKARRVALID(b);
409 
410  QSORT(a, 1);
411  a = _int_unique(a);
412  ca = ARRNELEMS(a);
413  QSORT(b, 1);
414  b = _int_unique(b);
415  cb = ARRNELEMS(b);
416  result = new_intArrayType(ca);
417  aa = ARRPTR(a);
418  bb = ARRPTR(b);
419  r = ARRPTR(result);
420  while (i < ca)
421  {
422  if (k == cb || aa[i] < bb[k])
423  r[n++] = aa[i++];
424  else if (aa[i] == bb[k])
425  {
426  i++;
427  k++;
428  }
429  else
430  k++;
431  }
432  result = resize_intArrayType(result, n);
433  pfree(a);
434  pfree(b);
435  PG_RETURN_POINTER(result);
436 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
signed int int32
Definition: c.h:347
#define QSORT(a, direction)
Definition: _int.h:162
void pfree(void *pointer)
Definition: mcxt.c:1056
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:249
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:221
ArrayType * _int_unique(ArrayType *a)
Definition: _int_tool.c:310
#define ARRNELEMS(x)
Definition: cube.c:25
int i
#define ARRPTR(x)
Definition: cube.c:24

◆ intset_union_elem()

Datum intset_union_elem ( PG_FUNCTION_ARGS  )

Definition at line 381 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, and QSORT.

Referenced by _int_inter().

382 {
384  ArrayType *result;
385 
386  result = intarray_add_elem(a, PG_GETARG_INT32(1));
387  PG_FREE_IF_COPY(a, 0);
388  QSORT(result, 1);
390 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define QSORT(a, direction)
Definition: _int.h:162
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
ArrayType * _int_unique(ArrayType *a)
Definition: _int_tool.c:310
ArrayType * intarray_add_elem(ArrayType *a, int32 elem)
Definition: _int_tool.c:351
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255

◆ PG_FUNCTION_INFO_V1() [1/20]

PG_FUNCTION_INFO_V1 ( _int_different  )

Referenced by _int_inter().

◆ PG_FUNCTION_INFO_V1() [2/20]

PG_FUNCTION_INFO_V1 ( _int_same  )

◆ PG_FUNCTION_INFO_V1() [3/20]

PG_FUNCTION_INFO_V1 ( _int_contains  )

◆ PG_FUNCTION_INFO_V1() [4/20]

PG_FUNCTION_INFO_V1 ( _int_contained  )

◆ PG_FUNCTION_INFO_V1() [5/20]

PG_FUNCTION_INFO_V1 ( _int_overlap  )

◆ PG_FUNCTION_INFO_V1() [6/20]

PG_FUNCTION_INFO_V1 ( _int_union  )

◆ PG_FUNCTION_INFO_V1() [7/20]

PG_FUNCTION_INFO_V1 ( _int_inter  )

◆ PG_FUNCTION_INFO_V1() [8/20]

PG_FUNCTION_INFO_V1 ( intset  )

◆ PG_FUNCTION_INFO_V1() [9/20]

PG_FUNCTION_INFO_V1 ( icount  )

◆ PG_FUNCTION_INFO_V1() [10/20]

PG_FUNCTION_INFO_V1 ( sort  )

◆ PG_FUNCTION_INFO_V1() [11/20]

PG_FUNCTION_INFO_V1 ( sort_asc  )

◆ PG_FUNCTION_INFO_V1() [12/20]

PG_FUNCTION_INFO_V1 ( sort_desc  )

◆ PG_FUNCTION_INFO_V1() [13/20]

PG_FUNCTION_INFO_V1 ( uniq  )

◆ PG_FUNCTION_INFO_V1() [14/20]

PG_FUNCTION_INFO_V1 ( idx  )

◆ PG_FUNCTION_INFO_V1() [15/20]

PG_FUNCTION_INFO_V1 ( subarray  )

◆ PG_FUNCTION_INFO_V1() [16/20]

PG_FUNCTION_INFO_V1 ( intarray_push_elem  )

◆ PG_FUNCTION_INFO_V1() [17/20]

PG_FUNCTION_INFO_V1 ( intarray_push_array  )

◆ PG_FUNCTION_INFO_V1() [18/20]

PG_FUNCTION_INFO_V1 ( intarray_del_elem  )

◆ PG_FUNCTION_INFO_V1() [19/20]

PG_FUNCTION_INFO_V1 ( intset_union_elem  )

◆ PG_FUNCTION_INFO_V1() [20/20]

PG_FUNCTION_INFO_V1 ( intset_subtract  )

◆ sort()

Datum sort ( PG_FUNCTION_ARGS  )

Definition at line 199 of file _int_op.c.

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

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

200 {
202  text *dirstr = (fcinfo->nargs == 2) ? PG_GETARG_TEXT_PP(1) : NULL;
203  int32 dc = (dirstr) ? VARSIZE_ANY_EXHDR(dirstr) : 0;
204  char *d = (dirstr) ? VARDATA_ANY(dirstr) : NULL;
205  int dir = -1;
206 
207  CHECKARRVALID(a);
208  if (ARRNELEMS(a) < 2)
210 
211  if (dirstr == NULL || (dc == 3
212  && (d[0] == 'A' || d[0] == 'a')
213  && (d[1] == 'S' || d[1] == 's')
214  && (d[2] == 'C' || d[2] == 'c')))
215  dir = 1;
216  else if (dc == 4
217  && (d[0] == 'D' || d[0] == 'd')
218  && (d[1] == 'E' || d[1] == 'e')
219  && (d[2] == 'S' || d[2] == 's')
220  && (d[3] == 'C' || d[3] == 'c'))
221  dir = 0;
222  if (dir == -1)
223  ereport(ERROR,
224  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
225  errmsg("second parameter must be \"ASC\" or \"DESC\"")));
226  QSORT(a, dir);
228 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define VARDATA_ANY(PTR)
Definition: postgres.h:348
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
int errcode(int sqlerrcode)
Definition: elog.c:608
signed int int32
Definition: c.h:347
#define QSORT(a, direction)
Definition: _int.h:162
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:303
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
#define ARRNELEMS(x)
Definition: cube.c:25
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
int errmsg(const char *fmt,...)
Definition: elog.c:822
Definition: c.h:556

◆ sort_asc()

Datum sort_asc ( PG_FUNCTION_ARGS  )

Definition at line 231 of file _int_op.c.

References CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, and QSORT.

Referenced by _int_inter().

232 {
234 
235  CHECKARRVALID(a);
236  QSORT(a, 1);
238 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
#define QSORT(a, direction)
Definition: _int.h:162

◆ sort_desc()

Datum sort_desc ( PG_FUNCTION_ARGS  )

Definition at line 241 of file _int_op.c.

References CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, and QSORT.

Referenced by _int_inter().

242 {
244 
245  CHECKARRVALID(a);
246  QSORT(a, 0);
248 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
#define QSORT(a, direction)
Definition: _int.h:162

◆ subarray()

Datum subarray ( PG_FUNCTION_ARGS  )

Definition at line 277 of file _int_op.c.

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

Referenced by _int_inter().

278 {
280  int32 start = PG_GETARG_INT32(1);
281  int32 len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
282  int32 end = 0;
283  int32 c;
284  ArrayType *result;
285 
286  start = (start > 0) ? start - 1 : start;
287 
288  CHECKARRVALID(a);
289  if (ARRISEMPTY(a))
290  {
291  PG_FREE_IF_COPY(a, 0);
293  }
294 
295  c = ARRNELEMS(a);
296 
297  if (start < 0)
298  start = c + start;
299 
300  if (len < 0)
301  end = c + len;
302  else if (len == 0)
303  end = c;
304  else
305  end = start + len;
306 
307  if (end > c)
308  end = c;
309 
310  if (start < 0)
311  start = 0;
312 
313  if (start >= end || end <= 0)
314  {
315  PG_FREE_IF_COPY(a, 0);
317  }
318 
319  result = new_intArrayType(end - start);
320  if (end - start > 0)
321  memcpy(ARRPTR(result), ARRPTR(a) + start, (end - start) * sizeof(int32));
322  PG_FREE_IF_COPY(a, 0);
323  PG_RETURN_POINTER(result);
324 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define CHECKARRVALID(x)
Definition: _int.h:18
signed int int32
Definition: c.h:347
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
char * c
#define ARRISEMPTY(x)
Definition: _int.h:26
ArrayType * new_intArrayType(int num)
Definition: _int_tool.c:221
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:255
#define ARRNELEMS(x)
Definition: cube.c:25
#define ARRPTR(x)
Definition: cube.c:24

◆ uniq()

Datum uniq ( PG_FUNCTION_ARGS  )

Definition at line 251 of file _int_op.c.

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

Referenced by _int_inter().

252 {
254 
255  CHECKARRVALID(a);
256  if (ARRNELEMS(a) < 2)
258  a = _int_unique(a);
260 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:18
ArrayType * _int_unique(ArrayType *a)
Definition: _int_tool.c:310
#define ARRNELEMS(x)
Definition: cube.c:25

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 8 of file _int_op.c.