OSDN Git Service

736b43dd19ee16011f5c5b9069eebeb24c897202
[pgbigm/pg_bigm.git] / bigm.h
1 /*-------------------------------------------------------------------------
2  *
3  * Portions Copyright (c) 2017-2019, pg_bigm Development Group
4  * Portions Copyright (c) 2013-2016, NTT DATA Corporation
5  * Portions Copyright (c) 2004-2012, PostgreSQL Global Development Group
6  *
7  * Changelog:
8  *       2013/01/09
9  *       Support full text search using bigrams.
10  *       Author: NTT DATA Corporation
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef __BIGM_H__
15 #define __BIGM_H__
16
17 #include "access/itup.h"
18 #include "storage/bufpage.h"
19 #include "utils/builtins.h"
20
21 /* GUC variable */
22 extern bool bigm_enable_recheck;
23 extern int      bigm_gin_key_limit;
24 extern double bigm_similarity_limit;
25 extern char     *bigm_last_update;
26
27 /* options */
28 #define LPADDING                1
29 #define RPADDING                1
30
31 /* operator strategy numbers */
32 #define LikeStrategyNumber                      1
33 #define SimilarityStrategyNumber        2
34
35 typedef struct
36 {
37         bool            pmatch;                 /* partial match is required? */
38         int8            bytelen;                /* byte length of bi-gram string */
39
40         /*
41          * Bi-gram string; we assume here that the maximum bytes for a character
42          * are four.
43          */
44         char            str[8];
45 }       bigm;
46
47 #define BIGMSIZE        sizeof(bigm)
48
49 extern inline int       bigmstrcmp(char *arg1, int len1, char *arg2, int len2);
50 #define CMPBIGM(a,b) ( bigmstrcmp(((bigm *)a)->str, ((bigm *)a)->bytelen, ((bigm *)b)->str, ((bigm *)b)->bytelen) )
51
52 #define CPBIGM(bptr, s, len) do {               \
53         Assert(len <= 8);                               \
54         memcpy(bptr->str, s, len);              \
55         bptr->bytelen = len;                    \
56         bptr->pmatch = false;                   \
57 } while(0);
58
59 #define ISESCAPECHAR(x) (*(x) == '\\')  /* Wildcard escape character */
60 #define ISWILDCARDCHAR(x) (*(x) == '%' || *(x) == '_')  /* Wildcard
61                                                                                                                  * meta-character */
62 typedef struct
63 {
64         int32           vl_len_;                /* varlena header (do not touch directly!) */
65         char            data[1];
66 }       BIGM;
67
68 #define CALCGTSIZE(len) (VARHDRSZ + len * sizeof(bigm))
69 #define GETARR(x)               ( (bigm *)( (char*)x + VARHDRSZ ) )
70 #define ARRNELEM(x) ( ( VARSIZE(x) - VARHDRSZ )/sizeof(bigm) )
71
72 extern BIGM *generate_bigm(char *str, int slen);
73 extern BIGM *generate_wildcard_bigm(const char *str, int slen, bool *removeDups);
74
75 #endif   /* __BIGM_H__ */