summaryrefslogtreecommitdiff
path: root/contrib/hstore
diff options
context:
space:
mode:
authorBruce Momjian2010-02-26 02:01:40 +0000
committerBruce Momjian2010-02-26 02:01:40 +0000
commit65e806cba1f0f154d51caa7478e7192ce58d1056 (patch)
tree99a656d7b4ec6d038d4c24e07fadf75db4c37e79 /contrib/hstore
parent16040575a04486d8e0823b4e304f4933144baf90 (diff)
pgindent run for 9.0
Diffstat (limited to 'contrib/hstore')
-rw-r--r--contrib/hstore/hstore.h14
-rw-r--r--contrib/hstore/hstore_compat.c170
-rw-r--r--contrib/hstore/hstore_gin.c37
-rw-r--r--contrib/hstore/hstore_gist.c51
-rw-r--r--contrib/hstore/hstore_io.c173
-rw-r--r--contrib/hstore/hstore_op.c565
6 files changed, 513 insertions, 497 deletions
diff --git a/contrib/hstore/hstore.h b/contrib/hstore/hstore.h
index 495ac1afc9b..796dce575e5 100644
--- a/contrib/hstore/hstore.h
+++ b/contrib/hstore/hstore.h
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/hstore/hstore.h,v 1.9 2009/09/30 19:50:22 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/hstore/hstore.h,v 1.10 2010/02/26 02:00:32 momjian Exp $
*/
#ifndef __HSTORE_H__
#define __HSTORE_H__
@@ -12,7 +12,7 @@
* HEntry: there is one of these for each key _and_ value in an hstore
*
* the position offset points to the _end_ so that we can get the length
- * by subtraction from the previous entry. the ISFIRST flag lets us tell
+ * by subtraction from the previous entry. the ISFIRST flag lets us tell
* whether there is a previous entry.
*/
typedef struct
@@ -51,7 +51,7 @@ typedef struct
/*
* it's not possible to get more than 2^28 items into an hstore,
* so we reserve the top few bits of the size field. See hstore_compat.c
- * for one reason why. Some bits are left for future use here.
+ * for one reason why. Some bits are left for future use here.
*/
#define HS_FLAG_NEWVERSION 0x80000000
@@ -88,7 +88,7 @@ typedef struct
* evaluation here.
*/
#define HS_COPYITEM(dent_,dbuf_,dptr_,sptr_,klen_,vlen_,vnull_) \
- do { \
+ do { \
memcpy((dptr_), (sptr_), (klen_)+(vlen_)); \
(dptr_) += (klen_)+(vlen_); \
(dent_)++->entry = ((dptr_) - (dbuf_) - (vlen_)) & HENTRY_POSMASK; \
@@ -119,7 +119,7 @@ typedef struct
/* finalize a newly-constructed hstore */
#define HS_FINALIZE(hsp_,count_,buf_,ptr_) \
do { \
- int buflen = (ptr_) - (buf_); \
+ int buflen = (ptr_) - (buf_); \
if ((count_)) \
ARRPTR(hsp_)[0].entry |= HENTRY_ISFIRST; \
if ((count_) != HS_COUNT((hsp_))) \
@@ -133,7 +133,7 @@ typedef struct
/* ensure the varlena size of an existing hstore is correct */
#define HS_FIXSIZE(hsp_,count_) \
do { \
- int bl = (count_) ? HSE_ENDPOS(ARRPTR(hsp_)[2*(count_)-1]) : 0; \
+ int bl = (count_) ? HSE_ENDPOS(ARRPTR(hsp_)[2*(count_)-1]) : 0; \
SET_VARSIZE((hsp_), CALCDATASIZE((count_),bl)); \
} while (0)
@@ -172,7 +172,7 @@ extern Pairs *hstoreArrayToPairs(ArrayType *a, int *npairs);
#define HStoreExistsStrategyNumber 9
#define HStoreExistsAnyStrategyNumber 10
#define HStoreExistsAllStrategyNumber 11
-#define HStoreOldContainsStrategyNumber 13 /* backwards compatibility */
+#define HStoreOldContainsStrategyNumber 13 /* backwards compatibility */
/*
* defining HSTORE_POLLUTE_NAMESPACE=0 will prevent use of old function names;
diff --git a/contrib/hstore/hstore_compat.c b/contrib/hstore/hstore_compat.c
index e2c2b55c100..033d945f9ca 100644
--- a/contrib/hstore/hstore_compat.c
+++ b/contrib/hstore/hstore_compat.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/hstore/hstore_compat.c,v 1.1 2009/09/30 19:50:22 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/hstore/hstore_compat.c,v 1.2 2010/02/26 02:00:32 momjian Exp $
*
* Notes on old/new hstore format disambiguation.
*
@@ -106,24 +106,24 @@ typedef struct
pos:31;
} HOldEntry;
-static int hstoreValidNewFormat(HStore *hs);
-static int hstoreValidOldFormat(HStore *hs);
+static int hstoreValidNewFormat(HStore *hs);
+static int hstoreValidOldFormat(HStore *hs);
/*
* Validity test for a new-format hstore.
- * 0 = not valid
- * 1 = valid but with "slop" in the length
- * 2 = exactly valid
+ * 0 = not valid
+ * 1 = valid but with "slop" in the length
+ * 2 = exactly valid
*/
static int
hstoreValidNewFormat(HStore *hs)
{
- int count = HS_COUNT(hs);
- HEntry *entries = ARRPTR(hs);
- int buflen = (count) ? HSE_ENDPOS(entries[2*(count)-1]) : 0;
- int vsize = CALCDATASIZE(count,buflen);
- int i;
+ int count = HS_COUNT(hs);
+ HEntry *entries = ARRPTR(hs);
+ int buflen = (count) ? HSE_ENDPOS(entries[2 * (count) - 1]) : 0;
+ int vsize = CALCDATASIZE(count, buflen);
+ int i;
if (hs->size_ & HS_FLAG_NEWVERSION)
return 2;
@@ -139,10 +139,10 @@ hstoreValidNewFormat(HStore *hs)
/* entry position must be nondecreasing */
- for (i = 1; i < 2*count; ++i)
+ for (i = 1; i < 2 * count; ++i)
{
if (HSE_ISFIRST(entries[i])
- || (HSE_ENDPOS(entries[i]) < HSE_ENDPOS(entries[i-1])))
+ || (HSE_ENDPOS(entries[i]) < HSE_ENDPOS(entries[i - 1])))
return 0;
}
@@ -150,9 +150,9 @@ hstoreValidNewFormat(HStore *hs)
for (i = 1; i < count; ++i)
{
- if (HS_KEYLEN(entries,i) < HS_KEYLEN(entries,i-1))
+ if (HS_KEYLEN(entries, i) < HS_KEYLEN(entries, i - 1))
return 0;
- if (HSE_ISNULL(entries[2*i]))
+ if (HSE_ISNULL(entries[2 * i]))
return 0;
}
@@ -164,18 +164,18 @@ hstoreValidNewFormat(HStore *hs)
/*
* Validity test for an old-format hstore.
- * 0 = not valid
- * 1 = valid but with "slop" in the length
- * 2 = exactly valid
+ * 0 = not valid
+ * 1 = valid but with "slop" in the length
+ * 2 = exactly valid
*/
static int
hstoreValidOldFormat(HStore *hs)
{
- int count = hs->size_;
- HOldEntry *entries = (HOldEntry *) ARRPTR(hs);
- int vsize;
- int lastpos = 0;
- int i;
+ int count = hs->size_;
+ HOldEntry *entries = (HOldEntry *) ARRPTR(hs);
+ int vsize;
+ int lastpos = 0;
+ int i;
if (hs->size_ & HS_FLAG_NEWVERSION)
return 0;
@@ -188,7 +188,7 @@ hstoreValidOldFormat(HStore *hs)
if (count > 0xFFFFFFF)
return 0;
- if (CALCDATASIZE(count,0) > VARSIZE(hs))
+ if (CALCDATASIZE(count, 0) > VARSIZE(hs))
return 0;
if (entries[0].pos != 0)
@@ -198,14 +198,14 @@ hstoreValidOldFormat(HStore *hs)
for (i = 1; i < count; ++i)
{
- if (entries[i].keylen < entries[i-1].keylen)
+ if (entries[i].keylen < entries[i - 1].keylen)
return 0;
}
/*
- * entry position must be strictly increasing, except for the
- * first entry (which can be ""=>"" and thus zero-length); and
- * all entries must be properly contiguous
+ * entry position must be strictly increasing, except for the first entry
+ * (which can be ""=>"" and thus zero-length); and all entries must be
+ * properly contiguous
*/
for (i = 0; i < count; ++i)
@@ -216,7 +216,7 @@ hstoreValidOldFormat(HStore *hs)
+ ((entries[i].valisnull) ? 0 : entries[i].vallen));
}
- vsize = CALCDATASIZE(count,lastpos);
+ vsize = CALCDATASIZE(count, lastpos);
if (vsize > VARSIZE(hs))
return 0;
@@ -255,108 +255,100 @@ hstoreUpgrade(Datum orig)
if (valid_new)
{
/*
- * force the "new version" flag and the correct varlena
- * length, but only if we have a writable copy already
- * (which we almost always will, since short new-format
- * values won't come through here)
+ * force the "new version" flag and the correct varlena length,
+ * but only if we have a writable copy already (which we almost
+ * always will, since short new-format values won't come through
+ * here)
*/
if (writable)
{
- HS_SETCOUNT(hs,HS_COUNT(hs));
- HS_FIXSIZE(hs,HS_COUNT(hs));
+ HS_SETCOUNT(hs, HS_COUNT(hs));
+ HS_FIXSIZE(hs, HS_COUNT(hs));
}
return hs;
}
else
{
- elog(ERROR,"invalid hstore value found");
+ elog(ERROR, "invalid hstore value found");
}
}
/*
- * this is the tricky edge case. It is only possible in some
- * quite extreme cases (the hstore must have had a lot
- * of wasted padding space at the end).
- * But the only way a "new" hstore value could get here is if
- * we're upgrading in place from a pre-release version of
- * hstore-new (NOT contrib/hstore), so we work off the following
- * assumptions:
- * 1. If you're moving from old contrib/hstore to hstore-new,
- * you're required to fix up any potential conflicts first,
- * e.g. by running ALTER TABLE ... USING col::text::hstore;
- * on all hstore columns before upgrading.
- * 2. If you're moving from old contrib/hstore to new
- * contrib/hstore, then "new" values are impossible here
- * 3. If you're moving from pre-release hstore-new to hstore-new,
- * then "old" values are impossible here
- * 4. If you're moving from pre-release hstore-new to new
- * contrib/hstore, you're not doing so as an in-place upgrade,
- * so there is no issue
- * So the upshot of all this is that we can treat all the edge
- * cases as "new" if we're being built as hstore-new, and "old"
- * if we're being built as contrib/hstore.
+ * this is the tricky edge case. It is only possible in some quite extreme
+ * cases (the hstore must have had a lot of wasted padding space at the
+ * end). But the only way a "new" hstore value could get here is if we're
+ * upgrading in place from a pre-release version of hstore-new (NOT
+ * contrib/hstore), so we work off the following assumptions: 1. If you're
+ * moving from old contrib/hstore to hstore-new, you're required to fix up
+ * any potential conflicts first, e.g. by running ALTER TABLE ... USING
+ * col::text::hstore; on all hstore columns before upgrading. 2. If you're
+ * moving from old contrib/hstore to new contrib/hstore, then "new" values
+ * are impossible here 3. If you're moving from pre-release hstore-new to
+ * hstore-new, then "old" values are impossible here 4. If you're moving
+ * from pre-release hstore-new to new contrib/hstore, you're not doing so
+ * as an in-place upgrade, so there is no issue So the upshot of all this
+ * is that we can treat all the edge cases as "new" if we're being built
+ * as hstore-new, and "old" if we're being built as contrib/hstore.
*
- * XXX the WARNING can probably be downgraded to DEBUG1 once this
- * has been beta-tested. But for now, it would be very useful to
- * know if anyone can actually reach this case in a non-contrived
- * setting.
+ * XXX the WARNING can probably be downgraded to DEBUG1 once this has been
+ * beta-tested. But for now, it would be very useful to know if anyone can
+ * actually reach this case in a non-contrived setting.
*/
if (valid_new)
{
#if HSTORE_IS_HSTORE_NEW
- elog(WARNING,"ambiguous hstore value resolved as hstore-new");
+ elog(WARNING, "ambiguous hstore value resolved as hstore-new");
/*
- * force the "new version" flag and the correct varlena
- * length, but only if we have a writable copy already
- * (which we almost always will, since short new-format
- * values won't come through here)
+ * force the "new version" flag and the correct varlena length, but
+ * only if we have a writable copy already (which we almost always
+ * will, since short new-format values won't come through here)
*/
if (writable)
{
- HS_SETCOUNT(hs,HS_COUNT(hs));
- HS_FIXSIZE(hs,HS_COUNT(hs));
+ HS_SETCOUNT(hs, HS_COUNT(hs));
+ HS_FIXSIZE(hs, HS_COUNT(hs));
}
return hs;
#else
- elog(WARNING,"ambiguous hstore value resolved as hstore-old");
+ elog(WARNING, "ambiguous hstore value resolved as hstore-old");
#endif
}
/*
- * must have an old-style value. Overwrite it in place as a new-style
- * one, making sure we have a writable copy first.
+ * must have an old-style value. Overwrite it in place as a new-style one,
+ * making sure we have a writable copy first.
*/
if (!writable)
hs = (HStore *) PG_DETOAST_DATUM_COPY(orig);
{
- int count = hs->size_;
- HEntry *new_entries = ARRPTR(hs);
- HOldEntry *old_entries = (HOldEntry *) ARRPTR(hs);
- int i;
-
+ int count = hs->size_;
+ HEntry *new_entries = ARRPTR(hs);
+ HOldEntry *old_entries = (HOldEntry *) ARRPTR(hs);
+ int i;
+
for (i = 0; i < count; ++i)
{
- uint32 pos = old_entries[i].pos;
- uint32 keylen = old_entries[i].keylen;
- uint32 vallen = old_entries[i].vallen;
- bool isnull = old_entries[i].valisnull;
+ uint32 pos = old_entries[i].pos;
+ uint32 keylen = old_entries[i].keylen;
+ uint32 vallen = old_entries[i].vallen;
+ bool isnull = old_entries[i].valisnull;
if (isnull)
vallen = 0;
- new_entries[2*i].entry = (pos + keylen) & HENTRY_POSMASK;
- new_entries[2*i+1].entry = (((pos + keylen + vallen) & HENTRY_POSMASK)
- | ((isnull) ? HENTRY_ISNULL : 0));
+ new_entries[2 * i].entry = (pos + keylen) & HENTRY_POSMASK;
+ new_entries[2 * i + 1].entry = (((pos + keylen + vallen) & HENTRY_POSMASK)
+ | ((isnull) ? HENTRY_ISNULL : 0));
}
if (count)
new_entries[0].entry |= HENTRY_ISFIRST;
- HS_SETCOUNT(hs,count);
- HS_FIXSIZE(hs,count);
+ HS_SETCOUNT(hs, count);
+ HS_FIXSIZE(hs, count);
}
return hs;
@@ -368,9 +360,9 @@ Datum hstore_version_diag(PG_FUNCTION_ARGS);
Datum
hstore_version_diag(PG_FUNCTION_ARGS)
{
- HStore *hs = (HStore *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
- int valid_new = hstoreValidNewFormat(hs);
- int valid_old = hstoreValidOldFormat(hs);
+ HStore *hs = (HStore *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+ int valid_new = hstoreValidNewFormat(hs);
+ int valid_old = hstoreValidOldFormat(hs);
- PG_RETURN_INT32(valid_old*10 + valid_new);
+ PG_RETURN_INT32(valid_old * 10 + valid_new);
}
diff --git a/contrib/hstore/hstore_gin.c b/contrib/hstore/hstore_gin.c
index 3bd9d718bb3..f5056f53ec6 100644
--- a/contrib/hstore/hstore_gin.c
+++ b/contrib/hstore/hstore_gin.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.7 2009/09/30 19:50:22 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/hstore/hstore_gin.c,v 1.8 2010/02/26 02:00:32 momjian Exp $
*/
#include "postgres.h"
@@ -36,10 +36,10 @@ gin_extract_hstore(PG_FUNCTION_ARGS)
HStore *hs = PG_GETARG_HS(0);
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL;
- HEntry *hsent = ARRPTR(hs);
- char *ptr = STRPTR(hs);
- int count = HS_COUNT(hs);
- int i;
+ HEntry *hsent = ARRPTR(hs);
+ char *ptr = STRPTR(hs);
+ int count = HS_COUNT(hs);
+ int i;
*nentries = 2 * count;
if (count)
@@ -49,21 +49,21 @@ gin_extract_hstore(PG_FUNCTION_ARGS)
{
text *item;
- item = makeitem(HS_KEY(hsent,ptr,i), HS_KEYLEN(hsent,i));
+ item = makeitem(HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i));
*VARDATA(item) = KEYFLAG;
- entries[2*i] = PointerGetDatum(item);
+ entries[2 * i] = PointerGetDatum(item);
- if (HS_VALISNULL(hsent,i))
+ if (HS_VALISNULL(hsent, i))
{
item = makeitem(NULL, 0);
*VARDATA(item) = NULLFLAG;
}
else
{
- item = makeitem(HS_VAL(hsent,ptr,i), HS_VALLEN(hsent,i));
+ item = makeitem(HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i));
*VARDATA(item) = VALFLAG;
}
- entries[2*i+1] = PointerGetDatum(item);
+ entries[2 * i + 1] = PointerGetDatum(item);
}
PG_RETURN_POINTER(entries);
@@ -103,14 +103,15 @@ gin_extract_hstore_query(PG_FUNCTION_ARGS)
else if (strategy == HStoreExistsAnyStrategyNumber ||
strategy == HStoreExistsAllStrategyNumber)
{
- ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
- Datum *key_datums;
- bool *key_nulls;
- int key_count;
- int i,j;
+ ArrayType *query = PG_GETARG_ARRAYTYPE_P(0);
+ Datum *key_datums;
+ bool *key_nulls;
+ int key_count;
+ int i,
+ j;
int32 *nentries = (int32 *) PG_GETARG_POINTER(1);
Datum *entries = NULL;
- text *item;
+ text *item;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
@@ -145,8 +146,10 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
{
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
+
/* HStore *query = PG_GETARG_HS(2); */
int32 nkeys = PG_GETARG_INT32(3);
+
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res = true;
@@ -178,7 +181,7 @@ gin_consistent_hstore(PG_FUNCTION_ARGS)
}
else if (strategy == HStoreExistsAllStrategyNumber)
{
- int i;
+ int i;
for (i = 0; res && i < nkeys; ++i)
if (!check[i])
diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c
index b036fa932f2..db58fb62ddf 100644
--- a/contrib/hstore/hstore_gist.c
+++ b/contrib/hstore/hstore_gist.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/hstore/hstore_gist.c,v 1.11 2009/09/30 19:50:22 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/hstore/hstore_gist.c,v 1.12 2010/02/26 02:00:32 momjian Exp $
*/
#include "postgres.h"
@@ -118,20 +118,20 @@ ghstore_compress(PG_FUNCTION_ARGS)
HStore *val = DatumGetHStoreP(entry->key);
HEntry *hsent = ARRPTR(val);
char *ptr = STRPTR(val);
- int count = HS_COUNT(val);
- int i;
+ int count = HS_COUNT(val);
+ int i;
SET_VARSIZE(res, CALCGTSIZE(0));
for (i = 0; i < count; ++i)
{
- int h;
+ int h;
- h = crc32_sz((char *) HS_KEY(hsent,ptr,i), HS_KEYLEN(hsent,i));
+ h = crc32_sz((char *) HS_KEY(hsent, ptr, i), HS_KEYLEN(hsent, i));
HASH(GETSIGN(res), h);
- if (!HS_VALISNULL(hsent,i))
+ if (!HS_VALISNULL(hsent, i))
{
- h = crc32_sz((char *) HS_VAL(hsent,ptr,i), HS_VALLEN(hsent,i));
+ h = crc32_sz((char *) HS_VAL(hsent, ptr, i), HS_VALLEN(hsent, i));
HASH(GETSIGN(res), h);
}
}
@@ -511,6 +511,7 @@ ghstore_consistent(PG_FUNCTION_ARGS)
{
GISTTYPE *entry = (GISTTYPE *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+
/* Oid subtype = PG_GETARG_OID(3); */
bool *recheck = (bool *) PG_GETARG_POINTER(4);
bool res = true;
@@ -530,18 +531,18 @@ ghstore_consistent(PG_FUNCTION_ARGS)
HStore *query = PG_GETARG_HS(1);
HEntry *qe = ARRPTR(query);
char *qv = STRPTR(query);
- int count = HS_COUNT(query);
- int i;
+ int count = HS_COUNT(query);
+ int i;
for (i = 0; res && i < count; ++i)
{
- int crc = crc32_sz((char *) HS_KEY(qe,qv,i), HS_KEYLEN(qe,i));
+ int crc = crc32_sz((char *) HS_KEY(qe, qv, i), HS_KEYLEN(qe, i));
if (GETBIT(sign, HASHVAL(crc)))
{
- if (!HS_VALISNULL(qe,i))
+ if (!HS_VALISNULL(qe, i))
{
- crc = crc32_sz((char *) HS_VAL(qe,qv,i), HS_VALLEN(qe,i));
+ crc = crc32_sz((char *) HS_VAL(qe, qv, i), HS_VALLEN(qe, i));
if (!GETBIT(sign, HASHVAL(crc)))
res = false;
}
@@ -559,11 +560,11 @@ ghstore_consistent(PG_FUNCTION_ARGS)
}
else if (strategy == HStoreExistsAllStrategyNumber)
{
- ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
- Datum *key_datums;
- bool *key_nulls;
- int key_count;
- int i;
+ ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
+ Datum *key_datums;
+ bool *key_nulls;
+ int key_count;
+ int i;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
@@ -571,7 +572,8 @@ ghstore_consistent(PG_FUNCTION_ARGS)
for (i = 0; res && i < key_count; ++i)
{
- int crc;
+ int crc;
+
if (key_nulls[i])
continue;
crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ);
@@ -581,11 +583,11 @@ ghstore_consistent(PG_FUNCTION_ARGS)
}
else if (strategy == HStoreExistsAnyStrategyNumber)
{
- ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
- Datum *key_datums;
- bool *key_nulls;
- int key_count;
- int i;
+ ArrayType *query = PG_GETARG_ARRAYTYPE_P(1);
+ Datum *key_datums;
+ bool *key_nulls;
+ int key_count;
+ int i;
deconstruct_array(query,
TEXTOID, -1, false, 'i',
@@ -595,7 +597,8 @@ ghstore_consistent(PG_FUNCTION_ARGS)
for (i = 0; !res && i < key_count; ++i)
{
- int crc;
+ int crc;
+
if (key_nulls[i])
continue;
crc = crc32_sz(VARDATA(key_datums[i]), VARSIZE(key_datums[i]) - VARHDRSZ);
diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c
index a79cddef0af..fa6da693e94 100644
--- a/contrib/hstore/hstore_io.c
+++ b/contrib/hstore/hstore_io.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.12 2009/09/30 19:50:22 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/hstore/hstore_io.c,v 1.13 2010/02/26 02:00:32 momjian Exp $
*/
#include "postgres.h"
@@ -18,7 +18,7 @@
PG_MODULE_MAGIC;
/* old names for C functions */
-HSTORE_POLLUTE(hstore_from_text,tconvert);
+HSTORE_POLLUTE(hstore_from_text, tconvert);
typedef struct
@@ -370,12 +370,12 @@ hstoreCheckValLen(size_t len)
HStore *
hstorePairs(Pairs *pairs, int4 pcount, int4 buflen)
{
- HStore *out;
+ HStore *out;
HEntry *entry;
char *ptr;
char *buf;
- int4 len;
- int4 i;
+ int4 len;
+ int4 i;
len = CALCDATASIZE(pcount, buflen);
out = palloc(len);
@@ -389,9 +389,9 @@ hstorePairs(Pairs *pairs, int4 pcount, int4 buflen)
buf = ptr = STRPTR(out);
for (i = 0; i < pcount; i++)
- HS_ADDITEM(entry,buf,ptr,pairs[i]);
+ HS_ADDITEM(entry, buf, ptr, pairs[i]);
- HS_FINALIZE(out,pcount,buf,ptr);
+ HS_FINALIZE(out, pcount, buf, ptr);
return out;
}
@@ -426,9 +426,9 @@ hstore_recv(PG_FUNCTION_ARGS)
int4 buflen;
HStore *out;
Pairs *pairs;
- int4 i;
- int4 pcount;
- StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
+ int4 i;
+ int4 pcount;
+ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
pcount = pq_getmsgint(buf, 4);
@@ -442,8 +442,8 @@ hstore_recv(PG_FUNCTION_ARGS)
for (i = 0; i < pcount; ++i)
{
- int rawlen = pq_getmsgint(buf, 4);
- int len;
+ int rawlen = pq_getmsgint(buf, 4);
+ int len;
if (rawlen < 0)
ereport(ERROR,
@@ -482,9 +482,9 @@ Datum hstore_from_text(PG_FUNCTION_ARGS);
Datum
hstore_from_text(PG_FUNCTION_ARGS)
{
- text *key;
- text *val = NULL;
- Pairs p;
+ text *key;
+ text *val = NULL;
+ Pairs p;
HStore *out;
if (PG_ARGISNULL(0))
@@ -524,13 +524,13 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
Pairs *pairs;
Datum *key_datums;
bool *key_nulls;
- int key_count;
+ int key_count;
Datum *value_datums;
bool *value_nulls;
- int value_count;
+ int value_count;
ArrayType *key_array;
ArrayType *value_array;
- int i;
+ int i;
if (PG_ARGISNULL(0))
PG_RETURN_NULL();
@@ -540,8 +540,8 @@ hstore_from_arrays(PG_FUNCTION_ARGS)
Assert(ARR_ELEMTYPE(key_array) == TEXTOID);
/*
- * must check >1 rather than != 1 because empty arrays have
- * 0 dimensions, not 1
+ * must check >1 rather than != 1 because empty arrays have 0 dimensions,
+ * not 1
*/
if (ARR_NDIM(key_array) > 1)
@@ -631,15 +631,15 @@ Datum
hstore_from_array(PG_FUNCTION_ARGS)
{
ArrayType *in_array = PG_GETARG_ARRAYTYPE_P(0);
- int ndims = ARR_NDIM(in_array);
- int count;
+ int ndims = ARR_NDIM(in_array);
+ int count;
int4 buflen;
HStore *out;
Pairs *pairs;
Datum *in_datums;
bool *in_nulls;
- int in_count;
- int i;
+ int in_count;
+ int i;
Assert(ARR_ELEMTYPE(in_array) == TEXTOID);
@@ -667,7 +667,7 @@ hstore_from_array(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
errmsg("wrong number of array subscripts")));
- }
+ }
deconstruct_array(in_array,
TEXTOID, -1, false, 'i',
@@ -679,26 +679,26 @@ hstore_from_array(PG_FUNCTION_ARGS)
for (i = 0; i < count; ++i)
{
- if (in_nulls[i*2])
+ if (in_nulls[i * 2])
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("null value not allowed for hstore key")));
- if (in_nulls[i*2+1])
+ if (in_nulls[i * 2 + 1])
{
- pairs[i].key = VARDATA_ANY(in_datums[i*2]);
+ pairs[i].key = VARDATA_ANY(in_datums[i * 2]);
pairs[i].val = NULL;
- pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i*2]));
+ pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));
pairs[i].vallen = 4;
pairs[i].isnull = true;
pairs[i].needfree = false;
}
else
{
- pairs[i].key = VARDATA_ANY(in_datums[i*2]);
- pairs[i].val = VARDATA_ANY(in_datums[i*2+1]);
- pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i*2]));
- pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i*2+1]));
+ pairs[i].key = VARDATA_ANY(in_datums[i * 2]);
+ pairs[i].val = VARDATA_ANY(in_datums[i * 2 + 1]);
+ pairs[i].keylen = hstoreCheckKeyLen(VARSIZE_ANY_EXHDR(in_datums[i * 2]));
+ pairs[i].vallen = hstoreCheckValLen(VARSIZE_ANY_EXHDR(in_datums[i * 2 + 1]));
pairs[i].isnull = false;
pairs[i].needfree = false;
}
@@ -740,25 +740,26 @@ hstore_from_record(PG_FUNCTION_ARGS)
HeapTupleHeader rec;
int4 buflen;
HStore *out;
- Pairs *pairs;
+ Pairs *pairs;
Oid tupType;
int32 tupTypmod;
TupleDesc tupdesc;
HeapTupleData tuple;
RecordIOData *my_extra;
int ncolumns;
- int i,j;
+ int i,
+ j;
Datum *values;
bool *nulls;
if (PG_ARGISNULL(0))
{
- Oid argtype = get_fn_expr_argtype(fcinfo->flinfo,0);
+ Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
/*
- * have no tuple to look at, so the only source of type info
- * is the argtype. The lookup_rowtype_tupdesc call below will
- * error out if we don't have a known composite type oid here.
+ * have no tuple to look at, so the only source of type info is the
+ * argtype. The lookup_rowtype_tupdesc call below will error out if we
+ * don't have a known composite type oid here.
*/
tupType = argtype;
tupTypmod = -1;
@@ -855,7 +856,7 @@ hstore_from_record(PG_FUNCTION_ARGS)
*/
if (column_info->column_type != column_type)
{
- bool typIsVarlena;
+ bool typIsVarlena;
getTypeOutputInfo(column_type,
&column_info->typiofunc,
@@ -889,18 +890,18 @@ Datum hstore_populate_record(PG_FUNCTION_ARGS);
Datum
hstore_populate_record(PG_FUNCTION_ARGS)
{
- Oid argtype = get_fn_expr_argtype(fcinfo->flinfo,0);
- HStore *hs;
- HEntry *entries;
- char *ptr;
+ Oid argtype = get_fn_expr_argtype(fcinfo->flinfo, 0);
+ HStore *hs;
+ HEntry *entries;
+ char *ptr;
HeapTupleHeader rec;
Oid tupType;
int32 tupTypmod;
TupleDesc tupdesc;
HeapTupleData tuple;
- HeapTuple rettuple;
+ HeapTuple rettuple;
RecordIOData *my_extra;
- int ncolumns;
+ int ncolumns;
int i;
Datum *values;
bool *nulls;
@@ -918,9 +919,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
rec = NULL;
/*
- * have no tuple to look at, so the only source of type info
- * is the argtype. The lookup_rowtype_tupdesc call below will
- * error out if we don't have a known composite type oid here.
+ * have no tuple to look at, so the only source of type info is the
+ * argtype. The lookup_rowtype_tupdesc call below will error out if we
+ * don't have a known composite type oid here.
*/
tupType = argtype;
tupTypmod = -1;
@@ -942,9 +943,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
ptr = STRPTR(hs);
/*
- * if the input hstore is empty, we can only skip the rest if
- * we were passed in a non-null record, since otherwise there
- * may be issues with domain nulls.
+ * if the input hstore is empty, we can only skip the rest if we were
+ * passed in a non-null record, since otherwise there may be issues with
+ * domain nulls.
*/
if (HS_COUNT(hs) == 0 && rec)
@@ -1012,8 +1013,8 @@ hstore_populate_record(PG_FUNCTION_ARGS)
ColumnIOData *column_info = &my_extra->columns[i];
Oid column_type = tupdesc->attrs[i]->atttypid;
char *value;
- int idx;
- int vallen;
+ int idx;
+ int vallen;
/* Ignore dropped columns in datatype */
if (tupdesc->attrs[i]->attisdropped)
@@ -1025,14 +1026,14 @@ hstore_populate_record(PG_FUNCTION_ARGS)
idx = hstoreFindKey(hs, 0,
NameStr(tupdesc->attrs[i]->attname),
strlen(NameStr(tupdesc->attrs[i]->attname)));
+
/*
- * we can't just skip here if the key wasn't found since we
- * might have a domain to deal with. If we were passed in a
- * non-null record datum, we assume that the existing values
- * are valid (if they're not, then it's not our fault), but if
- * we were passed in a null, then every field which we don't
- * populate needs to be run through the input function just in
- * case it's a domain type.
+ * we can't just skip here if the key wasn't found since we might have
+ * a domain to deal with. If we were passed in a non-null record
+ * datum, we assume that the existing values are valid (if they're
+ * not, then it's not our fault), but if we were passed in a null,
+ * then every field which we don't populate needs to be run through
+ * the input function just in case it's a domain type.
*/
if (idx < 0 && rec)
continue;
@@ -1050,11 +1051,11 @@ hstore_populate_record(PG_FUNCTION_ARGS)
column_info->column_type = column_type;
}
- if (idx < 0 || HS_VALISNULL(entries,idx))
+ if (idx < 0 || HS_VALISNULL(entries, idx))
{
/*
- * need InputFunctionCall to happen even for nulls, so
- * that domain checks are done
+ * need InputFunctionCall to happen even for nulls, so that domain
+ * checks are done
*/
values[i] = InputFunctionCall(&column_info->proc, NULL,
column_info->typioparam,
@@ -1063,9 +1064,9 @@ hstore_populate_record(PG_FUNCTION_ARGS)
}
else
{
- vallen = HS_VALLEN(entries,idx);
+ vallen = HS_VALLEN(entries, idx);
value = palloc(1 + vallen);
- memcpy(value, HS_VAL(entries,ptr,idx), vallen);
+ memcpy(value, HS_VAL(entries, ptr, idx), vallen);
value[vallen] = 0;
values[i] = InputFunctionCall(&column_info->proc, value,
@@ -1105,7 +1106,7 @@ hstore_out(PG_FUNCTION_ARGS)
HStore *in = PG_GETARG_HS(0);
int buflen,
i;
- int count = HS_COUNT(in);
+ int count = HS_COUNT(in);
char *out,
*ptr;
char *base = STRPTR(in);
@@ -1121,21 +1122,21 @@ hstore_out(PG_FUNCTION_ARGS)
buflen = 0;
/*
- * this loop overestimates due to pessimistic assumptions about
- * escaping, so very large hstore values can't be output. this
- * could be fixed, but many other data types probably have the
- * same issue. This replaced code that used the original varlena
- * size for calculations, which was wrong in some subtle ways.
+ * this loop overestimates due to pessimistic assumptions about escaping,
+ * so very large hstore values can't be output. this could be fixed, but
+ * many other data types probably have the same issue. This replaced code
+ * that used the original varlena size for calculations, which was wrong
+ * in some subtle ways.
*/
for (i = 0; i < count; i++)
{
/* include "" and => and comma-space */
- buflen += 6 + 2 * HS_KEYLEN(entries,i);
+ buflen += 6 + 2 * HS_KEYLEN(entries, i);
/* include "" only if nonnull */
- buflen += 2 + (HS_VALISNULL(entries,i)
+ buflen += 2 + (HS_VALISNULL(entries, i)
? 2
- : 2 * HS_VALLEN(entries,i));
+ : 2 * HS_VALLEN(entries, i));
}
out = ptr = palloc(buflen);
@@ -1143,11 +1144,11 @@ hstore_out(PG_FUNCTION_ARGS)
for (i = 0; i < count; i++)
{
*ptr++ = '"';
- ptr = cpw(ptr, HS_KEY(entries,base,i), HS_KEYLEN(entries,i));
+ ptr = cpw(ptr, HS_KEY(entries, base, i), HS_KEYLEN(entries, i));
*ptr++ = '"';
*ptr++ = '=';
*ptr++ = '>';
- if (HS_VALISNULL(entries,i))
+ if (HS_VALISNULL(entries, i))
{
*ptr++ = 'N';
*ptr++ = 'U';
@@ -1157,7 +1158,7 @@ hstore_out(PG_FUNCTION_ARGS)
else
{
*ptr++ = '"';
- ptr = cpw(ptr, HS_VAL(entries,base,i), HS_VALLEN(entries,i));
+ ptr = cpw(ptr, HS_VAL(entries, base, i), HS_VALLEN(entries, i));
*ptr++ = '"';
}
@@ -1179,8 +1180,8 @@ Datum
hstore_send(PG_FUNCTION_ARGS)
{
HStore *in = PG_GETARG_HS(0);
- int i;
- int count = HS_COUNT(in);
+ int i;
+ int count = HS_COUNT(in);
char *base = STRPTR(in);
HEntry *entries = ARRPTR(in);
StringInfoData buf;
@@ -1191,18 +1192,20 @@ hstore_send(PG_FUNCTION_ARGS)
for (i = 0; i < count; i++)
{
- int32 keylen = HS_KEYLEN(entries,i);
+ int32 keylen = HS_KEYLEN(entries, i);
+
pq_sendint(&buf, keylen, 4);
- pq_sendtext(&buf, HS_KEY(entries,base,i), keylen);
- if (HS_VALISNULL(entries,i))
+ pq_sendtext(&buf, HS_KEY(entries, base, i), keylen);
+ if (HS_VALISNULL(entries, i))
{
pq_sendint(&buf, -1, 4);
}
else
{
- int32 vallen = HS_VALLEN(entries,i);
+ int32 vallen = HS_VALLEN(entries, i);
+
pq_sendint(&buf, vallen, 4);
- pq_sendtext(&buf, HS_VAL(entries,base,i), vallen);
+ pq_sendtext(&buf, HS_VAL(entries, base, i), vallen);
}
}
diff --git a/contrib/hstore/hstore_op.c b/contrib/hstore/hstore_op.c
index cc1a162dacb..ebee60a1dbe 100644
--- a/contrib/hstore/hstore_op.c
+++ b/contrib/hstore/hstore_op.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/hstore/hstore_op.c,v 1.15 2009/09/30 21:26:17 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/hstore/hstore_op.c,v 1.16 2010/02/26 02:00:32 momjian Exp $
*/
#include "postgres.h"
@@ -13,18 +13,18 @@
#include "hstore.h"
/* old names for C functions */
-HSTORE_POLLUTE(hstore_fetchval,fetchval);
-HSTORE_POLLUTE(hstore_exists,exists);
-HSTORE_POLLUTE(hstore_defined,defined);
-HSTORE_POLLUTE(hstore_delete,delete);
-HSTORE_POLLUTE(hstore_concat,hs_concat);
-HSTORE_POLLUTE(hstore_contains,hs_contains);
-HSTORE_POLLUTE(hstore_contained,hs_contained);
-HSTORE_POLLUTE(hstore_akeys,akeys);
-HSTORE_POLLUTE(hstore_avals,avals);
-HSTORE_POLLUTE(hstore_skeys,skeys);
-HSTORE_POLLUTE(hstore_svals,svals);
-HSTORE_POLLUTE(hstore_each,each);
+HSTORE_POLLUTE(hstore_fetchval, fetchval);
+HSTORE_POLLUTE(hstore_exists, exists);
+HSTORE_POLLUTE(hstore_defined, defined);
+HSTORE_POLLUTE(hstore_delete, delete);
+HSTORE_POLLUTE(hstore_concat, hs_concat);
+HSTORE_POLLUTE(hstore_contains, hs_contains);
+HSTORE_POLLUTE(hstore_contained, hs_contained);
+HSTORE_POLLUTE(hstore_akeys, akeys);
+HSTORE_POLLUTE(hstore_avals, avals);
+HSTORE_POLLUTE(hstore_skeys, skeys);
+HSTORE_POLLUTE(hstore_svals, svals);
+HSTORE_POLLUTE(hstore_each, each);
/*
@@ -34,24 +34,24 @@ HSTORE_POLLUTE(hstore_each,each);
* one-off or unordered searches.
*/
int
-hstoreFindKey(HStore * hs, int *lowbound, char *key, int keylen)
+hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen)
{
HEntry *entries = ARRPTR(hs);
- int stopLow = lowbound ? *lowbound : 0;
- int stopHigh = HS_COUNT(hs);
- int stopMiddle;
+ int stopLow = lowbound ? *lowbound : 0;
+ int stopHigh = HS_COUNT(hs);
+ int stopMiddle;
char *base = STRPTR(hs);
while (stopLow < stopHigh)
{
- int difference;
+ int difference;
stopMiddle = stopLow + (stopHigh - stopLow) / 2;
- if (HS_KEYLEN(entries,stopMiddle) == keylen)
- difference = strncmp(HS_KEY(entries,base,stopMiddle), key, keylen);
+ if (HS_KEYLEN(entries, stopMiddle) == keylen)
+ difference = strncmp(HS_KEY(entries, base, stopMiddle), key, keylen);
else
- difference = (HS_KEYLEN(entries,stopMiddle) > keylen) ? 1 : -1;
+ difference = (HS_KEYLEN(entries, stopMiddle) > keylen) ? 1 : -1;
if (difference == 0)
{
@@ -73,12 +73,13 @@ hstoreFindKey(HStore * hs, int *lowbound, char *key, int keylen)
Pairs *
hstoreArrayToPairs(ArrayType *a, int *npairs)
{
- Datum *key_datums;
- bool *key_nulls;
- int key_count;
- Pairs *key_pairs;
- int bufsiz;
- int i,j;
+ Datum *key_datums;
+ bool *key_nulls;
+ int key_count;
+ Pairs *key_pairs;
+ int bufsiz;
+ int i,
+ j;
deconstruct_array(a,
TEXTOID, -1, false, 'i',
@@ -121,14 +122,14 @@ hstore_fetchval(PG_FUNCTION_ARGS)
text *key = PG_GETARG_TEXT_PP(1);
HEntry *entries = ARRPTR(hs);
text *out;
- int idx = hstoreFindKey(hs, NULL,
+ int idx = hstoreFindKey(hs, NULL,
VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
- if (idx < 0 || HS_VALISNULL(entries,idx))
+ if (idx < 0 || HS_VALISNULL(entries, idx))
PG_RETURN_NULL();
- out = cstring_to_text_with_len(HS_VAL(entries,STRPTR(hs),idx),
- HS_VALLEN(entries,idx));
+ out = cstring_to_text_with_len(HS_VAL(entries, STRPTR(hs), idx),
+ HS_VALLEN(entries, idx));
PG_RETURN_TEXT_P(out);
}
@@ -141,7 +142,7 @@ hstore_exists(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
text *key = PG_GETARG_TEXT_PP(1);
- int idx = hstoreFindKey(hs, NULL,
+ int idx = hstoreFindKey(hs, NULL,
VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
PG_RETURN_BOOL(idx >= 0);
@@ -155,23 +156,23 @@ hstore_exists_any(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
- int nkeys;
- Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys);
- int i;
- int lowbound = 0;
- bool res = false;
+ int nkeys;
+ Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys);
+ int i;
+ int lowbound = 0;
+ bool res = false;
/*
- * we exploit the fact that the pairs list is already sorted into
- * strictly increasing order to narrow the hstoreFindKey search;
- * each search can start one entry past the previous "found"
- * entry, or at the lower bound of the last search.
+ * we exploit the fact that the pairs list is already sorted into strictly
+ * increasing order to narrow the hstoreFindKey search; each search can
+ * start one entry past the previous "found" entry, or at the lower bound
+ * of the last search.
*/
for (i = 0; !res && i < nkeys; ++i)
{
- int idx = hstoreFindKey(hs, &lowbound,
- key_pairs[i].key, key_pairs[i].keylen);
+ int idx = hstoreFindKey(hs, &lowbound,
+ key_pairs[i].key, key_pairs[i].keylen);
if (idx >= 0)
res = true;
@@ -188,23 +189,23 @@ hstore_exists_all(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
ArrayType *keys = PG_GETARG_ARRAYTYPE_P(1);
- int nkeys;
- Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys);
- int i;
- int lowbound = 0;
- bool res = nkeys ? true : false;
+ int nkeys;
+ Pairs *key_pairs = hstoreArrayToPairs(keys, &nkeys);
+ int i;
+ int lowbound = 0;
+ bool res = nkeys ? true : false;
/*
- * we exploit the fact that the pairs list is already sorted into
- * strictly increasing order to narrow the hstoreFindKey search;
- * each search can start one entry past the previous "found"
- * entry, or at the lower bound of the last search.
+ * we exploit the fact that the pairs list is already sorted into strictly
+ * increasing order to narrow the hstoreFindKey search; each search can
+ * start one entry past the previous "found" entry, or at the lower bound
+ * of the last search.
*/
for (i = 0; res && i < nkeys; ++i)
{
- int idx = hstoreFindKey(hs, &lowbound,
- key_pairs[i].key, key_pairs[i].keylen);
+ int idx = hstoreFindKey(hs, &lowbound,
+ key_pairs[i].key, key_pairs[i].keylen);
if (idx < 0)
res = false;
@@ -222,9 +223,9 @@ hstore_defined(PG_FUNCTION_ARGS)
HStore *hs = PG_GETARG_HS(0);
text *key = PG_GETARG_TEXT_PP(1);
HEntry *entries = ARRPTR(hs);
- int idx = hstoreFindKey(hs, NULL,
+ int idx = hstoreFindKey(hs, NULL,
VARDATA_ANY(key), VARSIZE_ANY_EXHDR(key));
- bool res = (idx >= 0 && !HS_VALISNULL(entries,idx));
+ bool res = (idx >= 0 && !HS_VALISNULL(entries, idx));
PG_RETURN_BOOL(res);
}
@@ -237,20 +238,20 @@ hstore_delete(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
text *key = PG_GETARG_TEXT_PP(1);
- char *keyptr = VARDATA_ANY(key);
- int keylen = VARSIZE_ANY_EXHDR(key);
+ char *keyptr = VARDATA_ANY(key);
+ int keylen = VARSIZE_ANY_EXHDR(key);
HStore *out = palloc(VARSIZE(hs));
char *bufs,
- *bufd,
+ *bufd,
*ptrd;
HEntry *es,
*ed;
- int i;
- int count = HS_COUNT(hs);
- int outcount = 0;
+ int i;
+ int count = HS_COUNT(hs);
+ int outcount = 0;
SET_VARSIZE(out, VARSIZE(hs));
- HS_SETCOUNT(out, count); /* temporary! */
+ HS_SETCOUNT(out, count); /* temporary! */
bufs = STRPTR(hs);
es = ARRPTR(hs);
@@ -259,18 +260,19 @@ hstore_delete(PG_FUNCTION_ARGS)
for (i = 0; i < count; ++i)
{
- int len = HS_KEYLEN(es,i);
- char *ptrs = HS_KEY(es,bufs,i);
+ int len = HS_KEYLEN(es, i);
+ char *ptrs = HS_KEY(es, bufs, i);
if (!(len == keylen && strncmp(ptrs, keyptr, keylen) == 0))
{
- int vallen = HS_VALLEN(es,i);
- HS_COPYITEM(ed, bufd, ptrd, ptrs, len, vallen, HS_VALISNULL(es,i));
+ int vallen = HS_VALLEN(es, i);
+
+ HS_COPYITEM(ed, bufd, ptrd, ptrs, len, vallen, HS_VALISNULL(es, i));
++outcount;
}
}
- HS_FINALIZE(out,outcount,bufd,ptrd);
+ HS_FINALIZE(out, outcount, bufd, ptrd);
PG_RETURN_POINTER(out);
}
@@ -283,20 +285,21 @@ hstore_delete_array(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HStore *out = palloc(VARSIZE(hs));
- int hs_count = HS_COUNT(hs);
+ int hs_count = HS_COUNT(hs);
char *ps,
- *bufd,
+ *bufd,
*pd;
HEntry *es,
*ed;
- int i,j;
- int outcount = 0;
+ int i,
+ j;
+ int outcount = 0;
ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1);
- int nkeys;
- Pairs *key_pairs = hstoreArrayToPairs(key_array, &nkeys);
+ int nkeys;
+ Pairs *key_pairs = hstoreArrayToPairs(key_array, &nkeys);
SET_VARSIZE(out, VARSIZE(hs));
- HS_SETCOUNT(out, hs_count); /* temporary! */
+ HS_SETCOUNT(out, hs_count); /* temporary! */
ps = STRPTR(hs);
es = ARRPTR(hs);
@@ -313,22 +316,22 @@ hstore_delete_array(PG_FUNCTION_ARGS)
}
/*
- * this is in effect a merge between hs and key_pairs, both of
- * which are already sorted by (keylen,key); we take keys from
- * hs only
+ * this is in effect a merge between hs and key_pairs, both of which are
+ * already sorted by (keylen,key); we take keys from hs only
*/
- for (i = j = 0; i < hs_count; )
+ for (i = j = 0; i < hs_count;)
{
- int difference;
-
+ int difference;
+
if (j >= nkeys)
difference = -1;
else
{
- int skeylen = HS_KEYLEN(es,i);
+ int skeylen = HS_KEYLEN(es, i);
+
if (skeylen == key_pairs[j].keylen)
- difference = strncmp(HS_KEY(es,ps,i),
+ difference = strncmp(HS_KEY(es, ps, i),
key_pairs[j].key,
key_pairs[j].keylen);
else
@@ -342,14 +345,14 @@ hstore_delete_array(PG_FUNCTION_ARGS)
else
{
HS_COPYITEM(ed, bufd, pd,
- HS_KEY(es,ps,i), HS_KEYLEN(es,i),
- HS_VALLEN(es,i), HS_VALISNULL(es,i));
+ HS_KEY(es, ps, i), HS_KEYLEN(es, i),
+ HS_VALLEN(es, i), HS_VALISNULL(es, i));
++outcount;
++i;
}
}
- HS_FINALIZE(out,outcount,bufd,pd);
+ HS_FINALIZE(out, outcount, bufd, pd);
PG_RETURN_POINTER(out);
}
@@ -363,20 +366,21 @@ hstore_delete_hstore(PG_FUNCTION_ARGS)
HStore *hs = PG_GETARG_HS(0);
HStore *hs2 = PG_GETARG_HS(1);
HStore *out = palloc(VARSIZE(hs));
- int hs_count = HS_COUNT(hs);
- int hs2_count = HS_COUNT(hs2);
+ int hs_count = HS_COUNT(hs);
+ int hs2_count = HS_COUNT(hs2);
char *ps,
- *ps2,
- *bufd,
+ *ps2,
+ *bufd,
*pd;
HEntry *es,
- *es2,
+ *es2,
*ed;
- int i,j;
- int outcount = 0;
+ int i,
+ j;
+ int outcount = 0;
SET_VARSIZE(out, VARSIZE(hs));
- HS_SETCOUNT(out, hs_count); /* temporary! */
+ HS_SETCOUNT(out, hs_count); /* temporary! */
ps = STRPTR(hs);
es = ARRPTR(hs);
@@ -395,25 +399,25 @@ hstore_delete_hstore(PG_FUNCTION_ARGS)
}
/*
- * this is in effect a merge between hs and hs2, both of
- * which are already sorted by (keylen,key); we take keys from
- * hs only; for equal keys, we take the value from hs unless the
- * values are equal
+ * this is in effect a merge between hs and hs2, both of which are already
+ * sorted by (keylen,key); we take keys from hs only; for equal keys, we
+ * take the value from hs unless the values are equal
*/
- for (i = j = 0; i < hs_count; )
+ for (i = j = 0; i < hs_count;)
{
- int difference;
-
+ int difference;
+
if (j >= hs2_count)
difference = -1;
else
{
- int skeylen = HS_KEYLEN(es,i);
- int s2keylen = HS_KEYLEN(es2,j);
+ int skeylen = HS_KEYLEN(es, i);
+ int s2keylen = HS_KEYLEN(es2, j);
+
if (skeylen == s2keylen)
- difference = strncmp(HS_KEY(es,ps,i),
- HS_KEY(es2,ps2,j),
+ difference = strncmp(HS_KEY(es, ps, i),
+ HS_KEY(es2, ps2, j),
skeylen);
else
difference = (skeylen > s2keylen) ? 1 : -1;
@@ -423,15 +427,16 @@ hstore_delete_hstore(PG_FUNCTION_ARGS)
++j;
else if (difference == 0)
{
- int svallen = HS_VALLEN(es,i);
- int snullval = HS_VALISNULL(es,i);
- if (snullval != HS_VALISNULL(es2,j)
+ int svallen = HS_VALLEN(es, i);
+ int snullval = HS_VALISNULL(es, i);
+
+ if (snullval != HS_VALISNULL(es2, j)
|| (!snullval
- && (svallen != HS_VALLEN(es2,j)
- || strncmp(HS_VAL(es,ps,i), HS_VAL(es2,ps2,j), svallen) != 0)))
+ && (svallen != HS_VALLEN(es2, j)
+ || strncmp(HS_VAL(es, ps, i), HS_VAL(es2, ps2, j), svallen) != 0)))
{
HS_COPYITEM(ed, bufd, pd,
- HS_KEY(es,ps,i), HS_KEYLEN(es,i),
+ HS_KEY(es, ps, i), HS_KEYLEN(es, i),
svallen, snullval);
++outcount;
}
@@ -440,14 +445,14 @@ hstore_delete_hstore(PG_FUNCTION_ARGS)
else
{
HS_COPYITEM(ed, bufd, pd,
- HS_KEY(es,ps,i), HS_KEYLEN(es,i),
- HS_VALLEN(es,i), HS_VALISNULL(es,i));
+ HS_KEY(es, ps, i), HS_KEYLEN(es, i),
+ HS_VALLEN(es, i), HS_VALISNULL(es, i));
++outcount;
++i;
}
}
- HS_FINALIZE(out,outcount,bufd,pd);
+ HS_FINALIZE(out, outcount, bufd, pd);
PG_RETURN_POINTER(out);
}
@@ -463,16 +468,16 @@ hstore_concat(PG_FUNCTION_ARGS)
HStore *out = palloc(VARSIZE(s1) + VARSIZE(s2));
char *ps1,
*ps2,
- *bufd,
+ *bufd,
*pd;
HEntry *es1,
*es2,
*ed;
- int s1idx;
- int s2idx;
- int s1count = HS_COUNT(s1);
- int s2count = HS_COUNT(s2);
- int outcount = 0;
+ int s1idx;
+ int s2idx;
+ int s1count = HS_COUNT(s1);
+ int s2count = HS_COUNT(s2);
+ int outcount = 0;
SET_VARSIZE(out, VARSIZE(s1) + VARSIZE(s2) - HSHRDSIZE);
HS_SETCOUNT(out, s1count + s2count);
@@ -503,25 +508,26 @@ hstore_concat(PG_FUNCTION_ARGS)
ed = ARRPTR(out);
/*
- * this is in effect a merge between s1 and s2, both of which
- * are already sorted by (keylen,key); we take s2 for equal keys
+ * this is in effect a merge between s1 and s2, both of which are already
+ * sorted by (keylen,key); we take s2 for equal keys
*/
for (s1idx = s2idx = 0; s1idx < s1count || s2idx < s2count; ++outcount)
{
- int difference;
-
+ int difference;
+
if (s1idx >= s1count)
difference = 1;
else if (s2idx >= s2count)
difference = -1;
else
{
- int s1keylen = HS_KEYLEN(es1,s1idx);
- int s2keylen = HS_KEYLEN(es2,s2idx);
+ int s1keylen = HS_KEYLEN(es1, s1idx);
+ int s2keylen = HS_KEYLEN(es2, s2idx);
+
if (s1keylen == s2keylen)
- difference = strncmp(HS_KEY(es1,ps1,s1idx),
- HS_KEY(es2,ps2,s2idx),
+ difference = strncmp(HS_KEY(es1, ps1, s1idx),
+ HS_KEY(es2, ps2, s2idx),
s1keylen);
else
difference = (s1keylen > s2keylen) ? 1 : -1;
@@ -530,8 +536,8 @@ hstore_concat(PG_FUNCTION_ARGS)
if (difference >= 0)
{
HS_COPYITEM(ed, bufd, pd,
- HS_KEY(es2,ps2,s2idx), HS_KEYLEN(es2,s2idx),
- HS_VALLEN(es2,s2idx), HS_VALISNULL(es2,s2idx));
+ HS_KEY(es2, ps2, s2idx), HS_KEYLEN(es2, s2idx),
+ HS_VALLEN(es2, s2idx), HS_VALISNULL(es2, s2idx));
++s2idx;
if (difference == 0)
++s1idx;
@@ -539,13 +545,13 @@ hstore_concat(PG_FUNCTION_ARGS)
else
{
HS_COPYITEM(ed, bufd, pd,
- HS_KEY(es1,ps1,s1idx), HS_KEYLEN(es1,s1idx),
- HS_VALLEN(es1,s1idx), HS_VALISNULL(es1,s1idx));
+ HS_KEY(es1, ps1, s1idx), HS_KEYLEN(es1, s1idx),
+ HS_VALLEN(es1, s1idx), HS_VALISNULL(es1, s1idx));
++s1idx;
}
}
- HS_FINALIZE(out,outcount,bufd,pd);
+ HS_FINALIZE(out, outcount, bufd, pd);
PG_RETURN_POINTER(out);
}
@@ -558,15 +564,15 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HEntry *entries = ARRPTR(hs);
- char *ptr = STRPTR(hs);
+ char *ptr = STRPTR(hs);
ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1);
ArrayType *aout;
- Datum *key_datums;
- bool *key_nulls;
- Datum *out_datums;
- bool *out_nulls;
- int key_count;
- int i;
+ Datum *key_datums;
+ bool *key_nulls;
+ Datum *out_datums;
+ bool *out_nulls;
+ int key_count;
+ int i;
deconstruct_array(key_array,
TEXTOID, -1, false, 'i',
@@ -583,15 +589,15 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
for (i = 0; i < key_count; ++i)
{
- text *key = (text*) DatumGetPointer(key_datums[i]);
- int idx;
+ text *key = (text *) DatumGetPointer(key_datums[i]);
+ int idx;
if (key_nulls[i])
idx = -1;
else
idx = hstoreFindKey(hs, NULL, VARDATA(key), VARSIZE(key) - VARHDRSZ);
- if (idx < 0 || HS_VALISNULL(entries,idx))
+ if (idx < 0 || HS_VALISNULL(entries, idx))
{
out_nulls[i] = true;
out_datums[i] = (Datum) 0;
@@ -599,8 +605,8 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
else
{
out_datums[i] = PointerGetDatum(
- cstring_to_text_with_len(HS_VAL(entries,ptr,idx),
- HS_VALLEN(entries,idx)));
+ cstring_to_text_with_len(HS_VAL(entries, ptr, idx),
+ HS_VALLEN(entries, idx)));
out_nulls[i] = false;
}
}
@@ -609,7 +615,7 @@ hstore_slice_to_array(PG_FUNCTION_ARGS)
ARR_NDIM(key_array),
ARR_DIMS(key_array),
ARR_LBOUND(key_array),
- TEXTOID, -1, false, 'i');
+ TEXTOID, -1, false, 'i');
PG_RETURN_POINTER(aout);
}
@@ -622,16 +628,16 @@ hstore_slice_to_hstore(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
HEntry *entries = ARRPTR(hs);
- char *ptr = STRPTR(hs);
+ char *ptr = STRPTR(hs);
ArrayType *key_array = PG_GETARG_ARRAYTYPE_P(1);
- HStore *out;
- int nkeys;
- Pairs *key_pairs = hstoreArrayToPairs(key_array, &nkeys);
- Pairs *out_pairs;
- int bufsiz;
- int lastidx = 0;
- int i;
- int out_count = 0;
+ HStore *out;
+ int nkeys;
+ Pairs *key_pairs = hstoreArrayToPairs(key_array, &nkeys);
+ Pairs *out_pairs;
+ int bufsiz;
+ int lastidx = 0;
+ int i;
+ int out_count = 0;
if (nkeys == 0)
{
@@ -643,32 +649,32 @@ hstore_slice_to_hstore(PG_FUNCTION_ARGS)
bufsiz = 0;
/*
- * we exploit the fact that the pairs list is already sorted into
- * strictly increasing order to narrow the hstoreFindKey search;
- * each search can start one entry past the previous "found"
- * entry, or at the lower bound of the last search.
+ * we exploit the fact that the pairs list is already sorted into strictly
+ * increasing order to narrow the hstoreFindKey search; each search can
+ * start one entry past the previous "found" entry, or at the lower bound
+ * of the last search.
*/
for (i = 0; i < nkeys; ++i)
{
- int idx = hstoreFindKey(hs, &lastidx,
- key_pairs[i].key, key_pairs[i].keylen);
+ int idx = hstoreFindKey(hs, &lastidx,
+ key_pairs[i].key, key_pairs[i].keylen);
if (idx >= 0)
{
out_pairs[out_count].key = key_pairs[i].key;
bufsiz += (out_pairs[out_count].keylen = key_pairs[i].keylen);
- out_pairs[out_count].val = HS_VAL(entries,ptr,idx);
- bufsiz += (out_pairs[out_count].vallen = HS_VALLEN(entries,idx));
- out_pairs[out_count].isnull = HS_VALISNULL(entries,idx);
+ out_pairs[out_count].val = HS_VAL(entries, ptr, idx);
+ bufsiz += (out_pairs[out_count].vallen = HS_VALLEN(entries, idx));
+ out_pairs[out_count].isnull = HS_VALISNULL(entries, idx);
out_pairs[out_count].needfree = false;
++out_count;
}
}
/*
- * we don't use uniquePairs here because we know that the
- * pairs list is already sorted and uniq'ed.
+ * we don't use uniquePairs here because we know that the pairs list is
+ * already sorted and uniq'ed.
*/
out = hstorePairs(out_pairs, out_count, bufsiz);
@@ -687,8 +693,8 @@ hstore_akeys(PG_FUNCTION_ARGS)
ArrayType *a;
HEntry *entries = ARRPTR(hs);
char *base = STRPTR(hs);
- int count = HS_COUNT(hs);
- int i;
+ int count = HS_COUNT(hs);
+ int i;
if (count == 0)
{
@@ -700,13 +706,14 @@ hstore_akeys(PG_FUNCTION_ARGS)
for (i = 0; i < count; ++i)
{
- text *item = cstring_to_text_with_len(HS_KEY(entries,base,i),
- HS_KEYLEN(entries,i));
+ text *item = cstring_to_text_with_len(HS_KEY(entries, base, i),
+ HS_KEYLEN(entries, i));
+
d[i] = PointerGetDatum(item);
}
a = construct_array(d, count,
- TEXTOID, -1, false, 'i');
+ TEXTOID, -1, false, 'i');
PG_RETURN_POINTER(a);
}
@@ -719,13 +726,13 @@ hstore_avals(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
Datum *d;
- bool *nulls;
+ bool *nulls;
ArrayType *a;
HEntry *entries = ARRPTR(hs);
char *base = STRPTR(hs);
- int count = HS_COUNT(hs);
- int lb = 1;
- int i;
+ int count = HS_COUNT(hs);
+ int lb = 1;
+ int i;
if (count == 0)
{
@@ -738,22 +745,23 @@ hstore_avals(PG_FUNCTION_ARGS)
for (i = 0; i < count; ++i)
{
- if (HS_VALISNULL(entries,i))
+ if (HS_VALISNULL(entries, i))
{
d[i] = (Datum) 0;
nulls[i] = true;
}
else
{
- text *item = cstring_to_text_with_len(HS_VAL(entries,base,i),
- HS_VALLEN(entries,i));
+ text *item = cstring_to_text_with_len(HS_VAL(entries, base, i),
+ HS_VALLEN(entries, i));
+
d[i] = PointerGetDatum(item);
nulls[i] = false;
}
}
a = construct_md_array(d, nulls, 1, &count, &lb,
- TEXTOID, -1, false, 'i');
+ TEXTOID, -1, false, 'i');
PG_RETURN_POINTER(a);
}
@@ -764,12 +772,12 @@ hstore_to_array_internal(HStore *hs, int ndims)
{
HEntry *entries = ARRPTR(hs);
char *base = STRPTR(hs);
- int count = HS_COUNT(hs);
- int out_size[2] = { 0, 2 };
- int lb[2] = { 1, 1 };
+ int count = HS_COUNT(hs);
+ int out_size[2] = {0, 2};
+ int lb[2] = {1, 1};
Datum *out_datums;
bool *out_nulls;
- int i;
+ int i;
Assert(ndims < 3);
@@ -782,22 +790,24 @@ hstore_to_array_internal(HStore *hs, int ndims)
for (i = 0; i < count; ++i)
{
- text *key = cstring_to_text_with_len(HS_KEY(entries,base,i),
- HS_KEYLEN(entries,i));
- out_datums[i*2] = PointerGetDatum(key);
- out_nulls[i*2] = false;
+ text *key = cstring_to_text_with_len(HS_KEY(entries, base, i),
+ HS_KEYLEN(entries, i));
+
+ out_datums[i * 2] = PointerGetDatum(key);
+ out_nulls[i * 2] = false;
- if (HS_VALISNULL(entries,i))
+ if (HS_VALISNULL(entries, i))
{
- out_datums[i*2+1] = (Datum) 0;
- out_nulls[i*2+1] = true;
+ out_datums[i * 2 + 1] = (Datum) 0;
+ out_nulls[i * 2 + 1] = true;
}
else
{
- text *item = cstring_to_text_with_len(HS_VAL(entries,base,i),
- HS_VALLEN(entries,i));
- out_datums[i*2+1] = PointerGetDatum(item);
- out_nulls[i*2+1] = false;
+ text *item = cstring_to_text_with_len(HS_VAL(entries, base, i),
+ HS_VALLEN(entries, i));
+
+ out_datums[i * 2 + 1] = PointerGetDatum(item);
+ out_nulls[i * 2 + 1] = false;
}
}
@@ -811,7 +821,7 @@ Datum hstore_to_array(PG_FUNCTION_ARGS);
Datum
hstore_to_array(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HS(0);
ArrayType *out = hstore_to_array_internal(hs, 1);
PG_RETURN_POINTER(out);
@@ -822,7 +832,7 @@ Datum hstore_to_matrix(PG_FUNCTION_ARGS);
Datum
hstore_to_matrix(PG_FUNCTION_ARGS)
{
- HStore *hs = PG_GETARG_HS(0);
+ HStore *hs = PG_GETARG_HS(0);
ArrayType *out = hstore_to_array_internal(hs, 2);
PG_RETURN_POINTER(out);
@@ -838,11 +848,11 @@ hstore_to_matrix(PG_FUNCTION_ARGS)
*/
static void
-setup_firstcall(FuncCallContext *funcctx, HStore * hs,
+setup_firstcall(FuncCallContext *funcctx, HStore *hs,
FunctionCallInfoData *fcinfo)
{
MemoryContext oldcontext;
- HStore *st;
+ HStore *st;
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
@@ -858,7 +868,7 @@ setup_firstcall(FuncCallContext *funcctx, HStore * hs,
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
-
+
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
}
@@ -872,8 +882,8 @@ Datum
hstore_skeys(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
- HStore *hs;
- int i;
+ HStore *hs;
+ int i;
if (SRF_IS_FIRSTCALL())
{
@@ -888,11 +898,11 @@ hstore_skeys(PG_FUNCTION_ARGS)
if (i < HS_COUNT(hs))
{
- HEntry *entries = ARRPTR(hs);
+ HEntry *entries = ARRPTR(hs);
text *item;
- item = cstring_to_text_with_len(HS_KEY(entries,STRPTR(hs),i),
- HS_KEYLEN(entries,i));
+ item = cstring_to_text_with_len(HS_KEY(entries, STRPTR(hs), i),
+ HS_KEYLEN(entries, i));
SRF_RETURN_NEXT(funcctx, PointerGetDatum(item));
}
@@ -907,8 +917,8 @@ Datum
hstore_svals(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
- HStore *hs;
- int i;
+ HStore *hs;
+ int i;
if (SRF_IS_FIRSTCALL())
{
@@ -923,9 +933,9 @@ hstore_svals(PG_FUNCTION_ARGS)
if (i < HS_COUNT(hs))
{
- HEntry *entries = ARRPTR(hs);
+ HEntry *entries = ARRPTR(hs);
- if (HS_VALISNULL(entries,i))
+ if (HS_VALISNULL(entries, i))
{
ReturnSetInfo *rsi;
@@ -939,8 +949,8 @@ hstore_svals(PG_FUNCTION_ARGS)
{
text *item;
- item = cstring_to_text_with_len(HS_VAL(entries,STRPTR(hs),i),
- HS_VALLEN(entries,i));
+ item = cstring_to_text_with_len(HS_VAL(entries, STRPTR(hs), i),
+ HS_VALLEN(entries, i));
SRF_RETURN_NEXT(funcctx, PointerGetDatum(item));
}
@@ -962,31 +972,31 @@ hstore_contains(PG_FUNCTION_ARGS)
char *tstr = STRPTR(tmpl);
HEntry *ve = ARRPTR(val);
char *vstr = STRPTR(val);
- int tcount = HS_COUNT(tmpl);
- int lastidx = 0;
- int i;
+ int tcount = HS_COUNT(tmpl);
+ int lastidx = 0;
+ int i;
/*
- * we exploit the fact that keys in "tmpl" are in strictly
- * increasing order to narrow the hstoreFindKey search; each search
- * can start one entry past the previous "found" entry, or at the
- * lower bound of the search
+ * we exploit the fact that keys in "tmpl" are in strictly increasing
+ * order to narrow the hstoreFindKey search; each search can start one
+ * entry past the previous "found" entry, or at the lower bound of the
+ * search
*/
for (i = 0; res && i < tcount; ++i)
{
- int idx = hstoreFindKey(val, &lastidx,
- HS_KEY(te,tstr,i), HS_KEYLEN(te,i));
+ int idx = hstoreFindKey(val, &lastidx,
+ HS_KEY(te, tstr, i), HS_KEYLEN(te, i));
if (idx >= 0)
{
- bool nullval = HS_VALISNULL(te,i);
- int vallen = HS_VALLEN(te,i);
+ bool nullval = HS_VALISNULL(te, i);
+ int vallen = HS_VALLEN(te, i);
- if (nullval != HS_VALISNULL(ve,idx)
+ if (nullval != HS_VALISNULL(ve, idx)
|| (!nullval
- && (vallen != HS_VALLEN(ve,idx)
- || strncmp(HS_VAL(te,tstr,i), HS_VAL(ve,vstr,idx), vallen))))
+ && (vallen != HS_VALLEN(ve, idx)
+ || strncmp(HS_VAL(te, tstr, i), HS_VAL(ve, vstr, idx), vallen))))
res = false;
}
else
@@ -1015,8 +1025,8 @@ Datum
hstore_each(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
- HStore *hs;
- int i;
+ HStore *hs;
+ int i;
if (SRF_IS_FIRSTCALL())
{
@@ -1032,26 +1042,26 @@ hstore_each(PG_FUNCTION_ARGS)
if (i < HS_COUNT(hs))
{
HEntry *entries = ARRPTR(hs);
- char *ptr = STRPTR(hs);
+ char *ptr = STRPTR(hs);
Datum res,
dvalues[2];
bool nulls[2] = {false, false};
text *item;
HeapTuple tuple;
- item = cstring_to_text_with_len(HS_KEY(entries,ptr,i),
- HS_KEYLEN(entries,i));
+ item = cstring_to_text_with_len(HS_KEY(entries, ptr, i),
+ HS_KEYLEN(entries, i));
dvalues[0] = PointerGetDatum(item);
- if (HS_VALISNULL(entries,i))
+ if (HS_VALISNULL(entries, i))
{
dvalues[1] = (Datum) 0;
nulls[1] = true;
}
else
{
- item = cstring_to_text_with_len(HS_VAL(entries,ptr,i),
- HS_VALLEN(entries,i));
+ item = cstring_to_text_with_len(HS_VAL(entries, ptr, i),
+ HS_VALLEN(entries, i));
dvalues[1] = PointerGetDatum(item);
}
@@ -1078,15 +1088,15 @@ hstore_cmp(PG_FUNCTION_ARGS)
{
HStore *hs1 = PG_GETARG_HS(0);
HStore *hs2 = PG_GETARG_HS(1);
- int hcount1 = HS_COUNT(hs1);
- int hcount2 = HS_COUNT(hs2);
- int res = 0;
+ int hcount1 = HS_COUNT(hs1);
+ int hcount2 = HS_COUNT(hs2);
+ int res = 0;
if (hcount1 == 0 || hcount2 == 0)
{
/*
- * if either operand is empty, and the other is nonempty, the
- * nonempty one is larger. If both are empty they are equal.
+ * if either operand is empty, and the other is nonempty, the nonempty
+ * one is larger. If both are empty they are equal.
*/
if (hcount1 > 0)
res = 1;
@@ -1096,14 +1106,14 @@ hstore_cmp(PG_FUNCTION_ARGS)
else
{
/* here we know both operands are nonempty */
- char *str1 = STRPTR(hs1);
- char *str2 = STRPTR(hs2);
- HEntry *ent1 = ARRPTR(hs1);
- HEntry *ent2 = ARRPTR(hs2);
- size_t len1 = HSE_ENDPOS(ent1[2*hcount1 - 1]);
- size_t len2 = HSE_ENDPOS(ent2[2*hcount2 - 1]);
+ char *str1 = STRPTR(hs1);
+ char *str2 = STRPTR(hs2);
+ HEntry *ent1 = ARRPTR(hs1);
+ HEntry *ent2 = ARRPTR(hs2);
+ size_t len1 = HSE_ENDPOS(ent1[2 * hcount1 - 1]);
+ size_t len2 = HSE_ENDPOS(ent2[2 * hcount2 - 1]);
- res = memcmp(str1, str2, Min(len1,len2));
+ res = memcmp(str1, str2, Min(len1, len2));
if (res == 0)
{
@@ -1117,8 +1127,8 @@ hstore_cmp(PG_FUNCTION_ARGS)
res = -1;
else
{
- int count = hcount1 * 2;
- int i;
+ int count = hcount1 * 2;
+ int i;
for (i = 0; i < count; ++i)
if (HSE_ENDPOS(ent1[i]) != HSE_ENDPOS(ent2[i]) ||
@@ -1144,11 +1154,11 @@ hstore_cmp(PG_FUNCTION_ARGS)
}
/*
- * this is a btree support function; this is one of the few
- * places where memory needs to be explicitly freed.
+ * this is a btree support function; this is one of the few places where
+ * memory needs to be explicitly freed.
*/
- PG_FREE_IF_COPY(hs1,0);
- PG_FREE_IF_COPY(hs2,1);
+ PG_FREE_IF_COPY(hs1, 0);
+ PG_FREE_IF_COPY(hs2, 1);
PG_RETURN_INT32(res);
}
@@ -1158,9 +1168,10 @@ Datum hstore_eq(PG_FUNCTION_ARGS);
Datum
hstore_eq(PG_FUNCTION_ARGS)
{
- int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
- PG_GETARG_DATUM(0),
- PG_GETARG_DATUM(1)));
+ int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
+ PG_GETARG_DATUM(0),
+ PG_GETARG_DATUM(1)));
+
PG_RETURN_BOOL(res == 0);
}
@@ -1169,9 +1180,10 @@ Datum hstore_ne(PG_FUNCTION_ARGS);
Datum
hstore_ne(PG_FUNCTION_ARGS)
{
- int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
- PG_GETARG_DATUM(0),
- PG_GETARG_DATUM(1)));
+ int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
+ PG_GETARG_DATUM(0),
+ PG_GETARG_DATUM(1)));
+
PG_RETURN_BOOL(res != 0);
}
@@ -1180,9 +1192,10 @@ Datum hstore_gt(PG_FUNCTION_ARGS);
Datum
hstore_gt(PG_FUNCTION_ARGS)
{
- int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
- PG_GETARG_DATUM(0),
- PG_GETARG_DATUM(1)));
+ int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
+ PG_GETARG_DATUM(0),
+ PG_GETARG_DATUM(1)));
+
PG_RETURN_BOOL(res > 0);
}
@@ -1191,9 +1204,10 @@ Datum hstore_ge(PG_FUNCTION_ARGS);
Datum
hstore_ge(PG_FUNCTION_ARGS)
{
- int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
- PG_GETARG_DATUM(0),
- PG_GETARG_DATUM(1)));
+ int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
+ PG_GETARG_DATUM(0),
+ PG_GETARG_DATUM(1)));
+
PG_RETURN_BOOL(res >= 0);
}
@@ -1202,9 +1216,10 @@ Datum hstore_lt(PG_FUNCTION_ARGS);
Datum
hstore_lt(PG_FUNCTION_ARGS)
{
- int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
- PG_GETARG_DATUM(0),
- PG_GETARG_DATUM(1)));
+ int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
+ PG_GETARG_DATUM(0),
+ PG_GETARG_DATUM(1)));
+
PG_RETURN_BOOL(res < 0);
}
@@ -1213,9 +1228,10 @@ Datum hstore_le(PG_FUNCTION_ARGS);
Datum
hstore_le(PG_FUNCTION_ARGS)
{
- int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
- PG_GETARG_DATUM(0),
- PG_GETARG_DATUM(1)));
+ int res = DatumGetInt32(DirectFunctionCall2(hstore_cmp,
+ PG_GETARG_DATUM(0),
+ PG_GETARG_DATUM(1)));
+
PG_RETURN_BOOL(res <= 0);
}
@@ -1226,21 +1242,20 @@ Datum
hstore_hash(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
- Datum hval = hash_any((unsigned char *)VARDATA(hs),
+ Datum hval = hash_any((unsigned char *) VARDATA(hs),
VARSIZE(hs) - VARHDRSZ);
/*
- * this is the only place in the code that cares whether the
- * overall varlena size exactly matches the true data size;
- * this assertion should be maintained by all the other code,
- * but we make it explicit here.
+ * this is the only place in the code that cares whether the overall
+ * varlena size exactly matches the true data size; this assertion should
+ * be maintained by all the other code, but we make it explicit here.
*/
Assert(VARSIZE(hs) ==
(HS_COUNT(hs) != 0 ?
CALCDATASIZE(HS_COUNT(hs),
- HSE_ENDPOS(ARRPTR(hs)[2*HS_COUNT(hs) - 1])) :
+ HSE_ENDPOS(ARRPTR(hs)[2 * HS_COUNT(hs) - 1])) :
HSHRDSIZE));
- PG_FREE_IF_COPY(hs,0);
+ PG_FREE_IF_COPY(hs, 0);
PG_RETURN_DATUM(hval);
}