23 #define HENTRY_ISFIRST 0x80000000
24 #define HENTRY_ISNULL 0x40000000
25 #define HENTRY_POSMASK 0x3FFFFFFF
28 #define HSE_ISFIRST(he_) (((he_).entry & HENTRY_ISFIRST) != 0)
29 #define HSE_ISNULL(he_) (((he_).entry & HENTRY_ISNULL) != 0)
30 #define HSE_ENDPOS(he_) ((he_).entry & HENTRY_POSMASK)
31 #define HSE_OFF(he_) (HSE_ISFIRST(he_) ? 0 : HSE_ENDPOS((&(he_))[-1]))
32 #define HSE_LEN(he_) (HSE_ISFIRST(he_) \
34 : HSE_ENDPOS(he_) - HSE_ENDPOS((&(he_))[-1]))
41 #define HSTORE_MAX_KEY_LEN 0x3FFFFFFF
42 #define HSTORE_MAX_VALUE_LEN 0x3FFFFFFF
59 #define HS_FLAG_NEWVERSION 0x80000000
61 #define HS_COUNT(hsp_) ((hsp_)->size_ & 0x0FFFFFFF)
62 #define HS_SETCOUNT(hsp_,c_) ((hsp_)->size_ = (c_) | HS_FLAG_NEWVERSION)
71 #define HSHRDSIZE (sizeof(HStore))
72 #define CALCDATASIZE(x, lenstr) ( (x) * 2 * sizeof(HEntry) + HSHRDSIZE + (lenstr) )
75 #define ARRPTR(x) ( (HEntry*) ( (HStore*)(x) + 1 ) )
76 #define STRPTR(x) ( (char*)(ARRPTR(x) + HS_COUNT((HStore*)(x)) * 2) )
79 #define HSTORE_KEY(arr_,str_,i_) ((str_) + HSE_OFF((arr_)[2*(i_)]))
80 #define HSTORE_VAL(arr_,str_,i_) ((str_) + HSE_OFF((arr_)[2*(i_)+1]))
81 #define HSTORE_KEYLEN(arr_,i_) (HSE_LEN((arr_)[2*(i_)]))
82 #define HSTORE_VALLEN(arr_,i_) (HSE_LEN((arr_)[2*(i_)+1]))
83 #define HSTORE_VALISNULL(arr_,i_) (HSE_ISNULL((arr_)[2*(i_)+1]))
99 #define HS_COPYITEM(dent_,dbuf_,dptr_,sptr_,klen_,vlen_,vnull_) \
101 memcpy((dptr_), (sptr_), (klen_)+(vlen_)); \
102 (dptr_) += (klen_)+(vlen_); \
103 (dent_)++->entry = ((dptr_) - (dbuf_) - (vlen_)) & HENTRY_POSMASK; \
104 (dent_)++->entry = ((((dptr_) - (dbuf_)) & HENTRY_POSMASK) \
105 | ((vnull_) ? HENTRY_ISNULL : 0)); \
112 #define HS_ADDITEM(dent_,dbuf_,dptr_,pair_) \
114 memcpy((dptr_), (pair_).key, (pair_).keylen); \
115 (dptr_) += (pair_).keylen; \
116 (dent_)++->entry = ((dptr_) - (dbuf_)) & HENTRY_POSMASK; \
117 if ((pair_).isnull) \
118 (dent_)++->entry = ((((dptr_) - (dbuf_)) & HENTRY_POSMASK) \
122 memcpy((dptr_), (pair_).val, (pair_).vallen); \
123 (dptr_) += (pair_).vallen; \
124 (dent_)++->entry = ((dptr_) - (dbuf_)) & HENTRY_POSMASK; \
129 #define HS_FINALIZE(hsp_,count_,buf_,ptr_) \
131 int _buflen = (ptr_) - (buf_); \
133 ARRPTR(hsp_)[0].entry |= HENTRY_ISFIRST; \
134 if ((count_) != HS_COUNT((hsp_))) \
136 HS_SETCOUNT((hsp_),(count_)); \
137 memmove(STRPTR(hsp_), (buf_), _buflen); \
139 SET_VARSIZE((hsp_), CALCDATASIZE((count_), _buflen)); \
143 #define HS_FIXSIZE(hsp_,count_) \
145 int bl = (count_) ? HSE_ENDPOS(ARRPTR(hsp_)[2*(count_)-1]) : 0; \
146 SET_VARSIZE((hsp_), CALCDATASIZE((count_),bl)); \
152 #define DatumGetHStoreP(d) hstoreUpgrade(d)
154 #define PG_GETARG_HSTORE_P(x) DatumGetHStoreP(PG_GETARG_DATUM(x))
180 #define HStoreContainsStrategyNumber 7
181 #define HStoreExistsStrategyNumber 9
182 #define HStoreExistsAnyStrategyNumber 10
183 #define HStoreExistsAllStrategyNumber 11
184 #define HStoreOldContainsStrategyNumber 13
190 #ifndef HSTORE_POLLUTE_NAMESPACE
191 #define HSTORE_POLLUTE_NAMESPACE 1
194 #if HSTORE_POLLUTE_NAMESPACE
195 #define HSTORE_POLLUTE(newname_,oldname_) \
196 PG_FUNCTION_INFO_V1(oldname_); \
197 extern PGDLLEXPORT Datum newname_(PG_FUNCTION_ARGS); \
198 Datum oldname_(PG_FUNCTION_ARGS) { return newname_(fcinfo); } \
199 extern int no_such_variable
201 #define HSTORE_POLLUTE(newname_,oldname_) \
202 extern int no_such_variable
PGDLLEXPORT size_t hstoreCheckKeyLen(size_t len)
PGDLLEXPORT HStore * hstorePairs(Pairs *pairs, int32 pcount, int32 buflen)
PGDLLEXPORT int hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen)
PGDLLEXPORT size_t hstoreCheckValLen(size_t len)
PGDLLEXPORT Pairs * hstoreArrayToPairs(ArrayType *a, int *npairs)
PGDLLEXPORT int hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen)
PGDLLEXPORT HStore * hstoreUpgrade(Datum orig)