2 * contrib/pg_trgm/trgm.h
13 * Options ... but note that trgm_regexp.c effectively assumes these values
14 * of LPADDING and RPADDING.
19 * Caution: IGNORECASE macro means that trigrams are case-insensitive.
20 * If this macro is disabled, the ~* and ~~* operators must be removed from
21 * the operator classes, because we can't handle case-insensitive wildcard
22 * search with case-sensitive trigrams. Failure to do this will result in
23 * "cannot handle ~*(~~*) with case-sensitive trigrams" errors.
28/* operator strategy numbers */
29 #define SimilarityStrategyNumber 1
30 #define DistanceStrategyNumber 2
31 #define LikeStrategyNumber 3
32 #define ILikeStrategyNumber 4
33 #define RegExpStrategyNumber 5
34 #define RegExpICaseStrategyNumber 6
35 #define WordSimilarityStrategyNumber 7
36 #define WordDistanceStrategyNumber 8
37 #define StrictWordSimilarityStrategyNumber 9
38 #define StrictWordDistanceStrategyNumber 10
39 #define EqualStrategyNumber 11
43 #define CPTRGM(a,b) do { \
44 *(((char*)(a))+0) = *(((char*)(b))+0); \
45 *(((char*)(a))+1) = *(((char*)(b))+1); \
46 *(((char*)(a))+2) = *(((char*)(b))+2); \
48extern int (*
CMPTRGM) (
const void *
a,
const void *
b);
50 #define ISWORDCHR(c) (t_isalnum(c))
51 #define ISPRINTABLECHAR(a) ( isascii( *(unsigned char*)(a) ) && (isalnum( *(unsigned char*)(a) ) || *(unsigned char*)(a)==' ') )
52 #define ISPRINTABLETRGM(t) ( ISPRINTABLECHAR( ((char*)(t)) ) && ISPRINTABLECHAR( ((char*)(t))+1 ) && ISPRINTABLECHAR( ((char*)(t))+2 ) )
54 #define ISESCAPECHAR(x) (*(x) == '\\') /* Wildcard escape character */
55 #define ISWILDCARDCHAR(x) (*(x) == '_' || *(x) == '%') /* Wildcard
60 int32 vl_len_;
/* varlena header (do not touch directly!) */
65#define TRGMHDRSIZE (VARHDRSZ + sizeof(uint8))
68 #define SIGLEN_DEFAULT (sizeof(int) * 3)
69 #define SIGLEN_MAX GISTMaxIndexKeySize
72#define SIGLENBIT(siglen) ((siglen) * BITBYTE - 1) /* see makesign */
76#define LOOPBYTE(siglen) \
77 for (i = 0; i < (siglen); i++)
79 #define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITBYTE ) ) )
80 #define GETBITBYTE(x,i) ( (((char)(x)) >> (i)) & 0x01 )
81 #define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITBYTE ) )
82 #define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
83#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
85 #define HASHVAL(val, siglen) (((unsigned int)(val)) % SIGLENBIT(siglen))
86#define HASH(sign, val, siglen) SETBIT((sign), HASHVAL(val, siglen))
92 #define ISARRKEY(x) ( ((TRGM*)x)->flag & ARRKEY )
93 #define ISSIGNKEY(x) ( ((TRGM*)x)->flag & SIGNKEY )
94#define ISALLTRUE(x) ( ((TRGM*)x)->flag & ALLISTRUE )
96 #define CALCGTSIZE(flag, len) ( TRGMHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(trgm)) : (((flag) & ALLISTRUE) ? 0 : (len)) ) )
97 #define GETSIGN(x) ( (BITVECP)( (char*)x+TRGMHDRSIZE ) )
98 #define GETARR(x) ( (trgm*)( (char*)x+TRGMHDRSIZE ) )
99#define ARRNELEM(x) ( ( VARSIZE(x) - TRGMHDRSIZE )/sizeof(trgm) )
102 * If DIVUNION is defined then similarity formula is:
103 * count / (len1 + len2 - count)
104 * else if DIVUNION is not defined then similarity formula is:
105 * count / max(len1, len2)
108#define CALCSML(count, len1, len2) ((float4) (count)) / ((float4) ((len1) + (len2) - (count)))
110#define CALCSML(count, len1, len2) ((float4) (count)) / ((float4) (((len1) > (len2)) ? (len1) : (len2)))
131#endif /* __TRGM_H__ */
#define FLEXIBLE_ARRAY_MEMBER
double strict_word_similarity_threshold
TRGM * generate_trgm(char *str, int slen)
uint32 trgm2int(trgm *ptr)
int(* CMPTRGM)(const void *a, const void *b)
void compact_trigram(trgm *tptr, char *str, int bytelen)
bool * trgm_presence_map(TRGM *query, TRGM *key)
double word_similarity_threshold
double index_strategy_get_limit(StrategyNumber strategy)
TRGM * createTrgmNFA(text *text_re, Oid collation, TrgmPackedGraph **graph, MemoryContext rcontext)
double similarity_threshold
bool trigramsMatchGraph(TrgmPackedGraph *graph, bool *check)
bool trgm_contained_by(TRGM *trg1, TRGM *trg2)
TRGM * generate_wildcard_trgm(const char *str, int slen)
float4 cnt_sml(TRGM *trg1, TRGM *trg2, bool inexact)