Add PG_MODULE_MAGIC for 8.2
[hstore.git] / hstore.h
1 #ifndef __HSTORE_H__
2 #define __HSTORE_H__
3
4 #include "postgres.h"
5 #include "funcapi.h"
6 #include "access/gist.h"
7 #include "access/itup.h"
8 #include "utils/elog.h"
9 #include "utils/palloc.h"
10 #include "utils/builtins.h"
11 #include "storage/bufpage.h"
12
13
14 typedef struct {
15         uint16  keylen;
16         uint16  vallen;
17         uint32  
18                 valisnull:1,
19                 pos:31;
20 } HEntry; 
21
22
23 typedef struct {
24         int4    len;
25         int4    size;
26         char    data[1];
27 } HStore;
28
29 #define HSHRDSIZE       (2*sizeof(int4))
30 #define CALCDATASIZE(x, lenstr) ( (x) * sizeof(HEntry) + HSHRDSIZE + (lenstr) )
31 #define ARRPTR(x)       ( (HEntry*) ( (char*)(x) + HSHRDSIZE ) )
32 #define STRPTR(x)       ( (char*)(x) + HSHRDSIZE + ( sizeof(HEntry) * ((HStore*)x)->size ) )
33
34
35 #define PG_GETARG_HS(x) ((HStore*)PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))
36
37 typedef struct {
38         char    *key;
39         char    *val;
40         uint16  keylen;
41         uint16  vallen;
42         bool    isnull;  
43         bool    needfree;  
44 } Pairs;
45
46 int comparePairs(const void *a, const void *b);
47 int uniquePairs(Pairs * a, int4 l, int4 *buflen);
48
49 #endif