summaryrefslogtreecommitdiff
path: root/contrib/intarray
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/intarray')
-rw-r--r--contrib/intarray/Makefile4
-rw-r--r--contrib/intarray/_int.h4
-rw-r--r--contrib/intarray/_int_gist.c20
-rw-r--r--contrib/intarray/_int_op.c1
-rw-r--r--contrib/intarray/_int_tool.c52
-rw-r--r--contrib/intarray/intarray--unpackaged--1.0.sql2
6 files changed, 37 insertions, 46 deletions
diff --git a/contrib/intarray/Makefile b/contrib/intarray/Makefile
index 71f820ec4a..920c5b1ba0 100644
--- a/contrib/intarray/Makefile
+++ b/contrib/intarray/Makefile
@@ -1,10 +1,12 @@
# contrib/intarray/Makefile
MODULE_big = _int
-OBJS = _int_bool.o _int_gist.o _int_op.o _int_tool.o _intbig_gist.o _int_gin.o
+OBJS = _int_bool.o _int_gist.o _int_op.o _int_tool.o \
+ _intbig_gist.o _int_gin.o $(WIN32RES)
EXTENSION = intarray
DATA = intarray--1.0.sql intarray--unpackaged--1.0.sql
+PGFILEDESC = "intarray - functions and operators for arrays of integers"
REGRESS = _int
diff --git a/contrib/intarray/_int.h b/contrib/intarray/_int.h
index 7f93206e89..d524f0fed5 100644
--- a/contrib/intarray/_int.h
+++ b/contrib/intarray/_int.h
@@ -73,7 +73,7 @@ typedef struct
{
int32 vl_len_; /* varlena header (do not touch directly!) */
int32 flag;
- char data[1];
+ char data[FLEXIBLE_ARRAY_MEMBER];
} GISTTYPE;
#define ALLISTRUE 0x04
@@ -133,7 +133,7 @@ typedef struct QUERYTYPE
{
int32 vl_len_; /* varlena header (do not touch directly!) */
int32 size; /* number of ITEMs */
- ITEM items[1]; /* variable length array */
+ ITEM items[FLEXIBLE_ARRAY_MEMBER];
} QUERYTYPE;
#define HDRSIZEQT offsetof(QUERYTYPE, items)
diff --git a/contrib/intarray/_int_gist.c b/contrib/intarray/_int_gist.c
index 53abcc45a5..07108eb15e 100644
--- a/contrib/intarray/_int_gist.c
+++ b/contrib/intarray/_int_gist.c
@@ -3,6 +3,8 @@
*/
#include "postgres.h"
+#include <limits.h>
+
#include "access/gist.h"
#include "access/skey.h"
@@ -191,7 +193,7 @@ g_int_compress(PG_FUNCTION_ARGS)
cand = 1;
while (len > MAXNUMRANGE * 2)
{
- min = 0x7fffffff;
+ min = INT_MAX;
for (i = 2; i < len; i += 2)
if (min > (dr[i] - dr[i - 1]))
{
@@ -416,9 +418,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
size_waste = size_union - size_inter;
pfree(union_d);
-
- if (inter_d != (ArrayType *) NULL)
- pfree(inter_d);
+ pfree(inter_d);
/*
* are these a more promising split that what we've already seen?
@@ -517,10 +517,8 @@ g_int_picksplit(PG_FUNCTION_ARGS)
/* pick which page to add it to */
if (size_alpha - size_l < size_beta - size_r + WISH_F(v->spl_nleft, v->spl_nright, 0.01))
{
- if (datum_l)
- pfree(datum_l);
- if (union_dr)
- pfree(union_dr);
+ pfree(datum_l);
+ pfree(union_dr);
datum_l = union_dl;
size_l = size_alpha;
*left++ = i;
@@ -528,10 +526,8 @@ g_int_picksplit(PG_FUNCTION_ARGS)
}
else
{
- if (datum_r)
- pfree(datum_r);
- if (union_dl)
- pfree(union_dl);
+ pfree(datum_r);
+ pfree(union_dl);
datum_r = union_dr;
size_r = size_beta;
*right++ = i;
diff --git a/contrib/intarray/_int_op.c b/contrib/intarray/_int_op.c
index 70849be57f..537174175b 100644
--- a/contrib/intarray/_int_op.c
+++ b/contrib/intarray/_int_op.c
@@ -6,7 +6,6 @@
#include "_int.h"
-
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(_int_different);
diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c
index 511c7acb54..3c52912bbf 100644
--- a/contrib/intarray/_int_tool.c
+++ b/contrib/intarray/_int_tool.c
@@ -184,40 +184,34 @@ rt__int_size(ArrayType *a, float *size)
*size = (float) ARRNELEMS(a);
}
+/* qsort_arg comparison function for isort() */
+static int
+isort_cmp(const void *a, const void *b, void *arg)
+{
+ int32 aval = *((const int32 *) a);
+ int32 bval = *((const int32 *) b);
+
+ if (aval < bval)
+ return -1;
+ if (aval > bval)
+ return 1;
+
+ /*
+ * Report if we have any duplicates. If there are equal keys, qsort must
+ * compare them at some point, else it wouldn't know whether one should go
+ * before or after the other.
+ */
+ *((bool *) arg) = true;
+ return 0;
+}
+
/* Sort the given data (len >= 2). Return true if any duplicates found */
bool
isort(int32 *a, int len)
{
- int32 cur,
- prev;
- int32 *pcur,
- *pprev,
- *end;
- bool r = FALSE;
+ bool r = false;
- /*
- * We use a simple insertion sort. While this is O(N^2) in the worst
- * case, it's quite fast if the input is already sorted or nearly so.
- * Also, for not-too-large inputs it's faster than more complex methods
- * anyhow.
- */
- end = a + len;
- for (pcur = a + 1; pcur < end; pcur++)
- {
- cur = *pcur;
- for (pprev = pcur - 1; pprev >= a; pprev--)
- {
- prev = *pprev;
- if (prev <= cur)
- {
- if (prev == cur)
- r = TRUE;
- break;
- }
- pprev[1] = prev;
- }
- pprev[1] = cur;
- }
+ qsort_arg(a, len, sizeof(int32), isort_cmp, (void *) &r);
return r;
}
diff --git a/contrib/intarray/intarray--unpackaged--1.0.sql b/contrib/intarray/intarray--unpackaged--1.0.sql
index 5de64bf0ab..63814cef98 100644
--- a/contrib/intarray/intarray--unpackaged--1.0.sql
+++ b/contrib/intarray/intarray--unpackaged--1.0.sql
@@ -1,7 +1,7 @@
/* contrib/intarray/intarray--unpackaged--1.0.sql */
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
-\echo Use "CREATE EXTENSION intarray" to load this file. \quit
+\echo Use "CREATE EXTENSION intarray FROM unpackaged" to load this file. \quit
ALTER EXTENSION intarray ADD type query_int;
ALTER EXTENSION intarray ADD function bqarr_in(cstring);