2004-06-01 01:18:12 +08:00
|
|
|
#ifndef __TRGM_H__
|
|
|
|
#define __TRGM_H__
|
|
|
|
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/gist.h"
|
|
|
|
#include "access/itup.h"
|
2006-07-12 02:26:11 +08:00
|
|
|
#include "utils/builtins.h"
|
2004-06-01 01:18:12 +08:00
|
|
|
#include "storage/bufpage.h"
|
|
|
|
|
|
|
|
/* options */
|
2004-08-29 13:07:03 +08:00
|
|
|
#define LPADDING 2
|
|
|
|
#define RPADDING 1
|
2004-06-01 01:18:12 +08:00
|
|
|
#define KEEPONLYALNUM
|
2004-08-29 13:07:03 +08:00
|
|
|
#define IGNORECASE
|
2004-06-01 01:18:12 +08:00
|
|
|
#define DIVUNION
|
|
|
|
|
|
|
|
|
|
|
|
typedef char trgm[3];
|
|
|
|
|
|
|
|
#define CMPCHAR(a,b) ( ((a)==(b)) ? 0 : ( ((a)<(b)) ? -1 : 1 ) )
|
2004-08-29 13:07:03 +08:00
|
|
|
#define CMPPCHAR(a,b,i) CMPCHAR( *(((char*)(a))+i), *(((char*)(b))+i) )
|
2004-06-01 01:18:12 +08:00
|
|
|
#define CMPTRGM(a,b) ( CMPPCHAR(a,b,0) ? CMPPCHAR(a,b,0) : ( CMPPCHAR(a,b,1) ? CMPPCHAR(a,b,1) : CMPPCHAR(a,b,2) ) )
|
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
#define CPTRGM(a,b) do { \
|
2004-06-01 01:18:12 +08:00
|
|
|
*(((char*)(a))+0) = *(((char*)(b))+0); \
|
|
|
|
*(((char*)(a))+1) = *(((char*)(b))+1); \
|
|
|
|
*(((char*)(a))+2) = *(((char*)(b))+2); \
|
|
|
|
} while(0);
|
|
|
|
|
2007-03-14 22:15:40 +08:00
|
|
|
#define TRGMINT(a) ( (*(((char*)(a))+2)<<16)+(*(((char*)(a))+1)<<8)+*(((char*)(a))+0) )
|
2004-06-01 01:18:12 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2007-03-01 06:44:38 +08:00
|
|
|
int32 vl_len_; /* varlena header (do not touch directly!) */
|
2004-08-29 13:07:03 +08:00
|
|
|
uint8 flag;
|
|
|
|
char data[1];
|
|
|
|
} TRGM;
|
2004-06-01 01:18:12 +08:00
|
|
|
|
2007-03-01 06:44:38 +08:00
|
|
|
#define TRGMHDRSIZE (VARHDRSZ + sizeof(uint8))
|
2004-06-01 01:18:12 +08:00
|
|
|
|
|
|
|
/* gist */
|
|
|
|
#define BITBYTE 8
|
2004-08-29 13:07:03 +08:00
|
|
|
#define SIGLENINT 3 /* >122 => key will toast, so very slow!!! */
|
|
|
|
#define SIGLEN ( sizeof(int)*SIGLENINT )
|
2004-06-01 01:18:12 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
#define SIGLENBIT (SIGLEN*BITBYTE - 1) /* see makesign */
|
2004-06-01 01:18:12 +08:00
|
|
|
|
|
|
|
typedef char BITVEC[SIGLEN];
|
|
|
|
typedef char *BITVECP;
|
|
|
|
|
|
|
|
#define LOOPBYTE(a) \
|
2004-08-29 13:07:03 +08:00
|
|
|
for(i=0;i<SIGLEN;i++) {\
|
|
|
|
a;\
|
|
|
|
}
|
2004-06-01 01:18:12 +08:00
|
|
|
|
|
|
|
#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 HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
|
|
|
|
#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
|
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
#define ARRKEY 0x01
|
|
|
|
#define SIGNKEY 0x02
|
|
|
|
#define ALLISTRUE 0x04
|
|
|
|
|
2004-06-01 01:18:12 +08:00
|
|
|
#define ISARRKEY(x) ( ((TRGM*)x)->flag & ARRKEY )
|
2004-08-29 13:07:03 +08:00
|
|
|
#define ISSIGNKEY(x) ( ((TRGM*)x)->flag & SIGNKEY )
|
|
|
|
#define ISALLTRUE(x) ( ((TRGM*)x)->flag & ALLISTRUE )
|
2004-06-01 01:18:12 +08:00
|
|
|
|
2007-03-01 06:44:38 +08:00
|
|
|
#define CALCGTSIZE(flag, len) ( TRGMHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(trgm)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
|
|
|
|
#define GETSIGN(x) ( (BITVECP)( (char*)x+TRGMHDRSIZE ) )
|
|
|
|
#define GETARR(x) ( (trgm*)( (char*)x+TRGMHDRSIZE ) )
|
|
|
|
#define ARRNELEM(x) ( ( VARSIZE(x) - TRGMHDRSIZE )/sizeof(trgm) )
|
2004-06-01 01:18:12 +08:00
|
|
|
|
|
|
|
extern float4 trgm_limit;
|
2007-03-01 06:44:38 +08:00
|
|
|
|
2004-08-29 13:07:03 +08:00
|
|
|
TRGM *generate_trgm(char *str, int slen);
|
|
|
|
float4 cnt_sml(TRGM * trg1, TRGM * trg2);
|
2004-06-01 01:18:12 +08:00
|
|
|
|
|
|
|
#endif
|