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:268
Datum _int_contains(PG_FUNCTION_ARGS)
Definition: _int_op.c:28
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ _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:30
#define PREPAREARR(x)
Definition: _int.h:49
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:358

◆ _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 {
51 }
#define PointerGetDatum(X)
Definition: postgres.h:556
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define DatumGetBool(X)
Definition: postgres.h:393
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
Datum _int_same(PG_FUNCTION_ARGS)
Definition: _int_op.c:54
#define DirectFunctionCall2(func, arg1, arg2)
Definition: fmgr.h:626

◆ _int_inter()

Datum _int_inter ( PG_FUNCTION_ARGS  )

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

144 {
147  ArrayType *result;
148 
149  CHECKARRVALID(a);
150  CHECKARRVALID(b);
151 
152  SORT(a);
153  SORT(b);
154 
155  result = inner_int_inter(a, b);
156 
157  pfree(a);
158  pfree(b);
159 
160  PG_RETURN_POINTER(result);
161 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:30
ArrayType * inner_int_inter(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:135
#define SORT(x)
Definition: _int.h:41
void pfree(void *pointer)
Definition: mcxt.c:1056

◆ _int_overlap()

Datum _int_overlap ( PG_FUNCTION_ARGS  )

Definition at line 99 of file _int_op.c.

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

100 {
103  bool result;
104 
105  CHECKARRVALID(a);
106  CHECKARRVALID(b);
107  if (ARRISEMPTY(a) || ARRISEMPTY(b))
108  return false;
109 
110  SORT(a);
111  SORT(b);
112 
113  result = inner_int_overlap(a, b);
114 
115  pfree(a);
116  pfree(b);
117 
118  PG_RETURN_BOOL(result);
119 }
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:30
#define SORT(x)
Definition: _int.h:41
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:38
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358

◆ _int_same()

Datum _int_same ( PG_FUNCTION_ARGS  )

Definition at line 54 of file _int_op.c.

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

Referenced by _int_different().

55 {
58  int na,
59  nb;
60  int n;
61  int *da,
62  *db;
63  bool result;
64 
65  CHECKARRVALID(a);
66  CHECKARRVALID(b);
67  na = ARRNELEMS(a);
68  nb = ARRNELEMS(b);
69  da = ARRPTR(a);
70  db = ARRPTR(b);
71 
72  result = false;
73 
74  if (na == nb)
75  {
76  SORT(a);
77  SORT(b);
78  result = true;
79 
80  for (n = 0; n < na; n++)
81  {
82  if (da[n] != db[n])
83  {
84  result = false;
85  break;
86  }
87  }
88  }
89 
90  pfree(a);
91  pfree(b);
92 
93  PG_RETURN_BOOL(result);
94 }
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:30
#define SORT(x)
Definition: _int.h:41
void pfree(void *pointer)
Definition: mcxt.c:1056
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:358
#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 122 of file _int_op.c.

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

123 {
126  ArrayType *result;
127 
128  CHECKARRVALID(a);
129  CHECKARRVALID(b);
130 
131  SORT(a);
132  SORT(b);
133 
134  result = inner_int_union(a, b);
135 
136  pfree(a);
137  pfree(b);
138 
139  PG_RETURN_POINTER(result);
140 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:30
#define SORT(x)
Definition: _int.h:41
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 185 of file _int_op.c.

References ARRNELEMS, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

Referenced by _int_inter().

186 {
188  int32 count = ARRNELEMS(a);
189 
190  PG_FREE_IF_COPY(a, 0);
191  PG_RETURN_INT32(count);
192 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
signed int int32
Definition: c.h:362
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260
#define ARRNELEMS(x)
Definition: cube.c:25

◆ idx()

Definition at line 259 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(), s_init_lock_sema(), scan_available_timezones(), setalarm(), setPathArray(), SlabAlloc(), SlabFree(), SlabStats(), tbm_prepare_shared_iterate(), test_pattern(), and transformContainerSubscripts().

260 {
262  int32 result;
263 
264  CHECKARRVALID(a);
265  result = ARRNELEMS(a);
266  if (result)
267  result = intarray_match_first(a, PG_GETARG_INT32(1));
268  PG_FREE_IF_COPY(a, 0);
269  PG_RETURN_INT32(result);
270 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define CHECKARRVALID(x)
Definition: _int.h:30
#define PG_RETURN_INT32(x)
Definition: fmgr.h:353
signed int int32
Definition: c.h:362
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:260
#define ARRNELEMS(x)
Definition: cube.c:25

◆ intarray_del_elem()

Datum intarray_del_elem ( PG_FUNCTION_ARGS  )

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

348 {
350  int32 elem = PG_GETARG_INT32(1);
351  int32 c;
352  int32 *aa;
353  int32 n = 0,
354  i;
355 
356  CHECKARRVALID(a);
357  if (!ARRISEMPTY(a))
358  {
359  c = ARRNELEMS(a);
360  aa = ARRPTR(a);
361  for (i = 0; i < c; i++)
362  {
363  if (aa[i] != elem)
364  {
365  if (i > n)
366  aa[n++] = aa[i];
367  else
368  n++;
369  }
370  }
371  a = resize_intArrayType(a, n);
372  }
374 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:30
signed int int32
Definition: c.h:362
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition: _int_tool.c:249
char * c
#define ARRISEMPTY(x)
Definition: _int.h:38
#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 334 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().

335 {
338  ArrayType *result;
339 
340  result = intarray_concat_arrays(a, b);
341  PG_FREE_IF_COPY(a, 0);
342  PG_FREE_IF_COPY(b, 1);
343  PG_RETURN_POINTER(result);
344 }
ArrayType * intarray_concat_arrays(ArrayType *a, ArrayType *b)
Definition: _int_tool.c:368
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_ARRAYTYPE_P(n)
Definition: array.h:251
#define PG_FREE_IF_COPY(ptr, n)
Definition: fmgr.h:260

◆ intarray_push_elem()

Datum intarray_push_elem ( PG_FUNCTION_ARGS  )

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

324 {
326  ArrayType *result;
327 
328  result = intarray_add_elem(a, PG_GETARG_INT32(1));
329  PG_FREE_IF_COPY(a, 0);
330  PG_RETURN_POINTER(result);
331 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#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:260

◆ intset()

Datum intset ( PG_FUNCTION_ARGS  )

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

180 {
182 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
ArrayType * int_to_intset(int32 elem)
Definition: _int_tool.c:385

◆ intset_subtract()

Datum intset_subtract ( PG_FUNCTION_ARGS  )

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

390 {
393  ArrayType *result;
394  int32 ca;
395  int32 cb;
396  int32 *aa,
397  *bb,
398  *r;
399  int32 n = 0,
400  i = 0,
401  k = 0;
402 
403  CHECKARRVALID(a);
404  CHECKARRVALID(b);
405 
406  QSORT(a, 1);
407  a = _int_unique(a);
408  ca = ARRNELEMS(a);
409  QSORT(b, 1);
410  b = _int_unique(b);
411  cb = ARRNELEMS(b);
412  result = new_intArrayType(ca);
413  aa = ARRPTR(a);
414  bb = ARRPTR(b);
415  r = ARRPTR(result);
416  while (i < ca)
417  {
418  if (k == cb || aa[i] < bb[k])
419  r[n++] = aa[i++];
420  else if (aa[i] == bb[k])
421  {
422  i++;
423  k++;
424  }
425  else
426  k++;
427  }
428  result = resize_intArrayType(result, n);
429  pfree(a);
430  pfree(b);
431  PG_RETURN_POINTER(result);
432 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:30
signed int int32
Definition: c.h:362
#define QSORT(a, direction)
Definition: _int.h:183
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 377 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().

378 {
380  ArrayType *result;
381 
382  result = intarray_add_elem(a, PG_GETARG_INT32(1));
383  PG_FREE_IF_COPY(a, 0);
384  QSORT(result, 1);
386 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define QSORT(a, direction)
Definition: _int.h:183
#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:260

◆ 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 195 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_incremental_sort_path(), create_merge_append_plan(), create_mergejoin_plan(), and create_unique_plan().

196 {
198  text *dirstr = (fcinfo->nargs == 2) ? PG_GETARG_TEXT_PP(1) : NULL;
199  int32 dc = (dirstr) ? VARSIZE_ANY_EXHDR(dirstr) : 0;
200  char *d = (dirstr) ? VARDATA_ANY(dirstr) : NULL;
201  int dir = -1;
202 
203  CHECKARRVALID(a);
204  if (ARRNELEMS(a) < 2)
206 
207  if (dirstr == NULL || (dc == 3
208  && (d[0] == 'A' || d[0] == 'a')
209  && (d[1] == 'S' || d[1] == 's')
210  && (d[2] == 'C' || d[2] == 'c')))
211  dir = 1;
212  else if (dc == 4
213  && (d[0] == 'D' || d[0] == 'd')
214  && (d[1] == 'E' || d[1] == 'e')
215  && (d[2] == 'S' || d[2] == 's')
216  && (d[3] == 'C' || d[3] == 'c'))
217  dir = 0;
218  if (dir == -1)
219  ereport(ERROR,
220  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
221  errmsg("second parameter must be \"ASC\" or \"DESC\"")));
222  QSORT(a, dir);
224 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#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:30
int errcode(int sqlerrcode)
Definition: elog.c:610
signed int int32
Definition: c.h:362
#define QSORT(a, direction)
Definition: _int.h:183
#define PG_GETARG_TEXT_PP(n)
Definition: fmgr.h:308
#define ERROR
Definition: elog.h:43
#define ereport(elevel,...)
Definition: elog.h:144
#define ARRNELEMS(x)
Definition: cube.c:25
#define VARSIZE_ANY_EXHDR(PTR)
Definition: postgres.h:341
int errmsg(const char *fmt,...)
Definition: elog.c:824
Definition: c.h:562

◆ sort_asc()

Datum sort_asc ( PG_FUNCTION_ARGS  )

Definition at line 227 of file _int_op.c.

References CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, and QSORT.

Referenced by _int_inter().

228 {
230 
231  CHECKARRVALID(a);
232  QSORT(a, 1);
234 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:30
#define QSORT(a, direction)
Definition: _int.h:183

◆ sort_desc()

Datum sort_desc ( PG_FUNCTION_ARGS  )

Definition at line 237 of file _int_op.c.

References CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, and QSORT.

Referenced by _int_inter().

238 {
240 
241  CHECKARRVALID(a);
242  QSORT(a, 0);
244 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:30
#define QSORT(a, direction)
Definition: _int.h:183

◆ subarray()

Datum subarray ( PG_FUNCTION_ARGS  )

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

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

◆ uniq()

Datum uniq ( PG_FUNCTION_ARGS  )

Definition at line 247 of file _int_op.c.

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

Referenced by _int_inter().

248 {
250 
251  CHECKARRVALID(a);
252  if (ARRNELEMS(a) < 2)
254  a = _int_unique(a);
256 }
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:360
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition: array.h:252
#define CHECKARRVALID(x)
Definition: _int.h:30
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.