summaryrefslogtreecommitdiff
path: root/contrib/tsearch/gistidx.h
blob: dc991ab0d742a1cf6608632b75c8daa2f234624b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#ifndef __GISTIDX_H__
#define __GISTIDX_H__

/*
#define GISTIDX_DEBUG
*/

/*
 * signature defines
 */
#define BITBYTE 8
#define SIGLENINT  64			/* >121 => key will toast, so it will not work !!! */
#define SIGLEN	( sizeof(int4)*SIGLENINT )
#define SIGLENBIT (SIGLEN*BITBYTE)

typedef char BITVEC[SIGLEN];
typedef char *BITVECP;

#define LOOPBYTE(a) \
		for(i=0;i<SIGLEN;i++) {\
				a;\
		}
#define LOOPBIT(a) \
                for(i=0;i<SIGLENBIT;i++) {\
                                a;\
                }

#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
#define GETBITBYTE(x,i) ( ((char)(x)) >> i & 0x01 )
#define CLRBIT(x,i)   GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
#define SETBIT(x,i)   GETBYTE(x,i) |=  ( 0x01 << ( (i) % BITBYTE ) )
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )

#define abs(a)			((a) <	(0) ? -(a) : (a))
#define min(a,b)			((a) <	(b) ? (a) : (b))
#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
#define HASH(sign, val) SETBIT((sign), HASHVAL(val))


/*
 * type of index key 
 */
typedef struct {
	int4	len;
	int4	flag;
	char	data[1];
} GISTTYPE;

#define	ARRKEY		0x01
#define	SIGNKEY		0x02
#define	ALLISTRUE	0x04

#define ISARRKEY(x)	( ((GISTTYPE*)x)->flag & ARRKEY )
#define ISSIGNKEY(x)	( ((GISTTYPE*)x)->flag & SIGNKEY )
#define ISALLTRUE(x)	( ((GISTTYPE*)x)->flag & ALLISTRUE )

#define GTHDRSIZE	( sizeof(int4)*2  ) 
#define CALCGTSIZE(flag, len) ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int4)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )

#define GETSIGN(x)	( (BITVECP)( (char*)x+GTHDRSIZE ) )
#define GETARR(x)	( (int4*)( (char*)x+GTHDRSIZE ) )
#define ARRNELEM(x)	( ( ((GISTTYPE*)x)->len - GTHDRSIZE )/sizeof(int4) )
#endif